Skip to content

fix: default empty, nil, or null arguments to empty object to prevent unmarshal error#2689

Open
wibisanabama wants to merge 1 commit into
github:mainfrom
wibisanabama:fix-get-me-empty-arguments
Open

fix: default empty, nil, or null arguments to empty object to prevent unmarshal error#2689
wibisanabama wants to merge 1 commit into
github:mainfrom
wibisanabama:fix-get-me-empty-arguments

Conversation

@wibisanabama

@wibisanabama wibisanabama commented Jun 15, 2026

Copy link
Copy Markdown

Resolves #2587.

In certain MCP clients, zero-parameter tools (specifically get_me) are called with the arguments field omitted entirely (resulting in a nil raw message), empty, or set to null.

Currently, NewServerToolWithContextHandler attempts to unmarshal req.Params.Arguments directly. Unmarshalling a nil or empty byte slice in Go causes a JSON error (unexpected end of JSON input or json: Unmarshal(nil)), failing the tool call before the handler can execute.

Proposed solution

We update the MCP tool handler wrapper in pkg/inventory/server_tool.go to safely default empty, nil, or "null" arguments to []byte("{}") before unmarshalling.

This ensures that:

  1. Unmarshalling succeeds for zero-parameter tools.
  2. Tools that actually require arguments will still compile and run, failing cleanly during parameter validation rather than crashing on JSON unmarshalling.

How was this verified?

  1. Added TestNewServerToolWithContextHandler_EmptyArguments_Succeeds to pkg/inventory/server_tool_test.go to verify unmarshalling behavior with:
    • nil arguments
    • Empty string ""
    • "null" arguments
    • Empty JSON object {}
  2. Ran the local test suite to verify everything passes:
    • go test -v ./pkg/inventory/...
    • go test ./...

@wibisanabama wibisanabama requested a review from a team as a code owner June 15, 2026 01:32
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.

bug: get_me tool fails without parameters due to empty JSON object {} not being accepted as valid input

1 participant