fix(vaden_mcp): remove spurious initialized notification on startup - #171
Open
tecrodrigocastro wants to merge 2 commits into
Open
tecrodrigocastro wants to merge 2 commits into
tecrodrigocastro wants to merge 2 commits into
Conversation
vaden_mcp sent a server->client "initialized" notification immediately on boot, before any client request. Per the MCP spec, notifications/ initialized is sent by the client after the initialize handshake, not by the server. The bogus message (also missing the notifications/ prefix) breaks strict MCP clients like Claude Desktop, which fail to match it against any known request/response/notification schema.
_handleRequest treated every incoming message as a request, so a client notification (no "id" field, e.g. notifications/initialized) that didn't match a known method fell into the default case and got an unsolicited error response with id: null. Per JSON-RPC 2.0, notifications must never receive a response. Strict MCP clients like Claude Desktop reject that response outright: id null doesn't fit the expected string|number id, and the payload doesn't match a notification schema either, so it surfaces as a Zod invalid_union error right after the initialize handshake.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes two related JSON-RPC protocol violations in
vaden_mcpthat break strict MCP clients (observed with Claude Desktop, which rejects both messages with a Zodinvalid_unionschema error).1. Spurious server-initiated
initializednotification on bootvaden_mcpsent a bogusinitializedmessage to stdout immediately on startup, before any client request.notifications/initializedis sent by the client after theinitializehandshake completes — never by the server on boot. The message was also missing thenotifications/prefix._sendNotificationhelper. Server info is still returned correctly via theinitializeresponse handler (_handleInitialize).2. Server responded to notifications it didn't recognize
_handleRequesttreated every incoming message as a request. When the client sent a notification (noidfield, e.g. the client's ownnotifications/initialized) for a method not in the switch statement, it fell into thedefaultcase and got an unsolicited error response withid: null.id: nullalso doesn't fit the schema's expectedstring | numberid, compounding the failure.isNotificationcheck (message has noid) so the server no longer replies to notifications in the unknown-method and internal-error paths.Test plan
dart analyzeonvaden_mcp— no new issuesdart testinvaden_mcp— all 3 existing tests passinitialize→notifications/initialized→tools/list→resources/listintodart run bin/vaden_mcp.dart— stdout now contains only the correct responses, in order, with no extraneous or invalid messagesZodError: invalid_unionnow completes cleanly