Repository navigation
Fix: Harden MCP Transport Parsing against oversized JSON numbers - #228
localtrade1 wants to merge 1 commit into
Conversation
### Description This PR isolates the remaining unresolved transport vulnerability from the previous attempt (flop-labs#102). Since the room-list cache staleness and race condition improvements were beautifully addressed by recent upstream refactoring, this PR focuses strictly on the MCP session termination defect to maintain a clean, zero-conflict diff. ### Key Changes * **MCP Transport Parsing (`mcp/src/technocore_mcp/protocol.py`):** Modified the stdio `Server.serve` loop to explicitly catch `ValueError` alongside `json.JSONDecodeError`. This prevents Python's numeric-conversion limit on oversized JSON integers from crashing the wrapper process and terminating the active session. The transport now correctly emits a recoverable `PARSE_ERROR` response and continues reading subsequent frames. * **Regression Testing (`tests/test_mcp.py`):** Added session-continuity transport coverage (`test_oversized_json_numbers_do_not_kill_the_session`), proving that a 5000-digit request ID parses safely, correctly returns a `PARSE_ERROR`, and a subsequent ping receives a valid response without breaking the loop. ### Validation * Only transport and test files were touched (zero impact on `sz-baseline.json` limits). * Checked against the current `main` branch to ensure absolute compatibility and no CRLF/Code-Churn overhead.
|
Closing the PR, but not as a judgment that the concern is answered — worth separating the two. This hardens number parsing in Whether an oversized JSON number is still a problem on the SDK path is a separate, open question that nobody has measured. If it reproduces against Duplicate track: #399 and #90 cover the same ground and are closed for the same reason. Generated by Claude Code |
What
The MCP stdio wrapper now catches
ValueErroralongsidejson.JSONDecodeErrorduring JSON parsing. Clients sending oversized integers now receive a recoverablePARSE_ERRORrather than crashing the wrapper and terminating the active session.Why
Python's
json.loadsraises aValueErrorwhen an integer exceeds its string-conversion limit. Uncaught, a single malformed token kills the entire MCP session. This isolates the transport vulnerability from previous attempt #102. The room-list cache staleness and race condition fixes from #102 were subsumed by recent upstream refactoring and are deliberately left alone here to maintain a clean, zero-conflict diff.Checks
uv run coverage run -m pytest tests -q && uv run coverage reportuv run ruff check . && uv run ruff format --check .anduv run ty check/skill.mdare built insrc/app.py, plusREADME.md,src/patterns.md,mcp/README.mdor say "nothing new"
nothing new (strictly a crash fix for the existing transport loop)