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ΒΆ

MCPServerManagerV2

Refactored MCP Server Manager with Pydantic validation.

FunctionsΒΆ

main()

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 cleanup() NoneΒΆ

Clean up all resources including output monitors.

get_status() Dict[str, dict]ΒΆ

Get legacy-format status.

async health_check(name: str) boolΒΆ

MCP-specific health check implementation.

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.

show_status() NoneΒΆ

Show status in legacy format.

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.

stop_all_servers() NoneΒΆ

Stop all servers synchronously for legacy compatibility.

async stop_server(name: str, force: bool = False) boolΒΆ

Stop server with cleanup of MCP-specific resources.

stop_server_sync(name: str) boolΒΆ

Synchronous wrapper for legacy compatibility.

property available_servers: Dict[str, dict]ΒΆ

Legacy property for backward compatibility.

config_class: type[mcp.servers.models.MCPServerConfig] = NoneΒΆ
info_class: type[mcp.servers.models.MCPServerInfo] = NoneΒΆ
legacy_mode: bool = NoneΒΆ
output_monitors: Dict[str, threading.Thread] = NoneΒΆ
shutdown_requested: bool = NoneΒΆ
mcp.servers.mcp_server_manager_v2.main()ΒΆ

Main entry point for command-line usage.

mcp.servers.mcp_server_manager_v2.loggerΒΆ