python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

Bug: validate_scope rejects client scopes when required scopes in None

Open nik1097 opened this issue 9 months ago • 5 comments

Initial Checks

  • [x] I confirm that I'm using the latest version of MCP Python SDK
  • [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue

Description

The validate_scope() function in the Python SDK incorrectly handles cases where there are no required scopes from the client. Instead of treating None as no restrictions, it interprets it as an empty list of allowed scopes. This causes scopes in the token to be rejected with InvalidScopeError, even if the client should be allowed to request them.

Example Code


Python & MCP Python SDK

1.26.0

nik1097 avatar Mar 05 '26 16:03 nik1097

I'll take this. The bug is in OAuthClientMetadata.validate_scope() — when self.scope is None (no scopes registered), it converts to an empty list, rejecting all requested scopes. The fix is to treat None as "no restrictions" and allow any scope through.

@nik1097 thanks for reporting, will have a PR up shortly.

shivama205 avatar Mar 06 '26 03:03 shivama205

Hi! I've submitted a fix for this issue in PR #2246.

The fix handles the case where client registration has scope=None by returning all requested scopes immediately, instead of treating None as an empty allowed list.

Let me know if any changes are needed!

goingforstudying-ctrl avatar Mar 08 '26 05:03 goingforstudying-ctrl

Hey! Just realized I forgot to link my PR here — #2224 has been up since March 6 with tests and passing CI. Apologies for not linking it sooner!

shivama205 avatar Mar 08 '26 15:03 shivama205

Opened a fix in #2461 -- returns requested scopes immediately when self.scope is None (no restrictions registered), with 7 test cases covering the edge cases.

Christian-Sidak avatar Apr 17 '26 04:04 Christian-Sidak

From the current issue state, I understand #2301 from @maxisbey is the current path: remove the registration-scope check entirely, aligned with the step-up flow. I also see it is currently conflicting with main after the recent auth changes.

I hit this in practice: an OAuth client registered without a scope field cannot authorize with requested scopes, and the step-up flow fails after the scope challenge.

Would it help if I picked up one of two paths? Entirely your call:

  1. Rebase and carry #2301 forward against current main, preserving that approach and attribution.
  2. Prepare a narrow v1.x-only bugfix that early-returns when the registered scope is None, if you consider this eligible for v1.x maintenance.

Happy to be assigned either path, or to leave it alone if it's already planned.

AI assistance used for drafting; reviewed and owned by me.

saneGuy avatar Jul 22 '26 16:07 saneGuy