Spaces:
Running
Running
Maxi Fernandez commited on
docs: update get_state and set_state references (#1306)
Browse files
docs/python-sdk/fastmcp-server-context.mdx
CHANGED
|
@@ -45,8 +45,8 @@ def my_tool(x: int, ctx: Context) -> str:
|
|
| 45 |
client_id = ctx.client_id
|
| 46 |
|
| 47 |
# Manage state across the request
|
| 48 |
-
ctx.
|
| 49 |
-
value = ctx.
|
| 50 |
|
| 51 |
return str(x)
|
| 52 |
```
|
|
|
|
| 45 |
client_id = ctx.client_id
|
| 46 |
|
| 47 |
# Manage state across the request
|
| 48 |
+
ctx.set_state("key", "value")
|
| 49 |
+
value = ctx.get_state("key")
|
| 50 |
|
| 51 |
return str(x)
|
| 52 |
```
|
docs/servers/context.mdx
CHANGED
|
@@ -222,8 +222,8 @@ async def secure_operation(data: str, ctx: Context) -> str:
|
|
| 222 |
```
|
| 223 |
|
| 224 |
**Method signatures:**
|
| 225 |
-
- **`ctx.
|
| 226 |
-
- **`ctx.
|
| 227 |
|
| 228 |
**State Inheritance:**
|
| 229 |
When a new context is created (nested contexts), it inherits a copy of its parent's state. This ensures that:
|
|
|
|
| 222 |
```
|
| 223 |
|
| 224 |
**Method signatures:**
|
| 225 |
+
- **`ctx.set_state(key: str, value: Any) -> None`**: Store a value in the context state
|
| 226 |
+
- **`ctx.get_state(key: str) -> Any`**: Retrieve a value from the context state (returns None if not found)
|
| 227 |
|
| 228 |
**State Inheritance:**
|
| 229 |
When a new context is created (nested contexts), it inherits a copy of its parent's state. This ensures that:
|
src/fastmcp/server/context.py
CHANGED
|
@@ -85,8 +85,8 @@ class Context:
|
|
| 85 |
client_id = ctx.client_id
|
| 86 |
|
| 87 |
# Manage state across the request
|
| 88 |
-
ctx.
|
| 89 |
-
value = ctx.
|
| 90 |
|
| 91 |
return str(x)
|
| 92 |
```
|
|
|
|
| 85 |
client_id = ctx.client_id
|
| 86 |
|
| 87 |
# Manage state across the request
|
| 88 |
+
ctx.set_state("key", "value")
|
| 89 |
+
value = ctx.get_state("key")
|
| 90 |
|
| 91 |
return str(x)
|
| 92 |
```
|