Class: ActiveMcp::Server::ToolManager

Inherits:
Object
  • Object
show all
Defined in:
lib/active_mcp/server/tool_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri: nil, auth: nil) ⇒ ToolManager

Returns a new instance of ToolManager.



8
9
10
11
12
13
14
15
# File 'lib/active_mcp/server/tool_manager.rb', line 8

def initialize(uri: nil, auth: nil)
  @tools = {}
  @uri = uri

  if auth
    @auth_header = "#{auth[:type] == :bearer ? "Bearer" : "Basic"} #{auth[:token]}"
  end
end

Instance Attribute Details

#toolsObject (readonly)

Returns the value of attribute tools.



6
7
8
# File 'lib/active_mcp/server/tool_manager.rb', line 6

def tools
  @tools
end

Instance Method Details

#call_tool(name, arguments = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/active_mcp/server/tool_manager.rb', line 17

def call_tool(name, arguments = {})
  tool_info = @tools.find { _1[:name] == name }

  unless tool_info
    return {
      isError: true,
      content: [{type: "text", text: "Tool not found: #{name}"}]
    }
  end

  invoke_tool(name, arguments)
end

#load_registered_toolsObject



30
31
32
# File 'lib/active_mcp/server/tool_manager.rb', line 30

def load_registered_tools
  fetch_tools
end