Feedback

Chat Icon

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Session State
66%

Storing and Retrieving Values

The three methods you will reach for most often are ctx.set_state(), ctx.get_state(), and ctx.delete_state(). All three are asynchronous, so you always call them with await.

To store a value, you give it a string key and a value:

await ctx.set_state("last_breed", "labrador")

To retrieve it in a later call, use the same key:

breed = await ctx.get_state("last_breed")

Practical MCP with FastMCP & LangChain

Engineering the Agentic Experience

Enroll now to unlock current content and receive all future updates for free. Your purchase supports the author and fuels the creation of more exciting content. Act fast, as the price will rise as the course nears completion!