Skip to content

mcp: send empty arrays for completions and prompts with nothing to return - #1290

Merged
guglielmo-san merged 2 commits into
modelcontextprotocol:mainfrom
po-et:fix/null-completion-values
Sep 24, 2026
Merged

guglielmo-san merged 2 commits into
modelcontextprotocol:mainfrom
po-et:fix/null-completion-values

Conversation

@po-et

@po-et po-et commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

A completion handler with nothing to suggest naturally returns &CompleteResult{}, and a prompt handler can return a GetPromptResult with 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), both CompleteResultSchema and GetPromptResultSchema fail with expected 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 callTool already handles tool content (// avoid "null"). An input-required prompt result is left as is, like a tool result. Also like callTool, 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.

po-et and others added 2 commits September 24, 2026 14:12
…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
guglielmo-san merged commit e07f0c9 into modelcontextprotocol:main Sep 24, 2026
9 checks passed
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.

2 participants