Class: VSM::DSL::Builder::ChildrenBuilder
- Inherits:
-
Object
- Object
- VSM::DSL::Builder::ChildrenBuilder
- Defined in:
- lib/vsm/dsl.rb,
lib/vsm/dsl_mcp.rb
Instance Method Summary collapse
- #capsule(name, klass:, args: {}) ⇒ Object
-
#initialize(parent) ⇒ ChildrenBuilder
constructor
A new instance of ChildrenBuilder.
-
#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.
- #meta_tools(prefix: "", only: nil, except: nil) ⇒ Object
- #method_missing ⇒ Object
- #respond_to_missing? ⇒ Boolean
- #result ⇒ Object
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_missing ⇒ Object
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 (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
57 |
# File 'lib/vsm/dsl.rb', line 57 def respond_to_missing?(*) = true |
#result ⇒ Object
55 |
# File 'lib/vsm/dsl.rb', line 55 def result = @children |