Requests to oauth the token endpoint with refresh_token grant type set invalid content-type header
Inspector Version
0.21.1
Describe the bug
MCP inspector makes requests to the oauth token endpoint with an invalid content-type application/json, application/x-www-form-urlencoded for the refresh_token grant type.
When the MCP inspector initially authenticates, it makes the first request to the token endpoint with the "authorization_code" grant type, and it correctly sets content-type: application/x-www-form-urlencoded. When the initial access token expires, and it requests a new one from the token endpoint with the refresh_token endpoint, it incorrectly sets content-type: application/json, application/x-www-form-urlencoded.
Here are screenshots from chrome devtools, the first is the initial token request with the "authorization_code" grant type, which sets the correct content-type. And the second is the "refresh_token" request, which sets the invalid content-type.
Initial token request with "authorization_code" grant type:
And the subsequent request with "refresh_token" grant type:
To Reproduce
- Connect to an MCP server and go through the authorization flow. Observe network tools, and note that the initial request to the oauth token endpoint sets
content-type: application/x-www-form-urlencoded - Wait for the initial access token to expire, and note that the subsequent request to the token endpoint sets
content-type: application/json, application/x-www-form-urlencoded
Expected behavior
Requests to the token endpoint always set content-type: application/x-www-form-urlencoded. The OAuth spec is clear that requests to the token endpoint must use this:
https://www.ietf.org/archive/id/draft-ietf-oauth-v2-1-15.html#name-token-endpoint-request
Screenshots
Initial token request with "authorization_code" grant type:
Subsequent token request with "refresh_token" grant type:
Environment (please complete the following information):
- MacOS Tahoe
- Chrome
Additional context N/A
Version Consideration
Inspector V2 is under development to address architectural and UX improvements. During this time, V1 contributions should focus on bug fixes and MCP spec compliance. See CONTRIBUTING.md for more details.
This seems similar to #1143, but I wasn't totally sure if this is the same underlying issue or not. Feel free to close if this is the same underlying issue, and is fixed by https://github.com/modelcontextprotocol/inspector/pull/1157
This is a simple fix — the token refresh code is likely using JSON content-type instead of form-urlencoded when it should switch based on grant type. I can patch this today. lanxevo3: https://gist.github.com/lanxevo3/268a019f1f7d5b1fa2b465704a0301cd
This is a simple fix — the token refresh code is likely using JSON content-type instead of form-urlencoded when it should switch based on grant type. I can patch this today. lanxevo3: https://gist.github.com/lanxevo3/268a019f1f7d5b1fa2b465704a0301cd
@lanxevo3 thank you for taking a look. The content-type should always be form-urlencoded, no matter the grant type. Here is the relevant section of the OAuth2.1 spec:
https://www.ietf.org/archive/id/draft-ietf-oauth-v2-1-15.html#name-token-endpoint-request
PR up: https://github.com/modelcontextprotocol/typescript-sdk/pull/1774 — adds defensive Content-Type enforcement in executeTokenRequest() and registerClient() to ensure form-urlencoded is always used per OAuth 2.1 §3.2.
Same root cause also corrupts the Authorization header
I'm hitting this against my OAuth-protected MCP server with Inspector 0.21.2 and the failure mode is broader than the Content-Type. The same refresh-token request also has a malformed Authorization header:
POST /mcp/token HTTP/1.1
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...dTb03q-IpwmaWwcCfdgyOdRwYlBG3kI0cEnKsuEMt6U, Basic ZWNlZThiZDctMzdiNC00NTE1LWJiMGYtOTJjNWVjOTE1MjdiOjQyNTExYWVhZWY2MGRlN2NmNjg0ZTNkZmRiMTQ5NzhlZTE4MWQ2NzhkN2EwN2M3ODI0MDBlZmZmYWIyZGE4MmQ=
Content-Type: application/json, application/x-www-form-urlencoded
grant_type=refresh_token&refresh_token=...&resource=https%3A%2F%2Fapi.atlas.griddo.io%2Fmcp
Two schemes in one Authorization line (RFC 7235 forbids this) and two values in Content-Type. The pattern is identical — a previous request's headers are leaking into the new one — which strongly suggests the root cause is a shared, mutated headers object across requests in the token-refresh code path, not just a wrong Content-Type literal.
Downstream impact on servers
The Anthropic Python SDK's ClientAuthenticator (mcp 1.27.0) does:
auth_header = request.headers.get("Authorization", "")
if client.token_endpoint_auth_method == "client_secret_basic":
if not auth_header.startswith("Basic "):
raise AuthenticationError(...)
A merged header that starts with Bearer … fails this strict check, so the server returns 401 unauthorized_client: Missing client_id even when the Inspector ostensibly has all credentials. Most servers will hit this — the spec says Basic credentials live in Authorization, not in the body.
Reproduction (matches @kylekizirian's, plus the Authorization bit)
- Connect Inspector to an OAuth-protected MCP server. First
/token(grant_type=authorization_code) is well-formed. - Send any MCP message (which carries
Authorization: Bearer <access_token>). - Wait for token expiry — Inspector triggers a
grant_type=refresh_tokencall. - Capture in DevTools →
Authorizationheader now contains both schemes;Content-Typecontains both values.
Without step 2, the corruption doesn't happen — that's the smoking gun for shared header state.
Fix scope to consider
The PR'd fix in typescript-sdk#1774 only sets Content-Type defensively before the fetch — it doesn't address the Authorization side, which would still leak. A fuller fix needs executeTokenRequest() (and likely addClientAuthentication) to always construct a fresh Headers object per call rather than reusing or extending one carried from elsewhere.
Server-side workaround
For anyone hitting this in the meantime, I shipped an ASGI middleware that normalizes both headers on /mcp/token before the SDK sees them: it splits comma-separated values, picks the Basic credential and the form Content-Type, and rewrites the request to a clean canonical form. Diff: https://github.com/griddo/university_etl/pull/36 (file interfaces/api/middleware/oauth_basic_to_form.py). Scoped to /token paths only, no-op everywhere else.
— Daniel Serrano ([email protected])
Closing: v1 is deprecated.
Thank you for reporting this, and apologies for the long wait for a response.
v1 will receive security fixes only — this issue describes a functionality, compatibility, or usability problem rather than a vulnerability, so it is being closed against v1. This is not a judgment on whether the problem is real — it's a consequence of the v1 line being frozen. This is happening as part of #1872.
If this still happens in v2, we'd genuinely like to know. v2 is a complete rewrite — three clients over a shared core — so many v1 behaviours no longer exist in the same form. Please open a fresh issue against v2 with steps to reproduce, and we'll look at it. Note that we accept external contributions as issues rather than pull requests; maintainers handle design and implementation through a prompt-driven workflow. See CONTRIBUTING.md.
Thanks for taking the time to report it.