Skip to content

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 maxLineLength is 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 notify callback so the dispatcher can push server→client notifications (progress) back on the same stream.
  • When the client announced the elicitation capability in initialize, tools receive an elicit(prompt) that sends an elicitation/create request and resolves true only when the user accepted with confirm: true. Without the capability, elicit is absent — callers that need a confirmation must fail closed.
  • Each stream is its own session: a notifications/cancelled arriving here only reaches calls started on this stream.

Parameters ​

server ​

StdioServerLike

options? ​

ServeStdioOptions = {}

Returns ​

StdioHandle

Released under the MIT License.