Skip to content

Commit d52937b

Browse files
Make refresh_token grant type optional in DCR handler (#1651)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent c7cbfbb commit d52937b

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/mcp/server/auth/handlers/register.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ async def handle(self, request: Request) -> Response:
7373
),
7474
status_code=400,
7575
)
76-
if not {"authorization_code", "refresh_token"}.issubset(set(client_metadata.grant_types)):
76+
if "authorization_code" not in client_metadata.grant_types:
7777
return PydanticJSONResponse(
7878
content=RegistrationErrorResponse(
7979
error="invalid_client_metadata",
80-
error_description="grant_types must be authorization_code and refresh_token",
80+
error_description="grant_types must include 'authorization_code'",
8181
),
8282
status_code=400,
8383
)

tests/server/fastmcp/auth/test_auth_integration.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,19 +939,35 @@ async def test_client_registration_default_scopes(
939939
assert registered_client.scope == "read write"
940940

941941
@pytest.mark.anyio
942-
async def test_client_registration_invalid_grant_type(self, test_client: httpx.AsyncClient):
942+
async def test_client_registration_with_authorization_code_only(self, test_client: httpx.AsyncClient):
943+
"""Test that registration succeeds with only authorization_code (refresh_token is optional per RFC 7591)."""
943944
client_metadata = {
944945
"redirect_uris": ["https://client.example.com/callback"],
945946
"client_name": "Test Client",
946947
"grant_types": ["authorization_code"],
947948
}
948949

950+
response = await test_client.post("/register", json=client_metadata)
951+
assert response.status_code == 201
952+
client_info = response.json()
953+
assert "client_id" in client_info
954+
assert client_info["grant_types"] == ["authorization_code"]
955+
956+
@pytest.mark.anyio
957+
async def test_client_registration_missing_authorization_code(self, test_client: httpx.AsyncClient):
958+
"""Test that registration fails when authorization_code grant type is missing."""
959+
client_metadata = {
960+
"redirect_uris": ["https://client.example.com/callback"],
961+
"client_name": "Test Client",
962+
"grant_types": ["refresh_token"],
963+
}
964+
949965
response = await test_client.post("/register", json=client_metadata)
950966
assert response.status_code == 400
951967
error_data = response.json()
952968
assert "error" in error_data
953969
assert error_data["error"] == "invalid_client_metadata"
954-
assert error_data["error_description"] == "grant_types must be authorization_code and refresh_token"
970+
assert error_data["error_description"] == "grant_types must include 'authorization_code'"
955971

956972
@pytest.mark.anyio
957973
async def test_client_registration_with_additional_grant_type(self, test_client: httpx.AsyncClient):

0 commit comments

Comments
 (0)