-
Notifications
You must be signed in to change notification settings - Fork 5.8k
openmemory streamable_http endpoint crashes with current MCP Python transport due to missing terminate() #4618
Description
Summary
The streamable_http endpoint in openmemory/api/app/mcp_server.py calls await transport.terminate(), but the current mcp.server.streamable_http.StreamableHTTPServerTransport implementation does not expose a terminate() method.
This causes the OpenMemory HTTP MCP endpoint to return 500 Internal Server Error after handling a request.
Affected file
openmemory/api/app/mcp_server.py
Current upstream code still contains:
await transport.handle_request(request.scope, request.receive, capture_send)
await transport.terminate()
tg.cancel_scope.cancel()Reproduction
Environment:
- OpenMemory from
mem0ai/mem0main - Python MCP transport from the container image / current installed
mcppackage StreamableHTTPServerTransportonly exposesconnectandhandle_request
HTTP endpoint:
POST /mcp/openmemory/http/{user_id}
Observed behavior:
- request returns
500 Internal Server Error - server traceback shows:
AttributeError: 'StreamableHTTPServerTransport' object has no attribute 'terminate'
Expected behavior
The streamable_http endpoint should complete successfully and return the MCP JSON response instead of failing with 500.
Root cause
There appears to be a version mismatch between OpenMemory's streamable_http handler and the currently installed mcp Python package API.
StreamableHTTPServerTransport in the tested environment exposes:
connecthandle_request
but not:
terminate
Suggested fix
Guard the cleanup call, or rely on the surrounding context manager / task group cleanup only.
For example:
await transport.handle_request(request.scope, request.receive, capture_send)
terminate = getattr(transport, "terminate", None)
if terminate is not None:
await terminate()
tg.cancel_scope.cancel()Notes
After removing the hard dependency on terminate(), the HTTP MCP endpoint can successfully handle:
initializetools/listtools/call
when tested directly over MCP JSON-RPC.