inputSchema interface requires type key
When defining a tool without any arguments taken, it should be allowed
to not have to define the `input_schema` at all, and the default value
for such a scenario should be `{ type: "object" }` as per the schema.
16d91abb68/schema/2025-06-18/schema.ts (L896-L900)
This commit is contained in:
parent
4ba1e2b7f4
commit
2508defc79
5 changed files with 38 additions and 6 deletions
|
|
@ -6,7 +6,6 @@ module MCP
|
||||||
NOT_SET = Object.new
|
NOT_SET = Object.new
|
||||||
|
|
||||||
attr_reader :description_value
|
attr_reader :description_value
|
||||||
attr_reader :input_schema_value
|
|
||||||
attr_reader :annotations_value
|
attr_reader :annotations_value
|
||||||
|
|
||||||
def call(*args, server_context: nil)
|
def call(*args, server_context: nil)
|
||||||
|
|
@ -43,6 +42,10 @@ module MCP
|
||||||
@name_value || StringUtils.handle_from_class_name(name)
|
@name_value || StringUtils.handle_from_class_name(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def input_schema_value
|
||||||
|
@input_schema_value || InputSchema.new
|
||||||
|
end
|
||||||
|
|
||||||
def description(value = NOT_SET)
|
def description(value = NOT_SET)
|
||||||
if value == NOT_SET
|
if value == NOT_SET
|
||||||
@description_value
|
@description_value
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,13 @@ module MCP
|
||||||
validate_schema!
|
validate_schema!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def ==(other)
|
||||||
|
other.is_a?(InputSchema) && properties == other.properties && required == other.required
|
||||||
|
end
|
||||||
|
|
||||||
def to_h
|
def to_h
|
||||||
{ type: "object", properties: }.tap do |hsh|
|
{ type: "object" }.tap do |hsh|
|
||||||
|
hsh[:properties] = properties if properties.any?
|
||||||
hsh[:required] = required if required.any?
|
hsh[:required] = required if required.any?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ module MCP
|
||||||
assert_kind_of Array, result[:tools]
|
assert_kind_of Array, result[:tools]
|
||||||
assert_equal "test_tool", result[:tools][0][:name]
|
assert_equal "test_tool", result[:tools][0][:name]
|
||||||
assert_equal "Test tool", result[:tools][0][:description]
|
assert_equal "Test tool", result[:tools][0][:description]
|
||||||
assert_empty(result[:tools][0][:inputSchema])
|
assert_equal({ type: "object" }, result[:tools][0][:inputSchema])
|
||||||
assert_instrumentation_data({ method: "tools/list" })
|
assert_instrumentation_data({ method: "tools/list" })
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,6 +79,21 @@ module MCP
|
||||||
InputSchema.new(properties: { foo: { :$ref => "#/definitions/bar" } }, required: [:foo])
|
InputSchema.new(properties: { foo: { :$ref => "#/definitions/bar" } }, required: [:foo])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "== compares two input schemas with the same properties and required fields" do
|
||||||
|
schema1 = InputSchema.new(properties: { foo: { type: "string" } }, required: [:foo])
|
||||||
|
schema2 = InputSchema.new(properties: { foo: { type: "string" } }, required: [:foo])
|
||||||
|
assert_equal schema1, schema2
|
||||||
|
|
||||||
|
schema3 = InputSchema.new(properties: { bar: { type: "string" } }, required: [:bar])
|
||||||
|
refute_equal schema1, schema3
|
||||||
|
|
||||||
|
schema4 = InputSchema.new(properties: { foo: { type: "string" } }, required: [:bar])
|
||||||
|
refute_equal schema1, schema4
|
||||||
|
|
||||||
|
schema5 = InputSchema.new(properties: { bar: { type: "string" } }, required: [:foo])
|
||||||
|
refute_equal schema1, schema5
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ module MCP
|
||||||
|
|
||||||
test "#to_h returns a hash with name, description, and inputSchema" do
|
test "#to_h returns a hash with name, description, and inputSchema" do
|
||||||
tool = Tool.define(name: "mock_tool", description: "a mock tool for testing")
|
tool = Tool.define(name: "mock_tool", description: "a mock tool for testing")
|
||||||
assert_equal tool.to_h, { name: "mock_tool", description: "a mock tool for testing", inputSchema: {} }
|
assert_equal tool.to_h, { name: "mock_tool", description: "a mock tool for testing", inputSchema: { type: "object" } }
|
||||||
end
|
end
|
||||||
|
|
||||||
test "#to_h includes annotations when present" do
|
test "#to_h includes annotations when present" do
|
||||||
|
|
@ -71,6 +71,15 @@ module MCP
|
||||||
assert_equal tool.tool_name, "default_name_tool"
|
assert_equal tool.tool_name, "default_name_tool"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "input schema defaults to an empty hash" do
|
||||||
|
class NoInputSchemaTool < Tool; end
|
||||||
|
|
||||||
|
tool = NoInputSchemaTool
|
||||||
|
|
||||||
|
expected = { type: "object" }
|
||||||
|
assert_equal expected, tool.input_schema.to_h
|
||||||
|
end
|
||||||
|
|
||||||
test "accepts input schema as an InputSchema object" do
|
test "accepts input schema as an InputSchema object" do
|
||||||
class InputSchemaTool < Tool
|
class InputSchemaTool < Tool
|
||||||
input_schema InputSchema.new(properties: { message: { type: "string" } }, required: [:message])
|
input_schema InputSchema.new(properties: { message: { type: "string" } }, required: [:message])
|
||||||
|
|
@ -106,7 +115,7 @@ module MCP
|
||||||
|
|
||||||
assert_equal tool.name_value, "mock_tool"
|
assert_equal tool.name_value, "mock_tool"
|
||||||
assert_equal tool.description, "a mock tool for testing"
|
assert_equal tool.description, "a mock tool for testing"
|
||||||
assert_equal tool.input_schema, nil
|
assert_equal tool.input_schema, Tool::InputSchema.new
|
||||||
end
|
end
|
||||||
|
|
||||||
test ".define allows definition of tools with annotations" do
|
test ".define allows definition of tools with annotations" do
|
||||||
|
|
@ -123,7 +132,7 @@ module MCP
|
||||||
|
|
||||||
assert_equal tool.name_value, "mock_tool"
|
assert_equal tool.name_value, "mock_tool"
|
||||||
assert_equal tool.description, "a mock tool for testing"
|
assert_equal tool.description, "a mock tool for testing"
|
||||||
assert_equal tool.input_schema, nil
|
assert_equal tool.input_schema, Tool::InputSchema.new
|
||||||
assert_equal tool.annotations_value.to_h, { title: "Mock Tool", readOnlyHint: true }
|
assert_equal tool.annotations_value.to_h, { title: "Mock Tool", readOnlyHint: true }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue