# `Mead.MCP.Connection`
[🔗](https://github.com/albertosca/mead/blob/main/lib/mead/mcp/connection.ex#L1)

One process per configured MCP server. It owns a transport, performs the MCP handshake, keeps
the server's tools published in `Mead.MCP.Catalog`, and carries tool calls.

## Lifecycle

`:disconnected` -> `:initializing` -> `:listing` -> `:ready`. When the transport cannot start,
closes, dies, the handshake does not finish in `:handshake_timeout`, or a tool refresh does not
finish in `:refresh_timeout` (which defaults to the handshake timeout), the connection does not
crash: it removes its tools from the catalog, fails every pending caller with
`{:error, :connection_lost}`, stops the transport, and tries again after the next delay of
`:reconnect_delays` (the last one repeats). A missing command or a server that is down therefore
costs one retry per delay and never becomes a restart loop that could take the application down.

Only messages from the current transport are honoured: a late message from a replaced one is
ignored. The connection traps exits so that a transport that dies is an ordinary event.

Calls are carried by `call_tool/5`; each pending call monitors its caller and has its own timer.

# `call_tool`

```elixir
@spec call_tool(atom(), atom(), String.t(), map(), pos_integer()) ::
  {:ok, %{content: String.t(), is_error: boolean()}} | {:error, term()}
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `start_link`

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

---

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