`src/mcp/server.rs` — the MCP server side [feature: mcp]
Serve a ToolRegistry over MCP — your tools become usable by any MCP client. Exposes rmcp types deliberately (you’re embedding a real server).
Key items
McpServerAdapter::new(registry, context, server_name, server_version)—Clone; snapshot semantics (rebuild for a different tool set).serve_stdio(self)— the canonical interactive transport; the returnedRunningServicehas completed the handshake;.waiting()blocks until stdin closes; cancel via its token. Other transports:adapter.serve(transport)via rmcp’sServiceExt.
Behavior notes
- Advertises the tools capability only (no resources/prompts/sampling/logging; no
listChanged). list_toolsmaps every schema through the validation layer (see convert.rs) — invalid-schema tools are omitted with a warning, external$refs are refused (never fetched).call_tool: unknown name → MCPMETHOD_NOT_FOUNDnaming what is registered; everything the tool reports (soft error, hard failure, cancellation) is a tool-levelis_errorresult.- Cancellation drops in-flight tool futures — served tools must be cancellation-safe.
Deep dive: MCP.