MCP: add Streamable HTTP transport endpoint#4122
Merged
whysosaket merged 2 commits intomem0ai:mainfrom Mar 25, 2026
Merged
Conversation
Add a stateless Streamable HTTP transport at /mcp/{client_name}/http/{user_id}
alongside the existing SSE transport. This enables MCP clients that only support
Streamable HTTP (like openclaw-mcp-adapter) to connect to OpenMemory.
…ests The original handler wrote the MCP transport response directly to the raw ASGI send callable (request._send), then FastAPI also tried to send its own response — causing a double-response that only worked because uvicorn silently dropped the second one. Fix by intercepting the transport's ASGI messages via capture_send and returning a proper starlette Response to FastAPI. Also adds a response_started guard so a transport crash returns 500 instead of an empty 200. Adds 21 tests covering the full JSON-RPC protocol flow, error handling, context-variable isolation, and route registration. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
utkarsh240799
approved these changes
Mar 24, 2026
whysosaket
approved these changes
Mar 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2992
Fixes #2812
Description
Add a stateless Streamable HTTP transport endpoint at
/mcp/{client_name}/http/{user_id}alongside the existing SSE transport. This enables MCP clients that only support Streamable HTTP (e.g.openclaw-mcp-adapter) to connect to the OpenMemory MCP server.The existing SSE endpoint is untouched — this is purely additive.
What changed
StreamableHTTPServerTransportfrommcp.server.streamable_httpandanyio/{client_name}/http/{user_id}accepting POST, GET, and DELETEuser_idandclient_namefrom path params and sets context vars (same pattern as the SSE handler)StreamableHTTPServerTransportwith JSON responses enabledanyiotask group, delegates totransport.handle_request(), then terminatessendcallable. Without interception, FastAPI would also try to send its own response — a "double-response" bug that only worked because uvicorn silently dropped the second one. Fixed by capturing the transport's ASGI messages viacapture_sendand returning a properstarlette.responses.Responseto FastAPI. Aresponse_startedguard ensures a transport crash returns 500 instead of an empty 200.Why
The MCP spec defines two transports: SSE and Streamable HTTP. The OpenMemory MCP server currently only supports SSE. Some MCP client adapters (like
openclaw-mcp-adapter) only speak Streamable HTTP. Adding this transport makes OpenMemory accessible to a wider set of MCP clients without changing existing behavior.Type of change
Testing
Automated tests (21 tests)
New test suite at
openmemory/api/tests/test_mcp_server.pyusingpytest-asyncioandhttpxASGI transport:Run with:
Manual verification
Tested against a live uvicorn server (
OPENAI_API_KEY=test-key uvicorn main:app):Initialize:
tools/list:
tools/call:
Error handling: DELETE → 405, missing Accept → 406, invalid JSON → 400
Checklist: