Skip to content

Commit 1f614c2

Browse files
committed
Set default content to an empty array instead of nil
Follow-up to #147. According to the specification schema, `content` is not optional and therefore cannot be omitted: ```typescript interface CallToolResult { _meta?: { [key: string]: unknown }; content: ContentBlock[]; isError?: boolean; structuredContent?: { [key: string]: unknown }; [key: string]: unknown; } ``` https://modelcontextprotocol.io/specification/2025-06-18/schema#calltoolresult Instead of `nil`, an empty array is set as the default value. There may be a better value for `content`, but at the very least it should not be missing.
1 parent 010ae74 commit 1f614c2

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/mcp/tool/response.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Response
77

88
attr_reader :content, :structured_content
99

10-
def initialize(content = nil, deprecated_error = NOT_GIVEN, error: false, structured_content: nil)
10+
def initialize(content = [], deprecated_error = NOT_GIVEN, error: false, structured_content: nil)
1111
if deprecated_error != NOT_GIVEN
1212
warn("Passing `error` with the 2nd argument of `Response.new` is deprecated. Use keyword argument like `Response.new(content, error: error)` instead.", uplevel: 1)
1313
error = deprecated_error

test/mcp/tool/response_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ class ResponseTest < ActiveSupport::TestCase
106106
response = Response.new(structured_content: structured_content)
107107
actual = response.to_h
108108

109-
assert_equal [:isError, :structuredContent], actual.keys
110-
assert_nil actual[:content]
109+
assert_equal [:content, :isError, :structuredContent], actual.keys
110+
assert_empty actual[:content]
111111
assert_equal structured_content, actual[:structuredContent]
112112
refute actual[:isError]
113113
end

0 commit comments

Comments
 (0)