anthropics / anthropics/claude-code

MCP OAuth: AS discovery uses bare /.well-known/oauth-authorization-server instead of RFC 8414 path-based URL

Open
#95,270 0 comments 0 reactions 0 assignees View on GitHub
area:auth area:mcp bug has repro
Dominant language
Python
Stars
145k
Forks
23.1k
PR merge metrics
PR metrics pending

Description

## Summary

When Claude Code discovers the Authorization Server metadata for an MCP connector, it constructs the discovery URL by doing:

```js
new URL('/.well-known/oauth-authorization-server', issuerUrl)
```

For an issuer with a path (e.g. `https://gateway.example.com/github`), this strips the path and fetches:
```
https://gateway.example.com/.well-known/oauth-authorization-server
```

Per RFC 8414 Section 3, the correct URL for a path-based issuer is:
```
https://gateway.example.com/.well-known/oauth-authorization-server/github
```

## Impact

Any MCP gateway that serves per-server AS metadata at the RFC 8414 canonical path will have working metadata at `/.well-known/oauth-authorization-server/github` (with `registration_endpoint`) but the SDK fetches the bare URL which returns generic metadata without `registration_endpoint`. Claude Code then errors:

```
Incompatible auth server: does not support dynamic client registration
```

## Reproduction

1. Protected resource at `/.well-known/oauth-protected-resource/github/mcp` returns `authorization_servers: ["https://gateway/github"]`
2. Claude Code fetches `https://gateway/.well-known/oauth-authorization-server` (no `registration_endpoint`)
3. Error fires

The correct URL `https://gateway/.well-known/oauth-authorization-server/github` is never fetched even though it returns valid metadata with `registration_endpoint`.

## Expected behavior

For issuer `https://gateway/github` (has path `/github`), the AS discovery URL should be:
`https://gateway/.well-known/oauth-authorization-server/github`

This is RFC 8414 Section 3 compliant: `{issuer_host}/.well-known/oauth-authorization-server{issuer_path}`

## Verified in

Claude Code 2.1.275 — binary only contains the bare path string `/.well-known/oauth-authorization-server`, no path-appended variant.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the Authorization Server discovery URL construction described in the Claude Code binary and compare it with RFC 8414 Section 3. Reproduce the path-based issuer case using the URLs in the report; done means the canonical path-based URL is fetched and metadata including registration_endpoint is recognized.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
authentication
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.