Skip to content

Commit f6c95a0

Browse files
committed
Fix missing output_schema argument in 'define_tool' API
1 parent ba79d53 commit f6c95a0

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
@@ -145,8 +145,8 @@ def handle_json(request, session: nil)
145145
end
146146
end
147147

148-
def define_tool(name: nil, title: nil, description: nil, input_schema: nil, annotations: nil, meta: nil, &block)
149-
tool = Tool.define(name: name, title: title, description: description, input_schema: input_schema, annotations: annotations, meta: meta, &block)
148+
def define_tool(name: nil, title: nil, description: nil, input_schema: nil, output_schema: nil, annotations: nil, meta: nil, &block)
149+
tool = Tool.define(name: name, title: title, description: description, input_schema: input_schema, output_schema: output_schema, annotations: annotations, meta: meta, &block)
150150
tool_name = tool.name_value
151151

152152
@tool_names << tool_name

‎test/mcp/server_test.rb‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,19 +1127,24 @@ class Example < Tool
11271127
name: "defined_tool",
11281128
description: "Defined tool",
11291129
input_schema: { type: "object", properties: { message: { type: "string" } }, required: ["message"] },
1130+
output_schema: { type: "object", properties: { response: { type: "string" } }, required: ["response"] },
11301131
meta: { foo: "bar" },
11311132
) do |message:|
1132-
Tool::Response.new(message)
1133+
Tool::Response.new({ "response" => message })
11331134
end
11341135

1136+
stored_tool = @server.instance_variable_get(:@tools)["defined_tool"]
1137+
assert_not_nil(stored_tool)
1138+
assert_equal(MCP::Tool::OutputSchema.new({ type: "object", properties: { response: { type: "string" } }, required: ["response"] }), stored_tool.output_schema)
1139+
11351140
response = @server.handle({
11361141
jsonrpc: "2.0",
11371142
method: "tools/call",
11381143
params: { name: "defined_tool", arguments: { message: "success" } },
11391144
id: 1,
11401145
})
11411146

1142-
assert_equal({ content: "success", isError: false }, response[:result])
1147+
assert_equal({ content: { "response" => "success" }, isError: false }, response[:result])
11431148
end
11441149

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

0 commit comments

Comments
 (0)