Stdio-to-HTTP gateway — connects MCP clients to remote HTTP MCP servers
Project description
mcp-stdio
English | 日本語
Stdio-to-HTTP gateway — connects MCP clients to remote HTTP MCP servers.
Overview
MCP clients like Claude Desktop and Claude Code see mcp-stdio as a locally running self-hosted MCP server, while it relays all requests to a remote MCP server with support for various authentication methods:
flowchart BT
A[Claude<br>Desktop/Code] <-- stdio --> B(mcp-stdio)
B <== "<b>HTTPS</b><br>Streamable HTTP / SSE<br>Bearer Token<br>Header<br>OAuth" ==> C[Remote<br>MCP Server]
B -. "OAuth 2.1<br>(PKCE)" .-> D[Authorization<br>Server]
D -. callback .-> B
style B fill:#4a5,stroke:#333,color:#fff
Bearer tokens, custom headers, and OAuth 2.1 credentials are forwarded to the remote server.
Features
- Both MCP transports supported — Streamable HTTP (current spec, default) and SSE (MCP 2024-11-05 legacy), selectable with
--transport. SSE parser follows the WHATWG Server-Sent Events spec. - OAuth 2.1 client — built-in authorization code flow with PKCE, dynamic client registration, token refresh, and secure token persistence. Implements the full MCP authorization spec at the section level:
- RFC 9728 Protected Resource Metadata
- §3 discovery of authorization servers via
/.well-known/oauth-protected-resource - §3.1 path-aware well-known URL construction for path-based reverse-proxy deployments, with host-root fallback; preserves the resource URL's query component on the constructed metadata URL
- §3.3
resourcefield validation — warn on mismatch, continue
- §3 discovery of authorization servers via
- RFC 8414 Authorization Server Metadata
- §3 well-known URL construction, including path insertion for issuers with path components
- §3
issuervalidation — warn on mismatch, continue
- RFC 8707 Resource Indicators
- §2
resourceparameter in authorization, token exchange, and refresh requests
- §2
- RFC 7636 PKCE
- §4.1–4.2 S256
code_challenge_methodwith a 96-charcode_verifier
- §4.1–4.2 S256
- RFC 7591 Dynamic Client Registration
- §3 client registration request (public client with
token_endpoint_auth_method: none) - §3.2.1
client_secret_expires_athandling — auto re-register on expiry
- §3 client registration request (public client with
- RFC 6750 Bearer Token usage
- §2.1
Authorization: Bearer <token>request header
- §2.1
- RFC 9728 Protected Resource Metadata
- Retry with backoff — retries up to 3 times on connection errors
- Streaming resilience — streams SSE responses in real time; auto-reconnects on mid-stream disconnect
- Session recovery — resets MCP session ID on 404 and retries
- Token refresh on 401 — automatically refreshes expired OAuth tokens mid-session
- Bearer token auth — via
--bearer-tokenflag orMCP_BEARER_TOKENenv var - Custom headers — pass any header with
-H/--header - Graceful shutdown — handles SIGTERM/SIGINT
- Proxy support — respects
HTTP_PROXY,HTTPS_PROXY,NO_PROXYenv vars via httpx - Minimal dependencies — only httpx; OAuth uses stdlib only
Install
pip install mcp-stdio
Or with uv:
uv tool install mcp-stdio
Or run directly without installing:
uvx mcp-stdio https://your-server.example.com:8080/mcp
Or with Homebrew:
brew install shigechika/tap/mcp-stdio
Quick Start
mcp-stdio https://your-server.example.com:8080/mcp
With Bearer token authentication:
# Recommended: use env var (token is hidden from `ps`)
MCP_BEARER_TOKEN=YOUR_TOKEN mcp-stdio https://your-server.example.com:8080/mcp
# Or pass directly (token is visible in `ps` output)
mcp-stdio https://your-server.example.com:8080/mcp --bearer-token YOUR_TOKEN
With custom headers:
mcp-stdio https://your-server.example.com:8080/mcp --header "X-API-Key: YOUR_KEY"
With OAuth 2.1 authentication (for servers that require it):
mcp-stdio --oauth https://your-server.example.com:8080/mcp
# With a pre-registered client ID (skips dynamic registration)
mcp-stdio --oauth --client-id YOUR_CLIENT_ID https://your-server.example.com:8080/mcp
For legacy MCP servers using the 2024-11-05 SSE transport:
mcp-stdio --transport sse https://your-server.example.com:8080/sse
Check connectivity before use:
mcp-stdio --check https://your-server.example.com:8080/mcp
Claude Desktop Configuration
Add to claude_desktop_config.json:
{
"mcpServers": {
"my-remote-server": {
"command": "mcp-stdio",
"args": ["https://your-server.example.com:8080/mcp"],
"env": {
"MCP_BEARER_TOKEN": "YOUR_TOKEN"
}
}
}
}
Config file locations:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Claude Code Configuration
claude mcp add my-remote-server \
-e MCP_BEARER_TOKEN=YOUR_TOKEN \
-- mcp-stdio https://your-server.example.com:8080/mcp
Usage
mcp-stdio [OPTIONS] URL
Arguments:
URL Remote MCP server URL
Options:
--bearer-token TOKEN Bearer token (or set MCP_BEARER_TOKEN env var)
--oauth Enable OAuth 2.1 authentication
--client-id ID Pre-registered OAuth client ID (or set MCP_OAUTH_CLIENT_ID)
--oauth-scope SCOPE OAuth scope to request
-H, --header 'Key: Value' Custom header (can be repeated)
--transport {streamable-http,sse}
Transport type (default: streamable-http)
--timeout-connect SEC Connection timeout (default: 10)
--timeout-read SEC Read timeout (default: 120)
--check Check connection and exit
-V, --version Show version
-h, --help Show help
Workarounds
Claude Code
Works around known issues in Claude Code's HTTP transport:
- Bearer token not sent — Claude Code ignores
Authorizationheader on tool calls (#28293, #33817) - Missing Accept header — servers return 406, misinterpreted as auth failure (#42470)
- OAuth fallback loop — Claude Code enters OAuth discovery even when not needed (#34008, #39271)
- Session lost after disconnect — mcp-stdio recovers MCP sessions automatically on 404 (#34498, #38631)
- OAuth scope omitted — Claude Code sends no
scopeparameter in authorization requests, causing strict OAuth servers to reject the flow (#4540); mcp-stdio sends scopes via--oauth-scope - Proxy settings ignored — Claude Code does not respect
NO_PROXY(#34804); mcp-stdio inherits proxy settings from httpx prompt=consentforced on every authorize request — Claude Code v2.1.109 hardcodesprompt=consenton the OAuth authorize URL, which blocks sign-in on Microsoft Entra ID tenants that disable user consent (a common enterprise policy) even when admin consent has already been granted tenant-wide (#49722); mcp-stdio omitsprompt=from the authorize request, letting the authorization server decide whether the consent UI is needed based on the existing consent statetools/listpagination ignored — Claude Code sends only the firsttools/listrequest and silently discardsnextCursor, so tools beyond page 1 are invisible (breaks MCP gateways and large tool catalogs) (#39586); mcp-stdio followsnextCursortransparently acrosstools/list,resources/list,resources/templates/list, andprompts/list, returning a single merged response- 403
insufficient_scopestep-up never runs — when an MCP server requires broader scopes for a specific tool and returns 403 with aWWW-Authenticate: Bearer error="insufficient_scope", scope="..."challenge, Claude Code only re-fetches Protected Resource Metadata and never requests a new token, so tiered-scope servers are unusable (#44652); mcp-stdio parses the challenge, runs an RFC 9470 step-up authorization with the union of cached and challenge scopes (reusing the cached client — no DCR retry), and retries the original call - OAuth discovery silently fails when
/.well-known/oauth-authorization-serverreturns 404 — Claude Code does not fall back to default endpoint paths when the authorization server publishes Protected Resource Metadata but no Authorization Server Metadata, leaving the OAuth flow dead with no browser prompt (e.g. Snowflake Cortex MCP) (#31349); mcp-stdio first tries the RFC 8414 §3 path-inserted URL, then the host-root, and finally falls back to default paths (/authorize,/token,/register) so the flow proceeds without manual endpoint configuration - Late response to a cancelled tool call drops the stdio transport — when Claude Code cancels a request via
notifications/cancelled, any late JSON-RPC response the server still sends for that id is treated as a framing error, the stdio transport is dropped, and the MCP server reconnects — each cycle costs 5–10 s and heavy cancel usage can put the server in a near-permanent reconnect loop. The MCP spec requires the canceller to silently ignore such responses (#51073); mcp-stdio tracks cancelled ids seen on stdin and drops any matching response on the wire before it reaches the downstream client, which also compensates for servers that violate the reciprocal receiver-side SHOULD (python-sdk#2480). Disable with--no-cancel-filteronly for debugging raw upstream traffic.
mcp-remote
- OAuth discovery fails for auth server with path — mcp-remote does not implement the RFC 8414 §3 path insertion rule, causing OAuth metadata discovery to fail when the authorization server URL contains a path component (e.g. multi-tenant or realm-based servers) (mcp-remote#207); mcp-stdio constructs the correct well-known metadata URL.
- OAuth discovery fails for MCP server behind path-based reverse proxy — when an MCP server is mounted under a sub-path (e.g. Tailscale serve, nginx
location /mcp/), Protected Resource Metadata must be fetched at/.well-known/oauth-protected-resource/{path}per RFC 9728 §3.1, not at the host root (mcp-remote#249); mcp-stdio tries the path-aware URL first and falls back to host-root for compatibility. - Re-authentication loop when both tokens are rejected — after long inactivity or server-side token revocation, mcp-remote receives the authorization code at the localhost callback but does not exchange it for new tokens, leaving the client looping on the login screen (mcp-remote#256); mcp-stdio clears the stale cache after a failed refresh and drives the full authorization flow through code exchange.
- SSE stream hangs forever on half-open TCP — long-running MCP tool calls over SSE can end up on a TCP connection that a proxy, NAT, or firewall silently drops; mcp-remote then blocks
iter_lines()/reader.read()indefinitely because the transport has no idle timeout and no socket keepalive (mcp-remote#107, mcp-remote#226, typescript-sdk#1883, python-sdk#796). mcp-stdio applies two layers: a 300-second application-level read timeout (--sse-read-timeout, matches the Python SDK default) that triggers the existing reconnect loop, and TCP keepalive on the httpx transport (60s idle + 4×15s probes ≈ 120s half-open detection on Linux / macOS / FreeBSD / NetBSD;SO_KEEPALIVEalone on Windows). Disable either with--sse-read-timeout 0or--no-tcp-keepalive. - Stale callback server causes EADDRINUSE on reconnect — mcp-remote caches the local OAuth callback port in a lockfile and crashes on the next invocation when a prior instance's listener is still bound (mcp-remote#253); mcp-stdio binds an ephemeral port via
("127.0.0.1", 0)for each authorization flow and releases it withserver_close()before returning — no lockfile, no stale bind, EADDRINUSE is structurally impossible. - Duplicate processes corrupt PKCE
code_verifier— when Claude Desktop spawns two concurrent mcp-remote processes for the same MCP server, both race through DCR + PKCE and overwrite each other'scode_verifieron disk, causingInvalid code_verifieron token exchange (mcp-remote#251); mcp-stdio keeps the PKCEcode_verifieras an in-memory local of the authorization function and never writes it to disk, so concurrent flows cannot corrupt each other's state. - HTTP 429 rate limiting not honoured — the MCP TypeScript SDK's
StreamableHTTPClientTransport(which mcp-remote uses) does not readRetry-Afteron a 429 response; it surfaces a generic error, so any client without its own retry logic fails fast on any rate-limited server (typescript-sdk#1892). mcp-stdio parsesRetry-After(RFC 7231 §7.1.3 — delta-seconds or HTTP-date), sleeps for that long up to a 60-second cap, and retries the request up toMAX_RETRIEStimes; a missing header falls back to the same exponential backoff used for transient errors, and an over-cap wait surfaces the 429 to the client so it can decide whether to retry later.
Windows
- CRLF translation on stdio — Python's default
TextIOWrapperrewrites\nto\r\non Windows, corrupting the NDJSON wire format used by MCP. mcp-stdio reconfiguressys.stdin/sys.stdoutto bare LF mode so messages stay spec-compliant regardless of host OS (cf. modelcontextprotocol/python-sdk#2433 for the same class of bug instdio_server).
How It Works
- If
--oauthis set, obtains an access token (cached → refresh → browser flow) - Reads JSON-RPC messages from stdin (sent by Claude Desktop/Code)
- Relays them over HTTPS to the remote MCP server
- Parses responses and writes them to stdout
- On 401, refreshes the OAuth token and retries
Transport details:
- Streamable HTTP (default) — each stdin message is a single POST; session state is tracked via the
Mcp-Session-Idheader and re-initialized automatically on 404. - SSE (MCP 2024-11-05 legacy) — a persistent
GETstream delivers responses and the initialendpointevent containing the POST URL; the stream auto-reconnects on disconnect.
OAuth tokens are stored in ~/.config/mcp-stdio/tokens.json (permissions 0600).
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_stdio-0.8.0.tar.gz.
File metadata
- Download URL: mcp_stdio-0.8.0.tar.gz
- Upload date:
- Size: 87.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0e3ea6647674037147843cddff7b6035840fe087692774a3329b988898d0dd11
|
|
| MD5 |
4145fa08300b89f1f4a7852dd2c5530f
|
|
| BLAKE2b-256 |
e64cd434535a1ae46a5442c36f631dca92e5f329c94389b69496058f92d6feb8
|
Provenance
The following attestation bundles were made for mcp_stdio-0.8.0.tar.gz:
Publisher:
release.yml on shigechika/mcp-stdio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_stdio-0.8.0.tar.gz -
Subject digest:
0e3ea6647674037147843cddff7b6035840fe087692774a3329b988898d0dd11 - Sigstore transparency entry: 1343314032
- Sigstore integration time:
-
Permalink:
shigechika/mcp-stdio@a4203d834b9657a1835766274d30f25a562e4782 -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/shigechika
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a4203d834b9657a1835766274d30f25a562e4782 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mcp_stdio-0.8.0-py3-none-any.whl.
File metadata
- Download URL: mcp_stdio-0.8.0-py3-none-any.whl
- Upload date:
- Size: 35.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ca621215699b2ab9e0e350a295209ce26130b425572349ffe6202f9b79d519a
|
|
| MD5 |
dd5a52195d5569f5bf1562d569ea0948
|
|
| BLAKE2b-256 |
dca58684ab15a47bc2c733d4306ed1e820d28cd0f955b3ee744e74d9ddfa966d
|
Provenance
The following attestation bundles were made for mcp_stdio-0.8.0-py3-none-any.whl:
Publisher:
release.yml on shigechika/mcp-stdio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mcp_stdio-0.8.0-py3-none-any.whl -
Subject digest:
7ca621215699b2ab9e0e350a295209ce26130b425572349ffe6202f9b79d519a - Sigstore transparency entry: 1343314042
- Sigstore integration time:
-
Permalink:
shigechika/mcp-stdio@a4203d834b9657a1835766274d30f25a562e4782 -
Branch / Tag:
refs/tags/v0.8.0 - Owner: https://github.com/shigechika
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a4203d834b9657a1835766274d30f25a562e4782 -
Trigger Event:
release
-
Statement type: