Skip to main content

A MCP server which proxies requests to a remote MCP server over SSE transport.

Project description

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/StreamableHTTP
  2. SSE to stdio

1. stdio to SSE/StreamableHTTP

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.

graph LR
    A["Claude Desktop"] <--> |stdio| B["mcp-proxy"]
    B <--> |SSE| C["External MCP Server"]

    style A fill:#ffe6f9,stroke:#333,color:black,stroke-width:2px
    style B fill:#e6e6ff,stroke:#333,color:black,stroke-width:2px
    style C fill:#e6ffe6,stroke:#333,color:black,stroke-width:2px

1.1 Configuration

This mode requires providing the URL of the MCP Server's SSE endpoint as the program’s first argument. If the server uses Streamable HTTP transport, make sure to enforce it on the mcp-proxy side by passing --transport=streamablehttp.

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'
--transport No Decides which transport protocol to use when connecting to an MCP server. Can be either 'sse' or 'streamablehttp' streamablehttp

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:

{
  "mcpServers": {
    "mcp-proxy": {
      "command": "mcp-proxy",
      "args": [
        "http://example.io/sse"
      ],
      "env": {
        "API_ACCESS_TOKEN": "access-token"
      }
    }
  }
}

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.

graph LR
    A["LLM Client"] <-->|SSE| B["mcp-proxy"]
    B <-->|stdio| C["Local MCP Server"]

    style A fill:#ffe6f9,stroke:#333,color:black,stroke-width:2px
    style B fill:#e6e6ff,stroke:#333,color:black,stroke-width:2px
    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
--port No, random available The MCP server port to listen on 8080
--host No, 127.0.0.1 by default The host IP address that the MCP server will listen on 0.0.0.0
--env No Additional environment variables to pass to the MCP stdio server. Can be used multiple times. FOO BAR
--cwd No The working directory to pass to the MCP stdio server process. /tmp
--pass-environment No Pass through all environment variables when spawning the server --no-pass-environment
--allow-origin No Allowed origins for the SSE server. Can be used multiple times. Default is no CORS allowed. --allow-cors "*"
--stateless No Enable stateless mode for streamable http transports. Default is False --no-stateless
--sse-port (deprecated) No, random available The SSE server port to listen on 8080
--sse-host (deprecated) No, 127.0.0.1 by default The host IP address that the SSE server will listen on 0.0.0.0

2.2 Example usage

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

# Start the MCP server behind the proxy
mcp-proxy uvx mcp-server-fetch

# Start the MCP server behind the proxy with a custom port
# (deprecated) mcp-proxy --sse-port=8080 uvx mcp-server-fetch
mcp-proxy --port=8080 uvx mcp-server-fetch

# Start the MCP server behind the proxy with a custom host and port
# (deprecated) mcp-proxy --sse-host=0.0.0.0 --sse-port=8080 uvx mcp-server-fetch
mcp-proxy --host=0.0.0.0 --port=8080 uvx mcp-server-fetch

# Start the MCP server behind the proxy with a custom user agent
# Note that the `--` separator is used to separate the `mcp-proxy` arguments from the `mcp-server-fetch` arguments
# (deprecated) mcp-proxy --sse-port=8080 -- uvx mcp-server-fetch --user-agent=YourUserAgent
mcp-proxy --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 via SSE, or http://127.0.0.1:8080/mcp/ via StreamableHttp

Installation

Installing via Smithery

To install MCP Proxy for Claude Desktop automatically via Smithery:

npx -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:

# Option 1: With uv (recommended)
uv tool install mcp-proxy

# Option 2: With pipx (alternative)
pipx 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:

uv 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:

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

Troubleshooting

  • Problem: Claude Desktop can't start the server: ENOENT code in the logs

    Solution: Try to use the full path to the binary. To do so, open a terminal and run the commandwhere mcp-proxy ( macOS, Linux) or where.exe mcp-proxy (Windows). Then, use the output path as a value for 'command' attribute:

      "fetch": {
        "command": "/full/path/to/bin/mcp-proxy",
        "args": [
          "http://localhost:8932/sse"
        ]
      }
    

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:

# file: mcp-proxy.Dockerfile

FROM ghcr.io/sparfenyuk/mcp-proxy:latest

# Install the 'uv' package
RUN python3 -m ensurepip && pip install --no-cache-dir uv

ENV PATH="/usr/local/bin:$PATH" \
    UV_PYTHON_PREFERENCE=only-system

ENTRYPOINT [ "mcp-proxy" ]

Docker Compose Setup

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

services:
  mcp-proxy-custom:
    build:
      context: .
      dockerfile: mcp-proxy.Dockerfile
    network_mode: host
    restart: unless-stopped
    ports:
      - 8096:8096
    command: "--pass-environment --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

usage: mcp-proxy [-h] [-H KEY VALUE] [--transport {sse,streamablehttp}] [-e KEY VALUE] [--cwd CWD] [--pass-environment | --no-pass-environment]
                 [--debug | --no-debug] [--port PORT] [--host HOST] [--stateless | --no-stateless] [--sse-port SSE_PORT] [--sse-host SSE_HOST]
                 [--allow-origin ALLOW_ORIGIN [ALLOW_ORIGIN ...]]
                 [command_or_url] [args ...]

Start the MCP proxy in one of two possible modes: as a client or a server.

positional arguments:
  command_or_url        Command or URL to connect to. When a URL, will run an SSE/StreamableHTTP client, otherwise will run the given command and connect as a stdio client. See corresponding options for more details.

options:
  -h, --help            show this help message and exit

SSE/StreamableHTTP client options:
  -H, --headers KEY VALUE
                        Headers to pass to the SSE server. Can be used multiple times.
  --transport {sse,streamablehttp}
                        The transport to use for the client. Default is SSE.

stdio client options:
  args                  Any extra arguments to the command to spawn the server
  -e, --env KEY VALUE   Environment variables used when spawning the server. Can be used multiple times.
  --cwd CWD             The working directory to use when spawning the process.
  --pass-environment, --no-pass-environment
                        Pass through all environment variables when spawning the server.
  --debug, --no-debug   Enable debug mode with detailed logging output.

SSE server options:
  --port PORT           Port to expose an SSE server on. Default is a random port
  --host HOST           Host to expose an SSE server on. Default is 127.0.0.1
  --stateless, --no-stateless
                        Enable stateless mode for streamable http transports. Default is False
  --sse-port SSE_PORT   (deprecated) Same as --port
  --sse-host SSE_HOST   (deprecated) Same as --host
  --allow-origin ALLOW_ORIGIN [ALLOW_ORIGIN ...]
                        Allowed origins for the SSE server. Can be used multiple times. Default is no CORS allowed.

Examples:
  mcp-proxy http://localhost:8080/sse
  mcp-proxy --transport streamablehttp http://localhost:8080/mcp
  mcp-proxy --headers Authorization 'Bearer YOUR_TOKEN' http://localhost:8080/sse
  mcp-proxy --port 8080 -- your-command --arg1 value1 --arg2 value2
  mcp-proxy your-command --port 8080 -e KEY VALUE -e ANOTHER_KEY ANOTHER_VALUE
  mcp-proxy your-command --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.

# Run the stdio server called mcp-server-fetch behind the proxy over SSE
mcp-proxy --port=8080 uvx mcp-server-fetch &

# Connect to the SSE proxy server spawned above using another instance of mcp-proxy given the URL of the SSE server
mcp-proxy http://127.0.0.1:8080/sse

# Send CTRL+C to stop the second server

# Bring the first server to the foreground
fg

# Send CTRL+C to stop the first server

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_proxy-0.7.0.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_proxy-0.7.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file mcp_proxy-0.7.0.tar.gz.

File metadata

  • Download URL: mcp_proxy-0.7.0.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for mcp_proxy-0.7.0.tar.gz
Algorithm Hash digest
SHA256 4e34ce5c417e5d2e0cbccb7968d0f74f23bf074a03fdb143f0511cdfe489b1c7
MD5 a88ba923e0025de8a7879bf30957405a
BLAKE2b-256 475b651c4f52c32179ca1a0360c926ee6395f8e97277d5ae99cca01b171c93ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_proxy-0.7.0.tar.gz:

Publisher: ci.yaml on sparfenyuk/mcp-proxy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcp_proxy-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_proxy-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for mcp_proxy-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f0bc7227f8a219fcd3079e1650b91920448fa9fd5ffe771ecdd091d92b94abe
MD5 3f5c3165d0b6a1f8ee5647de0d892f79
BLAKE2b-256 18e6834cbb631ee0f97041c3056c8a90718bccf4e971baa0be3c595a648a57a5

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_proxy-0.7.0-py3-none-any.whl:

Publisher: ci.yaml on sparfenyuk/mcp-proxy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page