part…
Building governance for MCP?
The gateway applies what the guide teaches: policies on discovery, invocation and authorisation.
The gateway applies what the guide teaches: policies on discovery, invocation and authorisation.
In the stdio transport the client launches the server as a subprocess and the two communicate over the standard streams. It is the transport for local servers and, according to the spec, clients SHOULD support it whenever they can.
stdin and writes JSON-RPC to stdout.stderr for any kind of logging (info, debug, error).stderr and SHOULD NOT assume its output indicates an error.stdout that is not a valid MCP message.stdin that is not a valid MCP message.A forgotten console.log in the server breaks the protocol: it is the most common failure in stdio servers.
Client → stdin: requests and notifications; it MUST NOT write responses.
Server → stdout, three classes of message that the client must demultiplex:
id.notifications/progress, notifications/message), by progressToken or context.subscriptions/listen, by _meta["io.modelcontextprotocol/subscriptionId"] (the client MUST use it to correlate).The server MUST NOT write JSON-RPC requests: server→client interactions go in InputRequiredResult.
Everything travels inline in the body's _meta; there is no header layer. Consequently there is no Mcp-Method, MCP-Protocol-Version or x-mcp-header (stdio clients MAY ignore that annotation).
notifications/cancelled with the requestId; there is no per-request stream to close. The server SHOULD stop as soon as possible and MUST NOT send further messages for that request.
The client SHOULD:
SIGTERM and then SIGKILL; Windows: TerminateProcess or Job Objects).Servers SHOULD exit promptly when stdin closes: it is the portable signal for an orderly shutdown. The server MAY initiate shutdown by closing its stdout and exiting.
If the process dies, the client SHOULD restart it. Since the protocol is stateless, in-flight requests are simply lost and can be retried against the new process; listen subscriptions must be re-established.
A dual-era client SHOULD probe with server/discover before any other request (lesson 4.4). The probe against a legacy server may go unanswered: set a timeout.
The framing (one JSON-RPC line per message over a reliable bidirectional byte stream) works just the same over Unix sockets, TCP or other channels. Custom transports built on them SHOULD reuse the framing and rules; only launching, stderr, shutdown-on-close and restart need equivalents.
A stdio client and server share the same trust domain: the server already has code execution on the machine. The real decisions are made before launching (provenance, pinned version) and in how it is launched (container, no mounts, no network, per-server credentials). OAuth authorisation SHOULD NOT be applied; credentials via the environment (lesson 3.7, Part 10).
stderr captured into the audit log (without assuming it is an error), shutdown timeouts and restart with a bounded number of attempts.1. What may a stdio server write to stderr?
stderr is free for any logging; the client must not interpret it as an error.
2. How is a request cancelled over stdio?
There is no per-request stream; the notification is used.
3. What is the portable signal for an orderly shutdown of a stdio server?
The client closes stdin; the server must exit promptly; force (SIGTERM/SIGKILL) is plan B.
4. What must a client do if the server process dies unexpectedly?
Thanks to statelessness, restarting is safe.