Return Invalid Params for unknown prompts and missing prompt arguments

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.
This commit is contained in:
latent-9 2026-08-15 07:55:27 +12:00
commit feba4d4893
No known key found for this signature in database

View file

@ -1260,7 +1260,16 @@ module MCP
prompt = @prompts[prompt_name]
unless prompt
add_instrumentation_data(error: :prompt_not_found)
raise RequestHandlerError.new("Prompt not found #{prompt_name}", request, error_type: :prompt_not_found)
# The explicit `error_code` maps an unknown prompt to Invalid Params (-32602) rather than
# the default Internal Error (-32603), matching the `tools/call`, `resources/read`, and
# `completion/complete` siblings for the same not-found condition, while `error_type:
# :prompt_not_found` keeps the descriptive message and instrumentation label.
raise RequestHandlerError.new(
"Prompt not found #{prompt_name}",
request,
error_type: :prompt_not_found,
error_code: JsonRpcHandler::ErrorCode::INVALID_PARAMS,
)
end
add_instrumentation_data(prompt_name: prompt_name)