Session State
How Long State Lasts
Session state automatically expires after one day. This is a sensible safeguard — without it, state from abandoned sessions would accumulate in memory indefinitely. For most interactive sessions this limit is irrelevant, since a conversation ends long before a day has passed.
The one-day TTL is not a parameter you can pass to FastMCP directly — it is a hardcoded class variable on Context named _STATE_TTL_SECONDS, initialised to 86400.
The workaround is to patch the class variable directly before starting the server:
from fastmcp.server.context import Context
# 1 hour instead of the default 24
Context._STATE_TTL_SECONDS = 60 * 60
This is a global mutation that touches every session on the server, and it seems to be the only current mechanism. The TTL is applied by FastMCP itself when it stores values — it passes ttl=_STATE_TTL_SECONDS to every put() call on the backend store — so changing the storage backend alone does not change the expiry window.
From FastMCP soure code:
# fastmcp/src/fastmcp/server/context.py
[...]
try:
await self.Practical MCP with FastMCP & LangChain
Engineering the Agentic ExperienceEnroll 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!
