Skip to content

mcp: reject prompts/get requests missing a required argument - #1297

Merged
guglielmo-san merged 1 commit into
modelcontextprotocol:mainfrom
po-et:fix/prompt-required-args
Sep 28, 2026
Merged

guglielmo-san merged 1 commit into
modelcontextprotocol:mainfrom
po-et:fix/prompt-required-args

Conversation

@po-et

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

Copy link
Copy Markdown
Contributor

Fixes #1296.

Server.getPrompt now returns -32602 when 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 in Prompt.Arguments is skipped as before. The AddPrompt doc comment now says that Required is enforced.

As #1080 did for completion/complete, MCPGODEBUG=disablepromptargsvalidation=1 restores the old behavior. It is documented in the 1.9.0 section of docs/mcpgodebug.md; go generate updated it.

TestGetPromptRequiresDeclaredArguments covers these cases:

  • a missing required argument, which fails without the change;
  • an empty required argument;
  • a missing optional argument;
  • a nil entry in Prompt.Arguments;
  • the MCPGODEBUG opt-out, set the way the other switches' tests set theirs.

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.

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
guglielmo-san merged commit a1b0a98 into modelcontextprotocol:main Sep 28, 2026
10 checks passed
@guglielmo-san

Copy link
Copy Markdown
Contributor

@po-et thank you for the contribution!

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.

mcp: prompts/get calls the handler when a required argument is missing

2 participants