Skip to content

openmemory streamable_http endpoint crashes with current MCP Python transport due to missing terminate() #4618

@zxfxpower

Description

@zxfxpower

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/mem0 main
  • Python MCP transport from the container image / current installed mcp package
  • StreamableHTTPServerTransport only exposes connect and handle_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:

  • connect
  • handle_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:

  • initialize
  • tools/list
  • tools/call

when tested directly over MCP JSON-RPC.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions