๐Ÿ”Œ MCP Bridge (STDIO โ†” SSE)

April 5, 2025 ยท View on GitHub

A lightweight bridge that connects Claude Desktop via STDIO to any MCP-compatible backend using SSE (Server-Sent Events).

This enables Claude to talk to modern MCP servers that expose an HTTP API using /sse and /messages, while Claude only supports STDIO.


๐Ÿ“ฆ Features

  • ๐ŸŒ‰ Bridges STDIO and SSE for full protocol compatibility
  • ๐Ÿ“จ Forwards all JSON-RPC requests to the backend
  • ๐Ÿ” Relays backend responses and events back to Claude
  • ๐Ÿ”ง Fully compatible with the Model Context Protocol (MCP)

๐Ÿ—‚๏ธ Folder Structure

mcp-bridge/
โ”œโ”€โ”€ cli.ts               # ๐Ÿง  Main entry point (runs the bridge logic)
โ”œโ”€โ”€ package.json         # ๐Ÿ“ฆ Project metadata and dependencies
โ”œโ”€โ”€ tsconfig.json        # โš™๏ธ TypeScript config
โ””โ”€โ”€ README.md            # ๐Ÿ“– Project documentation

๐Ÿš€ Usage

You can run the bridge manually:

npx mcp-bridge http://localhost:4000

Or make the script executable and run it:

chmod +x cli.ts
./cli.ts http://localhost:4000

Alternatively, configure it in your mcpServers:

{
    "mcpServers": {
        "mcp-hub": {
            "command": "npx",
            "args": ["mcp-bridge", "http://localhost:4000"]
        }
    }
}

โš™๏ธ Requirements

  • Node.js v18+ (must support fetch and top-level await)
  • TypeScript / tsx if using .ts directly

Your backend must implement:

  • GET /sse โ€” SSE endpoint for responses/events
  • POST /messages โ€” JSON-RPC POST endpoint for requests

๐Ÿง  How It Works

Claude Desktop
            โ”‚
            โ–ผ (STDIO)
[ MCP Bridge (cli.ts) ]
            โ”‚ (SSE + POST)
            โ–ผ
Your MCP Backend (McpServer)
  • Claude talks to the bridge over STDIO.
  • The bridge opens an SSE connection to your backend's /sse.
  • The bridge POSTs Claude's messages to /messages.
  • SSE responses are streamed back and passed to Claude via STDOUT.

๐Ÿงช Dev & Debugging

Install dependencies:

npm install

Run in dev mode:

npx tsx cli.ts http://localhost:4000

Enable verbose output:

DEBUG=1 npx tsx cli.ts http://localhost:4000

๐Ÿงฏ Troubleshooting

  • โŒ Permission denied โ†’ Run chmod +x cli.ts
  • โŒ Unknown file extension .ts โ†’ Make sure you're using tsx or ts-node
  • โŒ Claude can't connect โ†’ Check mcpServers config and stdout/stderr logs

Credits:

boilingdata/mcp-server-and-gw