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

Revocation requires client_secret to be present

Open jaworpa opened this issue 2 months ago • 7 comments

Initial Checks

  • [x] I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
  • [x] I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue

Release line

2.x (current stable)

Description

What happened?

When Claude Code (or any other public client) triggers revocation - revoke handler requires client_secret to be present, as seen here:

https://github.com/modelcontextprotocol/python-sdk/blob/9972c21aa42054fb1450c5fc614761ed11847ec6/src/mcp/server/auth/handlers/revoke.py#L23

Per OAuth 2.0 specifications (RFC 6749 Section 2.3 and RFC 7009 Section 5), public clients do not have a client_secret and identify themselves using only client_id. This leads to issue when public clients do not sent client secret at all.

In Pydantic v2, defining a field as str | None without a default value still marks the field as required (i.e., nullable value, but the key must exist in the request body).

Steps to reproduce

  1. Authenticate using a public OAuth client (e.g., Claude Code CLI).
  2. Trigger token revocation (e.g., re-authenticating or logging out).
  3. The authorization server returns a 400 Bad Request with: {"error":"invalid_request","error_description":"client_secret: Field required"}

Expected behavior

client_secret should be optional so public clients can revoke tokens without sending a client_secret key.

Fix

Adding default value for client_secret:

client_secret: str | None = None

Workaround

As workaround I'm overriding Request type:

from mcp.server.auth.handlers import revoke

class FixedRevocationRequest(revoke.RevocationRequest):
    client_secret: str | None = None

revoke.RevocationRequest = FixedRevocationRequest

Example Code

from mcp.server.auth.handlers.revoke import RevocationRequest
from pydantic import ValidationError

# Simulate a public client request: client_secret parameter omitted entirely
form_no_secret = {"token": "abc", "client_id": "local-scurri-mcp"}

try:
    req = RevocationRequest.model_validate(form_no_secret)
    print("no-secret: OK ->", req)
except ValidationError as e:
    print("no-secret: FAILS ->", e.errors()[0]["msg"])

Python & MCP Python SDK

MCP version:                                                                                                     2.2.0
Python version:                                                                                                 3.13.9

jaworpa avatar Sep 15 '26 20:09 jaworpa

Confirmed the bug on 2.2.0. RevocationRequest.client_secret is defined as str | None with no default, so Pydantic v2 treats it as required — public clients that omit the field entirely get a 400 {"error":"invalid_request","error_description":"client_secret: Field required"}.

Fix is one line in src/mcp/server/auth/handlers/revoke.py: client_secret: str | None = None

ClientAuthenticator already handles token_endpoint_auth_method == "none" correctly — this is purely a model validation gap. I'd like to fix it if you're open to an outside PR.

rajeevchandra avatar Sep 16 '26 02:09 rajeevchandra

I confirmed this behavior on 2.x. Omitting client_secret from a /revoke request for a client registered with token_endpoint_auth_method: "none" currently results in a 400 response with client_secret: Field required.

The cause is that RevocationRequest.client_secret is defined as str | None but does not have a default value, making the field required. ClientAuthenticator already handles public clients correctly, so the fix is to define it as client_secret: str | None = None.

I’ve implemented this fix and added a regression test that fails before the change and passes after it. The changes are included in #3512.

HARSHAVARDHAN-RAJU5 avatar Sep 16 '26 17:09 HARSHAVARDHAN-RAJU5

Same issue here.

A dynamically registered public client (token_endpoint_auth_method=none) can complete authorization-code + PKCE, obtain and rotate access/refresh tokens, and call the protected MCP resource.

Calling /revoke without client_secret then returns: 400 invalid_request, client_secret: Field required

mulatta avatar Sep 30 '26 14:09 mulatta

Adding one related detail from running a public-client flow with claude.ai (CIMD) on 2.3.0, in case it helps whoever picks this up.

Making client_secret optional in RevocationRequest fixes the 400, but the authorization server metadata built by build_metadata still advertises:

"revocation_endpoint_auth_methods_supported": ["client_secret_post", "client_secret_basic"]

without "none". A public client (Claude registers with token_endpoint_auth_method: "none" through CIMD or DCR) that reads the metadata can conclude it isn't allowed to revoke, so sessions may stay open after disconnecting. It's the same situation #2260 described for token_endpoint_auth_methods_supported.

So the fix probably needs both:

  1. client_secret: str | None = None in RevocationRequest.
  2. "none" in revocation_endpoint_auth_methods_supported (and in token_endpoint_auth_methods_supported, for public clients).

Our workaround on 2.3.0, in case it's useful to others: we replace the /revoke route with a small handler that reuses ClientAuthenticator (it already accepts none), and add "none" to both lists with OAuthMetadata.model_copy(update=...) before serving the metadata.

Enzo-TesterQA avatar Oct 10 '26 14:10 Enzo-TesterQA

I hit this too, running FastMCP's OAuthProxy in front of an upstream IdP with CIMD and DCR public clients on mcp 2.3.0 and fastmcp 4.1.0. POST /revoke with only token and client_id returns 400 invalid_request, client_secret: Field required.

As noted above, the root cause is that RevocationRequest.client_secret is str | None with no default, so pydantic treats the key as required. The metadata has the related gap that revocation_endpoint_auth_methods_supported advertises only client_secret_post and client_secret_basic, so a client has no way to learn that unauthenticated revocation is allowed.

I'm working around both on my side for now. I'd be happy to send the upstream fix. Could a maintainer assign this to me? The PR would cover:

  • client_secret: str | None = None
  • including none in revocation_endpoint_auth_methods_supported when public clients are accepted
  • tests for both

If you'd prefer the metadata change as a separate PR, that's fine too.

shearn89 avatar Oct 16 '26 10:10 shearn89

I have a tested fix ready and would open the PR if this issue can be assigned to me:

  • RevocationRequest.client_secret defaults to None, so a public client (token_endpoint_auth_method: none) can revoke with its client_id alone (RFC 7009 section 2.1);
  • the authorization server metadata adds "none" to revocation_endpoint_auth_methods_supported, as noted above.

Tests: a public client registers and revokes without a secret (400 before, 200 after), and the metadata test checks the three methods; tests/server, tests/shared and tests/client/test_auth.py pass (2545), ruff is clean. Branch: https://github.com/fedorello/python-sdk/tree/fix/revoke-public-client-secret (prepared with AI assistance).

fedorello avatar Oct 26 '26 01:10 fedorello

Confirmed on 2.3.0, with one case not mentioned above: confidential clients that use client_secret_basic are rejected too.

A client_secret_basic client sends its secret in the Authorization header (RFC 6749 §2.3.1), so the form body has no client_secret. ClientAuthenticator accepts the header, and then RevocationRequest.model_validate(dict(form_data)) fails on the missing field:

token_endpoint_auth_method Request Result on 2.3.0
none token, client_id 400 client_secret: Field required
client_secret_post token, client_id, client_secret in the form 200
client_secret_basic token, client_id, secret in the Basic header 400 client_secret: Field required

So client_secret_post is the only method that can revoke today, even though the SDK's metadata advertises client_secret_basic for the revocation endpoint.

The client_secret: str | None = None fix proposed above covers both cases, because ClientAuthenticator already checks the secret by itself. It would help if the regression test covered a Basic-header client as well as a none client.

Reproduction
import base64
from starlette.applications import Starlette
from starlette.routing import Route
from starlette.testclient import TestClient
from mcp.server.auth.handlers.revoke import RevocationHandler
from mcp.server.auth.middleware.client_auth import ClientAuthenticator
from mcp.shared.auth import OAuthClientInformationFull

CLIENTS = {
    "pub": dict(token_endpoint_auth_method="none"),
    "post": dict(token_endpoint_auth_method="client_secret_post", client_secret="s3"),
    "basic": dict(token_endpoint_auth_method="client_secret_basic", client_secret="s3"),
}

class Provider:
    async def get_client(self, cid):
        return OAuthClientInformationFull(client_id=cid, redirect_uris=["https://x/cb"], **CLIENTS[cid])
    async def load_access_token(self, t): return None
    async def load_refresh_token(self, c, t): return None
    async def revoke_token(self, t): pass

p = Provider()
app = Starlette(routes=[Route("/revoke", RevocationHandler(p, ClientAuthenticator(p)).handle, methods=["POST"])])
c = TestClient(app)
print(c.post("/revoke", data={"token": "t", "client_id": "pub"}).text)
print(c.post("/revoke", data={"token": "t", "client_id": "post", "client_secret": "s3"}).status_code)
basic = {"Authorization": "Basic " + base64.b64encode(b"basic:s3").decode()}
print(c.post("/revoke", data={"token": "t", "client_id": "basic"}, headers=basic).text)

For prioritisation: we run a remote MCP server on mcp 2.3.0 that Claude, ChatGPT and Antigravity connect to as public clients (CIMD and DCR). When those clients call /revoke on disconnect, the request fails, so the user's tokens stay valid until they expire.

If a maintainer would like an outside PR for this, I'm happy to send one. It would stay small:

  • client_secret: str | None = None in RevocationRequest, with no other change to the handler, since ClientAuthenticator already checks the secret;
  • "none" in revocation_endpoint_auth_methods_supported, as proposed above;
  • regression tests for revoking as a none client and as a client_secret_basic client, plus the metadata assertion.

If someone else is assigned, the Basic-header test is the part I'd ask them to include.

AI disclosure: drafted with Claude Code. I ran the reproduction against mcp 2.3.0 and reviewed this comment before posting.

rajeshreesingh-wework avatar Nov 11 '26 18:11 rajeshreesingh-wework