Skip to content

Commit d186988

Browse files
authored
Merge pull request #301 from amorde/define-tool-output-schema
Fix missing output_schema argument in 'define_tool' API
2 parents ebc6569 + f6c95a0 commit d186988

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎lib/mcp/server.rb‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ def handle_json(request, session: nil)
162162
end
163163
end
164164

165-
def define_tool(name: nil, title: nil, description: nil, input_schema: nil, annotations: nil, meta: nil, &block)
166-
tool = Tool.define(name: name, title: title, description: description, input_schema: input_schema, annotations: annotations, meta: meta, &block)
165+
def define_tool(name: nil, title: nil, description: nil, input_schema: nil, output_schema: nil, annotations: nil, meta: nil, &block)
166+
tool = Tool.define(name: name, title: title, description: description, input_schema: input_schema, output_schema: output_schema, annotations: annotations, meta: meta, &block)
167167
tool_name = tool.name_value
168168

169169
@tool_names << tool_name

‎test/mcp/server_test.rb‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,19 +1384,24 @@ class Example < Tool
13841384
name: "defined_tool",
13851385
description: "Defined tool",
13861386
input_schema: { type: "object", properties: { message: { type: "string" } }, required: ["message"] },
1387+
output_schema: { type: "object", properties: { response: { type: "string" } }, required: ["response"] },
13871388
meta: { foo: "bar" },
13881389
) do |message:|
1389-
Tool::Response.new(message)
1390+
Tool::Response.new({ "response" => message })
13901391
end
13911392

1393+
stored_tool = @server.instance_variable_get(:@tools)["defined_tool"]
1394+
assert_not_nil(stored_tool)
1395+
assert_equal(MCP::Tool::OutputSchema.new({ type: "object", properties: { response: { type: "string" } }, required: ["response"] }), stored_tool.output_schema)
1396+
13921397
response = @server.handle({
13931398
jsonrpc: "2.0",
13941399
method: "tools/call",
13951400
params: { name: "defined_tool", arguments: { message: "success" } },
13961401
id: 1,
13971402
})
13981403

1399-
assert_equal({ content: "success", isError: false }, response[:result])
1404+
assert_equal({ content: { "response" => "success" }, isError: false }, response[:result])
14001405
end
14011406

14021407
test "#define_tool adds a tool with duplicated tool name to the server" do

0 commit comments

Comments
 (0)