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

A client for the tests of an MCP server. It starts the server in the
test, opens a session through `OzMcp.Router` and gives the answers as
a client reads them.

    setup do
      {:ok, client} = OzMcp.Testing.start(MyApp.McpServer)
      %{client: client}
    end

    test "gives the weather", %{client: client} do
      assert {:ok, %{"content" => [%{"text" => "Sunny"}]}} =
               OzMcp.Testing.call_tool(client, "weather", %{"city" => "Paris"})
    end

The guide [Testing](guides/development/testing.md) shows the setup
and each call.

# `client`

```elixir
@type client() :: pid()
```

# `error`

```elixir
@type error() :: %{required(String.t()) =&gt; term()}
```

# `kind`

```elixir
@type kind() :: :tools | :prompts | :resources | :resource_templates
```

# `call_tool`

```elixir
@spec call_tool(client(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, error()}
```

Calls the tool `name` with `arguments`. The options are `:meta`, `:id`
and `:timeout`.

# `complete`

```elixir
@spec complete(client(), map(), map(), keyword()) :: {:ok, map()} | {:error, error()}
```

Completes the reference `ref` with `argument`. The options are `:meta`,
`:id` and `:timeout`.

# `get_prompt`

```elixir
@spec get_prompt(client(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, error()}
```

Gets the prompt `name` with `arguments`. The options are `:meta`, `:id`
and `:timeout`.

# `initialize_result`

```elixir
@spec initialize_result(client()) :: map()
```

The result of the `initialize` of the client, with string keys, as the
server sent it.

# `instance`

```elixir
@spec instance(client()) :: atom()
```

The name of the instance of the client, for `OzMcp.Notify`:
`OzMcp.Notify.resource_updated(OzMcp.Testing.instance(client), uri)`.

# `list`

```elixir
@spec list(client(), kind(), keyword()) :: {:ok, map()} | {:error, error()}
```

Lists the entities of `kind`. The option `:cursor` continues a
paginated list.

# `notify`

```elixir
@spec notify(client(), String.t(), map(), keyword()) :: :ok | {:error, error()}
```

Sends the notification `method` with `params`. The options are `:meta`
and `:timeout`.

# `read_resource`

```elixir
@spec read_resource(client(), String.t(), keyword()) ::
  {:ok, map()} | {:error, error()}
```

Reads the resource `uri`. The options are `:meta`, `:id` and
`:timeout`.

# `request`

```elixir
@spec request(client(), String.t(), map(), keyword()) ::
  {:ok, map()} | {:error, error()}
```

Sends the request `method` with `params` and gives its answer. The
options are `:meta`, `:id` and `:timeout`.

# `start`

```elixir
@spec start(module(), keyword()) :: {:ok, client()} | {:error, error()}
```

Starts the server `server` and one client of it, under the supervisor
of the test. The options of the client are `:token` (a bearer token),
`:capabilities` (the client capabilities of `initialize`, default
`%{}`), `:handle` (a function of `method` and `params` that answers a
request of the server with `{:ok, result}` or `{:error, error}`),
`:client_info` and `:timeout` (milliseconds, default `5_000`). Every
other option is an option of the instance.

It runs in a test process only: it calls
`ExUnit.Callbacks.start_supervised!/1`. A protected server needs a
`:resource_url` unless its test verifier gives the audience
`http://localhost/mcp`.

# `stop`

```elixir
@spec stop(client()) :: :ok
```

Ends the session of the client and stops it; the end of the test stops it without the `DELETE`.

---

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