Module

_mcp_router

Shared MCP method dispatch for leaf servers and gateway.

Classes

MethodNotFoundError 0
Raised when a JSON-RPC method is not implemented.

Raised when a JSON-RPC method is not implemented.

UnsupportedProtocolVersionError 1
Raised when per-request metadata asks for an unsupported MCP version.

Raised when per-request metadata asks for an unsupported MCP version.

Methods

Internal Methods 1
__init__ 1
def __init__(self, requested: str) -> None
Parameters
Name Type Description
requested
MCPHandler 8
Protocol for MCP method handlers. Implemented by the leaf MCP server (direct CLI calls) and the ga…

Protocol for MCP method handlers.

Implemented by the leaf MCP server (direct CLI calls) and the gateway (proxy to child processes). The router dispatches to the appropriate method without duplicating the match/case structure.

Methods

initialize 1 dict[str, Any]
def initialize(self, params: dict[str, Any]) -> dict[str, Any]
Parameters
Name Type Description
params
Returns
dict[str, Any]
server_discover 1 dict[str, Any]
def server_discover(self, params: dict[str, Any]) -> dict[str, Any]
Parameters
Name Type Description
params
Returns
dict[str, Any]
list_tools 1 dict[str, Any]
def list_tools(self, params: dict[str, Any]) -> dict[str, Any]
Parameters
Name Type Description
params
Returns
dict[str, Any]
call_tool 1 dict[str, Any]
def call_tool(self, params: dict[str, Any]) -> dict[str, Any]
Parameters
Name Type Description
params
Returns
dict[str, Any]
list_resources 1 dict[str, Any]
def list_resources(self, params: dict[str, Any]) -> dict[str, Any]
Parameters
Name Type Description
params
Returns
dict[str, Any]
read_resource 1 dict[str, Any]
def read_resource(self, params: dict[str, Any]) -> dict[str, Any]
Parameters
Name Type Description
params
Returns
dict[str, Any]
list_prompts 1 dict[str, Any]
def list_prompts(self, params: dict[str, Any]) -> dict[str, Any]
Parameters
Name Type Description
params
Returns
dict[str, Any]
get_prompt 1 dict[str, Any]
def get_prompt(self, params: dict[str, Any]) -> dict[str, Any]
Parameters
Name Type Description
params
Returns
dict[str, Any]

Functions

dispatch 3 dict[str, Any] | None
Route an MCP method to the appropriate handler method. Returns None for notifi…
def dispatch(handler: MCPHandler, method: str, params: dict[str, Any]) -> dict[str, Any] | None

Route an MCP method to the appropriate handler method.

Returns None for notification methods (no response required). Raises ValueError for unknown methods.

Parameters
Name Type Description
handler MCPHandler
method str
params dict[str, Any]
Returns
dict[str, Any] | None
_validate_requested_protocol 1 None
Reject explicit per-request MCP versions Milo does not implement. Legacy 2025-…
def _validate_requested_protocol(params: dict[str, Any]) -> None

Reject explicit per-request MCP versions Milo does not implement.

Legacy 2025-11-25 clients negotiate withinitializeand do not send request metadata, so absent metadata remains accepted for backward compatibility.

Parameters
Name Type Description
params dict[str, Any]