Class: Studio::Tool

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

Overview

rubocop:todo Style/Documentation

Class Method Summary collapse

Class Method Details

.for_blueprint(blueprint) ⇒ Object

rubocop:todo Metrics/AbcSize



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/studio/tool.rb', line 8

def self.for_blueprint(blueprint) # rubocop:todo Metrics/AbcSize
  Class.new(MCP::Tool) do
    tool_name blueprint.tool_name
    description blueprint.tool_description
    input_schema blueprint.input_schema

    define_singleton_method :call do |server_context:, **arguments| # rubocop:todo Lint/UnusedBlockArgument
      result = blueprint.execute(arguments)

      # Log stderr if present
      warn "[Studio] #{result[:stderr]}" unless result[:stderr].empty?

      if result[:success]
        MCP::Tool::Response.new([{
                                  type: "text",
                                  text: result[:stdout]
                                }])
      else
        MCP::Tool::Response.new([{
                                  type: "text",
                                  text: result[:stdout]
                                }], true)
      end
    end
  end
end