Class: MCP::Tool::Response
- Inherits:
-
Object
- Object
- MCP::Tool::Response
- Defined in:
- lib/mcp/tool/response.rb
Constant Summary collapse
- NOT_GIVEN =
Object.new.freeze
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#structured_content ⇒ Object
readonly
Returns the value of attribute structured_content.
Instance Method Summary collapse
- #content_provided? ⇒ Boolean
- #error? ⇒ Boolean
-
#initialize(content = NOT_GIVEN, deprecated_error = NOT_GIVEN, error: false, structured_content: nil, meta: nil) ⇒ Response
constructor
A new instance of Response.
- #to_h ⇒ Object
Constructor Details
#initialize(content = NOT_GIVEN, deprecated_error = NOT_GIVEN, error: false, structured_content: nil, meta: nil) ⇒ Response
Returns a new instance of Response.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/mcp/tool/response.rb', line 10 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_given = !content.equal?(NOT_GIVEN) @content_provided = content_given && !content.nil? @content = content_given ? (content || []) : [] @error = error @structured_content = structured_content @meta = end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
8 9 10 |
# File 'lib/mcp/tool/response.rb', line 8 def content @content end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
8 9 10 |
# File 'lib/mcp/tool/response.rb', line 8 def @meta end |
#structured_content ⇒ Object (readonly)
Returns the value of attribute structured_content.
8 9 10 |
# File 'lib/mcp/tool/response.rb', line 8 def structured_content @structured_content end |
Instance Method Details
#content_provided? ⇒ Boolean
24 25 26 |
# File 'lib/mcp/tool/response.rb', line 24 def content_provided? @content_provided end |
#error? ⇒ Boolean
28 29 30 |
# File 'lib/mcp/tool/response.rb', line 28 def error? !!@error end |
#to_h ⇒ Object
32 33 34 |
# File 'lib/mcp/tool/response.rb', line 32 def to_h { content: content, isError: error?, structuredContent: @structured_content, _meta: }.compact end |