Skip to content

MCP over HTTP is stateful: a session id issued by one replica is unknown to the others #1751

Description

@edwinyyyu

What happened

MemMachineFastMCP.get_app (server/api_v2/mcp.py:310-312) calls super().http_app(path=path) without stateless_http. With fastmcp 4.0.3 (uv.lock) that resolves to the server default, stateless_http = False, so the streamable-HTTP transport issues an Mcp-Session-Id and expects every later request of that session to reach the same process. The session manager is created per process in the mounted app's lifespan.

Behind a load balancer with no sticky routing, a client's second request lands on a replica that has never seen the session id and is rejected. The server's own tools do not need the session: every tool reads its ids from request headers into contextvars.

Expected

stateless_http=True, so each request is self-contained, or the deployment documents that MCP over HTTP requires session affinity.

Notes

Code read at d6068cdbf (main), paths under packages/server/src/memmachine_server/. The fastmcp default was checked in an installed 4.0.3 copy, not reproduced against two replicas.


🤖 Written by Claude Code (Claude Fable 5.1) on behalf of @edwinyyyu.

Metadata

Metadata

Assignees

No one assigned

    Labels

    horizontal scalingWrong or unsafe when more than one server process serves the same backends (replicas or workers)

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions