-
Notifications
You must be signed in to change notification settings - Fork 384
refactor: enable plugins extensibility #1372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Teryl Taylor <[email protected]>
Signed-off-by: Frederico Araujo <[email protected]>
Signed-off-by: Frederico Araujo <[email protected]>
ff0db6b to
9c6b8fc
Compare
Signed-off-by: Teryl Taylor <[email protected]>
Signed-off-by: Teryl Taylor <[email protected]>
Signed-off-by: Teryl Taylor <[email protected]>
Signed-off-by: Frederico Araujo <[email protected]>
Signed-off-by: Teryl Taylor <[email protected]>
…nto refactor/plugins
Signed-off-by: Frederico Araujo <[email protected]>
Signed-off-by: Frederico Araujo <[email protected]>
Signed-off-by: Teryl Taylor <[email protected]>
…nto refactor/plugins
Signed-off-by: Teryl Taylor <[email protected]>
Signed-off-by: Frederico Araujo <[email protected]>
Signed-off-by: Frederico Araujo <[email protected]>
araujof
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR is a major refactoring to make the plugin system more extensible with dynamic hook discovery. Overall, this is a significant improvement for the plugin framework.
The PR maintains backward compatibility - existing plugins work unchanged.
Notes:
- I fixed lint issues, tests, and doctests. Made minor changes all around.
Summary of Changes:
- Decouples plugin framework from common gateway objects; the plugin framework is ready to be split as an independent package
- Converts Plugin to an abstract base class (ABC) for better type safety
- Introduces 3 hook registration patterns: convention-based, decorator-based, and custom hooks
- Implements dynamic hook discovery using decorators, naming conventions, and explicit registration
- Adds new agent lifecycle hooks (agent_pre_invoke, agent_post_invoke) for multi-agent workflow interception
- Standardizes all hooks to return PluginResult[PayloadType] for consistent result handling.
Signed-off-by: Frederico Araujo <[email protected]>
Signed-off-by: Frederico Araujo <[email protected]>
Signed-off-by: Frederico Araujo <[email protected]>
Signed-off-by: Frederico Araujo <[email protected]>
Signed-off-by: Frederico Araujo <[email protected]>
|
Fixed the remaining tests and linting issues. Ready to merge. |
- Fix import path from mcpgateway.plugins.mcp.entities to correct location - Use ToolHookType from mcpgateway.plugins.framework.hooks.tools - Import HttpHeaderPayload from mcpgateway.plugins.framework.hooks.http - Update HookType references to ToolHookType
ec6cd6f to
941a882
Compare
Integrate plugin extensibility refactoring with observability features. Resolves conflicts in plugin manager, models, and tool service. # Conflicts: # mcpgateway/plugins/framework/manager.py # mcpgateway/services/tool_service.py
Signed-off-by: Mihai Criveti <[email protected]>
Plugin Framework Refactor: Dynamic Hook Discovery
This PR refactors the plugin framework to support flexible, dynamic hook registration patterns while maintaining
backward compatibility.
Key Changes
1. Plugin Base Class
Pluginis now an abstract base class (ABC)2. Three Hook Registration Patterns
Pattern 1: Convention-Based (Simplest)
Pattern 2: Decorator-Based (Custom Names)
Pattern 3: Custom Hooks (Advanced)
3. Dynamic Hook Discovery
The PluginManager now discovers hooks dynamically using:
4. Hook Invocation
5. Result Type System
All hooks return PluginResult[PayloadType]:
6. Agent Hooks
Added new hooks for intercepting and transforming agent interactions in multi-agent workflows:
agent_pre_invoke- Intercept agent requests before invocationUse cases:
agent_post_invoke - Process agent responses after invocation
Use cases:
Example Usage:
These hooks enable sophisticated multi-agent orchestration patterns like message filtering for safety, conversation
routing based on content, tool access control, and cross-agent observability. See
tests/unit/mcpgateway/plugins/agent/test_agent_plugins.pyfor complete examples including content filtering, contextpersistence across pre/post hooks, and partial message filtering.
Benefits
Testing
Documentation
Files Changed
Migration Guide
Existing plugins continue to work unchanged. To adopt new patterns:
See
tests/unit/mcpgateway/plugins/framework/hooks/test_hook_patterns.pyfor complete working examples.