Skip to content

MCP Python SDK Implementation Gap-13: Server Missing Token Issuer Validation #1445

Closed as duplicate

Description

@younaman

Initial Checks

Description

Summary

The MCP Python SDK server violates the specification requirement that "MCP servers MUST validate that tokens presented to them were specifically issued for their use." The server's verify_token() implementation only performs token loading without validating the token's issuer, allowing tokens from other authorization servers to be accepted.

Issue Details

Rule Violation

MCP Specification: "MCP servers MUST validate that tokens presented to them were specifically issued for their use."

Root Cause

File: src/mcp/server/auth/provider.py

# Lines 304-306: ProviderTokenVerifier.verify_token()
async def verify_token(self, token: str) -> AccessToken | None:
    """Verify token using the provider's load_access_token method."""
    return await self.provider.load_access_token(token)

Current validation only checks:

  • ✅ Token exists in storage
  • ✅ Token is not expired (in BearerAuthBackend)

Missing critical validation:

  • ❌ Token issuer verification

Evidence of Missing Issuer Validation

File: src/mcp/server/auth/middleware/bearer_auth.py

# Lines 30-49: BearerAuthBackend.authenticate()
async def authenticate(self, conn: HTTPConnection):
    # ... extract token ...
    
    # Validate the token with the verifier
    auth_info = await self.token_verifier.verify_token(token)
    
    if not auth_info:
        return None
    
    if auth_info.expires_at and auth_info.expires_at < int(time.time()):
        return None
    
    return AuthCredentials(auth_info.scopes), AuthenticatedUser(auth_info)
    # ❌ Missing: No validation of token issuer against server's issuer

Impact

  • Compliance Violation: Fails "MUST validate tokens were specifically issued for their use" requirement

Files Affected

  • src/mcp/server/auth/provider.py (lines 304-306)
  • src/mcp/server/auth/middleware/bearer_auth.py (lines 30-49)

One Possible Solution

Add issuer validation to verify_token() or BearerAuthBackend.authenticate():

# Validate token issuer matches server's issuer
if auth_info.issuer and auth_info.issuer != self.server_issuer_url:
    return None  # Token not issued for this server

Related Issues

This issue is related to #1435 (RFC 8707 resource validation), both stemming from incomplete verify_token() implementation. While they address different compliance requirements, fixing the comprehensive token validation in verify_token() would resolve both issues.

Example Code

Python & MCP Python SDK

latest

Activity

  1. added
    authIssues and PRs related to Authentication / OAuth
    ready for workEnough information for someone to start working on
    P3Nice to haves, rare edge cases
    bugSomething isn't working
    on Oct 8, 2025
  2. felixweinberger commented on Oct 8, 2025

    @felixweinberger
    Contributor

    Hi @younaman thanks for all these submissions so far - could you confirm whether you've validated and discovered these gaps directly via inspection or are these generated via an LLM or coding agent analysis?

    That would help us evaluate the priority here - in general if these are gaps you were able to confirm yourself that would provide a higher priority here.

  3. felixweinberger commented on Oct 10, 2025

    @felixweinberger
    Contributor

    Hi @younaman thanks for reporting all these issues - I think a lot of this goes very much in line with a SEP we currently have open for Conformance testing, please take a look modelcontextprotocol/modelcontextprotocol#1627 by @pcarleton with an early prototype currently WIP modelcontextprotocol/modelcontextprotocol#948 by @ochafik

    TL;DR we're working on building a test suite that makes it possible to verify correct, spec compliant behavior via automated test suites, with an initial focus on auth (which is also the area of most of the issues you reported here).

    It would be great if you'd be able to contribute to that implementation with runnable tests that demonstrate the compliance failure - that way we not only record potential spec violations but also have them as runnable regression tests to contribute to spec stability over time across all our SDKs (not just Python).

    Please take a look at the links for more info - I believe it'll be most useful to contribute these as test cases to modelcontextprotocol/modelcontextprotocol#1627

  4. removed
    ready for workEnough information for someone to start working on
    P3Nice to haves, rare edge cases
    on Oct 10, 2025
  5. younaman commented on Oct 10, 2025

    @younaman
    Author

    @felixweinberger Hi, thanks for sharing this!

    I’d be very happy to contribute to the conformance testing efforts. I’m currently busy with my paper writing and plan to submit it in mid-November. After that, I’ll take a closer look at the SEP and the prototype.

    I’d also be glad to help with compliance testing for other SDKs. In fact, I’ve already found similar compliance issues in several other SDKs. I’ll submit issues for those as well, and they can serve as inputs for regression testing and help strengthen MCP’s conformance checks.

    If you have any questions or concerns, feel free to let me know.

  6. younaman commented on Oct 11, 2025

    @younaman
    Author

    Hi @younaman thanks for all these submissions so far - could you confirm whether you've validated and discovered these gaps directly via inspection or are these generated via an LLM or coding agent analysis?

    That would help us evaluate the priority here - in general if these are gaps you were able to confirm yourself that would provide a higher priority here.

    I wrote a static analysis tool to identify all these potential risks. After that, I check each result manually to confirm it's a true positive. After that, I generate this report with the help of cursor.

  7. younaman commented on Oct 11, 2025

    @younaman
    Author

    Hi @younaman thanks for all these submissions so far - could you confirm whether you've validated and discovered these gaps directly via inspection or are these generated via an LLM or coding agent analysis?
    That would help us evaluate the priority here - in general if these are gaps you were able to confirm yourself that would provide a higher priority here.

    I wrote a static analysis tool to identify all these potential risks. After that, I check each result manually to confirm it's a true positive. After that, I generate this report with the help of cursor.

    Sorry for responding it late, my mailbox only shows your latest comments and ignores the former ones :)

  8. felixweinberger commented on Oct 13, 2025

    @felixweinberger
    Contributor

    Hi @younaman thanks for all these submissions so far - could you confirm whether you've validated and discovered these gaps directly via inspection or are these generated via an LLM or coding agent analysis?
    That would help us evaluate the priority here - in general if these are gaps you were able to confirm yourself that would provide a higher priority here.

    I wrote a static analysis tool to identify all these potential risks. After that, I check each result manually to confirm it's a true positive. After that, I generate this report with the help of cursor.

    Very cool - I think sharing what you can on how you implemented that could be a great addition to modelcontextprotocol/modelcontextprotocol#1627

  9. younaman commented on Oct 13, 2025

    @younaman
    Author

    @felixweinberger Thanks! I plan to open source it and will share you the link once it’s published.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    authIssues and PRs related to Authentication / OAuthbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions