fix: preserve explicit tool response content

This commit is contained in:
King Star 2026-07-23 03:11:48 +08:00
commit 43a0ba6266
No known key found for this signature in database

View file

@ -7,18 +7,24 @@ module MCP
attr_reader :content, :structured_content, :meta
def initialize(content = nil, deprecated_error = NOT_GIVEN, error: false, structured_content: nil, meta: nil)
def initialize(content = NOT_GIVEN, deprecated_error = NOT_GIVEN, error: false, structured_content: nil, meta: nil)
if deprecated_error != NOT_GIVEN
warn("Passing `error` with the 2nd argument of `Response.new` is deprecated. Use keyword argument like `Response.new(content, error: error)` instead.", uplevel: 1)
error = deprecated_error
end
@content = content || []
content_given = !content.equal?(NOT_GIVEN)
@content_provided = content_given && !content.nil?
@content = content_given ? (content || []) : []
@error = error
@structured_content = structured_content
@meta = meta
end
def content_provided?
@content_provided
end
def error?
!!@error
end