Class: Pikuri::Mcp::Servers::Connect
- Inherits:
-
Tool
- Object
- Tool
- Pikuri::Mcp::Servers::Connect
- Defined in:
- lib/pikuri/mcp/servers.rb
Overview
The mcp_connect tool exposed to the LLM. Private inner class —instantiated only by #build_mcp_connect_tool (called from Agent#initialize), never by application code.
Tracks its own activation Set so re-connecting an already-active server returns a recoverable “Error: …” String (the LLM has the tools in its toolset and should just call them). Each agent owns its own Connect instance and therefore its own activation set — activation does not propagate between parent and sub-agent. See IDEAS.md §“v1 implementation shape”.
Constant Summary collapse
- DESCRIPTION =
<<~DESC Connect to an MCP (Model Context Protocol) server, adding its tools to your toolset for the rest of this conversation. Usage: - The list of available server ids and their descriptions is in your system prompt under `<available_mcps>`. - Call with a single `id` that matches one of those entries. The server's tools become callable immediately after. - On `Error: server '...' is already connected`, do NOT retry — the tools are already in your toolset; call them directly. - On `Error: unknown MCP server id ...`, pick an id that actually appears in `<available_mcps>`. DESC
Instance Method Summary collapse
-
#initialize(servers:, agent:) ⇒ Connect
constructor
A new instance of Connect.
Constructor Details
#initialize(servers:, agent:) ⇒ Connect
Returns a new instance of Connect.
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 |
# File 'lib/pikuri/mcp/servers.rb', line 441 def initialize(servers:, agent:) activated = Set.new super( name: 'mcp_connect', description: DESCRIPTION, parameters: Pikuri::Tool::Parameters.build { |p| p.required_string :id, 'Id of the MCP server to connect to. ' \ 'Must match one of the ids listed under ' \ '`<available_mcps>` in the system prompt, e.g. "maven-tools".' }, execute: lambda { |id:| unless servers.live_ids.include?(id) available = servers.live_ids.empty? ? 'none' : servers.live_ids.join(', ') next "Error: unknown MCP server id #{id.inspect}. Available: #{available}." end if activated.include?(id) next "Error: server '#{id}' is already connected; its tools are in your toolset, call them directly." end count = servers.register_tools_with_agent(id, agent) activated << id "Connected to MCP server '#{id}'. Added #{count} tool#{'s' if count != 1} to your toolset." } ) end |