modelcontextprotocol / modelcontextprotocol/typescript-sdk

OAuth: scope parameter missing from token exchange requests

Open
#941 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

auth bug fix proposed P2 ready for work
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

Issue Description

The MCP SDK's OAuth implementation does not include the scope parameter when making token exchange requests (authorization code for access token). This causes OAuth flows to fail with certain providers, particularly Microsoft Azure AD and other providers that require the scope parameter to be present in token requests.

Root Cause

When the SDK constructs the token request in the OAuth flow, it only includes the following parameters:

  • grant_type
  • code
  • redirect_uri
  • code_verifier
  • client_id (added via client authentication)

The scope parameter is missing, even though it was included in the initial authorization request.

Impact

This breaks OAuth integration with providers that require scope consistency between authorization and token requests, including:

  • Microsoft Azure AD / Entra ID
  • Potentially other enterprise OAuth providers

Expected Behavior

The SDK should include the same scope parameter in the token exchange request that was used in the authorization URL. This is recommended by OAuth 2.0 best practices and required by some providers.

Workaround

Currently, we're working around this by:

  1. Capturing the scope from the authorization URL
  2. Implementing a custom addClientAuthentication callback that manually adds the scope parameter
  3. Storing OAuth metadata that contains scope information

Suggested Fix

The SDK should:

  1. Store the scope used in the authorization request
  2. Automatically include it in the token exchange request
  3. Follow the OAuth 2.0 specification more strictly

Code Reference

The issue appears to be in how the SDK constructs token requests. The scope should be extracted from either:

  • The authorization URL parameters
  • The OAuth server metadata (scope or default_scope fields)
  • The client metadata

And then included in the token exchange POST body.

Related Standards

  • RFC 6749 Section 4.1.3 - Token exchange should include scope if different from default
  • Many providers (like Azure AD) require scope for proper token validation and consent verification

Environment

  • SDK Version: Latest (as of 2025-09-13)
  • Affected flow: Authorization Code Flow
  • Provider: Microsoft Azure AD (and potentially others)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the OAuth token request construction described in the issue, then trace how scope is represented in the authorization URL and OAuth metadata. Compare the authorization-code exchange body with the authorization request and verify the resulting token POST includes the intended scope for Azure AD and other providers.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
authentication
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.