-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started
This page takes you from nothing to a working proxy wired into your MCP client.
-
Node.js 20+ (
node --version). - An OAuth2-protected MCP server speaking the Streamable HTTP MCP transport.
- An OAuth2 client registered with your identity provider (IdP). For the
interactive flow, register
http://127.0.0.1:53682/callbackas a redirect URI (or whatever you setOAUTH2_CALLBACK_PORTto).
You don't need to install anything — MCP clients can launch the proxy directly
via npx:
npx -y mcp-oauth2-proxyFor development against a local checkout:
git clone https://github.com/ChengleiYuan/mcp-oauth2-proxy.git
cd mcp-oauth2-proxy
npm install
npm run buildUPSTREAM_URL=https://mcp.example.com/mcp \
OAUTH2_GRANT=authorization_code \
OAUTH2_CLIENT_ID=<your-client-id> \
npx -y mcp-oauth2-proxyOn first launch the proxy:
- Discovers
token_endpointandauthorization_endpointfrom the upstream (RFC 9728 + RFC 8414 — see Discovery). - Opens your default browser at the IdP authorization endpoint with a PKCE S256 challenge.
- Captures the authorization code on
http://127.0.0.1:53682/callback. - Persists the refresh token under the OS user config dir, encrypted at rest.
- Starts the MCP stdio bridge.
Subsequent launches reuse the cached refresh token silently — no browser, no prompts. For the mechanics, see OAuth2 Grants and Tokens.
For service-to-service use where no human is present, use the
client_credentials grant:
UPSTREAM_URL=https://mcp.example.com/mcp \
OAUTH2_GRANT=client_credentials \
OAUTH2_TOKEN_URL=https://idp.example.com/oauth2/token \
OAUTH2_CLIENT_ID=my-service \
OAUTH2_CLIENT_SECRET='…' \
OAUTH2_SCOPE='mcp:read mcp:write' \
npx -y mcp-oauth2-proxyMost MCP clients accept a JSON server definition. Point command at npx and
pass configuration through env:
On Windows hosts that don't resolve .cmd shims (so command: "npx" fails to
start), use the explicit form:
{
"command": "cmd",
"args": ["/c", "npx", "-y", "mcp-oauth2-proxy"]
}Paths in the env block must be absolute and use forward slashes on every
platform.
- Tune behavior in Configuration.
- Understand token caching and refresh in OAuth2 Grants and Tokens.
- Running on a remote machine? See Remote Hosts (SSH Port Forwarding).
- Hitting a snag? See Troubleshooting.
GitHub repo · npm package · Licensed under MIT
Overview
Guides
- Getting Started
- Configuration
- OAuth2 Grants and Tokens
- Discovery
- Security
- Remote Hosts (SSH Port Forwarding)
- Troubleshooting
Internals
{ "mcpServers": { "remote-oauth2-mcp": { "command": "npx", "args": ["-y", "mcp-oauth2-proxy"], "env": { "UPSTREAM_URL": "https://mcp.example.com/mcp", "OAUTH2_GRANT": "authorization_code", "OAUTH2_CLIENT_ID": "<your-client-id>" } } } }