DEV Community

Cover image for Using FastMCP with OpenAI and Avoiding Session Termination Issues
Andreas Bergström
Andreas Bergström

Posted on Edited on Originally published at andreasbergstrom.dev

Using FastMCP with OpenAI and Avoiding Session Termination Issues

If you're plugging a FastMCP server into OpenAI's Responses API and your sessions keep dying with Session has been terminated, the fix is one flag: stateless_http=True when you instantiate FastMCP(...). OpenAI sends a DELETE after each call without recreating the session, so anything stateful gets terminated between requests.

The full post covers the JSON-RPC error you'll actually see, the minimal server change to make it work, and the caveats — session state and certain bi-directional streaming patterns drop out in stateless mode. Worth a quick read if you're hitting the same one-call-then-broken behaviour.


Originally published at andreasbergstrom.dev — read the full post there.

Top comments (1)

Collapse
 
chand1012 profile image
Chandler

Thanks for this tip! This is more useful to me as a debug tool as my code with errors now properly outputs error messages rather than just "Session Terminated" in the OpenAI Prompt Logs.