docs: add code fences to Example: docstring blocks (#2104)

This commit is contained in:
Jonathan Hefner 2026-02-19 14:06:11 -06:00 • committed by GitHub
commit cb07adeca3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 83 additions and 18 deletions

View file

@ -187,11 +187,13 @@ class ExperimentalTaskHandlers:
WARNING: These APIs are experimental and may change without notice.
Example:
```python
handlers = ExperimentalTaskHandlers(
get_task=my_get_task_handler,
list_tasks=my_list_tasks_handler,
)
session = ClientSession(..., experimental_task_handlers=handlers)
```
"""
# Pure task request handlers

View file

@ -5,6 +5,7 @@ This module provides client methods for interacting with MCP tasks.
WARNING: These APIs are experimental and may change without notice.
Example:
```python
# Call a tool as a task
result = await session.experimental.call_tool_as_task("tool_name", {"arg": "value"})
task_id = result.task.task_id
@ -21,6 +22,7 @@ Example:
# Cancel a task
await session.experimental.cancel_task(task_id)
```
"""
from collections.abc import AsyncIterator
@ -72,6 +74,7 @@ class ExperimentalClientFeatures:
CreateTaskResult containing the task reference
Example:
```python
# Create task
result = await session.experimental.call_tool_as_task(
"long_running_tool", {"input": "data"}
@ -87,6 +90,7 @@ class ExperimentalClientFeatures:
# Get result
final = await session.experimental.get_task_result(task_id, CallToolResult)
```
"""
return await self._session.send_request(
types.CallToolRequest(
@ -189,6 +193,7 @@ class ExperimentalClientFeatures:
GetTaskResult for each poll
Example:
```python
async for status in session.experimental.poll_task(task_id):
print(f"Status: {status.status}")
if status.status == "input_required":
@ -197,6 +202,7 @@ class ExperimentalClientFeatures:
# Task is now terminal, get the result
result = await session.experimental.get_task_result(task_id, CallToolResult)
```
"""
async for status in poll_until_terminal(self.get_task, task_id):
yield status

View file

@ -206,8 +206,10 @@ class ClientSession(
These APIs are experimental and may change without notice.
Example:
```python
status = await session.experimental.get_task(task_id)
result = await session.experimental.get_task_result(task_id, CallToolResult)
```
"""
if self._experimental_features is None:
self._experimental_features = ExperimentalClientFeatures(self)

View file

@ -91,13 +91,14 @@ class ClientSessionGroup:
For auxiliary handlers, such as resource subscription, this is delegated to
the client and can be accessed via the session.
Example Usage:
Example:
```python
name_fn = lambda name, server_info: f"{(server_info.name)}_{name}"
async with ClientSessionGroup(component_name_hook=name_fn) as group:
for server_param in server_params:
await group.connect_to_server(server_param)
...
```
"""
class _ComponentNames(BaseModel):