File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed
src/mcp/server/auth/handlers
tests/server/fastmcp/auth Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -74,12 +74,20 @@ async def handle(self, request: Request) -> Response:
7474 ),
7575 status_code = 400 ,
7676 )
77- if set (client_metadata .grant_types ) != {"authorization_code" , "refresh_token" }:
77+ grant_types_set = set (client_metadata .grant_types )
78+ valid_sets = [
79+ {"authorization_code" , "refresh_token" },
80+ {"client_credentials" },
81+ ]
82+
83+ if grant_types_set not in valid_sets :
7884 return PydanticJSONResponse (
7985 content = RegistrationErrorResponse (
8086 error = "invalid_client_metadata" ,
81- error_description = "grant_types must be authorization_code "
82- "and refresh_token" ,
87+ error_description = (
88+ "grant_types must be authorization_code and refresh_token "
89+ "or client_credentials"
90+ ),
8391 ),
8492 status_code = 400 ,
8593 )
Original file line number Diff line number Diff line change @@ -1001,9 +1001,31 @@ async def test_client_registration_invalid_grant_type(
10011001 assert error_data ["error" ] == "invalid_client_metadata"
10021002 assert (
10031003 error_data ["error_description" ]
1004- == "grant_types must be authorization_code and refresh_token"
1004+ == (
1005+ "grant_types must be authorization_code and "
1006+ "refresh_token or client_credentials"
1007+ )
1008+ )
1009+
1010+ @pytest .mark .anyio
1011+ async def test_client_registration_client_credentials (
1012+ self , test_client : httpx .AsyncClient
1013+ ):
1014+ client_metadata = {
1015+ "redirect_uris" : ["https://client.example.com/callback" ],
1016+ "client_name" : "CC Client" ,
1017+ "grant_types" : ["client_credentials" ],
1018+ }
1019+
1020+ response = await test_client .post (
1021+ "/register" ,
1022+ json = client_metadata ,
10051023 )
10061024
1025+ assert response .status_code == 201 , response .content
1026+ client_info = response .json ()
1027+ assert client_info ["grant_types" ] == ["client_credentials" ]
1028+
10071029
10081030class TestAuthorizeEndpointErrors :
10091031 """Test error handling in the OAuth authorization endpoint."""
You can’t perform that action at this time.
0 commit comments