π The fast, Pythonic way to build MCP servers and clients.
Drop unpinned ping from auth example clients (#6418)
nate nowack3e125b610ac1
diff --git a/examples/auth/authkit/client.py b/examples/auth/authkit/client.pyindex 562637bec..06f13a2cb 100644--- a/examples/auth/authkit/client.py+++ b/examples/auth/authkit/client.py@@ -20,7 +20,6 @@ async def main():# public client and avoid token exchange errors.auth = OAuth(additional_client_metadata={"token_endpoint_auth_method": "none"})async with Client(SERVER_URL, auth=auth) as client:- assert await client.ping()print("Successfully authenticated!")tools = await client.list_tools()diff --git a/examples/auth/aws_oauth/client.py b/examples/auth/aws_oauth/client.pyindex afcf54fd1..69c41b4f6 100644--- a/examples/auth/aws_oauth/client.py+++ b/examples/auth/aws_oauth/client.py@@ -16,7 +16,6 @@ SERVER_URL = "http://127.0.0.1:8000/mcp"async def main():try:async with Client(SERVER_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated!")tools = await client.list_tools()diff --git a/examples/auth/azure_oauth/client.py b/examples/auth/azure_oauth/client.pyindex 5f1f39bb2..256bd52cf 100644--- a/examples/auth/azure_oauth/client.py+++ b/examples/auth/azure_oauth/client.py@@ -16,7 +16,6 @@ SERVER_URL = "http://127.0.0.1:8000/mcp"async def main():try:async with Client(SERVER_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated!")tools = await client.list_tools()diff --git a/examples/auth/clerk_oauth/client.py b/examples/auth/clerk_oauth/client.pyindex d9d44c9d6..0f9d034d0 100644--- a/examples/auth/clerk_oauth/client.py+++ b/examples/auth/clerk_oauth/client.py@@ -17,7 +17,6 @@ SERVER_URL = "http://127.0.0.1:8000/mcp"async def main():try:async with Client(SERVER_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated!")tools = await client.list_tools()diff --git a/examples/auth/discord_oauth/client.py b/examples/auth/discord_oauth/client.pyindex 880b86f4d..6f0e1f3e7 100644--- a/examples/auth/discord_oauth/client.py+++ b/examples/auth/discord_oauth/client.py@@ -16,7 +16,6 @@ SERVER_URL = "http://127.0.0.1:8000/mcp"async def main():try:async with Client(SERVER_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated!")tools = await client.list_tools()diff --git a/examples/auth/github_oauth/client.py b/examples/auth/github_oauth/client.pyindex 8722a547c..c1c847570 100644--- a/examples/auth/github_oauth/client.py+++ b/examples/auth/github_oauth/client.py@@ -16,7 +16,6 @@ SERVER_URL = "http://127.0.0.1:8000/mcp"async def main():try:async with Client(SERVER_URL, auth=OAuth()) as client:- assert await client.ping()print("β Successfully authenticated!")tools = await client.list_tools()diff --git a/examples/auth/google_oauth/client.py b/examples/auth/google_oauth/client.pyindex 5f1f39bb2..256bd52cf 100644--- a/examples/auth/google_oauth/client.py+++ b/examples/auth/google_oauth/client.py@@ -16,7 +16,6 @@ SERVER_URL = "http://127.0.0.1:8000/mcp"async def main():try:async with Client(SERVER_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated!")tools = await client.list_tools()diff --git a/examples/auth/huggingface_oauth/client.py b/examples/auth/huggingface_oauth/client.pyindex d7f2b760a..e9cf1ff2b 100644--- a/examples/auth/huggingface_oauth/client.py+++ b/examples/auth/huggingface_oauth/client.py@@ -16,7 +16,6 @@ SERVER_URL = "http://localhost:8000/mcp"async def main():try:async with Client(SERVER_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated!")tools = await client.list_tools()diff --git a/examples/auth/keycloak_oauth/client.py b/examples/auth/keycloak_oauth/client.pyindex 4992abbab..93de5eea9 100644--- a/examples/auth/keycloak_oauth/client.py+++ b/examples/auth/keycloak_oauth/client.py@@ -13,7 +13,6 @@ SERVER_URL = "http://127.0.0.1:8000/mcp"async def main():async with Client(SERVER_URL, auth="oauth") as client:- assert await client.ping()print("Successfully authenticated!")tools = await client.list_tools()diff --git a/examples/auth/mounted/client.py b/examples/auth/mounted/client.pyindex 2b691951f..188030bad 100644--- a/examples/auth/mounted/client.py+++ b/examples/auth/mounted/client.py@@ -19,7 +19,6 @@ async def main():print("\n--- GitHub Server ---")try:async with Client(GITHUB_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated!")tools = await client.list_tools()@@ -34,7 +33,6 @@ async def main():print("\n--- Google Server ---")try:async with Client(GOOGLE_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated!")tools = await client.list_tools()diff --git a/examples/auth/oci_oauth/client.py b/examples/auth/oci_oauth/client.pyindex d7f2b760a..e9cf1ff2b 100644--- a/examples/auth/oci_oauth/client.py+++ b/examples/auth/oci_oauth/client.py@@ -16,7 +16,6 @@ SERVER_URL = "http://localhost:8000/mcp"async def main():try:async with Client(SERVER_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated!")tools = await client.list_tools()diff --git a/examples/auth/propelauth_oauth/client.py b/examples/auth/propelauth_oauth/client.pyindex fd6a84b4e..542f7917a 100644--- a/examples/auth/propelauth_oauth/client.py+++ b/examples/auth/propelauth_oauth/client.py@@ -16,7 +16,6 @@ SERVER_URL = "http://127.0.0.1:8000/mcp"async def main():try:async with Client(SERVER_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated with PropelAuth!")tools = await client.list_tools()diff --git a/examples/auth/scalekit_oauth/client.py b/examples/auth/scalekit_oauth/client.pyindex 4146b2c49..00ba0f494 100644--- a/examples/auth/scalekit_oauth/client.py+++ b/examples/auth/scalekit_oauth/client.py@@ -16,7 +16,6 @@ SERVER_URL = "http://127.0.0.1:8000/mcp"async def main():try:async with Client(SERVER_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated with Scalekit!")tools = await client.list_tools()diff --git a/examples/auth/workos_oauth/client.py b/examples/auth/workos_oauth/client.pyindex 5f1f39bb2..256bd52cf 100644--- a/examples/auth/workos_oauth/client.py+++ b/examples/auth/workos_oauth/client.py@@ -16,7 +16,6 @@ SERVER_URL = "http://127.0.0.1:8000/mcp"async def main():try:async with Client(SERVER_URL, auth="oauth") as client:- assert await client.ping()print("β Successfully authenticated!")tools = await client.list_tools()diff --git a/tests/test_examples_ping.py b/tests/test_examples_ping.pynew file mode 100644index 000000000..41c912682--- /dev/null+++ b/tests/test_examples_ping.py@@ -0,0 +1,38 @@+"""Example clients must not ping without pinning the legacy protocol era.++The default client negotiates the modern era, where `ping` is not a method,+so an unpinned `client.ping()` fails with "Method not found".+"""++import ast+from pathlib import Path++EXAMPLES_DIR = Path(__file__).parent.parent / "examples"+++def _calls_ping(tree: ast.AST) -> bool:+ return any(+ isinstance(node, ast.Call)+ and isinstance(node.func, ast.Attribute)+ and node.func.attr == "ping"+ for node in ast.walk(tree)+ )+++def _pins_legacy_mode(tree: ast.AST) -> bool:+ return any(+ isinstance(node, ast.keyword)+ and node.arg == "mode"+ and isinstance(node.value, ast.Constant)+ and node.value.value == "legacy"+ for node in ast.walk(tree)+ )+++def test_example_clients_only_ping_in_legacy_mode():+ offenders = []+ for path in sorted(EXAMPLES_DIR.rglob("*.py")):+ tree = ast.parse(path.read_text("utf-8"))+ if _calls_ping(tree) and not _pins_legacy_mode(tree):+ offenders.append(str(path.relative_to(EXAMPLES_DIR)))+ assert offenders == []