[BUG] MCP HTTP OAuth flow ignores custom "scope" from .mcp.json, sends hardcoded defaults instead

Status Fixed / completed
Reported on v2.1.220
Maintainer reply ✓ Yes — claude[bot]
Activity 3 comments · opened Aug 3, 2026 · closed Aug 19, 2026
💡 Likely answer: A maintainer (claude[bot], contributor) responded on this thread — see the highlighted reply below.

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

## Description

When an HTTP MCP server is configured in .mcp.json with a custom oauth.scope, Claude Code ignores it and sends
hardcoded default scopes (openid profile email uaa.offline_token user_attributes) in the authorization request. This
causes the OAuth flow to fail when the identity provider rejects unknown scopes.

## .mcp.json configuration

```json
{
"mcpServers": {
"designreviewmcp": {
"type": "http",
"url": "http://localhost:6010/xxxxxxxx/v1/mcp/session",
"oauth": {
"clientId": "xxxxxxxxxxxxxxxxxx",
"scope": "scope1 scope2",
"authServerMetadataUrl": "https://tenant.server.com/.well-known/openid-configuration"
}
}
}
}



### What Should Happen?

  The authorization request should use the scopes from .mcp.json:
  scope=scope1 scope2

### Error Messages/Logs

```shell
The authorization request uses hardcoded default scopes:
scope=openid+profile+email+uaa.offline_token+user_attributes

The identity providerrejects user_attributes as invalid:
error=invalid_scope&error_description=user_attributes is invalid.
Please use a valid scope name in the request

PS: My corporate identity server does not support user_attributes scope

Steps to Reproduce

  1. Configure an HTTP MCP server in .mcp.json with a custom oauth.scope (as above)
  2. Start Claude Code — /doctor reports the server needs authentication
  3. Initiate the OAuth flow (via /mcp or the authenticate tool)
  4. Observe the authorization URL that Claude Code generates

Claude Model

Opus

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

2.1.220

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

PowerShell

Additional Information

Error url shown in the browser: ?error=invalid_scope&error_description=user_attributes%20is%20invalid.%20Please%20use%20a%20valid%20scope%20name%20in%20the%20request&state=ukiZFySkdkdGEW65zBJTtmU55o6l6bLKtFJIZ0Pnodc

Root cause hypothesis

This appears related to #66456 (https://github.com/anthropics/claude-code/issues/66456) — the OAuth initiation path
reads from an internal cache rather than from the .mcp.json config. On first connection the cache is empty, so custom
fields like scope are undefined and fall back to hardcoded defaults.

View original on GitHub ↗

3 Comments

vjgn · 12 days ago

Hi. Any updates on this issue? Thank you.

claude[bot] contributor · 11 days ago

This is a config key mismatch rather than hardcoded scopes: the supported field is oauth.scopes (plural) — see https://code.claude.com/docs/en/mcp#restrict-oauth-scopes. oauth.scope is not a recognized key, so it has no effect, and as that section explains, when authServerMetadataUrl is configured the scopes_supported list from that metadata document is what gets requested. openid profile email uaa.offline_token user_attributes is the list your identity server advertises there, not a Claude Code default.

Verified on 2.1.235 (Linux) with your config shape against a local test server: with "scope": "scope1 scope2" the generated authorization URL carries scope=openid+profile+email+uaa.offline_token+user_attributes (the metadata's scopes_supported); renaming the key to "scopes": "scope1 scope2" produces scope=scope1+scope2.

🤖 Generated with Claude Code

---
_Generated by Claude Code_

vjgn · 10 days ago

There is still a bug. Here is Claude Code's findings based on the logs from Claude Code's debug folder:

Claude Code is using the correct authorization endpoint from metadata, but then overriding your configured scopes with the metadata defaults during the token exchange! Looking at your debug logs: Authorization request: Uses your scopes xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview ✓ Token exchange: Switches to metadata scopes openid profile email uaa.offline_token user_attributes ✗ The authorization code is tied to the scopes it was requested with. You can't redeem it with different scopes—that's why your server rejects it. This is Claude Code's issue to fix. When using authServerMetadataUrl, Claude Code should: Use metadata for endpoint discovery NOT override the configured scopes during the token exchange

In the logs, first i see:
Overrode authorization scope from openid profile email xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview to configured: xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview

Then later just before exchanging the code for a token I see this log line:
Using scope from metadata: openid profile email uaa.offline_token user_attributes

Here are the raw logs from debug folder (scrubbed to remove the server details):

2026-08-20T17:30:43.715Z [DEBUG] MCP server "mymcp": No access token in storage
2026-08-20T17:31:04.277Z [DEBUG] MCP server "mymcp": Initializing HTTP transport to http://localhost:6010/dcmcpreview/v1/mcp/session
2026-08-20T17:31:04.277Z [DEBUG] MCP server "mymcp": Node version: v26.3.0, Platform: win32
2026-08-20T17:31:04.278Z [DEBUG] MCP server "mymcp": Environment: {"NODE_OPTIONS":"not set","UV_THREADPOOL_SIZE":"default","HTTP_PROXY":"not set","HTTPS_PROXY":"not set","NO_PROXY":"not set"}
2026-08-20T17:31:04.279Z [DEBUG] MCP server "mymcp": HTTP transport options: {"url":"http://localhost:6010/dcmcpreview/v1/mcp/session","headers":{"User-Agent":"claude-code/2.1.237 (cli)","Accept-Encoding":"identity"},"hasAuthProvider":true,"timeoutMs":60000}
2026-08-20T17:31:04.279Z [DEBUG] MCP server "mymcp": HTTP transport created successfully
2026-08-20T17:31:04.286Z [DEBUG] MCP server "mymcp": Client created, setting up request handler
2026-08-20T17:31:04.286Z [DEBUG] MCP server "mymcp": Starting connection with timeout of 30000ms
2026-08-20T17:31:04.286Z [DEBUG] MCP server "mymcp": Testing basic HTTP connectivity to http://localhost:6010/dcmcpreview/v1/mcp/session
2026-08-20T17:31:04.286Z [DEBUG] MCP server "mymcp": Parsed URL: host=localhost, port=6010, protocol=http:
2026-08-20T17:31:04.287Z [DEBUG] MCP server "mymcp": Using loopback address: localhost
2026-08-20T17:31:04.292Z [DEBUG] MCP server "mymcp": No access token in storage
2026-08-20T17:31:04.342Z [DEBUG] MCP server "mymcp": Fetching metadata from configured URL: https://cloud.myauthserver.com/.well-known/openid-configuration
2026-08-20T17:31:04.346Z [DEBUG] MCP server "mymcp": No access token in storage
2026-08-20T17:31:04.727Z [DEBUG] MCP server "mymcp": Saving discovery state (authServer: https://cloud.myauthserver.com/oauth/token)
2026-08-20T17:31:04.817Z [DEBUG] MCP server "mymcp": Using pre-configured client ID
2026-08-20T17:31:04.822Z [DEBUG] MCP server "mymcp": No access token in storage
2026-08-20T17:31:04.822Z [DEBUG] MCP server "mymcp": Generated new OAuth state
2026-08-20T17:31:04.823Z [DEBUG] MCP server "mymcp": Saving code verifier
2026-08-20T17:31:04.824Z [DEBUG] MCP server "mymcp": Overrode authorization scope from openid profile email xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview to configured: xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview
2026-08-20T17:31:04.824Z [DEBUG] MCP server "mymcp": Authorization URL: https://cloud.myauthserver.com/oauth/authorize?response_type=code&client_id=dstesterdev-astpreprod-mcpvijay&code_challenge=%5BREDACTED%5D&code_challenge_method=S256&redirect_uri=http%3A%2F%2Flocalhost%3A3118%2Fcallback&state=%5BREDACTED%5D&scope=xf%3Anxxpreprod%3Anxxeng%3AViewer+dcmcpreview.mcpreview&resource=http%3A%2F%2Flocalhost%3A6010%2Fdcmcpreview%2Fv1%2Fmcp%2Fsession
2026-08-20T17:31:04.824Z [DEBUG] MCP server "mymcp": Scopes in URL: xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview
2026-08-20T17:31:04.824Z [DEBUG] MCP server "mymcp": Captured scopes from authorization URL: xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview
2026-08-20T17:31:04.824Z [DEBUG] MCP server "mymcp": Redirection handling is disabled, skipping redirect
2026-08-20T17:31:04.829Z [DEBUG] MCP server "mymcp": HTTP Connection failed after 552ms: Unauthorized (code: none, errno: none)
2026-08-20T17:31:04.829Z [ERROR] MCP server "mymcp" Error: Unauthorized
2026-08-20T17:31:04.830Z [DEBUG] MCP server "mymcp": Authentication required for HTTP server
2026-08-20T17:31:04.834Z [DEBUG] MCP server "mymcp": Reconnect returned 'needs-auth'; retrying once after cache clear
2026-08-20T17:31:04.834Z [DEBUG] MCP server "mymcp": Initializing HTTP transport to http://localhost:6010/dcmcpreview/v1/mcp/session
2026-08-20T17:31:04.834Z [DEBUG] MCP server "mymcp": Node version: v26.3.0, Platform: win32
2026-08-20T17:31:04.834Z [DEBUG] MCP server "mymcp": Environment: {"NODE_OPTIONS":"not set","UV_THREADPOOL_SIZE":"default","HTTP_PROXY":"not set","HTTPS_PROXY":"not set","NO_PROXY":"not set"}
2026-08-20T17:31:04.835Z [DEBUG] MCP server "mymcp": HTTP transport options: {"url":"http://localhost:6010/dcmcpreview/v1/mcp/session","headers":{"User-Agent":"claude-code/2.1.237 (cli)","Accept-Encoding":"identity"},"hasAuthProvider":true,"timeoutMs":60000}
2026-08-20T17:31:04.835Z [DEBUG] MCP server "mymcp": HTTP transport created successfully
2026-08-20T17:31:04.837Z [DEBUG] MCP server "mymcp": Client created, setting up request handler
2026-08-20T17:31:04.838Z [DEBUG] MCP server "mymcp": Starting connection with timeout of 30000ms
2026-08-20T17:31:04.838Z [DEBUG] MCP server "mymcp": Testing basic HTTP connectivity to http://localhost:6010/dcmcpreview/v1/mcp/session
2026-08-20T17:31:04.838Z [DEBUG] MCP server "mymcp": Parsed URL: host=localhost, port=6010, protocol=http:
2026-08-20T17:31:04.838Z [DEBUG] MCP server "mymcp": Using loopback address: localhost
2026-08-20T17:31:04.841Z [DEBUG] MCP server "mymcp": No access token in storage
2026-08-20T17:31:04.850Z [DEBUG] MCP server "mymcp": Fetching metadata from configured URL: https://cloud.myauthserver.com/.well-known/openid-configuration
2026-08-20T17:31:04.958Z [DEBUG] MCP server "mymcp": Saving discovery state (authServer: https://cloud.myauthserver.com/oauth/token)
2026-08-20T17:31:04.983Z [DEBUG] MCP server "mymcp": Using pre-configured client ID
2026-08-20T17:31:04.985Z [DEBUG] MCP server "mymcp": No access token in storage
2026-08-20T17:31:04.985Z [DEBUG] MCP server "mymcp": Generated new OAuth state
2026-08-20T17:31:04.987Z [DEBUG] MCP server "mymcp": Saving code verifier
2026-08-20T17:31:04.987Z [DEBUG] MCP server "mymcp": Overrode authorization scope from openid profile email xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview to configured: xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview
2026-08-20T17:31:04.988Z [DEBUG] MCP server "mymcp": Authorization URL: https://cloud.myauthserver.com/oauth/authorize?response_type=code&client_id=dstesterdev-astpreprod-mcpvijay&code_challenge=%5BREDACTED%5D&code_challenge_method=S256&redirect_uri=http%3A%2F%2Flocalhost%3A3118%2Fcallback&state=%5BREDACTED%5D&scope=xf%3Anxxpreprod%3Anxxeng%3AViewer+dcmcpreview.mcpreview&resource=http%3A%2F%2Flocalhost%3A6010%2Fdcmcpreview%2Fv1%2Fmcp%2Fsession
2026-08-20T17:31:04.988Z [DEBUG] MCP server "mymcp": Scopes in URL: xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview
2026-08-20T17:31:04.988Z [DEBUG] MCP server "mymcp": Captured scopes from authorization URL: xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview
2026-08-20T17:31:04.988Z [DEBUG] MCP server "mymcp": Redirection handling is disabled, skipping redirect
2026-08-20T17:31:04.988Z [DEBUG] MCP server "mymcp": HTTP Connection failed after 154ms: Unauthorized (code: none, errno: none)
2026-08-20T17:31:04.988Z [ERROR] MCP server "mymcp" Error: Unauthorized
2026-08-20T17:31:04.989Z [DEBUG] MCP server "mymcp": Authentication required for HTTP server
2026-08-20T17:31:05.077Z [DEBUG] MCP server "mymcp": No access token in storage
2026-08-20T17:31:20.958Z [DEBUG] MCP server "mymcp": Using redirect port: 49024
2026-08-20T17:31:20.978Z [DEBUG] MCP server "mymcp": Cleared stored tokens
2026-08-20T17:31:21.090Z [DEBUG] MCP server "mymcp": Fetched OAuth metadata with scope: NONE
2026-08-20T17:31:21.091Z [DEBUG] MCP server "mymcp": Generated new OAuth state
2026-08-20T17:31:21.111Z [DEBUG] MCP server "mymcp": Starting SDK auth
2026-08-20T17:31:21.111Z [DEBUG] MCP server "mymcp": Server URL: http://localhost:6010/dcmcpreview/v1/mcp/session
2026-08-20T17:31:21.111Z [DEBUG] MCP server "mymcp": Fetching metadata from configured URL: https://cloud.myauthserver.com/.well-known/openid-configuration
2026-08-20T17:31:21.240Z [DEBUG] MCP server "mymcp": Saving discovery state (authServer: https://cloud.myauthserver.com/oauth/token)
2026-08-20T17:31:21.272Z [DEBUG] MCP server "mymcp": Using pre-configured client ID
2026-08-20T17:31:21.277Z [DEBUG] MCP server "mymcp": No access token in storage
2026-08-20T17:31:21.278Z [DEBUG] MCP server "mymcp": Saving code verifier
2026-08-20T17:31:21.278Z [DEBUG] MCP server "mymcp": Overrode authorization scope from openid profile email xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview to configured: xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview
2026-08-20T17:31:21.279Z [DEBUG] MCP server "mymcp": Authorization URL: https://cloud.myauthserver.com/oauth/authorize?response_type=code&client_id=dstesterdev-astpreprod-mcpvijay&code_challenge=%5BREDACTED%5D&code_challenge_method=S256&redirect_uri=http%3A%2F%2Flocalhost%3A49024%2Fcallback&state=%5BREDACTED%5D&scope=xf%3Anxxpreprod%3Anxxeng%3AViewer+dcmcpreview.mcpreview&resource=http%3A%2F%2Flocalhost%3A6010%2Fdcmcpreview%2Fv1%2Fmcp%2Fsession
2026-08-20T17:31:21.279Z [DEBUG] MCP server "mymcp": Scopes in URL: xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview
2026-08-20T17:31:21.279Z [DEBUG] MCP server "mymcp": Captured scopes from authorization URL: xf:nxxpreprod:nxxeng:Viewer dcmcpreview.mcpreview
2026-08-20T17:31:21.279Z [DEBUG] MCP server "mymcp": Redirecting to authorization URL
2026-08-20T17:31:21.279Z [DEBUG] MCP server "mymcp": Authorization URL: https://cloud.myauthserver.com/oauth/authorize?response_type=code&client_id=dstesterdev-astpreprod-mcpvijay&code_challenge=%5BREDACTED%5D&code_challenge_method=S256&redirect_uri=http%3A%2F%2Flocalhost%3A49024%2Fcallback&state=%5BREDACTED%5D&scope=xf%3Anxxpreprod%3Anxxeng%3AViewer+dcmcpreview.mcpreview&resource=http%3A%2F%2Flocalhost%3A6010%2Fdcmcpreview%2Fv1%2Fmcp%2Fsession
2026-08-20T17:31:21.279Z [DEBUG] MCP server "mymcp": Opening authorization URL: https://cloud.myauthserver.com/oauth/authorize?response_type=code&client_id=dstesterdev-astpreprod-mcpvijay&code_challenge=%5BREDACTED%5D&code_challenge_method=S256&redirect_uri=http%3A%2F%2Flocalhost%3A49024%2Fcallback&state=%5BREDACTED%5D&scope=xf%3Anxxpreprod%3Anxxeng%3AViewer+dcmcpreview.mcpreview&resource=http%3A%2F%2Flocalhost%3A6010%2Fdcmcpreview%2Fv1%2Fmcp%2Fsession
2026-08-20T17:31:21.666Z [DEBUG] MCP server "mymcp": Initial auth result: REDIRECT
2026-08-20T17:31:25.059Z [DEBUG] MCP server "mymcp": MCP OAuth server cleaned up
2026-08-20T17:31:25.061Z [DEBUG] MCP server "mymcp": Completing auth flow with authorization code
2026-08-20T17:31:25.062Z [DEBUG] MCP server "mymcp": Fetching metadata from configured URL: https://cloud.myauthserver.com/.well-known/openid-configuration
2026-08-20T17:31:25.176Z [DEBUG] MCP server "mymcp": Saving discovery state (authServer: https://cloud.myauthserver.com/oauth/token)
2026-08-20T17:31:25.210Z [DEBUG] MCP server "mymcp": Using pre-configured client ID
2026-08-20T17:31:25.211Z [DEBUG] MCP server "mymcp": Using scope from metadata: openid profile email uaa.offline_token user_attributes
2026-08-20T17:31:25.211Z [DEBUG] MCP server "mymcp": Returning code verifier
2026-08-20T17:31:25.217Z [DEBUG] MCP server "mymcp": Using pre-configured client ID
2026-08-20T17:31:25.447Z [DEBUG] MCP server "mymcp": Error during auth completion: drt: HTTP 401: Invalid OAuth error response: ZodError: [
  {
    "expected": "object",
    "code": "invalid_type",
    "path": [],
    "message": "Invalid input: expected object, received array"
  }
]. Raw body: [{"logref":"59ae17fe364f48758731f948b4a55eb8","message":"Error : 'Fetch token call failed Bad credentials'"}]

Please reopen the issue. Thank you.