ExAthena.Mcp.Client (ExAthena v0.6.0)

Copy Markdown View Source

JSON-RPC 2.0 MCP client GenServer.

Manages a single MCP server connection over either:

  • :stdio transport — spawns a child process and communicates via stdin/stdout
  • :http transport — POSTs JSON-RPC messages to an HTTP endpoint

Options

  • :command — executable name (required for stdio)
  • :args — argument list (default [], stdio only)
  • :env — environment map (default %{}, stdio only)
  • :url — HTTP endpoint URL (required for HTTP)
  • :headers — HTTP headers map (default %{}, HTTP only)
  • :request_timeout_ms — per-request timeout in ms (default 30_000)
  • :auto_initialize? — run initialize handshake in init/1 (default true)

Summary

Functions

Call a tool by name with input map. Returns {:ok, result_map} or {:error, reason}.

Returns a specification to start this module under a supervisor.

Run the initialize handshake. Only needed when auto_initialize?: false.

List tools exposed by the MCP server. Returns {:ok, [tool_map]} or {:error, reason}.

Start the client. Links the calling process.

Functions

call_tool(client, name, input, timeout \\ 30000)

@spec call_tool(GenServer.server(), String.t(), map(), non_neg_integer()) ::
  {:ok, map()} | {:error, term()}

Call a tool by name with input map. Returns {:ok, result_map} or {:error, reason}.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

initialize(client, timeout \\ 30000)

@spec initialize(GenServer.server(), non_neg_integer()) ::
  :ok | {:error, ExAthena.Error.t()}

Run the initialize handshake. Only needed when auto_initialize?: false.

list_tools(client, timeout \\ 30000)

@spec list_tools(GenServer.server(), non_neg_integer()) ::
  {:ok, [map()]} | {:error, term()}

List tools exposed by the MCP server. Returns {:ok, [tool_map]} or {:error, reason}.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Start the client. Links the calling process.