mcp: reject prompts/get requests missing a required argument - #1297
Merged
guglielmo-san merged 1 commit intoSep 28, 2026
Merged
Conversation
The prompts spec asks a server to answer -32602 when a required
argument is missing (server/prompts, "Error Handling", in 2025-11-25
and 2026-07-28). Server.getPrompt only checked that the prompt exists,
so a prompt that declares {Name: "code", Required: true} still had its
handler called without "code", and every handler had to repeat the
check.
Check the declared arguments before calling the handler. A required
argument that is present but empty still reaches the handler, and a nil
entry in Prompt.Arguments is skipped as before. As modelcontextprotocol#1080 did for
completion/complete, MCPGODEBUG=disablepromptargsvalidation=1 restores
the previous behavior.
Fixes modelcontextprotocol#1296
guglielmo-san
approved these changes
Sep 28, 2026
Contributor
|
@po-et thank you for the contribution! |
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.
Fixes #1296.
Server.getPromptnow returns-32602when an argument the prompt declares as required is missing from the request, before calling the handler. The spec asks for this (server/prompts, "Error Handling": missing required arguments,-32602, in 2025-11-25 and 2026-07-28), and it saves every handler from repeating the check. A required argument that is present but empty still reaches the handler, and a nil entry inPrompt.Argumentsis skipped as before. TheAddPromptdoc comment now says thatRequiredis enforced.As #1080 did for
completion/complete,MCPGODEBUG=disablepromptargsvalidation=1restores the old behavior. It is documented in the 1.9.0 section ofdocs/mcpgodebug.md;go generateupdated it.TestGetPromptRequiresDeclaredArgumentscovers these cases:Prompt.Arguments;The conformance server suites give the same results as on main. On 2025-11-25 every scenario passes. On 2026-07-28 only the tasks scenarios fail, which this SDK does not implement yet.