Toolnexus.Mcp.Connection (toolnexus v0.9.4)

Copy Markdown View Source

One GenServer per configured MCP server (SPEC §2). Owns the transport (stdio port or streamable-HTTP state), correlates JSON-RPC request ids with per-call timeouts (config timeout, default 30000 ms), performs the initialize handshake, paginates tools/list, executes tools/call, and bridges inbound elicitation/create onto the host wait_for (§2 + §10): form → kind:"input", URL → kind:"authorization"; no wait_for ⇒ decline.

The stdio child's lifetime is owned by this process (ADR-0007): it outlives connect and is killed in terminate/2 on close/supervisor shutdown.

Summary

Functions

Call a tool by its ORIGINAL (unprefixed) name.

Returns a specification to start this module under a supervisor.

Connect + initialize. Bounded by the server timeout; returns :ok | {:error, reason}.

List all tool definitions, following nextCursor pagination.

The stdio child's OS pid (for lifetime assertions); :error for remote servers.

Functions

call_tool(pid, name, args)

Call a tool by its ORIGINAL (unprefixed) name.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

connect(pid, timeout)

Connect + initialize. Bounded by the server timeout; returns :ok | {:error, reason}.

list_tools(pid)

List all tool definitions, following nextCursor pagination.

os_pid(pid)

The stdio child's OS pid (for lifetime assertions); :error for remote servers.

start_link(opts)