Skip to content

Remote servers & OAuth

Streamable HTTP and SSE

{
  "mcpServers": {
    "docs":   {"url": "https://example.com/mcp"},
    "keyed":  {"url": "https://api.example.com/mcp", "headers": {"Authorization": "Bearer ${API_KEY}"}},
    "legacy": {"type": "sse", "url": "https://example.com/sse"}
  }
}

An entry with a url and no type uses Streamable HTTP.

OAuth 2.1

Many hosted MCP servers (Linear, Atlassian, Notion, …) require users to sign in. Turn on OAuth for the server:

{"mcpServers": {"linear": {"url": "https://mcp.linear.app/mcp", "oauth": true}}}

On first use, codemode-mcp:

  1. discovers the authorization server from the MCP server's metadata (RFC 9728 / RFC 8414);
  2. registers itself with dynamic client registration if the server supports it;
  3. opens your browser at the sign-in page, and prints the URL to stderr in case it can't;
  4. receives the authorization code on http://localhost:33418/callback (PKCE, S256);
  5. stores the tokens in ~/.codemode-mcp/oauth/<server>-<hash>.json, with permissions 0600 where the OS supports them.

Later runs reuse the stored tokens and refresh them automatically, so the browser only opens again if access is revoked.

Sign in ahead of time

When codemode-mcp is started by a desktop client, it's convenient to sign in once from a terminal first:

codemode-mcp login linear -c mcp.json
codemode-mcp login linear -c mcp.json --logout   # forget the stored credentials

Pre-registered clients

If the provider gave you client credentials:

{
  "mcpServers": {
    "corp": {
      "url": "https://mcp.corp.example/mcp",
      "oauth": {
        "client_id": "abc123",
        "client_secret": "${CORP_CLIENT_SECRET}",
        "scopes": ["read", "write"],
        "redirect_port": 33418
      }
    }
  }
}

Register http://localhost:<redirect_port>/callback as the redirect URI with the provider.

OAuth option Default Description
client_id dynamic registration Pre-registered client ID
client_secret none (public client) Confidential-client secret (client_secret_post)
scopes server default List or space-separated string
redirect_port 33418 Port for the local callback server
client_name codemode-mcp Name shown on the consent screen (dynamic registration)

Headless machines

The callback needs a browser that can reach localhost on the machine running codemode-mcp. On a remote server, either:

  • run codemode-mcp login on your workstation and copy ~/.codemode-mcp/oauth/ across, or
  • forward the port with ssh -L 33418:localhost:33418 server, run login on the server, and open the printed URL locally.

Try it locally

The repository includes an OAuth-protected demo server with an auto-approving authorization server:

python examples/oauth_server.py 8811
{"mcpServers": {"secure": {"url": "http://127.0.0.1:8811/mcp", "oauth": true}}}
codemode-mcp run -c mcp.json "await secure.secret_note()"