SuperPi.MCP.Client (super_pi v0.1.0)

Copy Markdown View Source

Client for one Model Context Protocol server, over stdio or Streamable HTTP.

The client runs the initialize handshake, lists the server's tools (following nextCursor), and then forwards tools/call requests. It owns the protocol: request ids, timeouts and the handshake. A SuperPi.MCP.Transport moves the messages:

Use SuperPi.MCP.Manager to start every configured server and expose its tools to the agent. This module only speaks the protocol. It declares no client capabilities, so a server cannot ask for sampling, roots or elicitation; it may still send ping.

Summary

Functions

Waits until the handshake and the tool listing finish. Returns :ok or {:error, reason}.

Calls a tool. Returns {:ok, result} with the server's tools/call result map, or {:error, reason} for a protocol error, a timeout, or a server that exited.

Returns a specification to start this module under a supervisor.

Starts a client. Options: :name (server name) and either :command, :args, :env (map), :cwd (stdio) or :url, :headers (map, ${ENV_VAR} is expanded) for Streamable HTTP. :transport names a SuperPi.MCP.Transport module explicitly.

Tool definitions as the server returned them (name, description, inputSchema).

Functions

await_ready(pid, timeout \\ 10000)

Waits until the handshake and the tool listing finish. Returns :ok or {:error, reason}.

call_tool(pid, tool, args, timeout \\ 60000)

Calls a tool. Returns {:ok, result} with the server's tools/call result map, or {:error, reason} for a protocol error, a timeout, or a server that exited.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

start_link(opts)

Starts a client. Options: :name (server name) and either :command, :args, :env (map), :cwd (stdio) or :url, :headers (map, ${ENV_VAR} is expanded) for Streamable HTTP. :transport names a SuperPi.MCP.Transport module explicitly.

Returns {:error, {:command_not_found, command}} when the executable does not exist, and {:error, {:invalid_url, url}} or {:error, {:missing_env, names}} for a bad url entry.

tools(pid)

Tool definitions as the server returned them (name, description, inputSchema).