Fix Context docstring examples to use async syntax

Updates both main docstring example and session_id property example to use async functions with proper await syntax for Context methods.

Co-authored-by: William Easton <strawgate@users.noreply.github.com>
This commit is contained in:
marvin-context-protocol[bot] 2025-09-10 23:21:59 +00:00
commit 7ede47729b

View file

@ -85,18 +85,18 @@ class Context:
```python
@server.tool
def my_tool(x: int, ctx: Context) -> str:
async def my_tool(x: int, ctx: Context) -> str:
# Log messages to the client
ctx.info(f"Processing {x}")
ctx.debug("Debug info")
ctx.warning("Warning message")
ctx.error("Error message")
await ctx.info(f"Processing {x}")
await ctx.debug("Debug info")
await ctx.warning("Warning message")
await ctx.error("Error message")
# Report progress
ctx.report_progress(50, 100, "Processing")
await ctx.report_progress(50, 100, "Processing")
# Access resources
data = ctx.read_resource("resource://data")
data = await ctx.read_resource("resource://data")
# Get request info
request_id = ctx.request_id
@ -261,7 +261,7 @@ class Context:
Example:
```python
@server.tool
def store_data(data: dict, ctx: Context) -> str:
async def store_data(data: dict, ctx: Context) -> str:
session_id = ctx.session_id
redis_client.set(f"session:{session_id}:data", json.dumps(data))
return f"Data stored for session {session_id}"