Class: Kailash::Mcp::McpServer

Inherits:
Object
  • Object
show all
Defined in:
lib/kailash/mcp.rb

Overview

McpServer block-based lifecycle (Ruby idiom matching File.open / Registry.open). Yields a fresh McpServer to the block and calls close automatically when the block returns. Returns the block's value.

Kailash::Mcp::McpServer.open(name: "srv", version: "1.0") do |srv|
srv.register_tool(name: "search", description: "...")
srv
end

When called WITHOUT a block, returns the constructed McpServer (equivalent to McpServer.new — caller MUST close explicitly).

Class Method Summary collapse

Class Method Details

.open(*args, **kwargs) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/kailash/mcp.rb', line 133

def self.open(*args, **kwargs)
  srv = if kwargs.empty?
          new(*args)
        elsif args.empty?
          new(kwargs)
        else
          new(*args, kwargs)
        end
  return srv unless block_given?

  begin
    yield srv
  ensure
    srv.close
  end
end