vapor-chamber API reference - v1.16.0
    Preparing search index...

    Function serveMcpStdio

    • Serve the bus as an MCP server over stdio (Node only): newline-delimited JSON-RPC 2.0 on process.stdin in, process.stdout out. This is the transport MCP clients like Claude Desktop spawn subprocess servers with.

      Unparseable lines get a JSON-RPC -32700 parse error; everything else is routed through createMcpHandler. Returns a stop() function that detaches from stdin.

      Two input-driven limits keep a hostile or broken client from growing memory without bound — see McpStdioOptions.maxLineLength and McpStdioOptions.maxInFlight.

      Replies are written in COMPLETION order, not arrival order: messages are dispatched concurrently, so a fast tool answers before a slow one issued earlier. That is deliberate and JSON-RPC-legal — responses may arrive in any order and id correlates them — and it is what keeps one slow tool call from blocking every reply queued behind it.

      IMPORTANT: while serving, do not console.log to stdout — it would corrupt the protocol stream. Log to stderr instead.

      Parameters

      Returns () => void

      // mcp-server.ts — spawned by an MCP client
      const bus = createSchemaCommandBus(schema);
      bus.use(agentOrigin(), { priority: 150 });
      registerHandlers(bus);
      const stop = serveMcpStdio(bus, { actions: ['cart*', 'productGet'] });
      process.on('SIGTERM', stop);