extensible_mcp_server.py
Source: src/sunholo/mcp/extensible_mcp_server.py
Functions
create_mcp_server(server_name: str = 'sunholo-mcp-server', include_vac_tools: bool = True, custom_registry: sunholo.mcp.extensible_mcp_server.MCPToolRegistry = None) -> sunholo.mcp.extensible_mcp_server.ExtensibleMCPServer
Create a new extensible MCP server instance.
Args: server_name: Name for the MCP server include_vac_tools: Whether to include built-in VAC tools custom_registry: Optional custom tool registry
Returns: Configured ExtensibleMCPServer instance
get_global_registry() -> sunholo.mcp.extensible_mcp_server.MCPToolRegistry
Get the global MCP tool registry.
mcp_resource(name: str = None, description: str = None)
Decorator to register a function as an MCP resource.
Args: name: Optional custom name for the resource description: Optional description (uses docstring if not provided)
mcp_tool(name: str = None, description: str = None)
Decorator to register a function as an MCP tool.
Args: name: Optional custom name for the tool description: Optional description (uses docstring if not provided)
Example: @mcp_tool("my_custom_tool", "Does something useful") async def my_tool(param1: str, param2: int = 5) -> str: return f"Result: {param1} * {param2}"
Classes
ExtensibleMCPServer
Extensible MCP Server that supports custom tool registration. Can be used both as a standalone server and integrated into FastAPI apps.
- init(self, server_name: str = 'extensible-mcp-server', registry: sunholo.mcp.extensible_mcp_server.MCPToolRegistry = None, include_vac_tools: bool = True)
- Initialize the extensible MCP server.
Args: server_name: Name for the MCP server registry: Custom tool registry (uses global if None) include_vac_tools: Whether to include built-in VAC tools
-
_register_resources(self)
- Register all resources from the registry with FastMCP.
-
_register_tools(self)
- Register all tools from the registry with FastMCP.
-
_register_vac_tools(self)
- Register built-in VAC tools.
-
add_resource(self, func: Callable, name: str = None, description: str = None)
- Add a resource function directly to the server.
Args:
func: The resource function
name: Optional custom name
description: Optional description
- add_tool(self, func: Callable, name: str = None, description: str = None)
- Add a tool function directly to the server.
Args: func: The tool function name: Optional custom name description: Optional description
-
get_http_app(self)
- Get the HTTP app for mounting in FastAPI.
-
get_server(self) -> fastmcp.server.server.FastMCP
- Get the underlying FastMCP server instance.
-
list_registered_resources(self) -> List[str]
- List all registered resources.
-
list_registered_tools(self) -> List[str]
- List all registered tools.
-
run(self, transport: str = 'stdio', **kwargs)
- Run the MCP server.
Args: transport: Transport type ("stdio" or "http") **kwargs: Additional arguments for the transport
- run_async(self, transport: str = 'stdio', **kwargs)
- Run the MCP server asynchronously.
Args: transport: Transport type ("stdio" or "http") **kwargs: Additional arguments for the transport
MCPToolRegistry
Registry for MCP tools that can be shared across server instances.
-
init(self)
- Initialize self. See help(type(self)) for accurate signature.
-
get_resource(self, name: str)
- Get a registered resource.
-
get_tool(self, name: str)
- Get a registered tool.
-
list_resources(self)
- List all registered resources.
-
list_tools(self)
- List all registered tools.
-
register_resource(self, name: str, func: Callable, description: str = None)
- Register a resource function.
-
register_tool(self, name: str, func: Callable, description: str = None)
- Register a tool function.