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:
commit
c4921ed09f
3 changed files with 24 additions and 2 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue