MCP tool discovery and invocation. Supports single-page listing, paginated iteration, synchronous calls, and SSE streaming calls.
Functions
call
fn (session: ::mcp::types/Session, name: Str, arguments: Map?): ::mcp::types/ToolResult
Call a tool on the MCP server and wait for the result.
Returns a ToolResult with content (Vec of ToolContent), is-error (Bool),
and optional structured-content. Returns err() when the server answers with
a JSON-RPC error, such as for a tool it doesn't have; err-message gives the
server's message. On a modern connection, a tool that tools/list doesn't
return is also an err().
Example
::tools ::mcp::tools
info ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, null)
result ::tools/call(session, "get_weather", {location: "Portland"})
result.is-error // => false
first(result.content).text // => "Sunny, 72°F"
// Call with empty arguments
result ::tools/call(session, "list_files", {})
// A JSON-RPC error is an Err the caller can test
result ::tools/call(session, "place_order", {id: "A-1"})
if(is-err(result), err-message(result), result) // => "the order system is down"
call-stream
fn (session: ::mcp::types/Session, name: Str, arguments: Map?): Iter
Call a tool on the MCP server with SSE streaming.
Returns an iterator of StreamEvent values. Each event contains a parsed JSON-RPC message — progress notifications, log messages, or the final result. The events are read until the server closes the stream and then returned, so nothing is delivered while the call is still running.
Example
::tools ::mcp::tools
info ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, null)
// Collect all stream events
events collect(::tools/call-stream(session, "long_analysis", {query: "..."}))
last-event last(events)
last-event.data.result // => final tool result
// Each event has .event (SSE type) and .data (parsed JSON-RPC message)
// Notifications: event.data.method => "notifications/progress"
// Final result: event.data.result => {...}
call-stream-tool
fn (session: ::mcp::types/Session, tool: ::mcp::types/Tool, arguments: Map?): Iter
Stream a tool call using a retained Tool definition for modern routing headers.
Example
info ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, null)
tool first(::mcp::tools/list(session))
events collect(::mcp::tools/call-stream-tool(session, tool, {query: "sales"}))
last(events).data.result
call-tool
fn (session: ::mcp::types/Session, tool: ::mcp::types/Tool, arguments: Map?): ::mcp::types/ToolResult
Call a previously listed Tool definition.
Prefer this form when retaining the Tool is convenient: modern Streamable HTTP
uses its input-schema to mirror any x-mcp-header parameters.
Returns err() when the server answers with a JSON-RPC error.
Example
info ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, null)
tool first(::mcp::tools/list(session))
result ::mcp::tools/call-tool(session, tool, {location: "Portland"})
first(result.content).text
call-tool-with-input
fn (session: ::mcp::types/Session, tool: ::mcp::types/Tool, arguments: Map?, handler: Fn, max-rounds: Int): ::mcp::types/ToolResult
Call a Tool and fulfill modern Multi Round-Trip input requests with handler.
Returns err() when the server answers with a JSON-RPC error.
Example
info ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, null)
ask (request) { {action: "accept", content: {confirmed: true}} }
tool first(::mcp::tools/list(session))
result ::mcp::tools/call-tool-with-input(session, tool, {env: "prod"}, ask, 3)
result.is-error
call-with-input
fn (session: ::mcp::types/Session, name: Str, arguments: Map?, handler: Fn, max-rounds: Int): ::mcp::types/ToolResult
Call a named tool and fulfill modern Multi Round-Trip input requests with handler.
Returns err() when the server answers with a JSON-RPC error or tools/list
doesn't return the tool.
Example
info ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, null)
ask (request) { {action: "accept", content: {confirmed: true}} }
result ::mcp::tools/call-with-input(session, "deploy", {env: "prod"}, ask, 3)
if(is-err(result), err-message(result), first(result.content).text)
list
fn (session: ::mcp::types/Session): Vec<::mcp::types/Tool>
List tools available on the MCP server (first page).
Returns a Vec of Tool, each with name, description, and input-schema fields.
Example
::tools ::mcp::tools
info ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, null)
tools ::tools/list(session)
// tools => [{name: "get_weather", description: "...", input-schema: {...}}, ...]
first(tools).name // => "get_weather"
list-all
fn (session: ::mcp::types/Session): Vec<::mcp::types/Tool>
List all tools across all pages, following pagination automatically.
Follows nextCursor links until all pages are exhausted. Returns a
single Vec containing every tool.
Example
::tools ::mcp::tools
info ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, null)
all-tools ::tools/list-all(session)
length(all-tools) // => total number of tools across all pages
list-page
fn (session: ::mcp::types/Session, cursor: Str?): Map
List tools with an explicit cursor for manual pagination.
Returns a Map with tools (Vec of Tool) and next-cursor (Str or null).
Pass null as the cursor for the first page.
Example
::tools ::mcp::tools
info ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, null)
page ::tools/list-page(session, null)
page.tools // => [{name: "get_weather", ...}, ...]
page.next-cursor // => "cursor-abc" or null
// Fetch next page if available
next-page if(is-some(page.next-cursor), ::tools/list-page(session, page.next-cursor), null)