refactor: refactor plugins to make them extensible. #1372
  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.