Class: Phronomy::Tool::McpTool

Inherits:
Base
  • Object
show all
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+.

Examples:

web_search = Phronomy::Tool::McpTool.from_server(
  "stdio://./mcp-server",
  tool_name: "search_web"
)
agent = MyAgent.new
agent_class.tools(web_search)

Defined Under Namespace

Classes: HttpTransport, StdioTransport

Class Method Summary collapse

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+.

Parameters:

  • server_uri (String)

    URI of the MCP server. Supported schemes:

    • "stdio://" — spawn a child process
    • "http://" / "https://" — connect to an HTTP/SSE server
  • tool_name (String)

    the tool name as registered in the MCP server

Returns:

  • (McpTool)

    a configured subclass instance ready for use with an Agent



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