Validate ToolCall Args against Schema

(cherry picked from commit eeb287117535dfb43785704171625323f01d5bda)
This commit is contained in:
Tyler Rowsell 2025-05-22 15:24:10 -04:00
commit 600c96f66a

View file

@ -150,7 +150,7 @@ module MCP
report_exception(e, { request: request })
if e.is_a?(RequestHandlerError)
add_instrumentation_data(error: e.error_type)
raise e
raise StandardError, e.message
end
add_instrumentation_data(error: :internal_error)
@ -213,6 +213,15 @@ module MCP
)
end
if configuration.validate_tool_call_arguments && tool.input_schema
begin
tool.input_schema.validate_arguments(arguments)
rescue Tool::InputSchema::ValidationError => e
add_instrumentation_data(error: :invalid_schema)
raise RequestHandlerError.new(e.message, request, error_type: :invalid_schema)
end
end
begin
call_params = tool_call_parameters(tool)