# `OzMcp.Instance`
[🔗](https://github.com/oz-elixir/oz_mcp/blob/v0.9.0/lib/oz_mcp/instance.ex#L1)

Supervisor of a single MCP server instance.

Each instance owns its own names and registries: a unique `Names`
Registry (which also carries the `%OzMcp.Instance.Config{}` as meta
data), a duplicate `Topics` Registry and a duplicate `Principals`
Registry (which holds one entry for each open session of a principal).
The instance is a tree of three levels. `Core` owns the three
Registries and the owner of the task table. `PubSub` holds the processes
of the `:pubsub` module (only when the module has them). `Workers` holds
the supervisor of the callbacks, the supervisor of the sessions, the
reaper, the supervisor of the tasks and the processes of the snapshot.

Use the child spec `{OzMcp, opts}` to embed one or more instances into
the supervision tree of the host application:

    children = [
      {OzMcp, server: MyApp.McpServer, allowed_origins: ["http://localhost:4000"]},
      {Bandit, plug: MyApp.Router, port: 4000}
    ]

# `t`

```elixir
@type t() :: atom()
```

# `config`

```elixir
@spec config(t()) :: {:ok, OzMcp.Instance.Config.t()} | :not_running
```

The config of a running instance, or `:not_running`. A Registry that does
not run gives `:not_running` and never raises.

# `fetch_opts`

```elixir
@spec fetch_opts(t()) :: {:ok, OzMcp.Instance.Config.opts()} | :not_running
```

The static options of the server of the instance (`{:ok, opts}`), or
`:not_running` when the instance is not running.

# `names`

```elixir
@spec names(t()) :: atom()
```

The name of the instance's `Names` Registry.

# `opts`

```elixir
@spec opts(t()) :: OzMcp.Instance.Config.opts()
```

The static options of the instance, or their defaults when the instance
is not running. A caller that must not hide that situation uses
`fetch_opts/1`.

# `principals`

```elixir
@spec principals(t()) :: atom()
```

The name of the instance's `Principals` Registry. It holds one entry for
each open session of a principal, under the key of the principal.

# `select`

```elixir
@spec select(t(), [tuple()]) :: [term()]
```

Runs a match specification on the instance's `Names` Registry, or gives
`[]` when the instance is not running.

# `server_module`

```elixir
@spec server_module(t()) :: module()
```

The server module of an instance. An instance that does not run (or a
module that is not the name of an instance) answers with its own name:
the name of an instance is the server module by default.

# `topics`

```elixir
@spec topics(t()) :: atom()
```

The name of the instance's `Topics` Registry.

# `via`

```elixir
@spec via(t(), term()) :: {:via, Registry, {atom(), term()}}
```

A via tuple that addresses `key` inside the instance's `Names` Registry.

# `whereis`

```elixir
@spec whereis(t(), term()) :: {:ok, pid()} | :not_running
```

Looks up a pid that is registered under `key` in the instance's `Names` Registry.
A process that died and that the Registry still holds is not running.

---

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