fix: resolve initialization protocol violation#189
Conversation
WalkthroughA controlled initialization state was added to the server's transport layer, delaying JSON-RPC notifications until after the MCP protocol handshake is complete. Console and stdout outputs are redirected to stderr during this phase. Once initialized, notifications are enabled. Logging during initialization was adjusted to avoid protocol violations. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant FilteredStdioTransport
Client->>Server: Connects and sends initialization request
Server->>FilteredStdioTransport: (Notifications disabled)
Server-->>Client: Sends initialization response
Client->>Server: Sends "initialized" notification
Server->>FilteredStdioTransport: enableNotifications()
Note right of FilteredStdioTransport: Notifications enabled
Server->>FilteredStdioTransport: Subsequent logs/outputs
FilteredStdioTransport-->>Client: Sends JSON-RPC notifications
Estimated code review effort2 (30–90 minutes) Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (3)
🧰 Additional context used🧠 Learnings (3)📓 Common learningssrc/index.ts (2)Learnt from: tillahoffmann Learnt from: tillahoffmann src/custom-stdio.ts (2)Learnt from: tillahoffmann Learnt from: tillahoffmann 🧬 Code Graph Analysis (1)src/index.ts (1)
🔇 Additional comments (6)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
|
Hey there, I created a new PR based on yours Need to fix some issues more in that direction. Closing yours, will merge soon new PR |
Resolves MCP server initialization failures, where clients receive
LoggingMessageNotificationinstead of expected initialization response.Root Cause
The
FilteredStdioServerTransportimmediately redirected console output to JSON-RPC notifications, causing protocol violations during the initialization phase.Solution
isInitializedflag prevents premature notificationsenableNotifications()method called after MCP connection establishedFiles Modified
src/custom-stdio.ts: Added state control and conditional redirectionsrc/index.ts: Proper timing for enabling notificationssrc/server.ts: Fixed initialization handler loggingclose #188
Summary by CodeRabbit
New Features
Bug Fixes
Chores