MCP TypeScript SDK (V2) / @modelcontextprotocol/server / server/serveStdio
server/serveStdio
Interfaces
ServeStdioOptions
Defined in: packages/server/src/server/serveStdio.ts:85
Options for serveStdio.
Properties
legacy?
optionallegacy?:"reject"|"serve"
Defined in: packages/server/src/server/serveStdio.ts:98
How a 2025-era opening (an initialize request, or any claim-less message) is handled:
'serve'(default) — the connection is pinned to a 2025-era instance from the same factory and served exactly as a hand-wired stdio server serves it today.'reject'— the opening request is answered with the unsupported-protocol-version error naming the supported modern revisions (claim-less notifications are dropped); the connection stays open for a modern opening.
maxSubscriptions?
optionalmaxSubscriptions?:number
Defined in: packages/server/src/server/serveStdio.ts:116
Reject a new subscriptions/listen with -32603 'Subscription limit reached' (in-band, before the ack) when this many subscriptions are already open on this connection.
Default
1024onerror?
optionalonerror?: (error) =>void
Defined in: packages/server/src/server/serveStdio.ts:109
Callback for out-of-band errors (reporting only; it never alters what is written to the wire).
Parameters
error
Error
Returns
void
transport?
optionaltransport?:Transport
Defined in: packages/server/src/server/serveStdio.ts:107
Bring your own transport (for example a StdioServerTransport constructed over a Unix domain socket or TCP stream, per the stdio binding's custom-transport guidance). Defaults to a StdioServerTransport over the current process's stdio. The entry owns the transport: it starts it, receives every inbound message, and closes it when the connection ends.
StdioServerHandle
Defined in: packages/server/src/server/serveStdio.ts:120
The handle returned by serveStdio.
Methods
close()
close():
Promise<void>
Defined in: packages/server/src/server/serveStdio.ts:122
Tears the connection down: closes the pinned instance (if any) and the underlying transport.
Returns
Promise<void>
Functions
serveStdio()
serveStdio(
factory,options?):StdioServerHandle
Defined in: packages/server/src/server/serveStdio.ts:375
Serves MCP over stdio from a server factory, owning the era decision for the connection: the opening exchange selects the era, ONE instance from the factory is pinned for the connection lifetime, and everything after passes straight through to it. See the module documentation for the opening rules.
import { serveStdio } from '@modelcontextprotocol/server/stdio';
serveStdio(() => {
const server = new McpServer({ name: 'my-server', version: '1.0.0' }, { capabilities: { tools: {} } });
// register tools/resources/prompts once — the same factory serves both eras
return server;
});Parameters
factory
options?
ServeStdioOptions = {}