Class: HTM::MCP::JoinGroupTool

Inherits:
FastMcp::Tool
  • Object
show all
Defined in:
lib/htm/mcp/group_tools.rb

Overview

Tool: Join current robot to an existing group

Instance Method Summary collapse

Instance Method Details

#call(name:, role: 'active') ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/htm/mcp/group_tools.rb', line 154

def call(name:, role: 'active')
  Session.logger&.info "JoinGroupTool called: name=#{name.inspect}, role=#{role}"

  group = GroupSession.get_group(name)
  unless group
    return { success: false, error: "Group '#{name}' not found in this session" }.to_json
  end

  robot_name = Session.robot_name

  if group.member?(robot_name)
    return { success: false, error: "Robot '#{robot_name}' is already a member of group '#{name}'" }.to_json
  end

  robot_id = if role == 'passive'
               group.add_passive(robot_name)
             else
               group.add_active(robot_name)
             end

  Session.logger&.info "Robot #{robot_name} joined group #{name} as #{role}"

  {
    success:    true,
    group_name: name,
    robot_name: robot_name,
    robot_id:   robot_id,
    role:       role,
    message:    "Robot '#{robot_name}' joined group '#{name}' as #{role}"
  }.to_json
rescue ArgumentError => e
  { success: false, error: e.message }.to_json
end