Skip to content

Commit cf7df00

Browse files
committed
Review, rebase and lint
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
1 parent 4e24a9b commit cf7df00

File tree

35 files changed

+325
-320
lines changed

35 files changed

+325
-320
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,4 @@ PLUGINS_CLI_COMPLETION=false
173173
# markdown: allow markdown in help strings
174174
# disabled: disable markup
175175
# If unset (commented out), uses "rich" if rich is detected, otherwise disables it.
176-
PLUGINS_CLI_MARKUP_MODE=rich
176+
PLUGINS_CLI_MARKUP_MODE=rich

docs/docs/using/plugins/lifecycle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,4 @@ make serve
160160
```
161161

162162
!!! note
163-
`PLUGINS_ENABLED=true` should be set in your gateway `.env` file.
163+
`PLUGINS_ENABLED=true` should be set in your gateway `.env` file.

mcpgateway/plugins/framework/external/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""External plugin which connects to a remote server.
23
34
Copyright 2025

mcpgateway/plugins/framework/external/mcp/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ async def __connect_to_stdio_server(self, server_script_path: str) -> None:
107107
ValueError: if stdio script is not a python script.
108108
"""
109109
is_python = server_script_path.endswith(PYTHON_SUFFIX) if server_script_path else False
110-
if not (is_python):
110+
if not is_python:
111111
raise ValueError("Server script must be a .py file")
112112

113113
current_env = os.environ.copy()

mcpgateway/plugins/framework/external/mcp/server/runtime.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@
3636

3737
logger = logging.getLogger(__name__)
3838

39-
server = None
39+
SERVER = None
4040

4141

4242
@mcp_tool(name="get_plugin_configs", description="Get the plugin configurations installed on the server")
4343
async def get_plugin_configs() -> list[dict]:
44-
"""Return a list of plugin configurations for plugins currently installed on the MCP server.
44+
"""Return a list of plugin configurations for plugins currently installed on the MCP SERVER.
4545
4646
Returns:
4747
A list of plugin configurations.
4848
"""
49-
return await server.get_plugin_configs()
49+
return await SERVER.get_plugin_configs()
5050

5151

5252
@mcp_tool(name="get_plugin_config", description="Get the plugin configuration installed on the server given a plugin name")
@@ -59,7 +59,7 @@ async def get_plugin_config(name: str) -> dict:
5959
Returns:
6060
A list of plugin configurations.
6161
"""
62-
return await server.get_plugin_config(name)
62+
return await SERVER.get_plugin_config(name)
6363

6464

6565
@mcp_tool(name="prompt_pre_fetch", description="Execute prompt prefetch hook for a plugin")
@@ -91,7 +91,7 @@ def prompt_pre_fetch_func(plugin: Plugin, payload: PromptPrehookPayload, context
9191
"""
9292
return plugin.prompt_pre_fetch(payload, context)
9393

94-
return await server.invoke_hook(PromptPrehookPayload, prompt_pre_fetch_func, plugin_name, payload, context)
94+
return await SERVER.invoke_hook(PromptPrehookPayload, prompt_pre_fetch_func, plugin_name, payload, context)
9595

9696

9797
@mcp_tool(name="prompt_post_fetch", description="Execute prompt postfetch hook for a plugin")
@@ -123,7 +123,7 @@ def prompt_post_fetch_func(plugin: Plugin, payload: PromptPosthookPayload, conte
123123
"""
124124
return plugin.prompt_post_fetch(payload, context)
125125

126-
return await server.invoke_hook(PromptPosthookPayload, prompt_post_fetch_func, plugin_name, payload, context)
126+
return await SERVER.invoke_hook(PromptPosthookPayload, prompt_post_fetch_func, plugin_name, payload, context)
127127

128128

129129
@mcp_tool(name="tool_pre_invoke", description="Execute tool pre-invoke hook for a plugin")
@@ -155,7 +155,7 @@ def tool_pre_invoke_func(plugin: Plugin, payload: ToolPreInvokePayload, context:
155155
"""
156156
return plugin.tool_pre_invoke(payload, context)
157157

158-
return await server.invoke_hook(ToolPreInvokePayload, tool_pre_invoke_func, plugin_name, payload, context)
158+
return await SERVER.invoke_hook(ToolPreInvokePayload, tool_pre_invoke_func, plugin_name, payload, context)
159159

160160

161161
@mcp_tool(name="tool_post_invoke", description="Execute tool post-invoke hook for a plugin")
@@ -187,7 +187,7 @@ def tool_post_invoke_func(plugin: Plugin, payload: ToolPostInvokePayload, contex
187187
"""
188188
return plugin.tool_post_invoke(payload, context)
189189

190-
return await server.invoke_hook(ToolPostInvokePayload, tool_post_invoke_func, plugin_name, payload, context)
190+
return await SERVER.invoke_hook(ToolPostInvokePayload, tool_post_invoke_func, plugin_name, payload, context)
191191

192192

193193
@mcp_tool(name="resource_pre_fetch", description="Execute resource prefetch hook for a plugin")
@@ -219,7 +219,7 @@ def resource_pre_fetch_func(plugin: Plugin, payload: ResourcePreFetchPayload, co
219219
"""
220220
return plugin.resource_pre_fetch(payload, context)
221221

222-
return await server.invoke_hook(ResourcePreFetchPayload, resource_pre_fetch_func, plugin_name, payload, context)
222+
return await SERVER.invoke_hook(ResourcePreFetchPayload, resource_pre_fetch_func, plugin_name, payload, context)
223223

224224

225225
@mcp_tool(name="resource_post_fetch", description="Execute resource postfetch hook for a plugin")
@@ -251,25 +251,25 @@ def resource_post_fetch_func(plugin: Plugin, payload: ResourcePostFetchPayload,
251251
"""
252252
return plugin.resource_post_fetch(payload, context)
253253

254-
return await server.invoke_hook(ResourcePostFetchPayload, resource_post_fetch_func, plugin_name, payload, context)
254+
return await SERVER.invoke_hook(ResourcePostFetchPayload, resource_post_fetch_func, plugin_name, payload, context)
255255

256256

257257
async def run(): # pragma: no cover
258-
"""Run the external plugin server.
258+
"""Run the external plugin SERVER.
259259
260260
Raises:
261-
Exception: if unnable to run the plugin server.
261+
Exception: if unnable to run the plugin SERVER.
262262
"""
263-
global server
264-
server = ExternalPluginServer()
265-
if await server.initialize():
263+
global SERVER # pylint: disable=global-statement
264+
SERVER = ExternalPluginServer()
265+
if await SERVER.initialize():
266266
try:
267267
await main_async()
268268
except Exception:
269269
logger.exception("Caught error while executing plugin server")
270270
raise
271271
finally:
272-
await server.shutdown()
272+
await SERVER.shutdown()
273273

274274

275275
if __name__ == "__main__": # pragma: no cover

mcpgateway/plugins/framework/external/mcp/server/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from pydantic import BaseModel
2020

2121
# First-Party
22-
from mcpgateway.plugins.framework import Plugin
22+
from mcpgateway.plugins.framework.base import Plugin
2323
from mcpgateway.plugins.framework.errors import convert_exception_to_error
2424
from mcpgateway.plugins.framework.loader.config import ConfigLoader
2525
from mcpgateway.plugins.framework.manager import DEFAULT_PLUGIN_TIMEOUT, PluginManager

mcpgateway/plugins/framework/loader/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
logger = logging.getLogger(__name__)
2424

2525

26-
class PluginLoader(object):
26+
class PluginLoader:
2727
"""A plugin loader object for loading and instantiating plugins.
2828
2929
Examples:

mcpgateway/plugins/framework/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ async def execute(
206206
if pluginref.plugin.mode == PluginMode.ENFORCE:
207207
logger.warning(f"Plugin {pluginref.plugin.name} blocked request in enforce mode")
208208
return (PluginResult[T](continue_processing=False, modified_payload=current_payload, violation=result.violation, metadata=combined_metadata), res_local_contexts)
209-
elif pluginref.plugin.mode == PluginMode.PERMISSIVE:
209+
if pluginref.plugin.mode == PluginMode.PERMISSIVE:
210210
logger.warning(f"Plugin {pluginref.plugin.name} would block (permissive mode): {result.violation.description if result.violation else 'No description'}")
211211

212212
except asyncio.TimeoutError:

mcpgateway/plugins/framework/models.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def validate_script(cls, script: str | None) -> str | None:
268268
file_path = Path(script)
269269
if not file_path.is_file():
270270
raise ValueError(f"MCP server script {script} does not exist.")
271-
elif file_path.suffix != PYTHON_SUFFIX:
271+
if file_path.suffix != PYTHON_SUFFIX:
272272
raise ValueError(f"MCP server script {script} does not have a .py suffix.")
273273
return script
274274

@@ -309,7 +309,7 @@ class PluginConfig(BaseModel):
309309
mcp: Optional[MCPConfig] = None
310310

311311
@model_validator(mode=AFTER)
312-
def check_url_or_script_filled(self) -> Self:
312+
def check_url_or_script_filled(self) -> Self: # pylint: disable=bad-classmethod-argument
313313
"""Checks to see that at least one of url or script are set depending on MCP server configuration.
314314
315315
Raises:
@@ -322,14 +322,14 @@ def check_url_or_script_filled(self) -> Self:
322322
return self
323323
if self.mcp.proto == TransportType.STDIO and not self.mcp.script:
324324
raise ValueError(f"Plugin {self.name} has transport type set to SSE but no script value")
325-
elif (self.mcp.proto == TransportType.STREAMABLEHTTP or self.mcp.proto == TransportType.SSE) and not self.mcp.url:
325+
if self.mcp.proto in (TransportType.STREAMABLEHTTP, TransportType.SSE) and not self.mcp.url:
326326
raise ValueError(f"Plugin {self.name} has transport type set to StreamableHTTP but no url value")
327-
elif self.mcp.proto != TransportType.SSE and self.mcp.proto != TransportType.STREAMABLEHTTP and self.mcp.proto != TransportType.STDIO:
327+
if self.mcp.proto not in (TransportType.SSE, TransportType.STREAMABLEHTTP, TransportType.STDIO):
328328
raise ValueError(f"Plugin {self.name} must set transport type to either SSE or STREAMABLEHTTP or STDIO")
329329
return self
330330

331331
@model_validator(mode=AFTER)
332-
def check_config_and_external(self, info: ValidationInfo) -> Self:
332+
def check_config_and_external(self, info: ValidationInfo) -> Self: # pylint: disable=bad-classmethod-argument
333333
"""Checks to see that a plugin's 'config' section is not defined if the kind is 'external'. This is because developers cannot override items in the plugin config section for external plugins.
334334
335335
Args:

mcpgateway/plugins/framework/utils.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def pre_prompt_matches(payload: PromptPrehookPayload, conditions: list[PluginCon
142142
current_result = False
143143
if current_result:
144144
return True
145-
elif index < len(conditions) - 1:
145+
if index < len(conditions) - 1:
146146
current_result = True
147147
return current_result
148148

@@ -167,7 +167,7 @@ def post_prompt_matches(payload: PromptPosthookPayload, conditions: list[PluginC
167167
current_result = False
168168
if current_result:
169169
return True
170-
elif index < len(conditions) - 1:
170+
if index < len(conditions) - 1:
171171
current_result = True
172172
return current_result
173173

@@ -203,7 +203,7 @@ def pre_tool_matches(payload: ToolPreInvokePayload, conditions: list[PluginCondi
203203
current_result = False
204204
if current_result:
205205
return True
206-
elif index < len(conditions) - 1:
206+
if index < len(conditions) - 1:
207207
current_result = True
208208
return current_result
209209

@@ -239,7 +239,7 @@ def post_tool_matches(payload: ToolPostInvokePayload, conditions: list[PluginCon
239239
current_result = False
240240
if current_result:
241241
return True
242-
elif index < len(conditions) - 1:
242+
if index < len(conditions) - 1:
243243
current_result = True
244244
return current_result
245245

@@ -275,7 +275,7 @@ def pre_resource_matches(payload: ResourcePreFetchPayload, conditions: list[Plug
275275
current_result = False
276276
if current_result:
277277
return True
278-
elif index < len(conditions) - 1:
278+
if index < len(conditions) - 1:
279279
current_result = True
280280
return current_result
281281

@@ -313,6 +313,6 @@ def post_resource_matches(payload: ResourcePostFetchPayload, conditions: list[Pl
313313
current_result = False
314314
if current_result:
315315
return True
316-
elif index < len(conditions) - 1:
316+
if index < len(conditions) - 1:
317317
current_result = True
318318
return current_result

0 commit comments

Comments
 (0)