diff --git a/src/mcp/server/auth/handlers/register.py b/src/mcp/server/auth/handlers/register.py index 621a0f37d6..fcceb050d0 100644 --- a/src/mcp/server/auth/handlers/register.py +++ b/src/mcp/server/auth/handlers/register.py @@ -117,6 +117,15 @@ async def handle(self, request: Request) -> Response: status_code=400, ) + if not client_metadata.redirect_uris: + return PydanticJSONResponse( + content=RegistrationErrorResponse( + error="invalid_client_metadata", + error_description="redirect_uris is required for authorization_code grant", + ), + status_code=400, + ) + client_id_issued_at = int(time.time()) # RFC 7591 ยง3.2.1: client_secret_expires_at is REQUIRED whenever a client_secret is # issued, with 0 (not omission) meaning it never expires; a public client gets none. diff --git a/tests/server/auth/test_error_handling.py b/tests/server/auth/test_error_handling.py index f13f23ea33..0fa401472a 100644 --- a/tests/server/auth/test_error_handling.py +++ b/tests/server/auth/test_error_handling.py @@ -117,6 +117,22 @@ async def test_registration_error_handling(client: httpx2.AsyncClient, oauth_pro assert data["error_description"] == "The redirect URI is invalid" +@pytest.mark.anyio +async def test_registration_rejects_null_redirect_uris(client: httpx2.AsyncClient): + """Explicit null redirect_uris must be rejected for authorization_code clients.""" + response = await client.post( + "/register", + json={ + "redirect_uris": None, + "client_name": "Null Redirect Client", + }, + ) + assert response.status_code == 400, response.content + data = response.json() + assert data["error"] == "invalid_client_metadata" + assert "redirect_uris" in data["error_description"] + + @pytest.mark.anyio async def test_authorize_error_handling( client: httpx2.AsyncClient,