A TypeScript streamable HTTP and SSE proxy for MCP servers that use stdio transport.
Note
CORS is enabled by default.
Note
For a Python implementation, see mcp-proxy.
Note
MCP Proxy is what FastMCP uses to enable streamable HTTP and SSE.
npm install mcp-proxynpx mcp-proxy --port 8080 --shell tsx server.jsThis starts a server and stdio server (tsx server.js). The server listens on port 8080 and /stream (streamable HTTP) and /sse (SSE) endpoints, and forwards messages to the stdio server.
options:
--server: Set tosseorstreamto only enable the respective transport (default: both)--endpoint: Ifserveris set tosseorstream, this option sets the endpoint path (default:/sseor/stream)--sseEndpoint: Set the SSE endpoint path (default:/sse). Overrides--endpointifserveris set tosse.--streamEndpoint: Set the streamable HTTP endpoint path (default:/stream). Overrides--endpointifserveris set tostream.--port: Specify the port to listen on (default: 8080)--debug: Enable debug logging--shell: Spawn the server via the user's shell
Note
Any arguments starting with - after <command> are parsed as mcp-proxy
options. Insert -- before such arguments to pass them to the wrapped
command. For example:
npx mcp-proxy --port 8080 --shell npx -- -y some-packageThe Node.js SDK provides several utilities that are used to create a proxy.
Sets up a proxy between a server and a client.
const transport = new StdioClientTransport();
const client = new Client();
const server = new Server(serverVersion, {
capabilities: {},
});
proxyServer({
server,
client,
capabilities: {},
});In this example, the server will proxy all requests to the client and vice versa.
Starts a proxy that listens on a port, and sends messages to the attached server via StreamableHTTPServerTransport and SSEServerTransport.
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { startHTTPServer } from "mcp-proxy";
const { close } = await startHTTPServer({
createServer: async () => {
return new Server();
},
eventStore: new InMemoryEventStore(),
port: 8080,
});
close();Starts a proxy that listens on a stdio, and sends messages to the attached sse or streamable server.
import { ServerType, startStdioServer } from "./startStdioServer.js";
await startStdioServer({
serverType: ServerType.SSE,
url: "http://127.0.0.1:8080/sse",
});Taps into a transport and logs events.
import { tapTransport } from "mcp-proxy";
const transport = tapTransport(new StdioClientTransport(), (event) => {
console.log(event);
});