Skip to content

fix: remove Content-Type header from OAuth metadata discovery GET requests#1157

Open
MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
MumuTW:fix/oauth-metadata-content-type
Open

fix: remove Content-Type header from OAuth metadata discovery GET requests#1157
MumuTW wants to merge 1 commit intomodelcontextprotocol:mainfrom
MumuTW:fix/oauth-metadata-content-type

Conversation

@MumuTW
Copy link
Contributor

@MumuTW MumuTW commented Mar 18, 2026

Summary

Fixes #1143

The custom fetch wrappers in both the SSE and Streamable HTTP direct-connection paths unconditionally set Content-Type: application/json on 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 a Content-Type header.

Some authorization servers (notably Keycloak) enforce this and respond with 415 Unsupported Media Type, breaking the entire OAuth flow.

Changes

  • SSE transport: Moved content-type: application/json from the shared requestHeaders object into the fetch wrapper, only applying it when the request has a body (init?.body).
  • Streamable HTTP transport: Same approach — Content-Type is now set conditionally inside the fetch wrapper rather than unconditionally before every request.

Both changes use a shallow copy (mergedHeaders) so the base requestHeaders object is not mutated across calls.

Test plan

  • Connect to an MCP server behind an OAuth authorization server (e.g. Keycloak) using direct Streamable HTTP or SSE transport
  • Verify that OAuth metadata discovery (GET /.well-known/oauth-authorization-server) no longer returns 415
  • Verify that POST requests (JSON-RPC messages) still include Content-Type: application/json

…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
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.

Regression in OAuth metadata discovery in mcp-inspector 0.21.x against authorization servers that reject Content-Type: application/json

1 participant