Module

mcp

MCP server — expose CLI commands as tools via JSON-RPC on stdin/stdout.

Classes

_CLIHandler 8
MCPHandler implementation for a single CLI (leaf server).

MCPHandler implementation for a single CLI (leaf server).

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]
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]
Internal Methods 1
__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.
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…
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
_list_tools 1 list[dict[str, Any]]
Generate MCP tools/list response from all commands including groups. Group com…
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.

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…
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…
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.
def _call_tool(cli: CLI, params: dict[str, Any]) -> dict[str, Any]
Parameters
Name Type Description
cli CLI
params dict[str, Any]
Returns
dict[str, Any]
_list_resources 1 list[dict[str, Any]]
Generate MCP resources/list response from registered resources.
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.
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.
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.
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]