Skip to content

Return Invalid Params for unknown prompts and missing prompt arguments - #517

Merged
koic merged 1 commit into
modelcontextprotocol:mainfrom
latent-9:prompts-get-invalid-params
Aug 15, 2026
Merged

Return Invalid Params for unknown prompts and missing prompt arguments#517
koic merged 1 commit into
modelcontextprotocol:mainfrom
latent-9:prompts-get-invalid-params

Conversation

@latent-9

Copy link
Copy Markdown
Contributor

Summary

prompts/get returns Internal Error (-32603) when the prompt name is unknown or a required argument is missing. Both are client input errors, so the JSON-RPC error code should be Invalid Params (-32602), which is what the sibling handlers already return for the same conditions.

Current behavior

Requesting an unknown prompt:

{"jsonrpc":"2.0","id":1,"error":{"code":-32603,"message":"Internal error","data":"Prompt not found ghost"}}

completion/complete (Server#complete), asked to complete an argument for that same unknown prompt, already returns -32602. The two handlers return different codes for the one condition.

Why Invalid Params

The not-found and missing-input paths of the neighboring methods already map to -32602:

  • tools/call unknown tool, in Server#call_tool
  • resources/read unknown resource, via ResourceNotFoundError, standardized to -32602 in SEP-2164
  • completion/complete unknown prompt, in Server#complete

prompts/get was the only not-found path left on -32603.

Change

Add an explicit error_code: JsonRpcHandler::ErrorCode::INVALID_PARAMS at the two prompts/get raise sites:

  • unknown prompt, in Server#get_prompt
  • missing required argument, in Prompt.validate_arguments!

This follows the ResourceNotFoundError pattern already in the tree: the wire code becomes -32602 and the descriptive message is surfaced, while error_type stays :prompt_not_found / :missing_required_arguments so the existing instrumentation labels are unchanged.

After:

{"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"Prompt not found ghost","data":"Prompt not found ghost"}}

Tests

Extended the two existing prompts/get error tests to assert the -32602 code; they fail on the current code and pass with the fix. bundle exec rake is green (1701 runs, 0 failures), RuboCop reports no offenses, and the conformance baseline is unchanged.

An unknown prompt name and a missing required prompt argument are client input errors, but prompts/get raised them with the default Internal Error (-32603). The tools/call, resources/read, and completion/complete siblings already return Invalid Params (-32602) for the same not-found and missing-input conditions (resources/read via ResourceNotFoundError, per SEP-2164).

Add an explicit error_code so both map to -32602 while keeping the descriptive message and the existing instrumentation labels.
@koic
koic merged commit c4921ed into modelcontextprotocol:main Aug 15, 2026
11 checks passed
@koic

koic commented Aug 15, 2026

Copy link
Copy Markdown
Member

Thanks!

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