go-sdk icon indicating copy to clipboard operation
go-sdk copied to clipboard

fix: preserve empty-method requests during decode

Open he-yufeng opened this issue 6 months ago • 3 comments

## 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 avatar May 27 '26 19:05 he-yufeng

Rebased on current origin/main and reran validation locally.

Validated:

gofmt -w $(git diff --name-only origin/main...HEAD | Where-Object { $_ -like '*.go' })
go test ./mcp
go test -race ./mcp
go test ./...
git diff --check origin/main...HEAD

All passed after the rebase.

he-yufeng avatar Jun 02 '26 19:06 he-yufeng

Rebased this branch onto the latest upstream main and force-pushed the cleaned head.

Validated locally:

  • gofmt -l internal/jsonrpc2/messages.go internal/jsonrpc2/wire_test.go (no output)
  • go test ./internal/jsonrpc2
  • go test ./...
  • git diff --check origin/main..HEAD

he-yufeng avatar Jun 06 '26 19:06 he-yufeng

Rebased this branch onto current upstream main and reran the focused/full Go validation.

Validation:

gofmt -l internal\jsonrpc2\messages.go internal\jsonrpc2\wire_test.go
go test ./internal/jsonrpc2
go test ./...
git diff --check origin/main..HEAD

Current head: dbbe137.

he-yufeng avatar Jun 12 '26 01:06 he-yufeng

Closing as duplicate of PR #1000

guglielmo-san avatar Jun 16 '26 07:06 guglielmo-san