# `ExAthena.Mcp.Client`
[🔗](https://github.com/udin-io/ex_athena/blob/v0.7.1/lib/ex_athena/mcp/client.ex#L1)

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`)

# `call_tool`

```elixir
@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`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `initialize`

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

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

# `list_tools`

```elixir
@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`

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

Start the client. Links the calling process.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
