refactor: enable plugins extensibility#1372
Merged
crivetimihai merged 24 commits intomainfrom Nov 8, 2025
Merged
Conversation
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
ff0db6b to
9c6b8fc
Compare
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
…nto refactor/plugins
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Teryl Taylor <terylt@ibm.com>
…nto refactor/plugins
Signed-off-by: Teryl Taylor <terylt@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
araujof
approved these changes
Nov 6, 2025
Member
araujof
left a comment
There was a problem hiding this comment.
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 <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com>
Member
|
Fixed the remaining tests and linting issues. Ready to merge. |
Merged
- 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
crivetimihai
approved these changes
Nov 8, 2025
49 tasks
49 tasks
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
* refactor: refactor plugins to make them extensible. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: pylint issues Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * chore: uv lock Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * refactor: created a common directory for classes used across packages. Signed-off-by: Teryl Taylor <terylt@ibm.com> * feat: added agent hooks. Signed-off-by: Teryl Taylor <terylt@ibm.com> * refactor: plugins to support 3 hook patterns Signed-off-by: Teryl Taylor <terylt@ibm.com> * chore: fix lint issues Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * feat: add comparison function to deal with PluginCondition Signed-off-by: Teryl Taylor <terylt@ibm.com> * chore: removed unrecognized mypy option Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * fix: static type check issues Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * fix: updated schemas imports. Signed-off-by: Teryl Taylor <terylt@ibm.com> * fix: doctests Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * fix: remaining doctests Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * fix: lint issues Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * chore: fix pylint issues Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * fix: pylint issues Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * fix: common validator tests Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * chore: fix flake8 issues Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> * fix: correct imports for plugin framework hooks - 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 * Fixes Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Teryl Taylor <terylt@ibm.com> Signed-off-by: Frederico Araujo <frederico.araujo@ibm.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Teryl Taylor <terylt@ibm.com> Co-authored-by: Frederico Araujo <frederico.araujo@ibm.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.