basalt / mcp-core/src / serveStdio
Function: serveStdio()
> serveStdio(server, options?): StdioHandle
Defined in: mcp-core/src/stdio.ts:100
Serve MCP over stdio — newline-delimited JSON-RPC on stdin/stdout, the transport local agents (Claude Desktop, IDEs) speak. Pure Node streams; no SDK.
- The byte stream is decoded with a
StringDecoder, so a multibyte character split across two chunks is reassembled, never turned into U+FFFD. - A line longer than
maxLineLengthis dropped (with an error reply) instead of growing the buffer without bound. - JSON-RPC batches (arrays) are accepted, as protocol revision 2025-03-26 requires.
- The transport supplies a
notifycallback so the dispatcher can push server→client notifications (progress) back on the same stream. - When the client announced the
elicitationcapability ininitialize, tools receive anelicit(prompt)that sends anelicitation/createrequest and resolvestrueonly when the user accepted withconfirm: true. Without the capability,elicitis absent — callers that need a confirmation must fail closed. - Each stream is its own session: a
notifications/cancelledarriving here only reaches calls started on this stream.
Parameters
server
options?
ServeStdioOptions = {}