Class: Silas::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/silas/connection.rb

Overview

A typed MCP integration declared by app/agent/connections/.yml. Filename is identity. Holds the credential PATH, never the secret (resolved from Rails credentials at call time). Data-only (eve's shape).

Defined Under Namespace

Classes: RemoteTool

Constant Summary collapse

TRANSPORTS =
%w[http].freeze
APPROVALS =
%i[never once always].freeze
EFFECTS =

not transactional: a remote call can't share our DB txn

%i[at_most_once idempotent].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attrs) ⇒ Connection

Returns a new instance of Connection.



19
20
21
22
23
24
25
26
27
# File 'lib/silas/connection.rb', line 19

def initialize(name, attrs)
  @name = name
  @transport = attrs.fetch("transport", "http")
  @url = attrs["url"]
  @auth = attrs["auth"] || {}
  @approval = (attrs["approval"] || "never").to_sym
  @effect = (attrs["effect"] || "at_most_once").to_sym
  validate!
end

Instance Attribute Details

#approvalObject (readonly)

Returns the value of attribute approval.



12
13
14
# File 'lib/silas/connection.rb', line 12

def approval
  @approval
end

#effectObject (readonly)

Returns the value of attribute effect.



12
13
14
# File 'lib/silas/connection.rb', line 12

def effect
  @effect
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/silas/connection.rb', line 12

def name
  @name
end

#transportObject (readonly)

Returns the value of attribute transport.



12
13
14
# File 'lib/silas/connection.rb', line 12

def transport
  @transport
end

#urlObject (readonly)

Returns the value of attribute url.



12
13
14
# File 'lib/silas/connection.rb', line 12

def url
  @url
end

Class Method Details

.parse(path) ⇒ Object



14
15
16
17
# File 'lib/silas/connection.rb', line 14

def self.parse(path)
  attrs = YAML.safe_load(File.read(path)) || {}
  attrs.empty? ? nil : new(File.basename(path, ".yml"), attrs)
end

Instance Method Details

#auth_headersObject



31
32
33
34
35
36
37
# File 'lib/silas/connection.rb', line 31

def auth_headers
  case @auth["type"]
  when "bearer" then { "Authorization" => "Bearer #{secret!}" }
  when "header" then { @auth.fetch("header") => secret! }
  else {}
  end
end

#clientObject



29
# File 'lib/silas/connection.rb', line 29

def client = Mcp::Client.new(url: url, headers: auth_headers)