Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Fix Context docstring examples to use async syntax

marvin-context-protocol[bot]7ede47729b6d
diff --git a/src/fastmcp/server/context.py b/src/fastmcp/server/context.py
index 65af5076b..97ca70dc3 100644
--- a/src/fastmcp/server/context.py
+++ b/src/fastmcp/server/context.py
@@ -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}"