# `MingaAgent.MCP.Registry`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_agent/mcp/registry.ex#L1)

In-memory registry for MCP clients attached to one native agent session.

The native provider owns this struct in its GenServer state. Each MCP server
still runs as its own client process, but the registry keeps routing data and
cleanup logic in-process so tool calls do not need another coordinator hop.

# `client_entry`

```elixir
@type client_entry() :: %{pid: pid(), ref: reference(), tool_names: [tool_name()]}
```

Tracked state for one MCP server client.

# `server_name`

```elixir
@type server_name() :: String.t()
```

Stable user-facing MCP server name.

# `start_opt`

```elixir
@type start_opt() ::
  {:transport, module()}
  | {:transport_opts, keyword()}
  | {:request_timeout, timeout()}
  | {:notify_pid, pid()}
  | {:reserved_tool_names, [tool_name()]}
  | {:supervisor, GenServer.server() | nil}
```

Options forwarded from the native provider to MCP clients.

# `t`

```elixir
@type t() :: %MingaAgent.MCP.Registry{
  clients: %{required(server_name()) =&gt; client_entry()}
}
```

MCP client registry owned by the native provider.

# `tool_name`

```elixir
@type tool_name() :: String.t()
```

Provider-facing safe tool name.

# `client_for_server`

```elixir
@spec client_for_server(t() | nil, String.t()) :: {:ok, pid()} | :error
```

Returns the client pid for a started MCP server.

# `ensure_server`

```elixir
@spec ensure_server(t(), MingaAgent.MCP.ServerConfig.t(), pid(), [start_opt()]) ::
  {:ok, t(), pid()} | {:error, String.t()}
```

Starts one MCP server if needed and returns the client pid.

# `new`

```elixir
@spec new() :: t()
```

Returns an empty registry.

# `remove_server`

```elixir
@spec remove_server(t() | nil, String.t()) :: {t() | nil, [String.t()]}
```

Removes one server from the registry and returns its removed tool names.

# `server_for_pid`

```elixir
@spec server_for_pid(t() | nil, pid()) :: String.t() | nil
```

Returns the server name for a monitored client pid.

# `start_all`

```elixir
@spec start_all([MingaAgent.MCP.ServerConfig.t()], pid(), [start_opt()]) ::
  {t(), [ReqLLM.Tool.t()], [String.t()]}
```

Starts all enabled MCP servers and returns the registry, tools, and startup failure messages.

# `stop_all`

```elixir
@spec stop_all(t() | nil) :: :ok
```

Stops all tracked MCP clients.

---

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