Create a transport-agnostic MCP message handler for a schema command bus.
Takes one parsed JSON-RPC 2.0 message, returns the reply object — or null
for notifications (messages without an id), which MUST NOT be answered.
Wire it to any transport: stdio (see serveMcpStdio), an HTTP POST
body, a WebSocket frame, or a test harness.
notifications/initialized — notification, no reply
ping — replies {}
tools/list — whitelisted schema actions as McpTools
tools/call — dispatches { target, payload } from params.arguments
through the bus; the CommandResult is serialized as a text content
block (result.value as JSON on success; error.message with
isError: true on failure — tool errors are results, not JSON-RPC errors)
anything else with an id — JSON-RPC error -32601 (method not found)
Origin stamping: install agentOrigin on the bus
(bus.use(agentOrigin(), { priority: 150 })) to stamp meta.origin='agent'
on MCP-driven dispatches. See agentOrigin for the concurrency
caveat on async buses.
Create a transport-agnostic MCP message handler for a schema command bus.
Takes one parsed JSON-RPC 2.0 message, returns the reply object — or
nullfor notifications (messages without anid), which MUST NOT be answered. Wire it to any transport: stdio (see serveMcpStdio), an HTTP POST body, a WebSocket frame, or a test harness.Protocol methods handled:
initialize— echoes the client'sprotocolVersion(or advertises'2025-06-18'), declarescapabilities: { tools: {} }notifications/initialized— notification, no replyping— replies{}tools/list— whitelisted schema actions as McpToolstools/call— dispatches{ target, payload }fromparams.argumentsthrough the bus; the CommandResult is serialized as a text content block (result.valueas JSON on success;error.messagewithisError: trueon failure — tool errors are results, not JSON-RPC errors)id— JSON-RPC error-32601(method not found)Origin stamping: install agentOrigin on the bus (
bus.use(agentOrigin(), { priority: 150 })) to stampmeta.origin='agent'on MCP-driven dispatches. See agentOrigin for the concurrency caveat on async buses.