Class: Sidekiq::Mcp::Tool

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/mcp/tool.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.argument_schemaObject

Returns the value of attribute argument_schema.



9
10
11
# File 'lib/sidekiq/mcp/tool.rb', line 9

def argument_schema
  @argument_schema
end

.tool_descriptionObject

Returns the value of attribute tool_description.



9
10
11
# File 'lib/sidekiq/mcp/tool.rb', line 9

def tool_description
  @tool_description
end

Class Method Details

.arguments(&block) ⇒ Object



15
16
17
# File 'lib/sidekiq/mcp/tool.rb', line 15

def arguments(&block)
  @argument_schema = Dry::Schema.Params(&block) if block_given?
end

.description(text) ⇒ Object



11
12
13
# File 'lib/sidekiq/mcp/tool.rb', line 11

def description(text)
  @tool_description = text
end

.schema_to_json_schemaObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/sidekiq/mcp/tool.rb', line 19

def schema_to_json_schema
  return { type: "object", properties: {}, required: [] } unless @argument_schema

  # For now, return a simple schema - can be enhanced later
  {
    type: "object",
    properties: {},
    required: []
  }
end

.to_tool_definitionObject



31
32
33
34
35
36
37
38
# File 'lib/sidekiq/mcp/tool.rb', line 31

def self.to_tool_definition
  tool_name = name.split("::").last.gsub(/Tool$/, "").gsub(/([A-Z])/, '_\1').downcase.sub(/^_/, "")
  {
    name: tool_name,
    description: @tool_description || "#{name} tool",
    inputSchema: schema_to_json_schema
  }
end

Instance Method Details

#call(**args) ⇒ Object



40
41
42
43
44
45
46
47
48
49
# File 'lib/sidekiq/mcp/tool.rb', line 40

def call(**args)
  # Validate arguments if schema is defined
  if self.class.argument_schema
    result = self.class.argument_schema.call(args)
    raise ArgumentError, "Invalid arguments: #{result.errors.to_h}" unless result.success?
    args = result.to_h
  end

  perform(**args)
end

#perform(**args) ⇒ Object

Raises:

  • (NotImplementedError)


51
52
53
# File 'lib/sidekiq/mcp/tool.rb', line 51

def perform(**args)
  raise NotImplementedError, "Subclasses must implement #perform"
end