Merge pull request #301 from amorde/define-tool-output-schema

Fix missing output_schema argument in 'define_tool' API
This commit is contained in:
Koichi ITO 2026-05-07 11:56:29 +09:00 • committed by GitHub
commit d18698890a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 4 deletions

View file

@ -162,8 +162,8 @@ module MCP
end
end
def define_tool(name: nil, title: nil, description: nil, input_schema: nil, annotations: nil, meta: nil, &block)
tool = Tool.define(name: name, title: title, description: description, input_schema: input_schema, annotations: annotations, meta: meta, &block)
def define_tool(name: nil, title: nil, description: nil, input_schema: nil, output_schema: nil, annotations: nil, meta: nil, &block)
tool = Tool.define(name: name, title: title, description: description, input_schema: input_schema, output_schema: output_schema, annotations: annotations, meta: meta, &block)
tool_name = tool.name_value
@tool_names << tool_name

View file

@ -1384,11 +1384,16 @@ module MCP
name: "defined_tool",
description: "Defined tool",
input_schema: { type: "object", properties: { message: { type: "string" } }, required: ["message"] },
output_schema: { type: "object", properties: { response: { type: "string" } }, required: ["response"] },
meta: { foo: "bar" },
) do |message:|
Tool::Response.new(message)
Tool::Response.new({ "response" => message })
end
stored_tool = @server.instance_variable_get(:@tools)["defined_tool"]
assert_not_nil(stored_tool)
assert_equal(MCP::Tool::OutputSchema.new({ type: "object", properties: { response: { type: "string" } }, required: ["response"] }), stored_tool.output_schema)
response = @server.handle({
jsonrpc: "2.0",
method: "tools/call",
@ -1396,7 +1401,7 @@ module MCP
id: 1,
})
assert_equal({ content: "success", isError: false }, response[:result])
assert_equal({ content: { "response" => "success" }, isError: false }, response[:result])
end
test "#define_tool adds a tool with duplicated tool name to the server" do