1313from inline_snapshot import snapshot
1414from pydantic import AnyHttpUrl
1515
16- from mcp .client .auth import ClientCredentialsProvider , OAuthClientProvider
16+ from mcp .client .auth import (
17+ ClientCredentialsProvider ,
18+ OAuthClientProvider ,
19+ _discover_oauth_metadata ,
20+ _get_authorization_base_url ,
21+ )
1722from mcp .server .auth .routes import build_metadata
1823from mcp .server .auth .settings import ClientRegistrationOptions , RevocationOptions
1924from mcp .shared .auth import (
@@ -190,21 +195,19 @@ def test_get_authorization_base_url(self, oauth_provider):
190195 """Test authorization base URL extraction."""
191196 # Test with path
192197 assert (
193- oauth_provider . _get_authorization_base_url ("https://api.example.com/v1/mcp" )
198+ _get_authorization_base_url ("https://api.example.com/v1/mcp" )
194199 == "https://api.example.com"
195200 )
196201
197202 # Test with no path
198203 assert (
199- oauth_provider . _get_authorization_base_url ("https://api.example.com" )
204+ _get_authorization_base_url ("https://api.example.com" )
200205 == "https://api.example.com"
201206 )
202207
203208 # Test with port
204209 assert (
205- oauth_provider ._get_authorization_base_url (
206- "https://api.example.com:8080/path/to/mcp"
207- )
210+ _get_authorization_base_url ("https://api.example.com:8080/path/to/mcp" )
208211 == "https://api.example.com:8080"
209212 )
210213
@@ -224,7 +227,7 @@ async def test_discover_oauth_metadata_success(
224227 mock_response .json .return_value = metadata_response
225228 mock_client .get .return_value = mock_response
226229
227- result = await oauth_provider . _discover_oauth_metadata (
230+ result = await _discover_oauth_metadata (
228231 "https://api.example.com/v1/mcp"
229232 )
230233
@@ -253,7 +256,7 @@ async def test_discover_oauth_metadata_not_found(self, oauth_provider):
253256 mock_response .status_code = 404
254257 mock_client .get .return_value = mock_response
255258
256- result = await oauth_provider . _discover_oauth_metadata (
259+ result = await _discover_oauth_metadata (
257260 "https://api.example.com/v1/mcp"
258261 )
259262
@@ -280,7 +283,7 @@ async def test_discover_oauth_metadata_cors_fallback(
280283 mock_response_success , # Second call succeeds
281284 ]
282285
283- result = await oauth_provider . _discover_oauth_metadata (
286+ result = await _discover_oauth_metadata (
284287 "https://api.example.com/v1/mcp"
285288 )
286289
@@ -334,9 +337,7 @@ async def test_register_oauth_client_fallback_endpoint(
334337 mock_client .post .return_value = mock_response
335338
336339 # Mock metadata discovery to return None (fallback)
337- with patch .object (
338- oauth_provider , "_discover_oauth_metadata" , return_value = None
339- ):
340+ with patch ("mcp.client.auth._discover_oauth_metadata" , return_value = None ):
340341 result = await oauth_provider ._register_oauth_client (
341342 "https://api.example.com/v1/mcp" ,
342343 oauth_provider .client_metadata ,
@@ -363,9 +364,7 @@ async def test_register_oauth_client_failure(self, oauth_provider):
363364 mock_client .post .return_value = mock_response
364365
365366 # Mock metadata discovery to return None (fallback)
366- with patch .object (
367- oauth_provider , "_discover_oauth_metadata" , return_value = None
368- ):
367+ with patch ("mcp.client.auth._discover_oauth_metadata" , return_value = None ):
369368 with pytest .raises (httpx .HTTPStatusError ):
370369 await oauth_provider ._register_oauth_client (
371370 "https://api.example.com/v1/mcp" ,
@@ -993,26 +992,26 @@ def test_build_metadata(
993992 revocation_options = RevocationOptions (enabled = True ),
994993 )
995994
996- assert metadata == snapshot (
997- OAuthMetadata (
998- issuer = AnyHttpUrl (issuer_url ),
999- authorization_endpoint = AnyHttpUrl (authorization_endpoint ),
1000- token_endpoint = AnyHttpUrl (token_endpoint ),
1001- registration_endpoint = AnyHttpUrl (registration_endpoint ),
1002- scopes_supported = ["read" , "write" , "admin" ],
1003- grant_types_supported = [
1004- "authorization_code" ,
1005- "refresh_token" ,
1006- "client_credentials" ,
1007- ],
1008- token_endpoint_auth_methods_supported = ["client_secret_post" ],
1009- service_documentation = AnyHttpUrl (service_documentation_url ),
1010- revocation_endpoint = AnyHttpUrl (revocation_endpoint ),
1011- revocation_endpoint_auth_methods_supported = ["client_secret_post" ],
1012- code_challenge_methods_supported = ["S256" ],
1013- )
995+ expected = OAuthMetadata (
996+ issuer = AnyHttpUrl (issuer_url ),
997+ authorization_endpoint = AnyHttpUrl (authorization_endpoint ),
998+ token_endpoint = AnyHttpUrl (token_endpoint ),
999+ registration_endpoint = AnyHttpUrl (registration_endpoint ),
1000+ scopes_supported = ["read" , "write" , "admin" ],
1001+ grant_types_supported = [
1002+ "authorization_code" ,
1003+ "refresh_token" ,
1004+ "client_credentials" ,
1005+ ],
1006+ token_endpoint_auth_methods_supported = ["client_secret_post" ],
1007+ service_documentation = AnyHttpUrl (service_documentation_url ),
1008+ revocation_endpoint = AnyHttpUrl (revocation_endpoint ),
1009+ revocation_endpoint_auth_methods_supported = ["client_secret_post" ],
1010+ code_challenge_methods_supported = ["S256" ],
10141011 )
10151012
1013+ assert metadata == expected
1014+
10161015
10171016class TestClientCredentialsProvider :
10181017 @pytest .mark .anyio
0 commit comments