Skip to content

auth: remote MCP OAuth fails with issuer mismatch for Microsoft Entra organizations tenant #64854

Open

Description

@viliamr

Summary

Remote MCP servers that use Microsoft Entra ID (login.microsoftonline.com/organizations/v2.0) fail OAuth sign-in with an issuer mismatch error. Microsoft's metadata returns the issuer with a {tenantid} placeholder, but opencode expects the literal organizations value, so the sign-in can't complete and the server can't connect.

Environment

  • opencode version: 2.2.6
  • OS: Windows 10/11 (win32 x64)
  • Shell: Windows PowerShell / cmd
  • Install/channel: latest
  • Active plugins: [email protected]

Reproduction

  1. Add a remote MCP server that uses the Microsoft Entra authorization server, for example:

    "powerbi": {
      "type": "remote",
      "url": "https://api.fabric.microsoft.com/v1/mcp/powerbi",
      "oauth": {
        "client_id": "<entra app client id>",
        "callback_port": 19876,
        "redirect_uri": "http://127.0.0.1:19876/callback"
      }
    }
  2. Run /mcps in opencode, select powerbi, and start sign-in.

  3. Sign-in fails with:

    Issuer mismatch in authorization server metadata (RFC 8414 §3.3): expected "https://login.microsoftonline.com/organizations/v2.0", received "https://login.microsoftonline.com/{tenantid}/v2.0"

  4. The same error occurs for https://fabriciq.svc.cloud.microsoft/v1/mcp/fabriciq.

Expected Behavior

Sign-in completes. organizations is a valid multi-tenant Entra authorization server, and the metadata Microsoft returns is the documented one.

Actual Behavior

opencode rejects the authorization server metadata during the RFC 8414 issuer check, and the server stays disconnected.

Additional Context

  • The protected resource metadata for fabriciq.svc.cloud.microsoft lists https://login.microsoftonline.com/organizations/v2.0 as the authorization server.
  • https://login.microsoftonline.com/organizations/v2.0/.well-known/openid-configuration returns "issuer": "https://login.microsoftonline.com/{tenantid}/v2.0".
  • Setting oauth.client_id, callback_port and redirect_uri does not change the error.
  • Reproduced consistently.

Activity

  1. added
    area/mcp
    type/bug
    version/v2
    on Nov 19, 2026
  2. opencodejr commented on Nov 19, 2026

    @opencodejr
    Contributor

    Thanks for the clear report. I reproduced this on 2.2.6 against the real Fabric IQ MCP endpoint and Microsoft's real Entra metadata, with nothing mocked:

    1. Configure a remote MCP server at https://fabriciq.svc.cloud.microsoft/v1/mcp/fabriciq with an oauth block (client_id, callback_port: 19876, redirect_uri).
    2. Run opencode mcp list and opencode mcp auth fabriciq.

    Both fail with:

    Issuer mismatch in authorization server metadata (RFC 8414 §3.3): expected "https://login.microsoftonline.com/organizations/v2.0", received "https://login.microsoftonline.com/{tenantid}/v2.0"
    

    It still happens on the latest dev (d33b578). There, mcp list shows the server as needing authentication, but mcp auth fails with the same error before the browser sign-in starts. The script below reproduces it.

    The check is done by the MCP client SDK during authorization server discovery. Microsoft's multi-tenant metadata uses a {tenantid} placeholder in its issuer, which fails that check. Related: #50036, the same check rejecting an issuer that differs only by a trailing slash.

    Reproduction script (repro.sh)
    #!/usr/bin/env bash
    # Repro for #64854: MCP OAuth issuer mismatch with Microsoft Entra "organizations".
    # Uses the real Fabric IQ MCP endpoint and the real Entra metadata; nothing mocked.
    # Usage: ./repro.sh   (opencode on PATH)   |   OC_DEV=/path/to/checkout ./repro.sh
    set -u
    mkdir -p /tmp/opencode/repro64854 && cd /tmp/opencode/repro64854
    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": { "fabriciq": { "type": "remote", "url": "https://fabriciq.svc.cloud.microsoft/v1/mcp/fabriciq",
      "oauth": { "client_id": "00000000-0000-0000-0000-000000000000", "callback_port": 19876, "redirect_uri": "http://127.0.0.1:19876/callback" } } } } }
    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
    export OPENCODE_PASSWORD=repro-pass
    "${OC[@]}" serve --hostname 127.0.0.1 --port 4599 > serve.log 2>&1 &
    OCS=$!; sleep 10
    for i in 1 2; do timeout 60 "${OC[@]}" mcp list --server http://127.0.0.1:4599 2>&1; sleep 3; done
    echo "--- mcp auth ---"
    timeout 30 "${OC[@]}" mcp auth fabriciq --server http://127.0.0.1:4599 2>&1 </dev/null
    kill $OCS 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

    Labels

    area/mcpplatform/windowsreproducedtype/bugversion/v2

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions