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

@ -111,8 +111,15 @@ module MCP
missing = required_args - args.keys
return if missing.empty?
# The explicit `error_code` maps a missing prompt argument to Invalid Params (-32602) rather
# than the default Internal Error (-32603); a missing required argument is client input, not a
# server fault. `error_type: :missing_required_arguments` keeps the descriptive message and
# instrumentation label. Mirrors `MCP::Server::ResourceNotFoundError`.
raise MCP::Server::RequestHandlerError.new(
"Missing required arguments: #{missing.join(", ")}", nil, error_type: :missing_required_arguments
"Missing required arguments: #{missing.join(", ")}",
nil,
error_type: :missing_required_arguments,
error_code: JsonRpcHandler::ErrorCode::INVALID_PARAMS,
)
end