Merge pull request #517 from latent-9/prompts-get-invalid-params

Return Invalid Params for unknown prompts and missing prompt arguments
This commit is contained in:
Koichi ITO 2026-08-15 11:24:58 +09:00 • committed by GitHub
commit c4921ed09f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

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

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)

View file

@ -1395,6 +1395,9 @@ module MCP
}
response = @server.handle(request)
# An unknown prompt is client input, so it maps to Invalid Params (-32602), not the
# default Internal Error (-32603); matches the tools/call and completion/complete siblings.
assert_equal JsonRpcHandler::ErrorCode::INVALID_PARAMS, response.dig(:error, :code)
assert_equal("Prompt not found unknown_prompt", response[:error][:data])
assert_instrumentation_data({ method: "prompts/get", error: :prompt_not_found })
end
@ -1411,6 +1414,9 @@ module MCP
}
response = @server.handle(request)
# A missing required argument is client input, so it maps to Invalid Params (-32602),
# not the default Internal Error (-32603).
assert_equal JsonRpcHandler::ErrorCode::INVALID_PARAMS, response.dig(:error, :code)
assert_equal "Missing required arguments: test_argument", response[:error][:data]
assert_instrumentation_data({
method: "prompts/get",