Files
Max Isbey 1b74b06753 Tighten comments and docstrings repo-wide
Cut comment and docstring volume roughly in half across src, tests,
examples, and docs_src: removed comments that restate the adjacent code,
leftover development narration, section banners, and self-evident
Args/Returns blocks, and compressed the remaining docstrings to a
Google-style summary line plus only the detail that earns its place.

Kept (and tightened) the load-bearing content: Raises sections,
deprecation and version-availability notes, spec/RFC/issue references,
why-comments for non-obvious decisions, and all coverage pragmas. The
generated mcp_types.v* wire modules are untouched.
2026-06-29 15:10:27 +00:00

37 lines
1.2 KiB
Python

"""Send a vendor-prefixed request via the `client.session` escape hatch."""
from typing import Literal, cast
import mcp_types as types
from mcp.client import Client
from stories._harness import Target, run_client
class SearchParams(types.RequestParams):
query: str
limit: int = 10
class SearchRequest(types.Request[SearchParams, Literal["acme/search"]]):
method: Literal["acme/search"] = "acme/search"
params: SearchParams
class SearchResult(types.Result):
items: list[str]
async def main(target: Target, *, mode: str = "auto") -> None:
async with Client(target, mode=mode) as client:
# `Client` only exposes spec-defined verbs, so vendor methods drop to `client.session` today.
# `send_request` is typed against the closed `ClientRequest` union, hence the cast; at runtime it
# only calls `.model_dump()`, and an unknown method skips the per-spec result-validation registry.
request = SearchRequest(params=SearchParams(query="mcp", limit=3))
result = await client.session.send_request(cast("types.ClientRequest", request), SearchResult)
assert result.items == ["mcp-0", "mcp-1", "mcp-2"], result
if __name__ == "__main__":
run_client(main)