mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 14:04:18 +02:00
docs: update get_state and set_state references (#1306)
This commit is contained in:
parent
6fdb8d6a1c
commit
845546c53f
3 changed files with 6 additions and 6 deletions
|
|
@ -45,8 +45,8 @@ def my_tool(x: int, ctx: Context) -> str:
|
|||
client_id = ctx.client_id
|
||||
|
||||
# Manage state across the request
|
||||
ctx.set_state_value("key", "value")
|
||||
value = ctx.get_state_value("key")
|
||||
ctx.set_state("key", "value")
|
||||
value = ctx.get_state("key")
|
||||
|
||||
return str(x)
|
||||
```
|
||||
|
|
|
|||
|
|
@ -222,8 +222,8 @@ async def secure_operation(data: str, ctx: Context) -> str:
|
|||
```
|
||||
|
||||
**Method signatures:**
|
||||
- **`ctx.set_state_value(key: str, value: Any) -> None`**: Store a value in the context state
|
||||
- **`ctx.get_state_value(key: str) -> Any`**: Retrieve a value from the context state (returns None if not found)
|
||||
- **`ctx.set_state(key: str, value: Any) -> None`**: Store a value in the context state
|
||||
- **`ctx.get_state(key: str) -> Any`**: Retrieve a value from the context state (returns None if not found)
|
||||
|
||||
**State Inheritance:**
|
||||
When a new context is created (nested contexts), it inherits a copy of its parent's state. This ensures that:
|
||||
|
|
|
|||
|
|
@ -85,8 +85,8 @@ class Context:
|
|||
client_id = ctx.client_id
|
||||
|
||||
# Manage state across the request
|
||||
ctx.set_state_value("key", "value")
|
||||
value = ctx.get_state_value("key")
|
||||
ctx.set_state("key", "value")
|
||||
value = ctx.get_state("key")
|
||||
|
||||
return str(x)
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue