mcp: send empty arrays for completions and prompts with nothing to return - #1290
Merged
guglielmo-san merged 2 commits intoSep 24, 2026
Merged
Conversation
…turn
A completion handler with no suggestions naturally returns
&CompleteResult{}, and a prompt handler can return a GetPromptResult
with no messages. Both went out with JSON null ("values": null,
"messages": null), although the schema requires arrays, so clients that
validate results reject them: the TypeScript SDK's CompleteResult and
GetPromptResult schemas fail with "expected array, received null".
Replace nil with an empty slice in the handler's result before sending,
as callTool already does for tool content. An input-required prompt
result is left as is, like a tool result.
guglielmo-san
approved these changes
Sep 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A completion handler with nothing to suggest naturally returns
&CompleteResult{}, and a prompt handler can return aGetPromptResultwith no messages. Both went out with JSON null,{"completion":{"values":null}}and{"messages":null}, although the schema requires arrays. So a client that validates results rejects them. With the TypeScript SDK (1.29), bothCompleteResultSchemaandGetPromptResultSchemafail withexpected array, received null, while[]parses fine. The Go client does not notice, because it decodes null as a nil slice.This replaces nil with an empty slice in the handler's result before it is sent, the same way
callToolalready handles tool content (// avoid "null"). An input-required prompt result is left as is, like a tool result. Also likecallTool, this covers what the handler returns: a receiving middleware that returns its own result is not normalized.The test is an extension of
TestNoJSONNull: its server gets a completion handler and a prompt that return empty results, and the client calls both. It fails without the change, on each of the two separately.