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.

Currently supports the stdio transport only: the MCP server is launched as a child process and communicates via newline-delimited JSON-RPC on stdin/stdout.

HTTP/SSE transport support can be added later by subclassing Transport.

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?, 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
  • tool_name (String)

    the tool name as registered in the MCP server

Returns:

  • (McpTool)

    a configured subclass instance ready for use with an Agent



36
37
38
39
40
# File 'lib/phronomy/tool/mcp_tool.rb', line 36

def from_server(server_uri, tool_name:)
  transport = build_transport(server_uri)
  tool_def = transport.fetch_tool(tool_name)
  build_tool_class(tool_name, tool_def, transport).new
end