Classes
_CLIHandler
8
▼
MCPHandler implementation for a single CLI (leaf server).
_CLIHandler
8
▼
MCPHandler implementation for a single CLI (leaf server).
Methods
initialize
1
dict[str, Any]
▼
initialize
1
dict[str, Any]
▼
def initialize(self, params: dict[str, Any]) -> dict[str, Any]
Parameters
| Name | Type | Description |
|---|---|---|
params |
— |
Returns
dict[str, Any]
list_tools
1
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]
▼
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]
▼
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]
▼
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]
▼
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]
▼
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]
Internal Methods 1 ▼
__init__
2
▼
__init__
2
▼
def __init__(self, cli: CLI, cached_tools: list[dict[str, Any]] | None = None) -> None
Parameters
| Name | Type | Description |
|---|---|---|
cli |
— |
|
cached_tools |
— |
Default:None
|
Functions
_to_text
1
str
▼
Convert a result to text for MCP content responses.
_to_text
1
str
▼
def _to_text(result: Any) -> str
Parameters
| Name | Type | Description |
|---|---|---|
result |
Any |
Returns
str
run_mcp_server
1
None
▼
Run MCP JSON-RPC server on stdin/stdout.
Implements the MCP protocol (initiali…
run_mcp_server
1
None
▼
def run_mcp_server(cli: CLI) -> None
Run MCP JSON-RPC server on stdin/stdout.
Implements the MCP protocol (initialize, tools/list, tools/call, resources/list, resources/read, prompts/list, prompts/get).
Parameters
| Name | Type | Description |
|---|---|---|
cli |
CLI |
_classify_exception
1
tuple[int, dict[str, Any…
▼
Map an exception to a JSON-RPC error code and optional data payload.
Returns (…
_classify_exception
1
tuple[int, dict[str, Any…
▼
def _classify_exception(exc: Exception) -> tuple[int, dict[str, Any] | None]
Map an exception to a JSON-RPC error code and optional data payload.
Returns (code, data) where:
- MiloError with validation/config codes -> -32602 (Invalid params)
- MiloError with not-found codes -> -32601 (Method not found)
- All others -> -32603 (Internal error) with traceback in data
When the MiloError carriesargument or constraintcontext, those
fields are included in the data payload so callers can tell agents which
parameter failed and what constraint was violated.
Parameters
| Name | Type | Description |
|---|---|---|
exc |
Exception |
Returns
tuple[int, dict[str, Any] | None]
_milo_error_data
1
dict[str, Any]
▼
Build the structured data payload for a MiloError.
_milo_error_data
1
dict[str, Any]
▼
def _milo_error_data(exc: Any) -> dict[str, Any]
Parameters
| Name | Type | Description |
|---|---|---|
exc |
Any |
Returns
dict[str, Any]
_constraint_example
1
Any
▼
Derive an example value from a JSON-Schema-style constraint dict.
Never uses u…
_constraint_example
1
Any
▼
def _constraint_example(constraint: dict[str, Any]) -> Any
Derive an example value from a JSON-Schema-style constraint dict.
Never uses user input. ReturnsNonewhen no safe example applies.
Parameters
| Name | Type | Description |
|---|---|---|
constraint |
dict[str, Any] |
Returns
Any
_builtin_resources
0
list[dict[str, Any]]
▼
Built-in MCP resources provided by the milo runtime.
_builtin_resources
0
list[dict[str, Any]]
▼
def _builtin_resources() -> list[dict[str, Any]]
Returns
list[dict[str, Any]]
_stats_resource
1
dict[str, Any]
▼
Return server statistics as an MCP resource.
_stats_resource
1
dict[str, Any]
▼
def _stats_resource(logger: RequestLogger) -> dict[str, Any]
Parameters
| Name | Type | Description |
|---|---|---|
logger |
RequestLogger |
Returns
dict[str, Any]
_pipeline_timeline_resource
0
dict[str, Any]
▼
Return the active pipeline's execution timeline as an MCP resource.
_pipeline_timeline_resource
0
dict[str, Any]
▼
def _pipeline_timeline_resource() -> dict[str, Any]
Returns
dict[str, Any]
_list_tools
1
list[dict[str, Any]]
▼
Generate MCP tools/list response from all commands including groups.
Group com…
_list_tools
1
list[dict[str, Any]]
▼
def _list_tools(cli: CLI) -> list[dict[str, Any]]
Generate MCP tools/list response from all commands including groups.
Group commands use dot-notation names:site.build, site.config.show.
Includes outputSchema when return type annotations are available.
Skips commands that fail to import with a warning.
Parameters
| Name | Type | Description |
|---|---|---|
cli |
CLI |
Returns
list[dict[str, Any]]
_tool_title
1
str
▼
Derive a human-readable title for a tool.
Uses the handler's docstring first l…
_tool_title
1
str
▼
def _tool_title(cmd: CommandDef | LazyCommandDef) -> str
Derive a human-readable title for a tool.
Uses the handler's docstring first line if available and different from the description. Falls back to a title-cased command name.
Parameters
| Name | Type | Description |
|---|---|---|
cmd |
CommandDef | LazyCommandDef |
Returns
str
_output_schema
1
dict[str, Any] | None
▼
Generate outputSchema from handler return type annotation.
Returns None for la…
_output_schema
1
dict[str, Any] | None
▼
def _output_schema(cmd: CommandDef | LazyCommandDef) -> dict[str, Any] | None
Generate outputSchema from handler return type annotation.
Returns None for lazy commands that haven't been resolved (avoids imports).
Parameters
| Name | Type | Description |
|---|---|---|
cmd |
CommandDef | LazyCommandDef |
Returns
dict[str, Any] | None
_call_tool
2
dict[str, Any]
▼
Handle tools/call by dispatching to the command handler.
Routes through the CL…
_call_tool
2
dict[str, Any]
▼
def _call_tool(cli: CLI, params: dict[str, Any]) -> dict[str, Any]
Handle tools/call by dispatching to the command handler.
Routes through the CLI's middleware stack when present, so middleware can intercept MCP-originated calls just like CLI-originated ones.
If the handler returns a generator yielding Progress objects, each
Progress is emitted as anotifications/progressJSON-RPC
notification before the final result is returned.
Parameters
| Name | Type | Description |
|---|---|---|
cli |
CLI |
|
params |
dict[str, Any] |
Returns
dict[str, Any]
_tool_error_response
3
dict[str, Any]
▼
Build the ``tools/call`` error response with structured context.
MiloError sub…
_tool_error_response
3
dict[str, Any]
▼
def _tool_error_response(exc: Exception, tool_name: str, cli: CLI) -> dict[str, Any]
Build thetools/callerror response with structured context.
MiloError subclasses contribute theirargument, constraint,
suggestion, and errorCode fields. Plain TypeError
messages about missing or unexpected keyword arguments are parsed so
agents see which argument was wrong, and theschemafield points
them at the tool's declared parameter schema for repair.
Parameters
| Name | Type | Description |
|---|---|---|
exc |
Exception |
|
tool_name |
str |
|
cli |
CLI |
Returns
dict[str, Any]
_tool_schema
2
dict[str, Any] | None
▼
Return the input schema for a named tool, if known.
_tool_schema
2
dict[str, Any] | None
▼
def _tool_schema(cli: CLI, tool_name: str) -> dict[str, Any] | None
Parameters
| Name | Type | Description |
|---|---|---|
cli |
CLI |
|
tool_name |
str |
Returns
dict[str, Any] | None
_list_resources
1
list[dict[str, Any]]
▼
Generate MCP resources/list response from registered resources.
_list_resources
1
list[dict[str, Any]]
▼
def _list_resources(cli: CLI) -> list[dict[str, Any]]
Parameters
| Name | Type | Description |
|---|---|---|
cli |
CLI |
Returns
list[dict[str, Any]]
_read_resource
2
dict[str, Any]
▼
Handle resources/read by calling the resource handler.
_read_resource
2
dict[str, Any]
▼
def _read_resource(cli: CLI, params: dict[str, Any]) -> dict[str, Any]
Parameters
| Name | Type | Description |
|---|---|---|
cli |
CLI |
|
params |
dict[str, Any] |
Returns
dict[str, Any]
_list_prompts
1
list[dict[str, Any]]
▼
Generate MCP prompts/list response from registered prompts.
_list_prompts
1
list[dict[str, Any]]
▼
def _list_prompts(cli: CLI) -> list[dict[str, Any]]
Parameters
| Name | Type | Description |
|---|---|---|
cli |
CLI |
Returns
list[dict[str, Any]]
_get_prompt
2
dict[str, Any]
▼
Handle prompts/get by calling the prompt handler.
_get_prompt
2
dict[str, Any]
▼
def _get_prompt(cli: CLI, params: dict[str, Any]) -> dict[str, Any]
Parameters
| Name | Type | Description |
|---|---|---|
cli |
CLI |
|
params |
dict[str, Any] |
Returns
dict[str, Any]