fix: bound Streamable HTTP session resources - #56
Merged
Jeomon merged 1 commit intoAug 16, 2026
Conversation
git-ksk
marked this pull request as draft
August 15, 2026 08:17
git-ksk
force-pushed
the
fix/streamable-http-resource-cleanup
branch
from
August 15, 2026 08:25
a29067a to
d1103cc
Compare
git-ksk
marked this pull request as ready for review
August 15, 2026 08:28
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.
Summary
Run MacOS-MCP's Streamable HTTP transport in FastMCP's supported stateless mode.
MacOS-MCP does not use per-client HTTP session state or server-initiated session features, so keeping SDK transports alive across requests only retains resources when clients reconnect without sending MCP
DELETE.SSE remains unchanged.
Root cause
The growth is specific to stateful Streamable HTTP session lifecycle, not tool execution, PyObjC workers, or raw request volume.
Controls on current
main(fastmcp 2.14.4,mcp 1.26.0):tools/listcalls in one process: +224 KB RSSDELETE: +3.7 MB RSSDELETE: RSS reached 208.1 MB from 155.7 MB (about +52.4 MB from the initial baseline)The MCP SDK's stateful
StreamableHTTPSessionManagerkeeps transports in_server_instances; sessions that disappear withoutDELETEstay alive, and current termination paths also have known cleanup gaps. Upgrading only tomcp 1.27.2did not resolve the abandoned-session growth because idle cleanup is opt-in and FastMCP 2.x does not expose that manager timeout through this run path.Related upstream work:
This PR intentionally does not monkeypatch FastMCP/MCP internals.
Change
Pass:
to the existing FastMCP HTTP run call.
This uses FastMCP's public API and leaves stdio/SSE behavior unchanged.
Verification
Regression tests
Added
tests/test_server_transport.pyto pin:stateless_http=Truestateless_http=FalseFull suite:
Code quality
Checked the PR branch against the same
upstream/mainbaseline with the same Ruff version:git diff --check— cleanruff check .— 462 pre-existing findings on bothupstream/mainand this branch; finding-code counts are identical, so this PR adds no Ruff findingsruff format --check .— the same 26 pre-existing files would be reformatted on both revisions; the new test file is already formattedFastMCP compatibility
fastmcpis intentionally not version-pinned by this project, so the change was also exercised against the current FastMCP 3.4.7 release in an isolated environment:stateless_http=TrueBundled bridge compatibility
Both bundled stdio-to-HTTP bridges were exercised against the stateless Streamable HTTP server:
bridge/mcp-stdio-bridge.py: initialize -> tools/list (12 tools) -> realShellcall (bridge-ok)bridge/MCPStdioBridge.swift: initialize -> tools/list (12 tools) -> realShellcall (bridge-ok)Mcp-Session-Id; after exit, server TCP state returned to listener-onlyFunctional E2E
On isolated test ports only (production port 8100 was not touched):
Shelltool call each roundRSS stress E2E
Modified CLI, 10,000 fresh reconnects without
DELETE:RSS plateaus after allocator warm-up; the final 4,000 reconnects add only about 64 KB. File descriptors and TCP connections return to the listener-only baseline.
SIGTERM
Before this change, a live stateful Streamable HTTP GET produced a forced Uvicorn cancellation plus an ASGI
CancelledErrortraceback during SIGTERM. With stateless Streamable HTTP there is no persistent GET/SSE request; shutdown reaches application shutdown without the ASGI traceback.FastMCP 2.14.4 still configures Uvicorn with
timeout_graceful_shutdown=0, so Uvicorn emits its genericCancel 0 running task(s), timeout graceful shutdown exceededline. That is separate from the retained Streamable HTTP session bug and is not overridden here.Compatibility note
Stateless Streamable HTTP cannot provide a persistent per-client back-channel for features that require session continuity. MacOS-MCP currently does not use sampling, elicitation, roots, or other server-initiated session features; its tool set and auth path were exercised successfully in stateless mode.