fix: remove Content-Type header from OAuth metadata discovery GET requests#1157
Open
MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: remove Content-Type header from OAuth metadata discovery GET requests#1157MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
…iscovery GET requests to /.well-known/oauth-authorization-server should not include a Content-Type header. Some authorization servers (e.g. Keycloak) respond with 415 Unsupported Media Type when a GET request carries Content-Type: application/json, breaking OAuth metadata discovery. Move Content-Type assignment inside the custom fetch wrapper so it is only applied when the request carries a body (i.e. POST), leaving GET requests header-clean. Fixes modelcontextprotocol#1143
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1143
The custom
fetchwrappers in both the SSE and Streamable HTTP direct-connection paths unconditionally setContent-Type: application/jsonon every outgoing request. This includes GET requests made during OAuth metadata discovery (e.g.GET /.well-known/oauth-authorization-server), which violates HTTP semantics — GET requests should not carry aContent-Typeheader.Some authorization servers (notably Keycloak) enforce this and respond with 415 Unsupported Media Type, breaking the entire OAuth flow.
Changes
content-type: application/jsonfrom the sharedrequestHeadersobject into thefetchwrapper, only applying it when the request has a body (init?.body).Content-Typeis now set conditionally inside thefetchwrapper rather than unconditionally before every request.Both changes use a shallow copy (
mergedHeaders) so the baserequestHeadersobject is not mutated across calls.Test plan
GET /.well-known/oauth-authorization-server) no longer returns 415Content-Type: application/json