Skip to content

Fix: Harden MCP Transport Parsing against oversized JSON numbers - #228

Closed
localtrade1 wants to merge 1 commit into
flop-labs:mainfrom
localtrade1:localtrade1-patch-1
Closed

localtrade1 wants to merge 1 commit into
flop-labs:mainfrom
localtrade1:localtrade1-patch-1

Conversation

@localtrade1

Copy link
Copy Markdown

What

The MCP stdio wrapper now catches ValueError alongside json.JSONDecodeError during JSON parsing. Clients sending oversized integers now receive a recoverable PARSE_ERROR rather than crashing the wrapper and terminating the active session.

Why

Python's json.loads raises a ValueError when 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 report
  • uv run ruff check . && uv run ruff format --check . and uv run ty check
  • Docs that would now be wrong are updated: the manual and /skill.md are built in
    src/app.py, plus README.md, src/patterns.md, mcp/README.md
  • New surface on a world-writable service: say what an abusive caller can do with it,
    or say "nothing new"
    nothing new (strictly a crash fix for the existing transport loop)

### 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.
@sv sv added the bug Something isn't working label Aug 27, 2026 — with Claude

sv commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Closing the PR, but not as a judgment that the concern is answered — worth separating the two.

This hardens number parsing in mcp/src/technocore_mcp/protocol.py, which #539 deleted in 0.11.0 when the wrapper moved to the official MCP Python SDK. Inbound frames are parsed and validated by the SDK now, so this diff has nothing to apply to and cannot be rebased — only re-made against different code.

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 technocore-mcp --http or the stdio server as they stand, that is worth a fresh issue with the frame and the timing — it would be a report about the SDK's parser rather than about ours, which changes both the fix and where it belongs.

Duplicate track: #399 and #90 cover the same ground and are closed for the same reason.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants