Purpose: Model Context Protocol implementation for standardized tool discovery, registration, and execution across all GNN modules
Pipeline Step: Step 21: Model Context Protocol processing (21_mcp.py)
Category: Protocol Integration / Tool Management
Status: ✅ Production Ready
Version: 1.7.0 (Extended from pipeline v1.6.0 — MCP subsystem has independent versioning)
Last Updated: 2026-04-16
- Implement Model Context Protocol (MCP) for tool registration and discovery
- Provide standardized interface for tool execution across modules
- Enable inter-module communication and resource sharing
- Manage MCP server lifecycle and client connections
- Support multiple MCP transport protocols (stdio, HTTP, WebSocket)
- Tool registration and discovery system
- Resource access and management
- JSON-RPC protocol implementation
- Server and client implementations
- Enhanced error handling and validation
- Performance monitoring and caching
- Concurrent execution control
process_mcp(target_dir: Path, output_dir: Path, verbose: bool = False, logger: Optional[logging.Logger] = None, **kwargs) -> bool
Description: Main MCP processing function called by orchestrator (21_mcp.py). Discovers and registers MCP tools from all modules.
Parameters:
target_dir(Path): Directory containing GNN filesoutput_dir(Path): Output directory for MCP resultsverbose(bool): Enable verbose logging (default: False)logger(Optional[logging.Logger]): Logger instance for progress reporting (default: None)mcp_mode(str, optional): MCP mode ("tool_discovery", "server", "client") (default: "tool_discovery")enable_tools(bool, optional): Enable MCP tools functionality (default: True)transport(str, optional): Transport protocol ("stdio", "http") (default: "stdio")**kwargs: Additional MCP options
Returns: bool - True if MCP processing succeeded, False otherwise
Example:
from mcp import process_mcp
from pathlib import Path
import logging
logger = logging.getLogger(__name__)
success = process_mcp(
target_dir=Path("input/gnn_files"),
output_dir=Path("output/21_mcp_output"),
logger=logger,
verbose=True,
mcp_mode="tool_discovery",
enable_tools=True,
transport="stdio"
)Description: Discover one (or all) pipeline modules and call their
register_tools(mcp_instance) function against the global singleton. Each
target module owns its tool definitions via src/<module>/mcp.py.
Parameters:
module_name(Optional[str]): Single module to register (e.g."gnn").Nonetriggers full discovery viaMCP.discover_modules().
Returns: bool when module_name is provided; a list of registered tool
dictionaries when discovering all modules.
Description: Module-level helper equivalent to
mcp.discover_modules(). Registers every module's tools against the supplied
MCP instance (default: the global singleton). Exposed from
mcp.server_core and re-exported from the package.
Returns: bool — True when discovery runs to completion.
Description: Get list of all available MCP tools across all modules.
Returns: List[Dict[str, Any]] - List of tool information dictionaries with:
name(str): Tool namemodule(str): Source moduledescription(str): Tool descriptionschema(Dict): Parameter schemacategory(str): Tool category
Description: Core Model Context Protocol implementation
Key Methods:
initialize()- Initialize MCP serverregister_tools()- Register available toolshandle_request()- Process incoming requestslist_available_tools()- List available tools
Description: Represents a registered MCP tool
Attributes:
name- Tool namedescription- Tool descriptioninput_schema- JSON schema for inputshandler- Function to execute tool
Description: Represents accessible MCP resources
Attributes:
uri- Resource URIname- Resource namedescription- Resource descriptionmime_type- Resource MIME type
- Purpose: Standard input/output communication
- Use Case: Local tool execution and testing
- Implementation:
mcp.server_stdio
- Purpose: Web-based MCP server
- Use Case: Remote tool access and web integration
- Implementation:
mcp.server_http
json- JSON-RPC protocol implementationpathlib- Path and URI handlingtyping- Type annotations and validationlogging- Request/response logging
aiohttp- HTTP server implementation (recovery: basic HTTP)websockets- WebSocket server (recovery: polling-based)fastapi- REST API framework (recovery: basic HTTP)
utils.pipeline_template- Standardized pipeline processingpipeline.config- Configuration management
MCP_SERVER_PORT- MCP server port (default: 8080)MCP_TRANSPORT- Transport protocol ("stdio", "http", "websocket")MCP_LOG_LEVEL- MCP logging level ("DEBUG", "INFO", "WARNING", "ERROR")MCP_TIMEOUT- MCP request timeout (default: 30 seconds)
mcp_config.yaml- MCP server and tool configuration
The live defaults are embedded in mcp.mcp.MCP.__init__ and exposed via
initialize(...). Authoritative table:
| Knob | Default | CLI flag (step 21) |
|---|---|---|
performance_mode |
"low" |
--performance-mode {low,medium,high} |
strict_validation |
False (from mode) |
--mcp-strict-validation |
enable_caching |
False (from mode) |
— |
enable_rate_limiting |
False (from mode) |
— |
cache_ttl |
300.0 s |
--mcp-cache-ttl <seconds> |
per_module_timeout |
30.0 s |
--mcp-per-module-timeout <seconds> |
overall_timeout |
120.0 s |
--mcp-overall-timeout <seconds> |
modules_allowlist |
None (all modules) |
--mcp-modules-allowlist a,b,c |
See src/mcp/MCP_DOCUMENTATION.md → Configuration for the complete surface
and src/mcp/SKILL.md for the capabilities-API summary.
from mcp.processor import process_mcp
success = process_mcp(
target_dir=Path("input/gnn_files"),
output_dir=Path("output/21_mcp_output"),
logger=logger,
mcp_mode="tool_discovery"
)from mcp import register_module_tools
success = register_module_tools("gnn")
all_tools = register_module_tools()from mcp import get_available_tools
tools = get_available_tools()
for tool in tools:
print(f"Tool: {tool['name']} - {tool['description']}")mcp_processing_summary.json- MCP processing summaryregistered_tools.json- All registered tools informationmcp_server_status.json- Server status and configurationtool_execution_log.json- Tool execution history
output/21_mcp_output/
├── mcp_processing_summary.json
├── registered_tools.json
├── mcp_server_status.json
└── tool_execution_log.json
- Duration: ~1-3 seconds (tool registration)
- Memory: ~10-20MB for tool registry
- Status: ✅ Production Ready
- Fast Path: <1s for tool discovery
- Slow Path: ~5s for comprehensive tool validation
- Memory: ~5-15MB for typical tool sets
- No transport libraries: Recovery to stdio-only mode
- Tool registration failures: Continue with available tools
- Server startup failures: Recovery to client-only mode
- Protocol Errors: Invalid JSON-RPC requests/responses
- Tool Errors: Tool execution failures or timeouts
- Transport Errors: Network or I/O communication failures
- Validation Errors: Invalid tool schemas or parameters
- Script:
21_mcp.py(Step 21) - Function:
process_mcp()
utils.pipeline_template- Standardized processing patternspipeline.config- Configuration management
src/tests/mcp/test_mcp_overall.py- MCP module testsmain.py- Pipeline orchestration
Module Tools → MCP Registration → Tool Discovery → Execution Requests → Response Handling
src/tests/mcp/test_mcp_tools.py- Tool registration testssrc/tests/mcp/test_mcp_functional.py- Functional testssrc/tests/mcp/test_mcp_audit.py- Audit testssrc/tests/mcp/test_mcp_tools.py- Tool registration tests
Measure on demand:
uv run --extra dev python -m pytest src/tests/test_mcp*.py \
--cov=src/mcp --cov-report=term-missing- Tool registration and discovery across modules
- JSON-RPC protocol compliance
- Multiple transport protocol operation
- Error handling with malformed requests
- Performance under concurrent tool execution
gnn_*- GNN file processing toolsanalysis_*- Statistical analysis toolsvisualization_*- Visualization generation toolsrender_*- Code generation toolsgui_*- GUI interaction tools
- File Processing: GNN parsing, validation, transformation
- Analysis: Statistical analysis, complexity metrics
- Visualization: Chart generation, interactive displays
- Code Generation: Multi-framework code rendering
- Model Management: Registry operations, version control
Symptom: Tools not discovered or registered
Cause: Module discovery issues or tool definition errors
Solution:
- Verify all modules have
mcp.pyfiles with tool definitions - Check tool function signatures match expected format
- Use
--verboseflag for detailed discovery logs - Review MCP tool registration patterns
Symptom: Tools registered but execution fails
Cause: Parameter validation errors or function implementation issues
Solution:
- Verify tool parameter schemas are correct
- Check tool function implementations handle errors
- Review tool execution logs for specific errors
- Validate tool inputs match schema
Features:
- Tool registration and discovery
- Resource access and management
- JSON-RPC protocol implementation
- Server and client implementations
- Enhanced error handling
- Performance monitoring
Known Issues:
- None currently
- Next Version: Enhanced transport protocols
- Future: Real-time tool monitoring
Last Updated: 2026-04-16 Maintainer: GNN Pipeline Team Status: ✅ Production Ready Architecture Compliance: ✅ 100% Thin Orchestrator Pattern