Switch RFC7523OAuthClientProvider warning to MCPDeprecationWarning (#2996)

This commit is contained in:
Marcelo Trylesinski 2026-06-26 15:27:57 +02:00 • committed by GitHub
commit cc596195bb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 3 deletions

View file

@ -19,6 +19,7 @@ from pydantic import BaseModel, Field
from mcp.client.auth import OAuthClientProvider, OAuthFlowError, OAuthTokenError, TokenStorage from mcp.client.auth import OAuthClientProvider, OAuthFlowError, OAuthTokenError, TokenStorage
from mcp.shared.auth import AuthorizationCodeResult, OAuthClientInformationFull, OAuthClientMetadata from mcp.shared.auth import AuthorizationCodeResult, OAuthClientInformationFull, OAuthClientMetadata
from mcp.shared.exceptions import MCPDeprecationWarning
class ClientCredentialsOAuthProvider(OAuthClientProvider): class ClientCredentialsOAuthProvider(OAuthClientProvider):
@ -412,7 +413,7 @@ class RFC7523OAuthClientProvider(OAuthClientProvider):
warnings.warn( warnings.warn(
"RFC7523OAuthClientProvider is deprecated. Use ClientCredentialsOAuthProvider " "RFC7523OAuthClientProvider is deprecated. Use ClientCredentialsOAuthProvider "
"or PrivateKeyJWTOAuthProvider instead.", "or PrivateKeyJWTOAuthProvider instead.",
DeprecationWarning, MCPDeprecationWarning,
stacklevel=2, stacklevel=2,
) )
super().__init__(server_url, client_metadata, storage, redirect_handler, callback_handler, timeout) super().__init__(server_url, client_metadata, storage, redirect_handler, callback_handler, timeout)

View file

@ -20,6 +20,7 @@ from mcp.shared.auth import (
OAuthMetadata, OAuthMetadata,
OAuthToken, OAuthToken,
) )
from mcp.shared.exceptions import MCPDeprecationWarning
class MockTokenStorage: class MockTokenStorage:
@ -68,7 +69,7 @@ def rfc7523_oauth_provider(client_metadata: OAuthClientMetadata, mock_storage: M
return AuthorizationCodeResult(code="test_auth_code", state="test_state") return AuthorizationCodeResult(code="test_auth_code", state="test_state")
with warnings.catch_warnings(): with warnings.catch_warnings():
warnings.simplefilter("ignore", DeprecationWarning) warnings.simplefilter("ignore", MCPDeprecationWarning)
return RFC7523OAuthClientProvider( return RFC7523OAuthClientProvider(
server_url="https://api.example.com/v1/mcp", server_url="https://api.example.com/v1/mcp",
client_metadata=client_metadata, client_metadata=client_metadata,

View file

@ -14,6 +14,7 @@ from mcp.client.auth.extensions.client_credentials import (
static_assertion_provider, static_assertion_provider,
) )
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken
from mcp.shared.exceptions import MCPDeprecationWarning
# See test_index.py for why this is a per-module mark and not a conftest hook. # See test_index.py for why this is a per-module mark and not a conftest hook.
pytestmark = [pytest.mark.anyio, pytest.mark.filterwarnings("error::mcp.MCPDeprecationWarning")] pytestmark = [pytest.mark.anyio, pytest.mark.filterwarnings("error::mcp.MCPDeprecationWarning")]
@ -105,7 +106,7 @@ async def test_the_one_more_provider_is_private_key_jwt() -> None:
async def test_the_page_does_not_count_the_deprecated_provider() -> None: async def test_the_page_does_not_count_the_deprecated_provider() -> None:
"""Why the `!!! info` says *one* more provider: `RFC7523OAuthClientProvider` warns on construction.""" """Why the `!!! info` says *one* more provider: `RFC7523OAuthClientProvider` warns on construction."""
with pytest.warns(DeprecationWarning, match="RFC7523OAuthClientProvider is deprecated"): with pytest.warns(MCPDeprecationWarning, match="RFC7523OAuthClientProvider is deprecated"):
RFC7523OAuthClientProvider( RFC7523OAuthClientProvider(
server_url="http://localhost:8001/mcp", server_url="http://localhost:8001/mcp",
client_metadata=tutorial001.oauth.context.client_metadata, client_metadata=tutorial001.oauth.context.client_metadata,