Fix MCP stdio compliance; add initialize.instructions#6
Open
WhymustIhaveaname wants to merge 2 commits into
Open
Fix MCP stdio compliance; add initialize.instructions#6WhymustIhaveaname wants to merge 2 commits into
WhymustIhaveaname wants to merge 2 commits into
Conversation
Two independent protocol bugs prevented Claude Code (and likely any strict MCP host) from keeping the connection alive: 1. All log output went through console.log, which writes to stdout. The MCP stdio transport requires stdout to contain only JSON-RPC messages, so these log lines corrupted the channel. Every log call now goes through console.error (stderr). 2. JSON-RPC notifications such as `notifications/initialized` have no `id` field and must not receive a response. The default switch case replied with a "Method not found" error, which the client treated as an orphan response and dropped the connection. Notifications are now detected and ignored at the top of handleRequest. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Populate the optional `instructions` field in the initialize response so that MCP clients can surface a one-line description of what this server is for, without needing to discover and load every tool first. Co-Bungled-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
This server currently fails the MCP init handshake under strict clients
like Claude Code CLI:
console.logleaks non-JSON into stdout, so I switched toconsole.error.notifications/initializedhas noid, but thedefaultbranch inhandleRequeststill replies with-32601; the client sees an orphanresponse and drops the connection. Now we skip any JSON-RPC message
without an
id.initialize.instructionsfield.