Skip to content

auth: use Bearer challenges for resource metadata - #1396

Merged
guglielmo-san merged 3 commits into
modelcontextprotocol:mainfrom
jay23606:fix/1379-bearer-resource-metadata
Oct 14, 2026
Merged

guglielmo-san merged 3 commits into
modelcontextprotocol:mainfrom
jay23606:fix/1379-bearer-resource-metadata

Conversation

@jay23606

Copy link
Copy Markdown
Contributor

resourceMetadataURLFromChallenges currently accepts resource_metadata from any authentication scheme. When a Basic challenge precedes a Bearer challenge, metadata discovery can select the Basic URL. Restrict both authorization handlers to the Bearer challenge and add regression coverage for each helper.

Validation:

  • go test ./auth ./auth/extauth — passed.
  • Regression gate against clean main — both test runs failed as expected; both runs on the fix passed.
  • go vet ./..., go build ./..., and git diff --check — passed.
  • go test ./... has a pre-existing Windows failure in mcp/TestServerConformance/resources.txtar: the fixture expects LF while Windows produces CRLF. The same failure occurs on clean main.

Fixes #1379

Comment thread auth/extauth/client_credentials.go Outdated
Comment on lines 242 to 243
if u := c.Params["resource_metadata"]; strings.EqualFold(c.Scheme, "Bearer") && u != "" {
return u

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this represent a behavioral change for existing users that were relying on the basic auth for example.
We should implement a preference for "bearer" with fallback to any other scheme defined

var fallback string
for _, c := range cs {
	u := c.Params["resource_metadata"]
	if u == "" {
		continue
	}
	if c.Scheme == "bearer" {
		return u
	}
	if fallback == "" {
		fallback = u
	}
}
return fallback

Restricting the resource_metadata lookup to a Bearer challenge dropped the
URL for servers that only challenge with another scheme, such as Basic.
Prefer a Bearer challenge and otherwise take the first other scheme that
carries one, in both the auth and extauth packages.

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
@guglielmo-san
guglielmo-san merged commit 2dee148 into modelcontextprotocol:main Oct 14, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auth: resource metadata lookup accepts URLs from non-Bearer challenges

2 participants