BaseMCPManager Reference
TheBaseMCPManager is the foundational class for creating MCP (Model Context Protocol) servers in the scmcphub ecosystem. It provides a standardized way to manage and organize multiple MCP modules, with built-in filtering capabilities for both modules and tools.
Overview
BaseMCPManager serves as an abstract base class that handles:
- Module registration and management
- Tool filtering (include/exclude)
- Module filtering (include/exclude)
- Backend integration
- FastMCP lifecycle management
Class Definition
Constructor
__init__(name, instructions=None, include_modules=None, exclude_modules=None, include_tools=None, exclude_tools=None, include_tags=None, exclude_tags=None, backend=None)
Initializes a new BaseMCPManager instance.
Parameters
Instance Attributes
Methods
init_mcp()
Abstract method - Must be implemented by subclasses.
Initializes the available_modules dictionary with module instances.
register_mcp()
Registers modules based on include/exclude filters and imports them into the main MCP server.
exec_lifespan(server)
Async context manager that provides the execution backend during the server’s lifespan.
Usage Examples
Basic Implementation
With Module Filtering
With Tool Filtering
With Tag Filtering
Complete Example
Real-World Examples
ScanpyMCPManager
CellrankMCPManager
Best Practices
1. Module Naming Convention
Use consistent module names across your MCP server:io- Input/Output operationspp- Preprocessingtl- Toolspl- Plottingul- Utilitiesauto- Auto-completion toolsnb- Notebook integration
2. Backend Selection
Choose the appropriate backend based on your use case:AdataManager- For AnnData-based operations/tool-modeNotebookManager- For notebook-based execution/code-mode
3. Filtering Strategy
- Use
include_moduleswhen you want to limit to specific modules - Use
exclude_moduleswhen you want to exclude specific modules from a larger set - Use
include_toolsfor fine-grained control over which tools are available - Use
exclude_toolsto remove specific tools from modules