mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-21 21:14:17 +02:00
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:
parent
8eadaaa958
commit
7ede47729b
1 changed files with 8 additions and 8 deletions
|
|
@ -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}"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue