π The fast, Pythonic way to build MCP servers and clients.
fix(client): identify as fastmcp in clientInfo by default (#6254)
nate nowack4e7d3271e7c0
diff --git a/docs/clients/client.mdx b/docs/clients/client.mdxindex 601ef0e04..92cdde5e6 100644--- a/docs/clients/client.mdx+++ b/docs/clients/client.mdx@@ -181,6 +181,16 @@ async with client:tools = await client.list_tools()```+Every connection also tells the server who is calling. By default a FastMCP client identifies itself as `fastmcp` at the installed FastMCP version. Servers see this in their logs and middleware, so an application that wants to be recognized on its own should pass `client_info`:++```python+from mcp.types import Implementation+from fastmcp import Client++client_info = Implementation(name="my-agent", version="1.0.0")+client = Client("https://example.com/mcp", client_info=client_info)+```+## Protocol negotiation<VersionBadge version="4.0.0" />diff --git a/fastmcp_slim/fastmcp/client/client.py b/fastmcp_slim/fastmcp/client/client.pyindex 08d1f1534..cda8a1489 100644--- a/fastmcp_slim/fastmcp/client/client.py+++ b/fastmcp_slim/fastmcp/client/client.py@@ -318,6 +318,8 @@ class Client(timeout: Optional timeout for requests (seconds or timedelta)init_timeout: Optional timeout for initial connection (seconds or timedelta).Set to 0 to disable. If None, uses the value in the FastMCP global settings.+ client_info: The identity this client declares to servers. Defaults to+ `fastmcp` and the installed FastMCP version.mode: Protocol-era negotiation at connect time. `"auto"` (the default) probes`server/discover` and negotiates the modern era, denylist-falling-back to theinitialize handshake for any server that is not positive evidence of a modern@@ -565,7 +567,8 @@ class Client("log_level": "debug","message_handler": effective_message_handler,"read_timeout_seconds": read_timeout_seconds,- "client_info": client_info,+ "client_info": client_info+ or mcp_types.Implementation(name="fastmcp", version=fastmcp.__version__),**self._build_extension_kwargs(),}diff --git a/tests/client/client/test_initialize.py b/tests/client/client/test_initialize.pyindex 7106806ae..82d75d886 100644--- a/tests/client/client/test_initialize.py+++ b/tests/client/client/test_initialize.py@@ -1,9 +1,27 @@"""Client initialization tests."""+import mcp_types+import pytest++import fastmcpfrom fastmcp.client import Client+from fastmcp.server.context import Contextfrom fastmcp.server.server import FastMCP+def _client_info_server() -> FastMCP:+ server = FastMCP("ClientInfoServer")++ @server.tool+ def who(ctx: Context) -> dict[str, str | None]:+ params = ctx.session.client_params+ assert params is not None+ info = params.client_info+ return {"name": info.name, "version": info.version}++ return server++class TestInitialize:"""Tests for client initialization behavior."""@@ -113,3 +131,20 @@ class TestInitialize:# Should be able to call tools after manual initializationresult = await client.call_tool("greet", {"name": "World"})assert "Hello, World!" in str(result.content)++[email protected]("mode", ["auto", "legacy"])+class TestClientInfo:+ async def test_identifies_as_fastmcp_by_default(self, mode: str):+ async with Client(_client_info_server(), mode=mode) as client:+ result = await client.call_tool("who")++ assert result.data == {"name": "fastmcp", "version": fastmcp.__version__}++ async def test_explicit_client_info_wins(self, mode: str):+ info = mcp_types.Implementation(name="my-client", version="1.2.3")++ async with Client(_client_info_server(), mode=mode, client_info=info) as client:+ result = await client.call_tool("who")++ assert result.data == {"name": "my-client", "version": "1.2.3"}