Skip to content

jsonrpc2: decode requests with empty method fields#996

Open
Zhang-986 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Zhang-986:codex/stdio-empty-method-error-response
Open

jsonrpc2: decode requests with empty method fields#996
Zhang-986 wants to merge 1 commit into
modelcontextprotocol:mainfrom
Zhang-986:codex/stdio-empty-method-error-response

Conversation

@Zhang-986
Copy link
Copy Markdown

PR Guideline

This change updates JSON-RPC message decoding to classify any payload with a method field as a request, even when the method value is an empty string.

Previously, DecodeMessage used the decoded method string to distinguish requests from responses. That meant {"jsonrpc":"2.0","id":5,"method":"","params":{}} was decoded as a response because the method string was empty, so stdio servers could fail to send the expected JSON-RPC error response for malformed requests.

The implementation now checks whether the method field exists in the raw JSON object before constructing the concrete message type, preserving empty-method requests for normal request handling and error reporting.

Fixes #976

Tests:

  • go test ./internal/jsonrpc2

@Zhang-986 Zhang-986 force-pushed the codex/stdio-empty-method-error-response branch from a9bbb38 to 7e3c1a8 Compare June 7, 2026 07:30
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