Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/mcp/prompt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,15 @@ def validate_arguments!(args)
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

Expand Down
11 changes: 10 additions & 1 deletion lib/mcp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1260,7 +1260,16 @@ def get_prompt(request, session: nil, related_request_id: nil, cancellation: nil
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)
Expand Down
6 changes: 6 additions & 0 deletions test/mcp/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,9 @@ class Example < Tool
}

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
Expand All @@ -1411,6 +1414,9 @@ class Example < Tool
}

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",
Expand Down