Skip to content

fix(mcp): harden stdio framing, notifications, and tool parameter handling - #564

Merged
ajianaz merged 1 commit into
developfrom
fix/mcp-framing-protocol-hardening
Oct 7, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/mcp-framing-protocol-hardening

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

What

Fixes the MCP stdio server framing and JSON-RPC protocol handling, and hardens several tool handlers (src/mcp/server.rs, src/mcp/tools.rs).

Why

  • stdin was read byte-by-byte with byte as char, corrupting multi-byte UTF-8; brace_depth could go negative on a stray } and never recover; there was no message size cap.
  • Notifications received responses, and notifications/cancelled shut the whole server down.
  • tools/call with a missing name fell through to "Unknown tool".
  • find_affected_tests used the file extension instead of the stem and passed unescaped LIKE wildcards; several params were unbounded.
  • cora.install ran with yes: true over MCP with no confirmation; cora.get_debt advertised since/branch but ignored them.

How

  • New byte-level Framer: accumulates bytes, decodes UTF-8 per message, supports newline-delimited and pretty-printed objects, resets and returns -32700 on stray }/garbage/invalid UTF-8/truncated input, caps messages at 16 MiB (oversized messages are skipped and the stream resyncs).
  • Messages without id never get a response; notifications/* handled silently; only shutdown (or EOF) stops the server. tools/call with missing/empty name returns -32602.
  • Tools: file stem via Path::file_stem, LIKE ... ESCAPE, files capped at 200, limit<=500, depth<=10, min_lines<=100000, review_diff diff capped at 1 MiB.
  • cora.install: requires confirm: true to write (not needed for list/dry_run) and validates agents against the known set.
  • cora.get_debt: removed unused since/branch from the schema. Tool count stays 18.
  • AGENT.md: 15 -> 18 tools.

Testing

  • cargo test --features tree-sitter passes
  • cargo fmt --all -- --check passes
  • cargo clippy --all-targets --features tree-sitter -- -D warnings passes
  • cargo build --release --features tree-sitter passes (not run; debug build/clippy/test clean)
  • Manual smoke-test of the affected feature: stdio-level tests drive serve() with Japanese/emoji split byte-by-byte, pretty-printed JSON, stray }, garbage lines, invalid UTF-8, truncated EOF, oversized message, notification without id, notifications/cancelled, shutdown, and missing tool name.

Tool tests cover the file-stem candidates, LIKE escaping against real SQLite, files cap, param clamping, diff cap, install confirm/agent validation, and the 18-tool count.

Related Issues

None.

Checklist

  • Branch name follows convention (fix/, feat/, docs/, chore/, refactor/, test/, perf/, security/)
  • Branch is from develop
  • Commit messages follow Conventional Commits
  • No secrets or credentials committed
  • One logical change per PR (no mixed concerns)

🤖 Generated with Claude Code

…dling

- Frame stdin as bytes and decode UTF-8 properly (no more byte-as-char),
  recover from stray '}'/garbage with a -32700 parse error, cap message size.
- Do not respond to notifications; notifications/cancelled no longer stops
  the server (only shutdown/EOF); tools/call without a name returns -32602.
- find_affected_tests: use file stem, escape LIKE wildcards, cap files.
- Clamp limit/depth/min_lines, cap review_diff size.
- cora.install requires confirm:true to write and validates agent names.
- Remove unused since/branch params from cora.get_debt schema.
- AGENT.md: tool count 15 -> 18.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Signed-off-by: ajianaz <[email protected]>
@ajianaz
ajianaz merged commit 0630b36 into develop Oct 7, 2026
14 checks passed
ajianaz added a commit that referenced this pull request Oct 8, 2026
)

Covers security hardening (#563, #572, #573), fixes (#553, #561, #562,
#564, #565, #574-#576), and the ignore-pattern semantic changes from
#577 that can alter which files existing configs exclude.

Signed-off-by: ajianaz <[email protected]>
Co-authored-by: ajianaz <[email protected]>
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
@ajianaz
ajianaz deleted the fix/mcp-framing-protocol-hardening branch October 16, 2026 00:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant