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. Non-existent tools return err().

Example

::tools ::mcp::tools
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", {})

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. Use collect to gather all events, or iterate to process them in real time.

Example

::tools ::mcp::tools

// 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.

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.

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.

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.

collect-pages

fn (session: ::mcp::types/Session, method: Str, key: Str, cursor: Str?, acc: Vec): Vec

find-tool

fn (session: ::mcp::types/Session, name: Str): ::mcp::types/Tool

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
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
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
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)

tool-result

fn (result: Map): ::mcp::types/ToolResult