2020import uuid
2121
2222# First-Party
23- from mcpgateway .plugins .framework .models import HookType , PluginCondition , PluginConfig , PluginMode
24- from mcpgateway .plugins .framework .plugin_types import (
23+ from mcpgateway .plugins .framework .models import (
24+ HookType ,
25+ PluginCondition ,
26+ PluginConfig ,
2527 PluginContext ,
28+ PluginMode ,
2629 PromptPosthookPayload ,
2730 PromptPosthookResult ,
2831 PromptPrehookPayload ,
@@ -138,6 +141,9 @@ def conditions(self) -> list[PluginCondition] | None:
138141 """
139142 return self ._config .conditions
140143
144+ async def initialize (self ) -> None :
145+ """Initialize the plugin."""
146+
141147 async def prompt_pre_fetch (self , payload : PromptPrehookPayload , context : PluginContext ) -> PromptPrehookResult :
142148 """Plugin hook run before a prompt is retrieved and rendered.
143149
@@ -177,18 +183,14 @@ async def tool_pre_invoke(self, payload: ToolPreInvokePayload, context: PluginCo
177183 payload: The tool payload to be analyzed.
178184 context: Contextual information about the hook call.
179185
180- Returns:
181- ToolPreInvokeResult with processing status and modified payload.
182-
183- Examples:
184- >>> from mcpgateway.plugins.framework.plugin_types import ToolPreInvokePayload, PluginContext, GlobalContext
185- >>> payload = ToolPreInvokePayload("calculator", {"operation": "add", "a": 5, "b": 3})
186- >>> context = PluginContext(GlobalContext(request_id="123"))
187- >>> # In async context:
188- >>> # result = await plugin.tool_pre_invoke(payload, context)
186+ Raises:
187+ NotImplementedError: needs to be implemented by sub class.
189188 """
190- # Default pass-through implementation
191- return ToolPreInvokeResult (continue_processing = True , modified_payload = payload )
189+ raise NotImplementedError (
190+ f"""'tool_pre_invoke' not implemented for plugin { self ._config .name }
191+ of plugin type { type (self )}
192+ """
193+ )
192194
193195 async def tool_post_invoke (self , payload : ToolPostInvokePayload , context : PluginContext ) -> ToolPostInvokeResult :
194196 """Plugin hook run after a tool is invoked.
@@ -197,18 +199,14 @@ async def tool_post_invoke(self, payload: ToolPostInvokePayload, context: Plugin
197199 payload: The tool result payload to be analyzed.
198200 context: Contextual information about the hook call.
199201
200- Returns:
201- ToolPostInvokeResult with processing status and modified result.
202-
203- Examples:
204- >>> from mcpgateway.plugins.framework.plugin_types import ToolPostInvokePayload, PluginContext, GlobalContext
205- >>> payload = ToolPostInvokePayload("calculator", {"result": 8, "status": "success"})
206- >>> context = PluginContext(GlobalContext(request_id="123"))
207- >>> # In async context:
208- >>> # result = await plugin.tool_post_invoke(payload, context)
202+ Raises:
203+ NotImplementedError: needs to be implemented by sub class.
209204 """
210- # Default pass-through implementation
211- return ToolPostInvokeResult (continue_processing = True , modified_payload = payload )
205+ raise NotImplementedError (
206+ f"""'tool_post_invoke' not implemented for plugin { self ._config .name }
207+ of plugin type { type (self )}
208+ """
209+ )
212210
213211 async def resource_pre_fetch (self , payload , context ):
214212 """Plugin hook run before a resource is fetched.
@@ -217,22 +215,14 @@ async def resource_pre_fetch(self, payload, context):
217215 payload: The resource payload to be analyzed.
218216 context: Contextual information about the hook call.
219217
220- Returns:
221- ResourcePreFetchResult with processing status and modified payload.
222-
223- Examples:
224- >>> from mcpgateway.plugins.framework.plugin_types import ResourcePreFetchPayload, PluginContext, GlobalContext
225- >>> payload = ResourcePreFetchPayload("file:///data.txt", {"cache": True})
226- >>> context = PluginContext(GlobalContext(request_id="123"))
227- >>> # In async context:
228- >>> # result = await plugin.resource_pre_fetch(payload, context)
218+ Raises:
219+ NotImplementedError: needs to be implemented by sub class.
229220 """
230- # Import here to avoid circular dependency
231- # First-Party
232- from mcpgateway .plugins .framework .plugin_types import ResourcePreFetchResult
233-
234- # Default pass-through implementation
235- return ResourcePreFetchResult (continue_processing = True , modified_payload = payload )
221+ raise NotImplementedError (
222+ f"""'resource_pre_fetch' not implemented for plugin { self ._config .name }
223+ of plugin type { type (self )}
224+ """
225+ )
236226
237227 async def resource_post_fetch (self , payload , context ):
238228 """Plugin hook run after a resource is fetched.
@@ -241,24 +231,14 @@ async def resource_post_fetch(self, payload, context):
241231 payload: The resource content payload to be analyzed.
242232 context: Contextual information about the hook call.
243233
244- Returns:
245- ResourcePostFetchResult with processing status and modified content.
246-
247- Examples:
248- >>> from mcpgateway.plugins.framework.plugin_types import ResourcePostFetchPayload, PluginContext, GlobalContext
249- >>> from mcpgateway.models import ResourceContent
250- >>> content = ResourceContent(type="resource", uri="file:///data.txt", text="Data")
251- >>> payload = ResourcePostFetchPayload("file:///data.txt", content)
252- >>> context = PluginContext(GlobalContext(request_id="123"))
253- >>> # In async context:
254- >>> # result = await plugin.resource_post_fetch(payload, context)
234+ Raises:
235+ NotImplementedError: needs to be implemented by sub class.
255236 """
256- # Import here to avoid circular dependency
257- # First-Party
258- from mcpgateway .plugins .framework .plugin_types import ResourcePostFetchResult
259-
260- # Default pass-through implementation
261- return ResourcePostFetchResult (continue_processing = True , modified_payload = payload )
237+ raise NotImplementedError (
238+ f"""'resource_post_fetch' not implemented for plugin { self ._config .name }
239+ of plugin type { type (self )}
240+ """
241+ )
262242
263243 async def shutdown (self ) -> None :
264244 """Plugin cleanup code."""
0 commit comments