mcp-remote

repository·main·Indexed 23 days ago

https://github.com/geelen/mcp-remote

A remote proxy for the Model Context Protocol (MCP) that allows local-only clients (such as Claude Desktop, Cursor, and Windsurf) to connect to remote MCP servers via HTTP/SSE. It provides full support for OAuth authorization flows, including Protected Resource Metadata (RFC 9728) discovery, custom header configuration, and tool filtering via the --ignore-tool flag.

Tokens
6K
Snippets
13
Records
34
Agent score
81%

What's inside mcp-remote

  1. Run Multiple Instances of the Same Remote Server

    main

    To run multiple instances of the same remote server with different configurations (e.g., different Atlassian tenants), use the --resource flag. This isolates OAuth sessions so that each combination of server URL, resource, and custom headers maintains separate token storage.

    {
      "mcpServers": {
        "atlassian_tenant1": {
          "command": "npx",
          "args": [
            "mcp-remote",
            "https://mcp.atlassian.com/v1/sse",
            "--resource",
            "https://tenant1.atlassian.net/"
          ]
        },
        "atlassian_tenant2": {
          "command": "npx",
          "args": [
            "mcp-remote",
            "https://mcp.atlassian.com/v1/sse",
            "--resource",
            "https://tenant2.atlassian.net/"
          ]
        }
      }
    }
  2. Connect an MCP Client to a Remote MCP Server

    main

    Use mcp-remote to bridge MCP clients that only support local stdio transport (like Claude Desktop, Cursor, and Windsurf) to remote MCP servers using HTTP/SSE with OAuth support.

    To use it, add mcp-remote as a command in your client's MCP configuration file, passing the remote server's SSE URL as an argument.

    {
      "mcpServers": {
        "remote-example": {
          "command": "npx",
          "args": [
            "mcp-remote",
            "https://remote.mcp.server/sse"
          ]
        }
      }
    }
  3. Configure Custom Headers for Authentication

    main

    You can bypass authentication or emit custom headers (like Authorization) by using the --header flag.

    Workaround for Cursor and Claude Desktop (Windows): These clients may mangle spaces inside args when invoking npx. To avoid this, use a colon : without spaces in the argument and move the space-containing value into an environment variable.

    Standard usage:

    {
      "mcpServers": {
        "remote-example": {
          "command": "npx",
          "args": [
            "mcp-remote",
            "https://remote.mcp.server/sse",
            "--header",
            "Authorization: Bearer ${AUTH_TOKEN}"
          ],
          "env": {
            "AUTH_TOKEN": "..."
          }
        }
      }
    }

    Workaround usage (no spaces around :):

    {
      "args": [
        "mcp-remote",
        "https://remote.mcp.server/sse",
        "--header",
        "Authorization:${AUTH_HEADER}"
      ],
      "env": {
        "AUTH_HEADER": "Bearer <auth-token>"
      }
    }
  4. Setup Claude Desktop for mcp-remote

    main

    To add an MCP server to Claude Desktop, edit the configuration file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json

    If the file does not exist, you may need to enable it under Settings > Developer in Claude Desktop. Restart Claude Desktop after editing to see the hammer icon in the input box.

  5. Setup Cursor for mcp-remote

    main

    The configuration file for Cursor is located at ~/.cursor/mcp.json.

    Note: As of version 0.48.0, Cursor supports unauthenticated SSE servers directly. However, if your MCP server uses the official MCP OAuth authorization protocol, you must still use a "command" server configuration that calls mcp-remote.

  6. How mcp-remote handles OAuth discovery

    main

    The client uses Protected Resource Metadata (RFC 9728) to automatically discover the OAuth configuration of the remote MCP server.

    When connecting, the client:

    1. Probes the MCP server for the WWW-Authenticate header.
    2. Fetches the Protected Resource Metadata (PRM).
    3. Identifies the authorizationServerUrl and any supported scopes.

    If no Protected Resource Metadata is found, the client defaults to using the server's own URL as the authorization server.

  7. Understand the MCP Remote configuration file structure

    main

    MCP Remote uses a hashed file naming convention to isolate configurations for different servers. Files are stored in the configuration directory using the pattern {server_hash}_{filename}.

    Commonly used files include:

    • {server_hash}_client_info.json: Contains OAuth client registration details.
    • {server_hash}_tokens.json: Contains OAuth access and refresh tokens.
    • {server_hash}_code_verifier.txt: Contains the PKCE code verifier for the current OAuth flow.
    • {server_hash}_lock.json: A lockfile used to manage running server instances.
  8. How scope resolution works in NodeOAuthClientProvider

    main

    The NodeOAuthClientProvider determines the effectiveScope used in authorization requests using a specific priority hierarchy. This ensures that the most specific or recently provided scope requirements are honored:

    1. staticOAuthClientMetadata.scope: Highest priority; if provided in the constructor options.
    2. wwwAuthenticateScope: Scope provided via the WWW-Authenticate header.
    3. protectedResourceMetadata.scopes_supported: Scopes defined in the protected resource metadata (RFC 9728).
    4. clientInformation.scope: The scope returned during the client registration response.
    5. authorizationServerMetadata.scopes_supported: Scopes supported by the authorization server.
    6. Fallback: If no other scope is found, it defaults to 'openid email profile'.
  9. Run the mcp-remote client via CLI

    main

    The mcp-remote client is a command-line tool designed to connect to an MCP server using SSE (Server-Sent Events) with OAuth authentication.

    To run the client, use the following command structure:

    npx tsx client.ts <https://server-url> [callback-port] [--debug]

    Arguments

    • <https://server-url>: The URL of the remote MCP server.
    • [callback-port]: (Optional) The port to use for the OAuth callback. If not specified, an available port will be automatically selected.
    • --debug: (Optional) Enables debug logging.
    npx tsx client.ts https://example.remote/server [callback-port]
  10. Troubleshoot authentication and credential issues

    main

    If you experience persistent authentication issues, you can clear all locally stored credential information. mcp-remote stores credentials in ~/.mcp-auth by default, or in the directory specified by the MCP_REMOTE_CONFIG_DIR environment variable.

    To clear the credentials, run:

    rm -rf ~/.mcp-auth

    After clearing, restart your MCP client. If you encounter the specific error Authentication Error Token exchange failed: HTTP 400 at the /callback URL, clearing this directory is the recommended fix.

  11. Monitor Claude Desktop MCP logs

    main

    To view MCP logs in real-time for debugging, use the following commands based on your operating system:

    MacOS / Linux:

    tail -n 20 -F ~/Library/Logs/Claude/mcp*.log

    WSL (Bash):

    tail -n 20 -f "C:\Users\YourUsername\AppData\Local\Claude\Logs\mcp.log"

    Windows (PowerShell):

    Get-Content "C:\Users\YourUsername\AppData\Local\Claude\Logs\mcp.log" -Wait -Tail 20