Skip to content

fix(mcp): JSON-RPC 2.0 spec compliance — omit error field & skip notification acks - #576

Merged
ajianaz merged 1 commit into
developfrom
fix/mcp-json-rpc-spec-compliance
Jul 6, 2026
Merged

ajianaz merged 1 commit into
developfrom
fix/mcp-json-rpc-spec-compliance

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #573 — uteke-mcp emits non-spec-compliant JSON-RPC, causing Claude Code to refuse connection.

Changes

File What
crates/uteke-mcp/src/lib.rs Changed JsonRpcResponse from flat struct with Option fields to tagged enum (Success/Error). handle_jsonrpc returns Option<String> — None for notifications (per §4.1).
crates/uteke-mcp/src/main.rs Skips stdout write when handler returns None (notification).
crates/uteke-server/src/handlers.rs Returns 204 No Content for notifications on HTTP endpoint. Also fixed pre-existing formatting.

What was broken

  1. Success responses included "error": null → violates JSON-RPC 2.0 §5.1 (result/error mutually exclusive)
  2. Notifications received an ack response {"id":null,...} → violates JSON-RPC 2.0 §4.1 (no response to notifications)

What's fixed

Before (2.0K output, Claude Code rejects):

{"jsonrpc":"2.0","id":1,"result":{...},"error":null}
{"jsonrpc":"2.0","id":null,"result":null,"error":null}

After (spec-compliant, Claude Code accepts):

{"jsonrpc":"2.0","id":1,"result":{...}}
(no second line — notification gets no response)

Test plan

  • cargo fmt --all -- --check passes locally
  • CI: check, fmt, clippy, test, build (depends on ubuntu-latest OpenSSL)
  • Manual: printf '...' | uteke-mcp no longer emits notification acks

…fication acks

Closes #573

Two violations fixed:

1. Success responses no longer include "error": null.
   Changed JsonRpcResponse from a flat struct with Option fields to a
   tagged enum (Success/Error) so serde omits the absent variant entirely,
   per JSON-RPC 2.0 §5.1 (result and error are mutually exclusive).

2. Notifications (requests with no "id") no longer receive a response.
   handle_jsonrpc now returns Option<String>: None for notifications,
   Some(response) for regular requests, per JSON-RPC 2.0 §4.1.

Updated callers:
- main.rs (stdio): skips writeln when handle_jsonrpc returns None
- handlers.rs (HTTP): returns 204 No Content for notifications

Also runs cargo fmt on pre-existing formatting issues in handlers.rs.
})
.unwrap_or_default(),
Ok(result) => {
if is_notification {
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown

🔍 Cora AI Code Review

❌ Blocked — critical issues found.

🔴 Error (1)

  • crates/uteke-mcp/src/lib.rs:89 — The new is_notification = req.id.is_none() branch causes handle_jsonrpc to return None for every handler error when id is absent. In JSON-RPC, true notifications should not receive responses, but requests that are structurally invalid still need error handling consistent with the spec and interoperability expectations. With the current code, a malformed request object that deserializes with id: None and then fails in handle_request will be silently dropped instead of returning an error response, making client debugging difficult and potentially hiding protocol misuse.

Review powered by cora-cli · BYOK · MIT

@ajianaz
ajianaz merged commit 179f497 into develop Jul 6, 2026
8 of 9 checks passed
@ajianaz
ajianaz deleted the fix/mcp-json-rpc-spec-compliance branch July 6, 2026 03:54
ajianaz added a commit that referenced this pull request Aug 13, 2026
…ance

fix(mcp): JSON-RPC 2.0 spec compliance — omit error field & skip notification acks
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.

uteke-mcp emits non-spec-compliant JSON-RPC ("error": null + notification acks) → Claude Code refuses connection

2 participants