Class: SignalWire::Skills::Builtin::McpGatewaySkill

Inherits:
SkillBase
  • Object
show all
Defined in:
lib/signalwire/skills/builtin/mcp_gateway.rb

Overview

Bridge MCP servers with SWAIG functions.

Instance Attribute Summary

Attributes inherited from SkillBase

#agent, #logger, #params, #swaig_fields

Instance Method Summary collapse

Methods inherited from SkillBase

#cleanup, #get_param, #initialize, #instance_key, #required_env_vars, #supports_multiple_instances?, #version

Constructor Details

This class inherits a constructor from SignalWire::Skills::SkillBase

Instance Method Details

#descriptionObject



16
# File 'lib/signalwire/skills/builtin/mcp_gateway.rb', line 16

def description; 'Bridge MCP servers with SWAIG functions'; end

#get_global_dataObject



53
54
55
56
57
58
59
# File 'lib/signalwire/skills/builtin/mcp_gateway.rb', line 53

def get_global_data
  {
    'mcp_gateway_url' => @gateway_url,
    'mcp_session_id'  => nil,
    'mcp_services'    => @services
  }
end

#get_hintsObject



47
48
49
50
51
# File 'lib/signalwire/skills/builtin/mcp_gateway.rb', line 47

def get_hints
  hints = %w[MCP gateway]
  @services.each { |s| hints << (s.is_a?(Hash) ? s['name'] : s.to_s) } if @services
  hints
end

#get_parameter_schemaObject



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/signalwire/skills/builtin/mcp_gateway.rb', line 72

def get_parameter_schema
  {
    'gateway_url'     => { 'type' => 'string', 'required' => true },
    'auth_token'      => { 'type' => 'string', 'hidden' => true },
    'auth_user'       => { 'type' => 'string' },
    'auth_password'   => { 'type' => 'string', 'hidden' => true },
    'services'        => { 'type' => 'array' },
    'tool_prefix'     => { 'type' => 'string', 'default' => 'mcp_' },
    'request_timeout' => { 'type' => 'integer', 'default' => 30 }
  }
end

#get_prompt_sectionsObject



61
62
63
64
65
66
67
68
69
70
# File 'lib/signalwire/skills/builtin/mcp_gateway.rb', line 61

def get_prompt_sections
  service_names = @services.map { |s| s.is_a?(Hash) ? s['name'] : s.to_s }
  [
    {
      'title' => 'MCP Gateway Integration',
      'body' => "Connected MCP services: #{service_names.join(', ')}",
      'bullets' => @mcp_tools.map { |t| "#{t[:name]}: #{t[:description]}" }
    }
  ]
end

#nameObject



15
# File 'lib/signalwire/skills/builtin/mcp_gateway.rb', line 15

def name;        'mcp_gateway'; end

#register_toolsObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/signalwire/skills/builtin/mcp_gateway.rb', line 34

def register_tools
  @mcp_tools.map do |tool|
    {
      name: tool[:name],
      description: tool[:description],
      parameters: tool[:parameters] || {},
      handler: lambda { |args, _raw_data|
        execute_mcp_tool(tool[:service], tool[:original_name], args)
      }
    }
  end
end

#setupObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/signalwire/skills/builtin/mcp_gateway.rb', line 18

def setup
  @gateway_url   = get_param('gateway_url')
  @auth_token    = get_param('auth_token')
  @auth_user     = get_param('auth_user')
  @auth_password = get_param('auth_password')
  @services      = get_param('services') || []
  @tool_prefix   = get_param('tool_prefix', default: 'mcp_')
  @timeout       = (get_param('request_timeout', default: 30)).to_i

  return false unless @gateway_url && !@gateway_url.empty?

  # Discover tools from gateway
  @mcp_tools = discover_tools
  true
end