Raxol.Agent.Harness.McpToolConfig (Raxol Agent v2.6.0)

Copy Markdown View Source

Builds the MCP configuration that injects Raxol's tools into a native CLI.

This is the "vendor owns the loop, we inject our tools" trick from omnigent: when a native harness runs its own agent loop, the framework cannot drive tool dispatch. Instead it exposes the agent's Actions to the CLI as an MCP server, which the CLI discovers via its --mcp-config <path> flag and calls directly.

Two artifacts are produced:

  • The MCP config the CLI consumes -- {"mcpServers": {"<name>": {command, args, env}}}. The CLI launches that command as a child and speaks MCP to it.
  • A tool manifest -- the Action tool definitions (derived via Raxol.Agent.Action.ToolConverter) written to a side file whose path is passed to the server command via the RAXOL_MCP_TOOLS_FILE env var, so the spawned MCP server can load exactly this agent's tools.

The referenced :command must be an MCP server that exposes the manifest's tools (e.g. a mix mcp.server variant); wiring a specific server binary is the caller's responsibility. This module owns the config/manifest format only.

Summary

Functions

Build the MCP config map the CLI consumes.

Derive MCP tool definitions (%{"name", "description", "inputSchema"}) from Action modules, via ToolConverter.to_tool_definitions/1.

The env var name carrying the tool manifest path to the MCP server.

Write the MCP config and tool manifest to disk.

Types

opts()

@type opts() :: [
  actions: [module()],
  tools: [map()],
  server_name: String.t(),
  command: String.t(),
  args: [String.t()],
  env: %{optional(String.t()) => String.t()},
  dir: Path.t()
]

Functions

config(opts)

@spec config(opts()) :: map()

Build the MCP config map the CLI consumes.

Requires :command (the MCP server launcher). Tools come from :tools (pre-derived) or :actions (derived here). The tool manifest path is injected into the server entry's env as RAXOL_MCP_TOOLS_FILE when :tools_file is given.

tool_definitions(actions)

@spec tool_definitions([module()]) :: [map()]

Derive MCP tool definitions (%{"name", "description", "inputSchema"}) from Action modules, via ToolConverter.to_tool_definitions/1.

tools_env_var()

@spec tools_env_var() :: String.t()

The env var name carrying the tool manifest path to the MCP server.

write(opts)

@spec write(opts()) :: {:ok, Path.t()} | {:error, term()}

Write the MCP config and tool manifest to disk.

Writes the manifest (<dir>/raxol_mcp_tools.json) and the config (<dir>/raxol_mcp_config.json), wiring the manifest path into the server env. Returns {:ok, config_path}. :dir defaults to a unique temp directory.