Skip to content

Commit 8ef5ac8

Browse files
docs: fix docstrings across public API surface
Fix typos (e.g., "respose", "loosing", "ommited", "beging"), grammar issues (article agreement, capitalization of "Pydantic"), and formatting (missing periods, PEP 257 blank lines after summary, erroneous literal `\n` in `cli.py` docstrings). Correct several inaccuracies in docstring content: - Update `JSONRPCMessage` references to `SessionMessage` in websocket docs - Fix `Returns` → `Yields` for `create_client_server_memory_streams()` - Fix return type description in `handle_protected_resource_response()` - Use `async def` / `await` in `Context` and `MCPServer` examples - Fix `requestedSchema` → `requested_schema` in example code - Fix `sampling/create_message` → `sampling/createMessage` - Fix `async get_data()` → `async def get_data()` syntax in example - Add missing parameter docs (`httpx_client_factory`, `icons`, `meta`, etc.)
1 parent b9431d4 commit 8ef5ac8

File tree

33 files changed

+177
-163
lines changed

33 files changed

+177
-163
lines changed

src/mcp/cli/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,12 @@ def run(
317317
) -> None: # pragma: no cover
318318
"""Run an MCP server.
319319
320-
The server can be specified in two ways:\n
321-
1. Module approach: server.py - runs the module directly, expecting a server.run() call.\n
322-
2. Import approach: server.py:app - imports and runs the specified server object.\n\n
320+
The server can be specified in two ways:
321+
1. Module approach: server.py - runs the module directly, expecting a server.run() call.
322+
2. Import approach: server.py:app - imports and runs the specified server object.
323323
324324
Note: This command runs the server directly. You are responsible for ensuring
325-
all dependencies are available.\n
325+
all dependencies are available.
326326
For dependency management, use `mcp install` or `mcp dev` instead.
327327
""" # noqa: E501
328328
file, server_object = _parse_file_path(file_spec)

src/mcp/client/auth/extensions/client_credentials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ def _add_client_authentication_jwt(self, *, token_data: dict[str, Any]): # prag
450450
# When using private_key_jwt, in a client_credentials flow, we use RFC 7523 Section 2.2
451451
token_data["client_assertion"] = assertion
452452
token_data["client_assertion_type"] = "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"
453-
# We need to set the audience to the resource server, the audience is difference from the one in claims
453+
# We need to set the audience to the resource server, the audience is different from the one in claims
454454
# it represents the resource server that will validate the token
455455
token_data["audience"] = self.context.get_resource_url()
456456

src/mcp/client/auth/oauth2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ def prepare_token_auth(
215215

216216
class OAuthClientProvider(httpx.Auth):
217217
"""OAuth2 authentication for httpx.
218+
218219
Handles OAuth flow with automatic client registration and token storage.
219220
"""
220221

@@ -241,7 +242,7 @@ def __init__(
241242
callback_handler: Handler for authorization callbacks.
242243
timeout: Timeout for the OAuth flow.
243244
client_metadata_url: URL-based client ID. When provided and the server
244-
advertises client_id_metadata_document_supported=true, this URL will be
245+
advertises client_id_metadata_document_supported=True, this URL will be
245246
used as the client_id instead of performing dynamic client registration.
246247
Must be a valid HTTPS URL with a non-root pathname.
247248
validate_resource_url: Optional callback to override resource URL validation.

src/mcp/client/auth/utils.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def extract_field_from_www_auth(response: Response, field_name: str) -> str | No
3838

3939

4040
def extract_scope_from_www_auth(response: Response) -> str | None:
41-
"""Extract scope parameter from WWW-Authenticate header as per RFC6750.
41+
"""Extract scope parameter from WWW-Authenticate header as per RFC 6750.
4242
4343
Returns:
4444
Scope string if found in WWW-Authenticate header, None otherwise
@@ -47,7 +47,7 @@ def extract_scope_from_www_auth(response: Response) -> str | None:
4747

4848

4949
def extract_resource_metadata_from_www_auth(response: Response) -> str | None:
50-
"""Extract protected resource metadata URL from WWW-Authenticate header as per RFC9728.
50+
"""Extract protected resource metadata URL from WWW-Authenticate header as per RFC 9728.
5151
5252
Returns:
5353
Resource metadata URL if found in WWW-Authenticate header, None otherwise
@@ -67,8 +67,8 @@ def build_protected_resource_metadata_discovery_urls(www_auth_url: str | None, s
6767
3. Fall back to root-based well-known URI: /.well-known/oauth-protected-resource
6868
6969
Args:
70-
www_auth_url: optional resource_metadata url extracted from the WWW-Authenticate header
71-
server_url: server url
70+
www_auth_url: Optional resource_metadata URL extracted from the WWW-Authenticate header
71+
server_url: Server URL
7272
7373
Returns:
7474
Ordered list of URLs to try for discovery
@@ -120,10 +120,10 @@ def get_client_metadata_scopes(
120120

121121

122122
def build_oauth_authorization_server_metadata_discovery_urls(auth_server_url: str | None, server_url: str) -> list[str]:
123-
"""Generate ordered list of (url, type) tuples for discovery attempts.
123+
"""Generate an ordered list of URLs for authorization server metadata discovery.
124124
125125
Args:
126-
auth_server_url: URL for the OAuth Authorization Metadata URL if found, otherwise None
126+
auth_server_url: OAuth Authorization Server Metadata URL if found, otherwise None
127127
server_url: URL for the MCP server, used as a fallback if auth_server_url is None
128128
"""
129129

@@ -170,7 +170,7 @@ async def handle_protected_resource_response(
170170
Per SEP-985, supports fallback when discovery fails at one URL.
171171
172172
Returns:
173-
True if metadata was successfully discovered, False if we should try next URL
173+
ProtectedResourceMetadata if successfully discovered, None if we should try next URL
174174
"""
175175
if response.status_code == 200:
176176
try:
@@ -206,7 +206,7 @@ def create_oauth_metadata_request(url: str) -> Request:
206206
def create_client_registration_request(
207207
auth_server_metadata: OAuthMetadata | None, client_metadata: OAuthClientMetadata, auth_base_url: str
208208
) -> Request:
209-
"""Build registration request or skip if already registered."""
209+
"""Build a client registration request."""
210210

211211
if auth_server_metadata and auth_server_metadata.registration_endpoint:
212212
registration_url = str(auth_server_metadata.registration_endpoint)
@@ -261,7 +261,7 @@ def should_use_client_metadata_url(
261261
"""Determine if URL-based client ID (CIMD) should be used instead of DCR.
262262
263263
URL-based client IDs should be used when:
264-
1. The server advertises client_id_metadata_document_supported=true
264+
1. The server advertises client_id_metadata_document_supported=True
265265
2. The client has a valid client_metadata_url configured
266266
267267
Args:
@@ -306,7 +306,7 @@ def create_client_info_from_metadata_url(
306306
async def handle_token_response_scopes(
307307
response: Response,
308308
) -> OAuthToken:
309-
"""Parse and validate token response with optional scope validation.
309+
"""Parse and validate a token response.
310310
311311
Parses token response JSON. Callers should check response.status_code before calling.
312312

src/mcp/client/client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
class Client:
3838
"""A high-level MCP client for connecting to MCP servers.
3939
40-
Currently supports in-memory transport for testing. Pass a Server or
41-
MCPServer instance directly to the constructor.
40+
Supports in-memory transport for testing (pass a Server or MCPServer instance),
41+
Streamable HTTP transport (pass a URL string), or a custom Transport instance.
4242
4343
Example:
4444
```python
@@ -205,7 +205,7 @@ async def read_resource(self, uri: str, *, meta: RequestParamsMeta | None = None
205205
206206
Args:
207207
uri: The URI of the resource to read.
208-
meta: Additional metadata for the request
208+
meta: Additional metadata for the request.
209209
210210
Returns:
211211
The resource content.
@@ -239,7 +239,7 @@ async def call_tool(
239239
meta: Additional metadata for the request
240240
241241
Returns:
242-
The tool result
242+
The tool result.
243243
"""
244244
return await self.session.call_tool(
245245
name=name,

src/mcp/client/experimental/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async def call_tool_as_task(
8383
status = await session.experimental.get_task(task_id)
8484
if status.status == "completed":
8585
break
86-
await asyncio.sleep(0.5)
86+
await anyio.sleep(0.5)
8787
8888
# Get result
8989
final = await session.experimental.get_task_result(task_id, CallToolResult)
@@ -177,7 +177,7 @@ async def poll_task(self, task_id: str) -> AsyncIterator[types.GetTaskResult]:
177177
"""Poll a task until it reaches a terminal status.
178178
179179
Yields GetTaskResult for each poll, allowing the caller to react to
180-
status changes (e.g., handle input_required). Exits when task reaches
180+
status changes (e.g., handle input_required). Exits when the task reaches
181181
a terminal status (completed, failed, cancelled).
182182
183183
Respects the pollInterval hint from the server.

src/mcp/client/session_group.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Tools, resources, and prompts are aggregated across servers. Servers may
44
be connected to or disconnected from at any point after initialization.
55
6-
This abstractions can handle naming collisions using a custom user-provided hook.
6+
This abstraction can handle naming collisions using a custom user-provided hook.
77
"""
88

99
import contextlib
@@ -30,7 +30,7 @@
3030

3131

3232
class SseServerParameters(BaseModel):
33-
"""Parameters for initializing a sse_client."""
33+
"""Parameters for initializing an sse_client."""
3434

3535
# The endpoint URL.
3636
url: str
@@ -67,8 +67,8 @@ class StreamableHttpParameters(BaseModel):
6767
ServerParameters: TypeAlias = StdioServerParameters | SseServerParameters | StreamableHttpParameters
6868

6969

70-
# Use dataclass instead of pydantic BaseModel
71-
# because pydantic BaseModel cannot handle Protocol fields.
70+
# Use dataclass instead of Pydantic BaseModel
71+
# because Pydantic BaseModel cannot handle Protocol fields.
7272
@dataclass
7373
class ClientSessionParameters:
7474
"""Parameters for establishing a client session to an MCP server."""
@@ -119,7 +119,7 @@ class _ComponentNames(BaseModel):
119119
_session_exit_stacks: dict[mcp.ClientSession, contextlib.AsyncExitStack]
120120

121121
# Optional fn consuming (component_name, server_info) for custom names.
122-
# This is provide a means to mitigate naming conflicts across servers.
122+
# This is to provide a means to mitigate naming conflicts across servers.
123123
# Example: (tool_name, server_info) => "{result.server_info.name}.{tool_name}"
124124
_ComponentNameHook: TypeAlias = Callable[[str, types.Implementation], str]
125125
_component_name_hook: _ComponentNameHook | None

src/mcp/client/sse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ async def sse_client(
4747
headers: Optional headers to include in requests.
4848
timeout: HTTP timeout for regular operations (in seconds).
4949
sse_read_timeout: Timeout for SSE read operations (in seconds).
50+
httpx_client_factory: Factory function for creating the HTTPX client.
5051
auth: Optional HTTPX authentication handler.
5152
on_session_created: Optional callback invoked with the session ID when received.
5253
"""

src/mcp/client/stdio.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ class StdioServerParameters(BaseModel):
8787

8888
encoding: str = "utf-8"
8989
"""
90-
The text encoding used when sending/receiving messages to the server
90+
The text encoding used when sending/receiving messages to the server.
9191
92-
defaults to utf-8
92+
Defaults to utf-8.
9393
"""
9494

9595
encoding_error_handler: Literal["strict", "ignore", "replace"] = "strict"
9696
"""
9797
The text encoding error handler.
9898
9999
See https://docs.python.org/3/library/codecs.html#codec-base-classes for
100-
explanations of possible values
100+
explanations of possible values.
101101
"""
102102

103103

src/mcp/client/streamable_http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ async def _handle_sse_response(
358358
resumption_callback=(ctx.metadata.on_resumption_token_update if ctx.metadata else None),
359359
is_initialization=is_initialization,
360360
)
361-
# If the SSE event indicates completion, like returning respose/error
361+
# If the SSE event indicates completion, like returning response/error
362362
# break the loop
363363
if is_complete:
364364
await response.aclose()

0 commit comments

Comments
 (0)