ClaudeCode.MCP.Router (ClaudeCode v0.20.0)
View SourceDispatches JSONRPC requests to in-process MCP tool server modules.
Handles the MCP protocol methods (initialize, tools/list, tools/call)
by routing to the appropriate tool module's execute/2 callback.
This module is called by the adapter when it receives an mcp_message
control request from the CLI for a type: "sdk" server.
Summary
Functions
Handles a JSONRPC request for the given tool server module.
Functions
Handles a JSONRPC request for the given tool server module.
Returns a JSONRPC response map ready for JSON encoding.
Parameters
server_module- A module that usesClaudeCode.MCP.Serverand exports__tool_server__/0message- A decoded JSONRPC request map with"method"keyassigns- Optional map of assigns to set on the Hermes frame (available to tools that defineexecute/2)
Supported Methods
"initialize"- Returns protocol version, capabilities, and server info"notifications/initialized"- Acknowledges initialization (returns empty result)"tools/list"- Returns all registered tools with their schemas"tools/call"- Dispatches to the named tool'sexecute/2callback
Examples
iex> message = %{"jsonrpc" => "2.0", "id" => 1, "method" => "initialize", "params" => %{}}
iex> Router.handle_request(MyApp.Tools, message)
%{"jsonrpc" => "2.0", "id" => 1, "result" => %{"protocolVersion" => "2024-11-05", ...}}