Skip to content

Conversation

@Nayana-Parameswarappa
Copy link

This pull request implements support for upscoping when an API request fails with a 403 Forbidden response due to insufficient_scope.

Motivation and Context

Before: When a request failed due to missing scopes, the SDK halted with a hard error, forcing users to manually determine the correct permissions and re-authenticate.

Now: We've introduced graceful error handling for insufficient_scope 403 responses. This change supports upscoping, allowing the SDK to either automatically prompt for the required scopes or guide the user, significantly enhancing resilience and user experience.

What changed (high level)

Extract scope and resource_metadata_url from WWW-Authenticate on 403 responses and use them to trigger an upscoping auth flow via the configured OAuthClientProvider.
Add a guard that records the last WWW-Authenticate header used for an upscoping attempt and prevents retrying an identical directive repeatedly; the guard is reset after successful responses.

Fixes

This resolves the issue described in:
#1039

How Has This Been Tested?

From running npm run test

Test Suites: 40 passed, 40 total
Tests: 836 passed, 836 total
Snapshots: 0 total
Time: 16.599 s

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [X ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • [ x] I have read the MCP Documentation
  • [ x] My code follows the repository's style guidelines
  • [ x] New and existing tests pass locally
  • [ x] I have added appropriate error handling
  • [ x] I have added or updated documentation as needed

Additional context

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 14, 2025

Open in StackBlitz

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/sdk@1115

commit: d4408cf

@davidmcwherter
Copy link

@felixweinberger I think this is in-line with SEP-835. Can you take a look?

@pcarleton
Copy link
Member

this duplicates some of #1133

I think we just need to add the 403 handling to the transports (e.g. I don't think we need to change auth.ts)

Copy link
Member

@pcarleton pcarleton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(see prev comment)

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.

3 participants