-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[v1.x] Add Streamable HTTP request body limits #3101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 The new test
test_streamable_http_app_passes_the_configured_request_body_limit_to_its_manageraccessesmcp.session_manager, which makes the# pragma: no coveron thereturn self._session_managerline (src/mcp/server/fastmcp/server.py:280) stale — the line is now executed by the suite but still excluded from coverage measurement. Since this PR already removes newly-stale pragmas elsewhere (themock_receivefunctions in test_streamable_http_manager.py), drop this one too; the None-checkraisebranch above it remains genuinely uncovered and keeps its pragma.Extended reasoning...
What the issue is
The
FastMCP.session_managerproperty insrc/mcp/server/fastmcp/server.pyends with:Before this PR, no test in the suite accessed the
session_managerproperty directly, so this pragma accurately marked an unexecuted line. This PR addstest_streamable_http_app_passes_the_configured_request_body_limit_to_its_manager(tests/server/fastmcp/test_server.py:1495-1501), which is now the only test that readsmcp.session_manager— and it does so after callingstreamable_http_app(), so theNoneguard does not fire and thereturnline executes.The specific code path
FastMCP(max_request_body_size=8)is constructed withself._session_manager = None.mcp.streamable_http_app()runs; the lazy-init branch creates theStreamableHTTPSessionManagerand assigns it toself._session_manager.mcp.session_manager, entering the property.self._session_manager is NoneisFalse, so theraise RuntimeError(...)branch is skipped andreturn self._session_managerat line 280 executes.So line 280 is now exercised on every test run while still being excluded from coverage measurement by the pragma.
Why nothing catches this
This repo enforces
fail_under = 100with"pragma: no cover"inexclude_lines(pyproject.toml). Coverage.py silently ignores excluded lines whether or not they execute — it never fails on an excluded-but-executed line — so CI stays green and the stale pragma persists unnoticed.Impact
Zero runtime impact; this is purely coverage hygiene. The cost is that a genuinely-covered line is invisible to coverage reporting, which erodes the value of the 100%-coverage convention: pragmas are supposed to mark only lines the suite truly cannot reach. Notably, this PR itself follows that convention elsewhere — it removes the now-stale
# pragma: no covercomments from severalmock_receivefunctions in tests/server/test_streamable_http_manager.py that became covered by the same change — so leaving this one behind is an internal inconsistency within the PR.How to fix
Delete the trailing comment on line 280:
The
raise RuntimeErrorbranch at lines 273-279 (theself._session_manager is Nonecase) remains genuinely unexecuted by the suite and should keep its pragma.Step-by-step proof
grep -rn "\.session_manager" tests/— the only hit is the new test at tests/server/fastmcp/test_server.py:1501, confirming the pragma was accurate before this PR.FastMCP(max_request_body_size=8)→streamable_http_app()sets_session_manager→mcp.session_manager.max_request_body_size == 8passes, which requires the property to have returnedself._session_manager— i.e., line 280 executed.