mcp.servers.mcp_server_manager_v2ΒΆ
MCP Server Manager V2 - Pydantic-based refactor.
This module provides a refactored MCPServerManager that inherits from the base server management framework, adding MCP-specific functionality with full Pydantic validation.
- Key improvements:
Inherits from BaseServerManager for type-safe management
Full Pydantic validation for all configurations
Backward compatibility with existing MCPServerManager API
Enhanced error handling and logging
Better separation of concerns
Example
Basic usage with new typed API:
from haive.mcp.servers import MCPServerManagerV2
manager = MCPServerManagerV2()
manager.add_config("filesystem", {
"command": ["npx", "-y", "@modelcontextprotocol/server-filesystem"],
"description": "File system operations",
"transport": "stdio"
})
await manager.start_server("filesystem")
Legacy compatibility mode:
manager = MCPServerManagerV2()
manager.run(servers_to_start=["filesystem", "time"])
AttributesΒΆ
ClassesΒΆ
Refactored MCP Server Manager with Pydantic validation. |
FunctionsΒΆ
|
Main entry point for command-line usage. |
Module ContentsΒΆ
- class mcp.servers.mcp_server_manager_v2.MCPServerManagerV2(**data)ΒΆ
Bases:
haive.dataflow.server_management.base.BaseServerManager
[mcp.servers.models.MCPServerConfig
,mcp.servers.models.MCPServerInfo
]Refactored MCP Server Manager with Pydantic validation.
Inherits from BaseServerManager to provide type-safe server management with MCP-specific extensions for stdio transport, environment validation, and protocol handling.
- config_classΒΆ
MCPServerConfig class for validation
- info_classΒΆ
MCPServerInfo class for runtime state
- output_monitorsΒΆ
Thread references for stdio output monitoring
- legacy_modeΒΆ
Enable backward compatibility behaviors
Example
>>> manager = MCPServerManagerV2() >>> config = MCPServerConfig( ... name="github", ... command=["npx", "-y", "@modelcontextprotocol/server-github"], ... transport=MCPTransport.STDIO, ... requires_env=["GITHUB_TOKEN"] ... ) >>> manager.add_config("github", config) >>> await manager.start_server("github", {"GITHUB_TOKEN": "token"})
- async restart_server(name: str) mcp.servers.models.MCPServerInfo ΒΆ
Restart server preserving environment configuration.
- run(servers_to_start: List[str] | None = None, blocking: bool = True) bool ΒΆ
Legacy run method for backward compatibility.
- async start_server(name: str, env_overrides: Dict[str, str] | None = None) mcp.servers.models.MCPServerInfo ΒΆ
Start an MCP server with proper validation.
Extends base start_server with MCP-specific features like environment validation and stdio output monitoring.
- Parameters:
name β Server name
env_overrides β Optional environment variable overrides
- Returns:
MCPServerInfo with running server details
- Raises:
ValueError β If required environment variables are missing
RuntimeError β If server fails to start
- start_server_sync(name: str, env_overrides: Dict[str, str] | None = None) bool ΒΆ
Synchronous wrapper for legacy compatibility.
- async stop_server(name: str, force: bool = False) bool ΒΆ
Stop server with cleanup of MCP-specific resources.
- config_class: type[mcp.servers.models.MCPServerConfig] = NoneΒΆ
- info_class: type[mcp.servers.models.MCPServerInfo] = NoneΒΆ
- output_monitors: Dict[str, threading.Thread] = NoneΒΆ
- mcp.servers.mcp_server_manager_v2.main()ΒΆ
Main entry point for command-line usage.
- mcp.servers.mcp_server_manager_v2.loggerΒΆ