Class: VSM::DSL::Builder::ChildrenBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/vsm/dsl.rb,
lib/vsm/dsl_mcp.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent) ⇒ ChildrenBuilder

Returns a new instance of ChildrenBuilder.



40
41
42
43
# File 'lib/vsm/dsl.rb', line 40

def initialize(parent)
  @parent = parent
  @children = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject



56
# File 'lib/vsm/dsl.rb', line 56

def method_missing(*) = result

Instance Method Details

#capsule(name, klass:, args: {}) ⇒ Object



44
45
46
47
48
# File 'lib/vsm/dsl.rb', line 44

def capsule(name, klass:, args: {})
  instance = klass.new(**args)
  VSM::Meta::Support.record_constructor_args(instance, args)
  @children[name.to_s] = instance
end

#mcp_server(name, cmd:, env: {}, include: nil, exclude: nil, prefix: nil, cwd: nil) ⇒ Object

Reflect tools from a remote MCP server and add them as tool capsules. Options:

include: Array<String> whitelist of tool names
exclude: Array<String> blacklist of tool names
prefix:  String prefix for local names to avoid collisions
env:     Hash environment passed to the server process
cwd:     Working directory for spawning the process

Example:

mcp_server :smith, cmd: "smith-server --stdio", include: %w[search read], prefix: "smith_"


20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vsm/dsl_mcp.rb', line 20

def mcp_server(name, cmd:, env: {}, include: nil, exclude: nil, prefix: nil, cwd: nil)
  client = VSM::MCP::Client.new(cmd: cmd, env: env, cwd: cwd, name: name.to_s).start
  tools  = client.list_tools
  tools.each do |t|
    tool_name = t[:name]
    next if include && !Array(include).include?(tool_name)
    next if exclude &&  Array(exclude).include?(tool_name)
    local_name = [prefix, tool_name].compact.join
    capsule = VSM::MCP::RemoteToolCapsule.new(client: client, remote_name: tool_name, descriptor: t)
    @children[local_name] = capsule
  end
end

#meta_tools(prefix: "", only: nil, except: nil) ⇒ Object



49
50
51
52
53
54
# File 'lib/vsm/dsl.rb', line 49

def meta_tools(prefix: "", only: nil, except: nil)
  @parent.__send__(:after_build) do |capsule|
    VSM::Meta.attach!(capsule, prefix: prefix, only: only, except: except)
  end
  result
end

#respond_to_missing?Boolean

Returns:

  • (Boolean)


57
# File 'lib/vsm/dsl.rb', line 57

def respond_to_missing?(*) = true

#resultObject



55
# File 'lib/vsm/dsl.rb', line 55

def result = @children