MCP Now
mcp-proxy

mcp-proxy

by sparfenyuk
GitHub

Connect to MCP servers that run on SSE transport, or expose stdio servers as an SSE server.

server
sse
stdio
argument
command

mcp-proxy

GitHub License PyPI - Python Version PyPI - Downloads codecov smithery badge

About

The mcp-proxy is a tool that lets you switch between server transports. There are two supported modes:

  1. stdio to SSE
  2. SSE to stdio

1. stdio to SSE

Run a proxy server from stdio that connects to a remote SSE server.

This mode allows clients like Claude Desktop to communicate to a remote server over SSE even though it is not supported natively.

1graph LR 2 A["Claude Desktop"] <--> |stdio| B["mcp-proxy"] 3 B <--> |SSE| C["External MCP Server"] 4 5 style A fill:#ffe6f9,stroke:#333,color:black,stroke-width:2px 6 style B fill:#e6e6ff,stroke:#333,color:black,stroke-width:2px 7 style C fill:#e6ffe6,stroke:#333,color:black,stroke-width:2px

1.1 Configuration

This mode requires passing the URL to the MCP Server SSE endpoint as the first argument to the program.

Arguments

| Name | Required | Description | Example | | ---------------- | -------- | ------------------------------------------------ | --------------------------------------------- | | command_or_url | Yes | The MCP server SSE endpoint to connect to | http://example.io/sse | | --headers | No | Headers to use for the MCP server SSE connection | Authorization 'Bearer my-secret-access-token' |

Environment Variables

| Name | Required | Description | Example | | ------------------ | -------- | ---------------------------------------------------------------------------- | ---------- | | API_ACCESS_TOKEN | No | Can be used instead of --headers Authorization 'Bearer <API_ACCESS_TOKEN>' | YOUR_TOKEN |

1.2 Example usage

mcp-proxy is supposed to be started by the MCP Client, so the configuration must be done accordingly.

For Claude Desktop, the configuration entry can look like this:

1{ 2 "mcpServers": { 3 "mcp-proxy": { 4 "command": "mcp-proxy", 5 "args": ["http://example.io/sse"], 6 "env": { 7 "API_ACCESS_TOKEN": "access-token" 8 } 9 } 10 } 11}

2. SSE to stdio

Run a proxy server exposing a SSE server that connects to a local stdio server.

This allows remote connections to the local stdio server. The mcp-proxy opens a port to listen for SSE requests, spawns a local stdio server that handles MCP requests.

1graph LR 2 A["LLM Client"] <-->|SSE| B["mcp-proxy"] 3 B <-->|stdio| C["Local MCP Server"] 4 5 style A fill:#ffe6f9,stroke:#333,color:black,stroke-width:2px 6 style B fill:#e6e6ff,stroke:#333,color:black,stroke-width:2px 7 style C fill:#e6ffe6,stroke:#333,color:black,stroke-width:2px

2.1 Configuration

This mode requires the --sse-port argument to be set. The --sse-host argument can be set to specify the host IP address that the SSE server will listen on. Additional environment variables can be passed to the local stdio server using the --env argument. The command line arguments for the local stdio server must be passed after the -- separator.

Arguments

| Name | Required | Description | Example | | -------------------- | -------------------------- | ---------------------------------------------------------------- | --------------------- | | command_or_url | Yes | The command to spawn the MCP stdio server | uvx mcp-server-fetch | | --sse-port | No, random available | The SSE server port to listen on | 8080 | | --sse-host | No, 127.0.0.1 by default | The host IP address that the SSE server will listen on | 0.0.0.0 | | --env | No | Additional environment variables to pass to the MCP stdio server | FOO=BAR | | --pass-environment | No | Pass through all environment variables when spawning the server | --no-pass-environment | | --allow-origin | No | Pass through all environment variables when spawning the server | --allow-cors "*" |

2.2 Example usage

To start the mcp-proxy server that listens on port 8080 and connects to the local MCP server:

1# Start the MCP server behind the proxy 2mcp-proxy uvx mcp-server-fetch 3 4# Start the MCP server behind the proxy with a custom port 5mcp-proxy --sse-port=8080 uvx mcp-server-fetch 6 7# Start the MCP server behind the proxy with a custom host and port 8mcp-proxy --sse-host=0.0.0.0 --sse-port=8080 uvx mcp-server-fetch 9 10# Start the MCP server behind the proxy with a custom user agent 11# Note that the `--` separator is used to separate the `mcp-proxy` arguments from the `mcp-server-fetch` arguments 12mcp-proxy --sse-port=8080 -- uvx mcp-server-fetch --user-agent=YourUserAgent

This will start an MCP server that can be connected to at http://127.0.0.1:8080/sse

Installation

Installing via Smithery

To install MCP Proxy for Claude Desktop automatically via Smithery:

1npx -y @smithery/cli install mcp-proxy --client claude

Installing via PyPI

The stable version of the package is available on the PyPI repository. You can install it using the following command:

1# Option 1: With uv (recommended) 2uv tool install mcp-proxy 3 4# Option 2: With pipx (alternative) 5pipx install mcp-proxy

Once installed, you can run the server using the mcp-proxy command. See configuration options for each mode above.

Installing via Github repository (latest)

The latest version of the package can be installed from the git repository using the following command:

1uv tool install git+https://github.com/sparfenyuk/mcp-proxy

[!NOTE] If you have already installed the server, you can update it using uv tool upgrade --reinstall command.

[!NOTE] If you want to delete the server, use the uv tool uninstall mcp-proxy command.

Installing as container

Starting from version 0.3.2, it's possible to pull and run the corresponding container image:

1docker run -t ghcr.io/sparfenyuk/mcp-proxy:v0.3.2-alpine --help

Extending the container image

You can extend the mcp-proxy container image to include additional executables. For instance, uv is not included by default, but you can create a custom image with it:

1# file: mcp-proxy.Dockerfile 2 3FROM ghcr.io/sparfenyuk/mcp-proxy:latest 4 5# Install the 'uv' package 6RUN python3 -m ensurepip && pip install --no-cache-dir uv 7 8ENV PATH="/usr/local/bin:$PATH" \ 9 UV_PYTHON_PREFERENCE=only-system 10 11ENTRYPOINT [ "mcp-proxy" ]

Docker Compose Setup

With the custom Dockerfile, you can define a service in your Docker Compose file:

1services: 2 mcp-proxy-custom: 3 build: 4 context: . 5 dockerfile: mcp-proxy.Dockerfile 6 network_mode: host 7 restart: unless-stopped 8 ports: 9 - 8096:8096 10 command: "--pass-environment --sse-port=8096 --sse-host 0.0.0.0 uvx mcp-server-fetch"

[!NOTE] Don't forget to set --pass-environment argument, otherwise you'll end up with the error "No interpreter found in managed installations or search path"

Command line arguments

1usage: mcp-proxy [-h] [-H KEY VALUE] [-e KEY VALUE] [--pass-environment | --no-pass-environment] [--sse-port SSE_PORT] [--sse-host SSE_HOST] 2 [--allow-origin ALLOW_ORIGIN [ALLOW_ORIGIN ...]] 3 [command_or_url] [args ...] 4 5Start the MCP proxy in one of two possible modes: as an SSE or stdio client. 6 7positional arguments: 8 command_or_url Command or URL to connect to. When a URL, will run an SSE client, otherwise will run the given command and connect as a stdio client. See corresponding options for more details. 9 10options: 11 -h, --help show this help message and exit 12 13SSE client options: 14 -H KEY VALUE, --headers KEY VALUE 15 Headers to pass to the SSE server. Can be used multiple times. 16 17stdio client options: 18 args Any extra arguments to the command to spawn the server 19 -e KEY VALUE, --env KEY VALUE 20 Environment variables used when spawning the server. Can be used multiple times. 21 --pass-environment, --no-pass-environment 22 Pass through all environment variables when spawning the server. 23 24SSE server options: 25 --sse-port SSE_PORT Port to expose an SSE server on. Default is a random port 26 --sse-host SSE_HOST Host to expose an SSE server on. Default is 127.0.0.1 27 --allow-origin ALLOW_ORIGIN [ALLOW_ORIGIN ...] 28 Allowed origins for the SSE server. Can be used multiple times. Default is no CORS allowed. 29 30Examples: 31 mcp-proxy http://localhost:8080/sse 32 mcp-proxy --headers Authorization 'Bearer YOUR_TOKEN' http://localhost:8080/sse 33 mcp-proxy --sse-port 8080 -- your-command --arg1 value1 --arg2 value2 34 mcp-proxy your-command --sse-port 8080 -e KEY VALUE -e ANOTHER_KEY ANOTHER_VALUE 35 mcp-proxy your-command --sse-port 8080 --allow-origin='*'

Testing

Check the mcp-proxy server by running it with the mcp-server-fetch server. You can use the inspector tool to test the target server.

1# Run the stdio server called mcp-server-fetch behind the proxy over SSE 2mcp-proxy --sse-port=8080 uvx mcp-server-fetch & 3 4# Connect to the SSE proxy server spawned above using another instance of mcp-proxy given the URL of the SSE server 5mcp-proxy http://127.0.0.1:8080/sse 6 7# Send CTRL+C to stop the second server 8 9# Bring the first server to the foreground 10fg 11 12# Send CTRL+C to stop the first server