2626
2727
2828class Client :
29- """
30- A high-level MCP client for connecting to MCP servers.
29+ """A high-level MCP client for connecting to MCP servers.
3130
3231 Currently supports in-memory transport for testing. Pass a Server or
3332 FastMCP instance directly to the constructor.
3433
3534 Example:
35+ ```python
36+ from mcp.client import Client
37+ from mcp.server.fastmcp import FastMCP
38+
3639 server = FastMCP("test")
3740
3841 @server.tool()
@@ -41,15 +44,16 @@ def add(a: int, b: int) -> int:
4144
4245 async with Client(server) as client:
4346 result = await client.call_tool("add", {"a": 1, "b": 2})
44-
45- TODO(felixweinberger): Expand to support all transport types (like FastMCP 2):
46- - Add ClientTransport base class with connect_session() method
47- - Add StreamableHttpTransport, SSETransport, StdioTransport
48- - Add infer_transport() to auto-detect transport from input type
49- - Accept URL strings, Path objects, config dicts in constructor
50- - Add auth support (OAuth, bearer tokens)
47+ ```
5148 """
5249
50+ # TODO(felixweinberger): Expand to support all transport types (like FastMCP 2):
51+ # - Add ClientTransport base class with connect_session() method
52+ # - Add StreamableHttpTransport, SSETransport, StdioTransport
53+ # - Add infer_transport() to auto-detect transport from input type
54+ # - Accept URL strings, Path objects, config dicts in constructor
55+ # - Add auth support (OAuth, bearer tokens)
56+
5357 def __init__ (
5458 self ,
5559 server : Server [Any ] | FastMCP ,
@@ -147,13 +151,9 @@ def session(self) -> ClientSession:
147151 raise RuntimeError ("Client must be used within an async context manager" )
148152 return self ._session
149153
150- def get_server_capabilities (self ) -> types .ServerCapabilities | None :
151- """
152- Return the server capabilities received during initialization.
153-
154- Returns:
155- The server capabilities, or None if not yet initialized
156- """
154+ @property
155+ def server_capabilities (self ) -> types .ServerCapabilities | None :
156+ """The server capabilities received during initialization, or None if not yet initialized."""
157157 return self .session .get_server_capabilities ()
158158
159159 async def send_ping (self ) -> types .EmptyResult :
0 commit comments