Repository navigation
Closed as not planned
Closed as not planned
Copy link
Labels
bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.Something isn't working. Reports of errors, unexpected behavior, or broken functionality.high-prioritysecuritySecurity fixes: input validation, SSRF/LFI prevention, auth hardening, injection defenses.Security fixes: input validation, SSRF/LFI prevention, auth hardening, injection defenses.serverRelated to FastMCP server implementation or server-side functionality.Related to FastMCP server implementation or server-side functionality.
Description
What happened?
With ResponseCachingMiddleware installed, a tools/call whose result depends on session-scoped state (Context.set_state / get_state) returns another session's cached answer: session B making the same call as session A gets session A's result, even after B has stored its own value. Without the middleware, each session sees its own state. The same happens for resources/read and prompts/get handlers that read session state. On main, cache keys include the caller's access token but not the session identity.
Example Code
import asyncio
from fastmcp import Client, FastMCP
from fastmcp.server.context import Context
from fastmcp.server.middleware.caching import ResponseCachingMiddleware
mcp = FastMCP()
mcp.add_middleware(ResponseCachingMiddleware())
@mcp.tool
async def remember(key: str, value: str, ctx: Context) -> str:
await ctx.set_state(key, value)
return "stored"
@mcp.tool
async def recall(key: str, ctx: Context) -> str:
return await ctx.get_state(key) or "<unset>"
async def main():
# Session A stores and recalls its own value (the recall result is cached).
async with Client(mcp, mode="legacy") as a:
await a.call_tool("remember", {"key": "k", "value": "A-secret"})
print("A:", (await a.call_tool("recall", {"key": "k"})).content[0].text)
# Session B stores its OWN value, then makes the same recall call.
async with Client(mcp, mode="legacy") as b:
await b.call_tool("remember", {"key": "k", "value": "B-secret"})
print("B:", (await b.call_tool("recall", {"key": "k"})).content[0].text)
asyncio.run(main())Expected:
A: A-secret
B: B-secret
Actual:
A: A-secret
B: A-secret
Version Information
FastMCP version: 4.0.11.dev1+0ebabc0c
MCP version: 2.0.0
Python version: 3.12.14
Platform: macOS-26.6.2-arm64-arm-64bit
Metadata
Metadata
Assignees
Labels
bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.Something isn't working. Reports of errors, unexpected behavior, or broken functionality.high-prioritysecuritySecurity fixes: input validation, SSRF/LFI prevention, auth hardening, injection defenses.Security fixes: input validation, SSRF/LFI prevention, auth hardening, injection defenses.serverRelated to FastMCP server implementation or server-side functionality.Related to FastMCP server implementation or server-side functionality.
Activity
zzstoatzz commentedon Nov 11, 2026
Working as designed: sessions without a token share one cache partition. Exclude tools whose output depends on session state from ResponseCachingMiddleware.