From f6c95a0c979ed9a8b78cafa7a2d0395ec6233fb1 Mon Sep 17 00:00:00 2001 From: Eric Amorde Date: Mon, 6 Apr 2026 14:45:56 -0700 Subject: [PATCH] Fix missing output_schema argument in 'define_tool' API --- lib/mcp/server.rb | 4 ++-- test/mcp/server_test.rb | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/mcp/server.rb b/lib/mcp/server.rb index d085b8ba..131d1de5 100644 --- a/lib/mcp/server.rb +++ b/lib/mcp/server.rb @@ -145,8 +145,8 @@ def handle_json(request, session: nil) 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 diff --git a/test/mcp/server_test.rb b/test/mcp/server_test.rb index 785e16ee..7dfef985 100644 --- a/test/mcp/server_test.rb +++ b/test/mcp/server_test.rb @@ -1127,11 +1127,16 @@ class Example < Tool 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", @@ -1139,7 +1144,7 @@ class Example < Tool 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