Skip to content

Commit 9323efa

Browse files
authored
Issue 1379 patch - Fix MCP server OAuth not working with Visual Studio Code and others with extra grant_types (#1380)
1 parent 1940040 commit 9323efa

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def handle(self, request: Request) -> Response:
6868
),
6969
status_code=400,
7070
)
71-
if set(client_metadata.grant_types) != {"authorization_code", "refresh_token"}:
71+
if not {"authorization_code", "refresh_token"}.issubset(set(client_metadata.grant_types)):
7272
return PydanticJSONResponse(
7373
content=RegistrationErrorResponse(
7474
error="invalid_client_metadata",

src/mcp/shared/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class OAuthClientMetadata(BaseModel):
4747
# ie: we do not support client_secret_basic
4848
token_endpoint_auth_method: Literal["none", "client_secret_post"] = "client_secret_post"
4949
# grant_types: this implementation only supports authorization_code & refresh_token
50-
grant_types: list[Literal["authorization_code", "refresh_token"]] = [
50+
grant_types: list[Literal["authorization_code", "refresh_token"] | str] = [
5151
"authorization_code",
5252
"refresh_token",
5353
]

tests/server/fastmcp/auth/test_auth_integration.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -937,6 +937,23 @@ async def test_client_registration_invalid_grant_type(self, test_client: httpx.A
937937
assert error_data["error"] == "invalid_client_metadata"
938938
assert error_data["error_description"] == "grant_types must be authorization_code and refresh_token"
939939

940+
@pytest.mark.anyio
941+
async def test_client_registration_with_additional_grant_type(self, test_client: httpx.AsyncClient):
942+
client_metadata = {
943+
"redirect_uris": ["https://client.example.com/callback"],
944+
"client_name": "Test Client",
945+
"grant_types": ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:device_code"],
946+
}
947+
948+
response = await test_client.post("/register", json=client_metadata)
949+
assert response.status_code == 201
950+
client_info = response.json()
951+
952+
# Verify client was registered successfully
953+
assert "client_id" in client_info
954+
assert "client_secret" in client_info
955+
assert client_info["client_name"] == "Test Client"
956+
940957
@pytest.mark.anyio
941958
async def test_client_registration_with_additional_response_types(
942959
self, test_client: httpx.AsyncClient, mock_oauth_provider: MockOAuthProvider

0 commit comments

Comments
 (0)