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
2 changes: 1 addition & 1 deletion lib/mcp/tool/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def initialize(content = nil, deprecated_error = NOT_GIVEN, error: false, struct
error = deprecated_error
end

@content = content
@content = content || []
@error = error
@structured_content = structured_content
end
Expand Down
15 changes: 13 additions & 2 deletions test/mcp/tool/response_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,24 @@ class ResponseTest < ActiveSupport::TestCase
refute actual[:isError]
end

test "#to_h for a standard response with nil content and structured content" do
structured_content = { code: 401, message: "Unauthorized" }
response = Response.new(nil, structured_content: structured_content)
actual = response.to_h

assert_equal [:content, :isError, :structuredContent], actual.keys
assert_empty actual[:content]
assert_equal structured_content, actual[:structuredContent]
refute actual[:isError]
end

test "#to_h for a standard response with structured content only" do
structured_content = { code: 401, message: "Unauthorized" }
response = Response.new(structured_content: structured_content)
actual = response.to_h

assert_equal [:isError, :structuredContent], actual.keys
assert_nil actual[:content]
assert_equal [:content, :isError, :structuredContent], actual.keys
assert_empty actual[:content]
assert_equal structured_content, actual[:structuredContent]
refute actual[:isError]
end
Expand Down