Skip to content

Commit 4d83310

Browse files
refactor: address additional PR review comments
- Add imports to docstring example for self-contained rendering - Move TODO from docstring to regular comment - Rename get_server_capabilities() to server_capabilities property - Use Google-style docstring (opening on same line)
1 parent 27f896d commit 4d83310

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/mcp/client/client.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@
2626

2727

2828
class 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:

tests/client/test_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ async def test_creates_client(app: FastMCP):
6868
async def test_client_is_initialized(app: FastMCP):
6969
"""Test that the client is initialized after entering context."""
7070
async with Client(app) as client:
71-
caps = client.get_server_capabilities()
71+
caps = client.server_capabilities
7272
assert caps is not None
7373
assert caps.tools is not None
7474

@@ -77,7 +77,7 @@ async def test_with_simple_server(simple_server: Server):
7777
"""Test that from_server works with a basic Server instance."""
7878
async with Client(simple_server) as client:
7979
assert client is not None
80-
caps = client.get_server_capabilities()
80+
caps = client.server_capabilities
8181
assert caps is not None
8282
# Verify list_resources works and returns expected resource
8383
resources = await client.list_resources()
@@ -204,10 +204,10 @@ async def test_aexit_without_aenter(app: FastMCP):
204204
assert client._session is None
205205

206206

207-
async def test_get_server_capabilities_after_init(app: FastMCP):
208-
"""Test getting server capabilities after initialization."""
207+
async def test_server_capabilities_after_init(app: FastMCP):
208+
"""Test server_capabilities property after initialization."""
209209
async with Client(app) as client:
210-
caps = client.get_server_capabilities()
210+
caps = client.server_capabilities
211211
assert caps is not None
212212
# FastMCP should advertise tools capability
213213
assert caps.tools is not None

0 commit comments

Comments
 (0)