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"})
endThe guide Testing shows the setup and each call.
Summary
Functions
Calls the tool name with arguments. The options are :meta, :id
and :timeout.
Completes the reference ref with argument. The options are :meta,
:id and :timeout.
Gets the prompt name with arguments. The options are :meta, :id
and :timeout.
The result of the initialize of the client, with string keys, as the
server sent it.
The name of the instance of the client, for OzMcp.Notify:
OzMcp.Notify.resource_updated(OzMcp.Testing.instance(client), uri).
Lists the entities of kind. The option :cursor continues a
paginated list.
Sends the notification method with params. The options are :meta
and :timeout.
Reads the resource uri. The options are :meta, :id and
:timeout.
Sends the request method with params and gives its answer. The
options are :meta, :id and :timeout.
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.
Ends the session of the client and stops it; the end of the test stops it without the DELETE.
Types
Functions
Calls the tool name with arguments. The options are :meta, :id
and :timeout.
Completes the reference ref with argument. The options are :meta,
:id and :timeout.
Gets the prompt name with arguments. The options are :meta, :id
and :timeout.
The result of the initialize of the client, with string keys, as the
server sent it.
The name of the instance of the client, for OzMcp.Notify:
OzMcp.Notify.resource_updated(OzMcp.Testing.instance(client), uri).
Lists the entities of kind. The option :cursor continues a
paginated list.
Sends the notification method with params. The options are :meta
and :timeout.
Reads the resource uri. The options are :meta, :id and
:timeout.
Sends the request method with params and gives its answer. The
options are :meta, :id and :timeout.
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.
@spec stop(client()) :: :ok
Ends the session of the client and stops it; the end of the test stops it without the DELETE.