Skip to content

fix(mcp-oauth): fall back to root well-known URL for non-root resource paths (fixes #2675)#2673

Merged
code-yeongyu merged 2 commits intocode-yeongyu:devfrom
sanoyphilippe:fix/oauth-discovery-root-fallback
Mar 25, 2026
Merged

fix(mcp-oauth): fall back to root well-known URL for non-root resource paths (fixes #2675)#2673
code-yeongyu merged 2 commits intocode-yeongyu:devfrom
sanoyphilippe:fix/oauth-discovery-root-fallback

Conversation

@sanoyphilippe
Copy link
Copy Markdown
Contributor

@sanoyphilippe sanoyphilippe commented Mar 18, 2026

Problem

When a skill-embedded MCP server has a resource URL with a sub-path (e.g. https://mcp.sentry.dev/mcp), OAuth discovery fails because the path-suffixed well-known URL doesn't exist on some servers.

Fixes #2675

Discovery flow (before this fix):

  1. Try /.well-known/oauth-protected-resource → 404 (not all servers serve PRM)
  2. Try /.well-known/oauth-authorization-server/mcp (RFC 8414 path suffix) → 404
  3. Throw "OAuth authorization server metadata not found"

The root well-known URL (/.well-known/oauth-authorization-server) returns 200 with valid metadata, but is never tried.

Affected servers: Sentry MCP (https://mcp.sentry.dev/mcp), and potentially any MCP server that:

  • Serves resources at a sub-path (e.g. /mcp)
  • Serves OAuth metadata only at the root well-known URL
  • Doesn't implement the Protected Resource Metadata endpoint

Note: OpenCode core handles this case correctly — this only affects oh-my-openagent's skill MCP OAuth flow.

Fix

Add a fallback in fetchAuthorizationServerMetadata: when the path-suffixed well-known URL returns 404 and the resource has a non-root path, try the root well-known URL before giving up.

Discovery flow (after this fix):

  1. Try /.well-known/oauth-protected-resource → 404
  2. Try /.well-known/oauth-authorization-server/mcp → 404
  3. Try /.well-known/oauth-authorization-server200

Also extracts parseMetadataFields helper to avoid duplicating the response parsing logic.

Changes

  • src/features/mcp-oauth/discovery.ts — Add root-path fallback, extract parseMetadataFields
  • src/features/mcp-oauth/discovery.test.ts — Add 2 test cases for sub-path resource URLs

Checklist

  • Code follows project conventions
  • bun run typecheck passes
  • bun test src/features/mcp-oauth/discovery.test.ts passes (7/7)
  • No version changes in package.json

When the resource URL has a sub-path (e.g. https://mcp.sentry.dev/mcp),
the RFC 8414 path-suffixed well-known URL may not exist. Fall back to
the root well-known URL before giving up.

This matches OpenCode core's behavior and fixes authentication for
servers like Sentry that serve OAuth metadata only at the root path.
@sanoyphilippe sanoyphilippe changed the title Fix OAuth discovery for servers with non-root resource paths fix(mcp-oauth): fall back to root well-known URL for non-root resource paths Mar 18, 2026
Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Auto-approved: Fixes a 404 error in OAuth discovery by adding a safe fallback to the root metadata endpoint; implementation is well-tested and only triggers if the primary lookup fails.

@sanoyphilippe sanoyphilippe changed the title fix(mcp-oauth): fall back to root well-known URL for non-root resource paths fix(mcp-oauth): fall back to root well-known URL for non-root resource paths (fixes #2675) Mar 18, 2026
@code-yeongyu code-yeongyu added the triage:bug-fix PR: Bug fix label Mar 24, 2026
@code-yeongyu code-yeongyu merged commit 7a52639 into code-yeongyu:dev Mar 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

triage:bug-fix PR: Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Skill MCP OAuth discovery fails for servers with non-root resource paths (e.g. Sentry)

2 participants