This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
pnpm build # Compile TypeScript to JavaScript (tsup)
pnpm build:watch # Watch mode for development
pnpm check # Run prettier check + TypeScript type checking
pnpm lint-fix # Auto-fix formatting with prettier# After building, run the proxy
node dist/proxy.js <remote-server-url> [port] [options]
# Test client mode
node dist/client.js <remote-server-url> [options]# Build Docker image
docker build -t mcp-remote:latest .
# Run with Docker
docker run -it mcp-remote:latest https://remote.mcp.server/sse
# Run with docker-compose
docker-compose run mcp-remote https://remote.mcp.server/sse
# Run with persistent token storage
docker run -it -v mcp-auth:/home/mcp/.mcp-auth mcp-remote:latest https://remote.mcp.server/sseThis project acts as a bidirectional proxy between:
- Local stdio transport (used by Claude Desktop, Cursor, Windsurf)
- Remote HTTP/SSE transport with OAuth 2.0 authentication
-
proxy.ts: Main entry point that handles stdio ↔ remote communication
- Reads from stdin, writes to stdout
- Implements transport strategy pattern (http-first, sse-first, http-only, sse-only)
- Manages OAuth authentication flow when needed
-
client.ts: Standalone test client for debugging remote connections
- Useful for testing OAuth flows outside of MCP clients
- Run with
npx -p mcp-remote@latest mcp-remote-client <url>
-
lib/coordination.ts: OAuth flow orchestration
- Spins up temporary Express server for OAuth callbacks
- Handles authorization code exchange
- Manages browser opening for auth
-
lib/mcp-auth-config.ts: Token persistence and management
- Stores OAuth tokens in
~/.mcp-auth/ - Automatic token refresh
- Debug logging to
~/.mcp-auth/{server_hash}_debug.logwhen --debug flag is used
- Stores OAuth tokens in
-
lib/utils.ts: Core transport and connection logic
- Implements reconnection with exponential backoff
- Handles both HTTP and SSE transports
- Message proxying between transports
- If server requires auth, proxy intercepts auth error
- Spins up local Express server on configurable port (default: 3334)
- Opens browser for user authorization
- Receives callback with authorization code
- Exchanges code for tokens
- Stores tokens locally for reuse
- Automatically refreshes tokens when expired
- Default behavior: Try HTTP first, fall back to SSE
- Configurable via
--transportflag - Handles connection failures and retries gracefully
- No test suite exists - testing is manual via the client command
- Uses pnpm package manager (v10.11.0)
- TypeScript strict mode enabled
- ES modules output only
- Prettier formatting with 140 char lines, single quotes, no semicolons
- OAuth tokens stored in
~/.mcp-auth/(or$MCP_REMOTE_CONFIG_DIR) - Debug logs available with
--debugflag for troubleshooting auth issues