Skip to content

fix: preserve empty-method requests during decode#980

Open
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/stdio-empty-method-error
Open

fix: preserve empty-method requests during decode#980
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/stdio-empty-method-error

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Summary

Fixes #976.

DecodeMessage used msg.Method != "" to distinguish requests from responses. That means a wire payload with a present but empty method field, such as:

{"jsonrpc":"2.0","id":5,"method":"","params":{}}

was decoded as a response instead of a request. Since there was no matching outgoing call, the server ignored it and did not send a correlated JSON-RPC error, even though the session stayed alive.

This PR checks whether the wire payload contains the method field instead of checking whether the decoded string is non-empty. An empty method now reaches the normal request dispatch path and receives the existing method-not-found handling.

Tests

go test ./internal/jsonrpc2
go test ./mcp
go test ./...
git diff --check

@he-yufeng he-yufeng force-pushed the fix/stdio-empty-method-error branch from 0c23e45 to ed19f70 Compare May 29, 2026 19:38
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.

Stdio server leaves some malformed JSON-RPC requests unanswered while the session remains alive

1 participant