MCP代理服务器

一个将多个MCP服务器通过统一HTTP接口暴露给AI客户端的轻量级代理服务,支持多客户端共享常驻进程。

  • by wasikarn
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 wasikarn/mcp-proxy-server

使用说明

MCP Proxy Server

A lightweight stdio-to-HTTP proxy that exposes multiple MCP servers over a single HTTP endpoint using the Streamable HTTP transport. Built with Bun and the official MCP TypeScript SDK.

Why?

MCP clients like Claude Desktop and Claude Code normally spawn a separate stdio subprocess for each MCP server, per session. This proxy runs all backends once as long-lived processes and exposes them via HTTP — so multiple clients share the same server instances without duplicating processes.

┌─────────────────┐
│  Claude Desktop  │──┐
└─────────────────┘  │    ┌───────────────┐     ┌── stdio ── MCP Server A
┌─────────────────┐  ├───▶│  MCP Proxy    │─────┼── stdio ── MCP Server B
│  Claude Code    │──┤    │  (Bun HTTP)   │     └── stdio ── MCP Server C
└─────────────────┘  │    └───────────────┘
┌─────────────────┐  │     localhost:9802
│  Other Client   │──┘
└─────────────────┘

Requirements

Quick Start

# Clone
git clone https://github.com/wasikarn/mcp-proxy-server.git
cd mcp-proxy-server

# Install dependencies
bun install

# Configure
cp config.example.json config.json
cp .env.example .env
# Edit config.json to add your MCP servers

# Run
bun run start

Configuration

config.json

Define your MCP backend servers. Each server must have a command and optionally args and env:

{
  "servers": {
    "sequential-thinking": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-sequential-thinking@latest"]
    },
    "github": {
      "command": "github-mcp-server",
      "args": ["stdio"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_xxx"
      }
    }
  }
}

.env

PORT=9802

API Endpoints

Method Path Description
POST/GET /mcp/{server-name} MCP Streamable HTTP endpoint
GET /health Health check with server list
GET / List available servers

Management Scripts

The project includes a management script at scripts/mcp-proxy.sh:

# Using the script directly
./scripts/mcp-proxy.sh start
./scripts/mcp-proxy.sh stop
./scripts/mcp-proxy.sh restart
./scripts/mcp-proxy.sh status
./scripts/mcp-proxy.sh log

# Or via bun
bun run mcp:start
bun run mcp:status

The script manages the server as a background daemon with PID tracking at /tmp/mcp-proxy.pid and logs at /tmp/mcp-proxy.log.

Client Configuration

Claude Code

claude mcp add server-name \
  --transport http -s user \
  http://localhost:9802/mcp/server-name

Claude Desktop

In ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "server-name": {
      "command": "mcp-remote",
      "args": [
        "http://localhost:9802/mcp/server-name",
        "--allow-http"
      ]
    }
  }
}

Claude Desktop requires mcp-remote to bridge HTTP transport to stdio.

Development

bun run dev   # Watch mode with auto-reload

License

ISC