Support structuredContent in tool response (#147)

This commit is contained in:
Anandaroop Roy 2025-09-27 02:23:41 -04:00 • committed by GitHub
commit f7cf080cc0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -5,9 +5,9 @@ module MCP
class Response
NOT_GIVEN = Object.new.freeze
attr_reader :content
attr_reader :content, :structured_content
def initialize(content, deprecated_error = NOT_GIVEN, error: false)
def initialize(content = nil, deprecated_error = NOT_GIVEN, error: false, structured_content: 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
@ -15,6 +15,7 @@ module MCP
@content = content
@error = error
@structured_content = structured_content
end
def error?
@ -22,7 +23,7 @@ module MCP
end
def to_h
{ content:, isError: error? }.compact
{ content:, isError: error?, structuredContent: @structured_content }.compact
end
end
end