Sets up a proxy between a server and a client
Starts a proxy that listens on a port and endpoint, and sends messages to the attached server via SSEServerTransport
Starts a proxy that listens on a port and endpoint, and sends messages to the attached server via StreamableHTTPServerTransport
Starts a proxy that listens on stdio, and sends messages to the attached SSE or streamable server
Taps into a transport and logs events
MCP Proxy provides a bridge between Model Context Protocol (MCP) servers that use stdio transport and clients that expect Server-Sent Events (SSE) or HTTP streaming. It enables seamless communication between different transport mechanisms, making it easier to integrate MCP servers with web applications. With built-in CORS support and flexible configuration options, MCP Proxy simplifies the development workflow for AI-powered applications.
MCP Proxy is a TypeScript utility that creates a proxy between MCP servers using stdio transport and clients that expect Server-Sent Events (SSE) or HTTP streaming. This makes it easier to integrate MCP servers with web applications and other clients that don't directly support stdio communication.
You can install MCP Proxy using npm:
npm install mcp-proxy
Or using other package managers:
pnpm add mcp-proxy
yarn add mcp-proxy
MCP Proxy can be used directly from the command line to quickly set up a proxy server:
npx mcp-proxy --port 8080 --endpoint /sse tsx server.js
This starts a server and stdio server (running tsx server.js
). The server listens on port 8080 and endpoint /sse
by default, and forwards messages to the stdio server.
Command-line options:
--port
: Specify the port to listen on (default: 8080)--endpoint
: Specify the endpoint to listen on (default: /sse
for SSE server, /stream
for stream server)--server
: Specify the server type to use (default: sse
)--debug
: Enable debug loggingThe Node.js SDK provides several utilities for creating a proxy:
The proxyServer
function sets up a proxy between a server and a client:
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/transports/index.js";
import { proxyServer } from "mcp-proxy";
const transport = new StdioClientTransport();
const client = new Client();
const server = new Server(serverVersion, {
capabilities: {},
});
proxyServer({
server,
client,
capabilities: {},
});
The startSSEServer
function starts a proxy that listens on a specified port and endpoint, sending messages to the attached server via SSEServerTransport
:
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { startSSEServer } from "mcp-proxy";
const { close } = await startSSEServer({
port: 8080,
endpoint: "/sse",
createServer: async () => {
return new Server();
},
});
// To close the server when done
close();
The startHTTPStreamServer
function starts a proxy that uses HTTP streaming:
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { startHTTPStreamServer, InMemoryEventStore } from "mcp-proxy";
const { close } = await startHTTPStreamServer({
port: 8080,
endpoint: "/stream",
createServer: async () => {
return new Server();
},
eventStore: new InMemoryEventStore(), // optional - you can provide your own event store
});
// To close the server when done
close();
The startStdioServer
function starts a proxy that listens on stdio and sends messages to an attached SSE or streamable server:
import { ServerType, startStdioServer } from "mcp-proxy";
await startStdioServer({
serverType: ServerType.SSE,
url: "http://127.0.0.1:3000/sse",
});
The tapTransport
function allows you to tap into a transport and log events:
import { tapTransport } from "mcp-proxy";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/transports/index.js";
const transport = tapTransport(new StdioClientTransport(), (event) => {
console.log(event);
});
If you encounter issues with the proxy:
--debug
flag when using the command-line interface