Repository navigation
feat(transport): make the Python transport body-size limit configurable - #7337
Open
DawnofGenX wants to merge 1 commit into
Open
DawnofGenX wants to merge 1 commit into
DawnofGenX wants to merge 1 commit into
Conversation
…le (IBM#7261) Add MCP_MAX_REQUEST_BODY_SIZE_BYTES (default 4194304, validated > 0) and pass it to the MCP SDK StreamableHTTPSessionManager(max_request_body_size=...) at the Python Streamable HTTP transport construction site. Larger requests are rejected with HTTP 413. MCP_BODY_PEEK_MAX_BYTES remains a soft body-inspection threshold and does not change this hard limit. Document the variable in .env.example. Add unit tests for the configured and default values and a behavioural ASGI test: a body over the configured limit returns 413, a body under it is accepted. Closes IBM#7261 Signed-off-by: Priyansh <pkansara0412@gmail.com>
DawnofGenX
requested review from
Lang-Akshay,
brian-hussey,
ja8zyjits and
msureshkumar88
as code owners
October 24, 2026 14:26
This branch has not been deployed
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.
Pull Request
🔗 Related Issue
Closes #7261
📝 Summary
Adds
MCP_MAX_REQUEST_BODY_SIZE_BYTESto configure the hard inbound request-body limit for the Python Streamable HTTP transport. The value passes to the MCP SDK'sStreamableHTTPSessionManager(max_request_body_size=...). The default stays4194304(4 MiB) when the variable is unset. The setting validates> 0.MCP_BODY_PEEK_MAX_BYTESremains a soft body-inspection threshold. It does not change this hard limit.The
mcpgateway/translate.pyconstruction sites stay on the SDK default: they serve the standalonepython -m mcpgateway.translate --stdiobridge CLI, not the gateway's Python Streamable HTTP transport that this issue targets.📏 Reviewability
triage🏷️ Type of Change
🧪 Verification
make ruffscoped to the changed filespytest tests/unit/mcpgateway/transports/ tests/unit/mcpgateway/test_config.py -qpytest ...::test_session_manager_wrapper_* ...::test_streamable_http_rejects_bodies_over_configured_limitruff format --check(pinned 0.15.20)make test/make coverageCommands run:
✅ Checklist
make black isort pre-commit)📓 Notes (optional)
Only the affected test subset and scoped linters were run here; the full
make test/make coverage diff-covergate was not executed in this environment, so the coverage row is left as not run rather than claimed.New setting
mcp_max_request_body_size_bytesinmcpgateway/config.py(Field(default=4 * 1024 * 1024, ge=1, ...)), env varMCP_MAX_REQUEST_BODY_SIZE_BYTES.Wired at the
SessionManagerWrapperconstruction site inmcpgateway/transports/streamablehttp_transport.py.Documented in
.env.examplenext toMCP_BODY_PEEK_MAX_BYTES, with the soft-vs-hard distinction.Behavioural test drives the real SDK session manager over ASGI: a body of
limit + 1bytes returns HTTP 413, a body oflimit - 1bytes is accepted.