Skip to content

MCP OAuth: issuer mismatch on a trailing slash rejects a valid authorization server (regression since 2.0.3) #50036

Done

Description

@mustafa89

Description

Remote MCP servers whose authorization server has an issuer identifier ending in / fail to connect on 2.0.4+:

Issuer mismatch in authorization server metadata (RFC 8414 §3.3): expected "https://oauth.id.jumpcloud.com", received "https://oauth.id.jumpcloud.com/"

The protected resource metadata (RFC 9728) advertises the authorization server without a trailing slash. The authorization server's own metadata returns its issuer with one. Both forms resolve to the same metadata URL, because RFC 8414 §3.1 requires any terminating / to be removed before inserting the well-known path. So the two strings name the same issuer but fail the §3.3 equality check.

This is a regression. I have logs of the same config connecting on 2.0.1 (2026-09-18) and failing on 2.0.10 (2026-09-19); I have not bisected the releases in between. #48937 (MCP client rework for SDK v2) merged 2026-09-14, between 2.0.3 and 2.0.4, and looks like where the comparison was introduced.

oauth.auth_server_metadata_url from #49126 is not a workaround — it changes where the metadata is fetched from, not the comparison done afterwards. I tested it on 2.0.10 and the error is unchanged.

JumpCloud is publicly reproducible: both https://oauth.id.jumpcloud.com/.well-known/oauth-authorization-server and https://oauth.id.jumpcloud.com/.well-known/openid-configuration return "issuer": "https://oauth.id.jumpcloud.com/". An AWS Bedrock AgentCore gateway configured with a JumpCloud discovery URL publishes "authorization_servers": ["https://oauth.id.jumpcloud.com"], which is the pairing that triggers this.

Would it be reasonable to normalize a trailing slash when comparing issuer identifiers on the metadata path?

OpenCode version

2.0.10 (working on 2.0.1)

Steps to reproduce

  1. Configure a remote MCP server whose protected resource metadata lists "authorization_servers": ["https://oauth.id.jumpcloud.com"], with OAuth against that JumpCloud tenant.
  2. Run opencode mcp list.
  3. The server fails with the error above. opencode upgrade 2.0.1 and the same config connects.

Operating System

macOS 26.6.1 (arm64)

Terminal

ghostty

Activity

  1. cestercian commented on Sep 19, 2026

    @cestercian
    Contributor

    Taking this — will treat trailing-slash issuer mismatch as equivalent for MCP OAuth.

  2. opencodejr commented on Oct 28, 2026

    @opencodejr
    Contributor

    Thanks for the detailed report. I reproduced this.

    Setup:

    • A local mock MCP resource server that returns 401 and protected resource metadata with "authorization_servers": ["https://oauth.id.jumpcloud.com"] (no trailing slash).
    • The real JumpCloud authorization server, whose metadata returns "issuer": "https://oauth.id.jumpcloud.com/".
    • A remote MCP entry pointing at the mock, then opencode mcp list.

    Results:

    • 2.0.10: failed: Issuer mismatch in authorization server metadata (RFC 8414 §3.3): expected "https://oauth.id.jumpcloud.com", received "https://oauth.id.jumpcloud.com/"
    • 2.0.3: the same setup gets past discovery and shows needs authentication, which confirms the regression.
    • Latest dev (62ae125), run from source: still fails with the same error.

    The strict comparison is done inside the MCP client SDK that OpenCode switched to in 2.0.4. The script below reproduces it.

    Related:

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Repro for #50036: MCP OAuth issuer trailing-slash mismatch.
    # server.ts is a mock MCP resource server: every MCP request gets 401 + RFC 9728
    # metadata listing "https://oauth.id.jumpcloud.com" (no trailing slash). The REAL
    # JumpCloud AS metadata (fetched over the internet) returns issuer
    # "https://oauth.id.jumpcloud.com/".
    # Usage: ./repro.sh   (opencode on PATH)   |   OC_DEV=/path/to/checkout ./repro.sh
    set -u
    cd "$(dirname "$0")"
    bun server.ts > server.log 2>&1 &
    SRV=$!
    mkdir -p proj && cd proj
    export XDG_DATA_HOME=$(mktemp -d) XDG_CONFIG_HOME=$(mktemp -d) XDG_STATE_HOME=$(mktemp -d) XDG_CACHE_HOME=$(mktemp -d)
    cat > opencode.json <<'JSON'
    { "mcp": { "servers": { "agentcore": { "type": "remote", "url": "http://127.0.0.1:8765/mcp", "oauth": { "client_id": "test-client" } } } } }
    JSON
    if [ -n "${OC_DEV:-}" ]; then
      export BUN_OPTIONS="--conditions=browser --preload=$OC_DEV/packages/tui/node_modules/@opentui/solid/scripts/preload.js"
      OC=(bun "$OC_DEV/packages/cli/src/index.ts")
    else OC=(opencode); fi
    "${OC[@]}" --version
    if "${OC[@]}" mcp list --help 2>&1 | grep -q -- "--server"; then
      # Newer builds: run an explicit server so MCP servers have time to connect.
      export OPENCODE_PASSWORD=repro-pass
      "${OC[@]}" serve --hostname 127.0.0.1 --port 4599 > serve.log 2>&1 &
      OCS=$!; sleep 8
      for i in 1 2; do timeout 60 "${OC[@]}" mcp list --server http://127.0.0.1:4599 2>&1; sleep 3; done
    else
      # 2.0.10: uses the managed background service; the first call can race MCP startup.
      OCS=""
      for i in 1 2 3; do timeout 60 "${OC[@]}" mcp list 2>&1; sleep 3; done
    fi
    kill $OCS $SRV 2>/dev/null

    Run it: bash repro.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions