Skip to content

fix: decode empty jsonrpc methods as requests#983

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

fix: decode empty jsonrpc methods as requests#983
he-yufeng wants to merge 1 commit into
modelcontextprotocol:mainfrom
he-yufeng:fix/respond-empty-method

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Fixes #976.

An incoming JSON-RPC message with an explicit empty method field was decoded as a response because the wire struct could not distinguish a missing method from an empty method. That meant stdio servers silently ignored requests like id=5/method="" instead of routing them through request handling and returning a correlated JSON-RPC error.

This keeps method presence during decode by storing the wire method as a pointer, then decodes method="" as a Request. The existing dispatch path can then return method-not-found for the request id while leaving the session alive.

Validation:

  • go test ./internal/jsonrpc2
  • go test ./mcp -run "TestIOConnRead|TestServerSessionHandle|TestKeepAliveMethodNotFound"
  • go test ./...

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