Class: Elelem::MCP::Server

Inherits:
Object
  • Object
show all
Includes:
ServerInterface
Defined in:
lib/elelem/mcp/client.rb

Instance Method Summary collapse

Methods included from ServerInterface

#call, #extract_content, #tools

Constructor Details

#initialize(command:, args: [], env: {}) ⇒ Server

Returns a new instance of Server.



106
107
108
109
110
111
112
113
# File 'lib/elelem/mcp/client.rb', line 106

def initialize(command:, args: [], env: {})
  resolved_env = env.transform_values do |v|
    v.gsub(/\$\{(\w+)\}/) { ENV[$1] || raise("Missing environment variable: #{$1}") }
  end
  @stdin, @stdout, @stderr, @wait = Open3.popen3(resolved_env, command, *args)
  @id = 0
  handshake!
end

Instance Method Details

#close ⇒ Object



115
116
117
118
119
120
121
122
123
124
# File 'lib/elelem/mcp/client.rb', line 115

def close
  [@stdin, @stdout, @stderr].each do |io|
    io.close
  rescue IOError
    nil
  end
  @wait.kill
rescue StandardError
  nil
end