-
-
Notifications
You must be signed in to change notification settings - Fork 558
Fix MCP stdio protocol violation during startup (Docker/langchain compatibility) #285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -277,13 +277,25 @@ export class FilteredStdioServerTransport extends StdioServerTransport { | |||||||
|
|
||||||||
| /** | ||||||||
| * Public method to send log notifications from anywhere in the application | ||||||||
| * Now properly buffers messages before MCP initialization to avoid breaking stdio protocol | ||||||||
| */ | ||||||||
| public sendLog(level: "emergency" | "alert" | "critical" | "error" | "warning" | "notice" | "info" | "debug", message: string, data?: any) { | ||||||||
| // Skip if notifications are disabled (e.g., for Cline) | ||||||||
| if (this.disableNotifications) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| // Buffer messages before initialization to avoid breaking MCP protocol | ||||||||
| // MCP requires client to send first message - server cannot write to stdout before that | ||||||||
| if (!this.isInitialized) { | ||||||||
| this.messageBuffer.push({ | ||||||||
| level, | ||||||||
| args: [data ? { message, ...data } : message], | ||||||||
| timestamp: Date.now() | ||||||||
| }); | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| try { | ||||||||
| const notification: LogNotification = { | ||||||||
| jsonrpc: "2.0", | ||||||||
|
|
@@ -315,6 +327,11 @@ export class FilteredStdioServerTransport extends StdioServerTransport { | |||||||
| * Send a progress notification (useful for long-running operations) | ||||||||
| */ | ||||||||
| public sendProgress(token: string, value: number, total?: number) { | ||||||||
| // Don't send progress before initialization - would break MCP protocol | ||||||||
| if (!this.isInitialized) { | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| try { | ||||||||
| const notification = { | ||||||||
| jsonrpc: "2.0" as const, | ||||||||
|
|
@@ -346,6 +363,11 @@ export class FilteredStdioServerTransport extends StdioServerTransport { | |||||||
| * Send a custom notification with any method name | ||||||||
| */ | ||||||||
| public sendCustomNotification(method: string, params: any) { | ||||||||
| // Don't send custom notifications before initialization - would break MCP protocol | ||||||||
| if (!this.isInitialized) { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: The custom notification method does not check the Severity Level: Minor
Suggested change
Why it matters? ⭐Same story here: Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** src/custom-stdio.ts
**Line:** 367:367
**Comment:**
*Logic Error: The custom notification method does not check the `disableNotifications` flag, so even when a client has been configured to disable all notifications, custom JSON-RPC notifications will still be sent, leading to inconsistent behavior and potential protocol issues for those clients; this should also bail out when notifications are disabled.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. |
||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| try { | ||||||||
| const notification = { | ||||||||
| jsonrpc: "2.0" as const, | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The progress notification method currently ignores the
disableNotificationsflag, so clients explicitly configured to have notifications disabled (e.g., Cline/vscode/claude-dev) will still receive progress JSON-RPC messages, which contradicts the intent ofconfigureForClientand can break those clients; you should also short‑circuit when notifications are disabled. [logic error]Severity Level: Minor⚠️
Why it matters? ⭐
This is a real behavioral bug, not cosmetic. The class has an explicit
disableNotificationsflag set inconfigureForClientfor Cline/vscode/claude-dev,and both
sendLogandsendLogNotificationalready short-circuit on that flag,meaning "notifications disabled" is intended to apply globally. However,
sendProgressonly checksisInitializedand still emits JSON-RPC progressnotifications even when
disableNotificationsis true, which contradicts thestated behavior and can still break those same clients. Adding the
this.disableNotificationscheck alignssendProgresswith the rest of theclass' behavior and prevents unwanted notifications from being sent.
Prompt for AI Agent 🤖