Skip to content

Conversation

@pull
Copy link

@pull pull bot commented Jun 25, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by Sourcery

Add conditional resource parameter support to OAuth requests driven by protocol version or protected resource metadata

New Features:

  • Conditionally include the resource parameter in authorization, token exchange, and refresh requests when the protocol version is >=2025-06-18 or protected resource metadata is present

Enhancements:

  • Add protocol_version field to OAuthContext and implement should_include_resource_param helper
  • Capture MCP_PROTOCOL_VERSION header into context during the async auth flow

Tests:

  • Introduce TestProtectedResourceMetadata suite to verify resource parameter inclusion and exclusion across different protocol versions and metadata scenarios

@pull pull bot added the ⤵️ pull label Jun 25, 2025
@pull pull bot merged commit 41f3bc3 into Stars1233:main Jun 25, 2025
@gitnotebooks
Copy link

gitnotebooks bot commented Jun 25, 2025

Review these changes at https://app.gitnotebooks.com/Stars1233/python-sdk/pull/87

@sourcery-ai
Copy link

sourcery-ai bot commented Jun 25, 2025

Reviewer's Guide

Introduce conditional handling of the OAuth “resource” parameter based on protocol version or explicit metadata by extending the context, updating the auth flows to respect this logic, and adding tests to verify all scenarios.

Sequence diagram for conditional inclusion of OAuth resource parameter

sequenceDiagram
    participant Client as OAuthClientProvider
    participant Context as OAuthContext
    participant Server as OAuth Server

    Client->>Context: Get protocol_version from request headers
    Client->>Context: should_include_resource_param(protocol_version)
    alt Should include resource param
        Context-->>Client: true
        Client->>Context: get_resource_url()
        Client->>Server: Send request with resource param
    else Should not include resource param
        Context-->>Client: false
        Client->>Server: Send request without resource param
    end
Loading

Class diagram for updated OAuthContext and OAuthClientProvider

classDiagram
    class OAuthContext {
        +ProtectedResourceMetadata|None protected_resource_metadata
        +OAuthMetadata|None oauth_metadata
        +str|None auth_server_url
        +str|None protocol_version
        +OAuthClientInformationFull|None client_info
        +get_resource_url() str
        +should_include_resource_param(protocol_version: str|None) bool
    }

    class OAuthClientProvider {
        +OAuthContext context
        +async_auth_flow(request: httpx.Request) AsyncGenerator[httpx.Request, None]
        +_perform_authorization() tuple[str, str]
        +_exchange_token(auth_code: str, code_verifier: str) httpx.Request
        +_refresh_token() httpx.Request
    }

    OAuthClientProvider --> OAuthContext
Loading

File-Level Changes

Change Details Files
Extend OAuthContext with protocol_version tracking and resource-inclusion logic
  • Add protocol_version attribute to OAuthContext
  • Implement should_include_resource_param based on protected metadata or version ≥ 2025-06-18
src/mcp/client/auth.py
Make OAuthClientProvider include the resource param only when appropriate and capture version header
  • Wrap resource field additions in _perform_authorization, _exchange_token, _refresh_token with should_include_resource_param check
  • Set context.protocol_version from MCP-Protocol-Version header in async_auth_flow
src/mcp/client/auth.py
Add tests for protected resource parameter behavior under different conditions
  • Verify inclusion for protocol ≥ 2025-06-18
  • Verify exclusion for protocol < 2025-06-18
  • Verify override inclusion when protected_resource_metadata is set
tests/client/test_auth.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant