MCP & Connectors

How do you configure standard input/output (stdio) transport for MCP?

QUICK ANSWER

To run an MCP server on stdio transport, connect it using StdioServerTransport from the SDK. The host process will spawn the server as a background process and communicate by reading and writing to its stdin/stdout streams.

Standard Implementation

import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const server = new Server(
  { name: "stdio-demo", version: "1.0.0" },
  { capabilities: {} }
);

// Connect process stdout and stdin stream channels
const transport = new StdioServerTransport();
await server.connect(transport);

Ensure your server does not print anything else to console.log during execution, as extra output on stdout will corrupt the JSON-RPC messaging frame. Use console.error for logging.

Verified against: MCP SDK v0.7.0