Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/mcp/client/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,11 @@ async def send_request(
"""Send a request and wait for its typed result.

Args:
request: The request to send, carrying its method and params.
result_type: Pydantic adapter used to validate the typed result.
request_read_timeout_seconds: Per-request read timeout override.
metadata: Streamable HTTP resumption hints.
progress_callback: Called with progress notifications for this request.

Raises:
MCPError: Error response, read timeout, or connection closed.
Expand Down Expand Up @@ -942,8 +946,10 @@ async def read_resource(
"""Send a resources/read request.

Args:
uri: The URI of the resource to read.
input_responses: Responses to a prior `InputRequiredResult.input_requests`.
request_state: Opaque state echoed from a prior `InputRequiredResult`.
meta: Additional metadata for the request.
allow_input_required: When `False` (default), an `InputRequiredResult`
from the server raises `RuntimeError`; when `True`, it is returned
so the caller can resolve the requests and retry.
Expand Down Expand Up @@ -1070,8 +1076,13 @@ async def call_tool(
the tool before calling it to enable header emission.

Args:
name: The name of the tool to call.
arguments: Arguments to pass to the tool.
read_timeout_seconds: Per-request read timeout override.
progress_callback: Called with progress notifications for this call.
input_responses: Responses to a prior `InputRequiredResult.input_requests`.
request_state: Opaque state echoed from a prior `InputRequiredResult`.
meta: Additional metadata for the request.
allow_input_required: When ``False`` (default), an `InputRequiredResult`
from the server raises `RuntimeError`; when ``True``, it is returned
so the caller can resolve the requests and retry.
Expand Down Expand Up @@ -1227,8 +1238,11 @@ async def get_prompt(
"""Send a prompts/get request.

Args:
name: The name of the prompt to retrieve.
arguments: Arguments to bind to the prompt template.
input_responses: Responses to a prior `InputRequiredResult.input_requests`.
request_state: Opaque state echoed from a prior `InputRequiredResult`.
meta: Additional metadata for the request.
allow_input_required: When `False` (default), an `InputRequiredResult`
from the server raises `RuntimeError`; when `True`, it is returned
so the caller can resolve the requests and retry.
Expand Down
58 changes: 58 additions & 0 deletions tests/client/test_docstring_args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"""Regression test for #3846: public ClientSession methods must document every parameter.

The API reference renders Google-style ``Args:`` blocks verbatim. When a parameter
is missing from the block, it silently disappears from the rendered docs — and the
mandatory parameters are the ones most likely to be omitted (they have no default
to copy from a neighbouring overload). This test walks the implementation methods
and fails when any parameter name is absent from its ``Args:`` section.
"""
from __future__ import annotations

import ast
import inspect
import re
from pathlib import Path

from mcp.client.session import ClientSession

# Public request methods that funnel calls through send_request and were affected by #3846.
AFFECTED = ("send_request", "read_resource", "call_tool", "get_prompt")


def _implementation(node: ast.AST, name: str) -> ast.FunctionDef | ast.AsyncFunctionDef:
match = [
n for n in node.body # type: ignore[attr-defined]
if isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef))
and n.name == name
and not any(isinstance(d, ast.Name) and d.id == "overload" for d in n.decorator_list)
]
assert match, f"no implementation found for {name}"
return match[0]


def _documented(doc: str) -> set[str]:
section = re.search(r"Args:\s*\n(.*?)(?=\n\s*(?:Raises:|Returns:|Note:|\Z))", doc, re.S)
if not section:
return set()
return set(re.findall(r"^\s*(\w+)\s*:", section.group(1), re.M))


def test_clientsession_args_blocks_cover_all_parameters() -> None:
source = inspect.getsource(ClientSession)
tree = ast.parse(source)
cls = next(n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == "ClientSession")

missing: dict[str, list[str]] = {}
for name in AFFECTED:
fn = _implementation(cls, name)
params = [
a.arg
for a in (*fn.args.posonlyargs, *fn.args.args, *fn.args.kwonlyargs)
if a.arg not in ("self", "cls")
]
documented = _documented(ast.get_docstring(fn) or "")
gap = [p for p in params if p not in documented]
if gap:
missing[name] = gap

assert not missing, f"ClientSession docstring Args blocks missing parameters: {missing}"
Loading