Class: MCP::Tool
- Inherits:
-
Object
show all
- Defined in:
- lib/mcp/tool.rb,
lib/mcp/tool/response.rb,
lib/mcp/tool/annotations.rb,
lib/mcp/tool/input_schema.rb
Defined Under Namespace
Classes: Annotations, InputSchema, Response
Constant Summary
collapse
- NOT_SET =
Object.new
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.annotations_value ⇒ Object
Returns the value of attribute annotations_value.
10
11
12
|
# File 'lib/mcp/tool.rb', line 10
def annotations_value
@annotations_value
end
|
.description_value ⇒ Object
Returns the value of attribute description_value.
8
9
10
|
# File 'lib/mcp/tool.rb', line 8
def description_value
@description_value
end
|
Returns the value of attribute input_schema_value.
9
10
11
|
# File 'lib/mcp/tool.rb', line 9
def input_schema_value
@input_schema_value
end
|
Class Method Details
.annotations(hash = NOT_SET) ⇒ Object
66
67
68
69
70
71
72
|
# File 'lib/mcp/tool.rb', line 66
def annotations(hash = NOT_SET)
if hash == NOT_SET
@annotations_value
else
@annotations_value = Annotations.new(**hash)
end
end
|
.call(*args, server_context:) ⇒ Object
12
13
14
|
# File 'lib/mcp/tool.rb', line 12
def call(*args, server_context:)
raise NotImplementedError, "Subclasses must implement call"
end
|
.define(name: nil, description: nil, input_schema: nil, annotations: nil, &block) ⇒ Object
74
75
76
77
78
79
80
81
82
|
# File 'lib/mcp/tool.rb', line 74
def define(name: nil, description: nil, input_schema: nil, annotations: nil, &block)
Class.new(self) do
tool_name name
description description
input_schema input_schema
self.annotations(annotations) if annotations
define_singleton_method(:call, &block) if block
end
end
|
.description(value = NOT_SET) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/mcp/tool.rb', line 46
def description(value = NOT_SET)
if value == NOT_SET
@description_value
else
@description_value = value
end
end
|
.inherited(subclass) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/mcp/tool.rb', line 26
def inherited(subclass)
super
subclass.instance_variable_set(:@name_value, nil)
subclass.instance_variable_set(:@description_value, nil)
subclass.instance_variable_set(:@input_schema_value, nil)
subclass.instance_variable_set(:@annotations_value, nil)
end
|
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/mcp/tool.rb', line 54
def input_schema(value = NOT_SET)
if value == NOT_SET
input_schema_value
elsif value.is_a?(Hash)
properties = value[:properties] || value["properties"] || {}
required = value[:required] || value["required"] || []
@input_schema_value = InputSchema.new(properties:, required:)
elsif value.is_a?(InputSchema)
@input_schema_value = value
end
end
|
.to_h ⇒ Object
16
17
18
19
20
21
22
23
24
|
# File 'lib/mcp/tool.rb', line 16
def to_h
result = {
name: name_value,
description: description_value,
inputSchema: input_schema_value.to_h,
}
result[:annotations] = annotations_value.to_h if annotations_value
result
end
|
34
35
36
37
38
39
40
|
# File 'lib/mcp/tool.rb', line 34
def tool_name(value = NOT_SET)
if value == NOT_SET
name_value
else
@name_value = value
end
end
|