Skip to content

fix(mcp): ignore JSON-RPC notifications without id (so can working with codex)#15

Open
wukeying wants to merge 1 commit into
zeenix:mainfrom
wukeying:fix/mcp-ignore-notification-without-id
Open

fix(mcp): ignore JSON-RPC notifications without id (so can working with codex)#15
wukeying wants to merge 1 commit into
zeenix:mainfrom
wukeying:fix/mcp-ignore-notification-without-id

Conversation

@wukeying

Copy link
Copy Markdown

Summary

This change makes the MCP server ignore JSON-RPC notifications (requests without id) instead of replying with an
error.

Why

Some MCP clients send notification messages such as notifications/initialized during handshake.
Per JSON-RPC semantics, notifications must not receive responses. Returning an error response can cause client
transport/session startup failures.

Change

  • In the MCP request loop, skip response writing when request.id.is_none().
  • Keep existing request/response behavior unchanged for normal requests with id.

Validation

  • Built and ran the patched server.
  • Verified initialize + tools/list still work.
  • Verified notification messages no longer generate error responses.
  • Tested in codex

@ervinpopescu

ervinpopescu commented Apr 10, 2026

Copy link
Copy Markdown

I think this will fix gemini-cli as well:

│ ℹ  Registering notification handlers for server 'rust-analyzer'. Capabilities: { tools: {} }                                                                                               │
│ ℹ  Server 'rust-analyzer' has tools but did not declare 'listChanged' capability. Listening anyway for robustness...                                                                       │
│ ⚠  [STARTUP] Cannot start phase 'load_builtin_commands': phase is already active. Call end() before starting again.                                                                        │
│ ℹ  [MCP error] MCP ERROR (rust-analyzer) Error: Received a response for an unknown message ID: {"jsonrpc":"2.0","error":{"code":-32601,"message":"Method not found:                        │
│    notifications/initialized","data":null}}                                                                                                                                                │
│        at Client._onresponse (file:///usr/local/google/home/ervinadrian/node/lib/node_modules/@google/gemini-cli/bundle/chunk-IKYTUXTH.js:270841:21)                                       │
│        at _transport.onmessage (file:///usr/local/google/home/ervinadrian/node/lib/node_modules/@google/gemini-cli/bundle/chunk-IKYTUXTH.js:270653:14)                                     │
│        at StdioClientTransport.processReadBuffer (file:///usr/local/google/home/ervinadrian/node/lib/node_modules/@google/gemini-cli/bundle/chunk-IKYTUXTH.js:273671:25)                   │
│        at Socket.<anonymous> (file:///usr/local/google/home/ervinadrian/node/lib/node_modules/@google/gemini-cli/bundle/chunk-IKYTUXTH.js:273633:14)                                       │
│        at Socket.emit (node:events:508:28)                                                                                                                                                 │
│        at addChunk (node:internal/streams/readable:563:12)                                                                                                                                 │
│        at readableAddChunkPushByteMode (node:internal/streams/readable:514:3)                                                                                                              │
│        at Readable.push (node:internal/streams/readable:394:5)                                                                                                                             │
│        at Pipe.onStreamRead (node:internal/stream_base_commons:189:23)                                                                                                                     │
│ ℹ  [MCP error] Error during discovery for MCP server 'rust-analyzer': Client is not connected, must connect before interacting with the server. Current state is disconnected Error:       │
│    Client is not connected, must connect before interacting with the server. Current state is disconnected                                                                                 │
│        at McpClient.assertConnected (file:///usr/local/google/home/ervinadrian/node/lib/node_modules/@google/gemini-cli/bundle/chunk-IKYTUXTH.js:340721:13)                                │
│        at McpClient.discoverResources (file:///usr/local/google/home/ervinadrian/node/lib/node_modules/@google/gemini-cli/bundle/chunk-IKYTUXTH.js:340738:10)                              │
│        at McpClient.discoverInto (file:///usr/local/google/home/ervinadrian/node/lib/node_modules/@google/gemini-cli/bundle/chunk-IKYTUXTH.js:340657:34)                                   │
│        at process.processTicksAndRejections (node:internal/process/task_queues:104:5)                                                                                                      │
│        at async file:///usr/local/google/home/ervinadrian/node/lib/node_modules/@google/gemini-cli/bundle/chunk-IKYTUXTH.js:342020:15                                                      │
│ ℹ  Scheduling MCP context refresh...                                                                                                                                                       │
│ ℹ  Executing MCP context refresh...                                                                                                                                                        │
│ ⚠  [STARTUP] Cannot start phase 'load_builtin_commands': phase is already active. Call end() before starting again. (x2)                                                                   │
│ ⚠  [STARTUP] Phase 'load_builtin_commands' was started but never ended. Skipping metrics.                                                                                                  │
│ ℹ  MCP context refresh complete.                

Testing it now.

Looks like it does:

 ℹ  MCP context refresh complete.                                                                                                                                                          █│
│ ℹ  Registering notification handlers for server 'rust-analyzer'. Capabilities: { tools: {} }                                                                                              █│
│ ℹ  Server 'rust-analyzer' has tools but did not declare 'listChanged' capability. Listening anyway for robustness...                                                                      █│
│ ℹ  Scheduling MCP context refresh...                                                                                                                                                      █│
│ ℹ  Executing MCP context refresh...                                                                                                                                                       █│
│ ℹ  MCP context refresh complete. 

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.

2 participants