Skip to content

OAuth: handleAuthError ignores upstream WWW-Authenticate resource_metadata in proxy mode (suffix-style RFC 9728 metadata) #1288

Closed

Description

@HeatherFlux

Summary

Inspector v0.21.2 sends users to a bogus <resource-host>/authorize URL instead of the auth server when:

  • The MCP server is OAuth-protected (401 + WWW-Authenticate: Bearer resource_metadata=...)
  • The protected-resource metadata is exposed at the RFC 9728 §3 suffix location (i.e. /<resource-path>/.well-known/oauth-protected-resource) rather than the prepend location the SDK probes by default.

This is a focused report of one of the symptoms tracked under #675. Since #675 has gathered many distinct sub-issues, opening this one to track the specific proxy-mode handleAuthError path independently.

Reproduction

  1. Stand up an MCP server that:
    • Returns 401 + WWW-Authenticate: Bearer resource_metadata="https://<host>/<resource-path>/.well-known/oauth-protected-resource" on unauthenticated requests
    • Hosts the metadata at the suffix location (200 with { authorization_servers: [...] })
    • Does not host metadata at the prepend location /.well-known/oauth-protected-resource/<resource-path>
    • This is the shape used by managed runtimes that mount each MCP server under a path (e.g. AWS Bedrock AgentCore Runtime: /runtimes/<arn>/invocations?qualifier=DEFAULT).
  2. In Inspector → Streamable HTTP transport, paste the MCP URL.
  3. Set Client ID (any pre-registered SPA client_id with PKCE).
  4. Click Connect.

Expected

Browser redirects to the auth server's /authorize endpoint (URL discovered via the resource_metadata URL → authorization_servers).

Actual

Browser redirects to <resource-host>/authorize (using the resource server's host as the auth server). The page 404s, and useConnection.ts toasts OAuth Authentication Failed.

Network trace (truncated)

POST /<resource-path>                                         → 401 + WWW-Authenticate: Bearer resource_metadata=<META_URL>
[Inspector proxy wraps as JSON-RPC error code -32099 with data.upstream401.wwwAuthenticate]
GET /.well-known/oauth-protected-resource/<resource-path>     → 404  (SDK's default prepend probe)
GET /.well-known/oauth-protected-resource                     → 404  (SDK's root fallback)
GET <resource-host>/.well-known/oauth-authorization-server    → 404  (auth server discovery on resource host)
[redirect] <resource-host>/authorize?response_type=code&...   → 404

Root cause

handleAuthError (in client/src/lib/hooks/useConnection.ts) calls auth(provider, { serverUrl, scope, fetchFn }) without a resourceMetadataUrl. That makes the SDK's default discovery probe the prepend path, fall back to the root, and then treat the resource server as the auth server when both 404.

In proxy mode, the proxy unwraps the upstream 401 into a JSON-RPC error containing data.upstream401.wwwAuthenticate (see server/src/mcpProxy.ts serializeProxyTransportError). The SDK's StreamableHTTPClientTransport._send therefore never sees a 401 status and the provider's onUnauthorized hook never fires — so even when the upstream advertises a metadata URL, Inspector ignores it.

Related work

Proposed fix

Extract resource_metadata=... from any of three sources (priority order: SDK error's resourceMetadataUrl → response/headers' WWW-Authenticate → proxy upstream401.wwwAuthenticate) and pass it to both discoverOAuthProtectedResourceMetadata and auth(). PR submitted.

Environment

  • Inspector v0.21.2
  • Streamable HTTP transport
  • connectionType: "proxy" (default)

Activity

  1. HeatherFlux commented on May 5, 2026

    @HeatherFlux
    Author

    Closing — will reopen if/when needed with a cleaner repro.

  2. renatogcarvalho commented on May 12, 2026

    @renatogcarvalho

    We hit this exact bug yesterday with Inspector 0.21.2 — a second concrete case beyond the AWS Bedrock AgentCore Runtime shape.

    Setup

    • MCP mounted under /mcp/<service-name> behind a path-prefixed ALB rule
    • Issuer: https://<host>/mcp/<service-name>
    • WWW-Authenticate: Bearer resource_metadata="https://<host>/mcp/<service-name>/.well-known/oauth-protected-resource" (path-preserving / "suffix" location)
    • Protected-resource metadata served only at the path-preserving location — nothing at apex

    Observation

    Inspector's first 4 requests were all apex probes — never POSTed to the MCP transport, never saw the 401 with WWW-Authenticate:

    GET /.well-known/oauth-protected-resource/mcp/<service-name>  → 401
    GET /.well-known/oauth-protected-resource                      → 401
    GET /.well-known/oauth-authorization-server                    → 401
    GET /.well-known/openid-configuration                          → 401
    

    Inspector failed with "Failed to discover OAuth metadata" before any transport-level interaction.

    Side note: in our case the 401s came from the MCP's own auth middleware (apex paths weren't on the public-paths allowlist). If Inspector treats 401 as a hard fail rather than "wrong location, try next," that compounds the issue here.

    Why this matters for our topology

    Like AWS Bedrock AgentCore, we run multiple MCPs under a shared host with a path prefix per service. The ALB listener rule matches /mcp/<service-name>/*; apex .well-known/* goes to the ALB default action. Without resourceMetadataUrl support, every org-wide MCP has to either:

    • add N apex listener rules per service (verbose; awkward shared-host routing)
    • drop the path component from the issuer (breaks per-MCP OAuth-AS isolation)
    • skip Inspector entirely

    Workaround (local dev only)

    Register apex aliases on the MCP server itself — works in single-container docker-compose, doesn't scale to a shared org ALB.

    The proposed fix in the original report (extract resource_metadata from SDK error / response headers / proxy upstream401.wwwAuthenticate and pass to discoverOAuthProtectedResourceMetadata + auth()) would unblock all three setups without server-side workarounds. Happy to test a PR.

  3. FMCorz commented on Jun 15, 2026

    @FMCorz

    +1

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions