Class: Phronomy::Tool::McpTool
- Defined in:
- lib/phronomy/tool/mcp_tool.rb
Overview
A Phronomy::Tool::Base subclass that wraps a tool exposed by an external MCP (Model Context Protocol) server.
Supports two transport schemes:
- "stdio://<command>" — spawns a child process that communicates via newline-delimited JSON-RPC on stdin/stdout.
- "http://<url>" / "https://<url>" — connects to a running HTTP/SSE MCP server using +net/http+.
Defined Under Namespace
Classes: HttpTransport, StdioTransport
Class Method Summary collapse
-
.from_server(server_uri, tool_name:) ⇒ McpTool
Build a McpTool instance by querying a running MCP server for the tool definition identified by +tool_name+.
Methods inherited from Base
#call, #execute, #name, on_error, on_schema_error, param, param_enums, #params_schema, requires_approval, #requires_approval, #requires_approval?, retry_on, retry_policies, scope, tool_name
Class Method Details
.from_server(server_uri, tool_name:) ⇒ McpTool
Build a McpTool instance by querying a running MCP server for the tool definition identified by +tool_name+.
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/phronomy/tool/mcp_tool.rb', line 39 def from_server(server_uri, tool_name:) # Use a short-lived transport only to query the tool definition, # then close it. Each McpTool instance creates its own transport # so that concurrent callers never share IO streams. transport = build_transport(server_uri) begin tool_def = transport.fetch_tool(tool_name) ensure transport.close end build_tool_class(tool_name, server_uri, tool_def).new end |