MCP client connection and request handling. Supports the modern 2026-07-28 stateless protocol and legacy initialization-based protocol revisions over the same Streamable HTTP endpoint.
Values
HEADER-MISMATCH
HEADER-MISMATCH: Int -32020
LEGACY-PROTOCOL-VERSION
LEGACY-PROTOCOL-VERSION: Str "2025-11-25"
META-CLIENT-CAPABILITIES
META-CLIENT-CAPABILITIES: Str "io.modelcontextprotocol/clientCapabilities"
META-CLIENT-INFO
META-CLIENT-INFO: Str "io.modelcontextprotocol/clientInfo"
META-LOG-LEVEL
META-LOG-LEVEL: Str "io.modelcontextprotocol/logLevel"
META-PROTOCOL-VERSION
META-PROTOCOL-VERSION: Str "io.modelcontextprotocol/protocolVersion"
META-SERVER-INFO
META-SERVER-INFO: Str "io.modelcontextprotocol/serverInfo"
MISSING-CLIENT-CAPABILITY
MISSING-CLIENT-CAPABILITY: Int -32021
MODERN-PROTOCOL-VERSION
MODERN-PROTOCOL-VERSION: Str "2026-07-28"
UNSUPPORTED-PROTOCOL-VERSION
UNSUPPORTED-PROTOCOL-VERSION: Int -32022
Functions
connect
fn (url: Str, client-info: ::mcp::types/ClientInfo, capabilities: ::mcp::types/ClientCapabilities?): ::mcp::types/Session
fn (url: Str, client-info: ::mcp::types/ClientInfo, capabilities: ::mcp::types/ClientCapabilities?, options: ::mcp::types/ConnectionOptions?): ::mcp::types/Session
Connect to an MCP server.
The default auto mode probes the modern 2026-07-28 protocol with
server/discover and falls back to the legacy initialize handshake only when
the response is not a recognized modern response. Pass ConnectionOptions
with mode: "modern" to pin modern behavior or mode: "legacy" to skip the
probe. Caller headers are retained on every request.
Example
::types ::mcp::types
info ::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, null)
session.protocol-version
// Pin the protocol and send a token on every request
options ::types/ConnectionOptions({
mode: "modern",
headers: {Authorization: `Bearer ${::hot::ctx/get("MCP_TOKEN")}`}
})
caps ::types/ClientCapabilities({elicitation: {form: {}}})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, caps, options)
session.server-info.name
encode-header-value
fn (value: Str): Str
Encode an MCP routing header value using the Base64 sentinel when plain ASCII is unsafe.
Example
::mcp::client/encode-header-value("search") // "search"
::mcp::client/encode-header-value(" padded") // "=?base64?IHBhZGRlZA==?="
initialize
fn (url: Str, client-info: ::mcp::types/ClientInfo, capabilities: ::mcp::types/ClientCapabilities?): ::mcp::types/Session
fn (url: Str, client-info: ::mcp::types/ClientInfo, capabilities: ::mcp::types/ClientCapabilities?, headers: Map): ::mcp::types/Session
Connect using the legacy initialize/initialized handshake.
Use connect for automatic modern/legacy negotiation. The four-argument form
accepts base HTTP headers such as Authorization.
Example
info ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/initialize("https://mcp.example.com/mcp", info, null)
session.session-id
// With base headers
headers {Authorization: `Bearer ${::hot::ctx/get("MCP_TOKEN")}`}
session ::mcp::client/initialize("https://mcp.example.com/mcp", info, null, headers)
mrtr-retry-params
fn (params: Map?, result: Map, responses: Map?): Map
Build MRTR retry params without leaking fields from an earlier round.
Example
previous {name: "deploy", requestState: "old"}
::mcp::client/mrtr-retry-params(previous, {requestState: "new"}, {confirm: {action: "accept"}})
// {name: "deploy", inputResponses: {confirm: {action: "accept"}}, requestState: "new"}
ping
fn (session: ::mcp::types/Session): Bool
Check server connectivity using discovery for modern MCP or ping for legacy MCP.
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)
alive ::mcp::client/ping(session)
if(is-err(alive), err-message(alive), alive)
request-context
fn (session: ::mcp::types/Session, method: Str, params: Map?, tool: ::mcp::types/Tool?): Map
Build the era-specific params and HTTP headers for an MCP request.
Example
session ::mcp::types/Session({
url: "https://mcp.example.com/mcp",
protocol-version: "2026-07-28",
server-info: ::mcp::types/ServerInfo({name: "server", version: "1"}),
server-capabilities: ::mcp::types/ServerCapabilities({tools: {listChanged: true}}),
headers: {},
era: "modern",
client-info: ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
})
context ::mcp::client/request-context(session, "tools/list", {}, null)
get(context.headers, "Mcp-Method") // "tools/list"
response-json-rpc-message
fn (response: ::hot::http/HttpResponse): Map?
Extract a JSON-RPC message from JSON or buffered SSE transport responses.
Example
response ::hot::http/HttpResponse({
status: 200,
headers: {"content-type": "application/json"},
body: {jsonrpc: "2.0", id: "call-1", result: {}}
})
::mcp::client/response-json-rpc-message(response).id // "call-1"
response-result
fn (session: ::mcp::types/Session, response: Result): Map
Return the MCP result carried by a JSON-RPC response.
A JSON-RPC error response is returned as the same Err, so callers can test it
with is-err and read the server's message with err-message.
Example
session ::mcp::types/Session({
url: "https://mcp.example.com/mcp",
protocol-version: "2026-07-28",
server-info: ::mcp::types/ServerInfo({name: "server", version: "1"}),
server-capabilities: ::mcp::types/ServerCapabilities({tools: {listChanged: true}}),
headers: {},
era: "modern",
client-info: ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
})
::mcp::client/response-result(session, {result: {resultType: "complete"}})
// {resultType: "complete"}
session-request
fn (session: ::mcp::types/Session, method: Str, params: Map?): Map
Send a request over an active MCP connection and return its result.
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)
result ::mcp::client/session-request(session, "tools/list", {})
if(is-err(result), err-message(result), result.tools)
session-request-stream
fn (session: ::mcp::types/Session, method: Str, params: Map?): ::hot::http/StreamingHttpResponse
Send a streaming request over an active MCP connection.
Example
info ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
session ::mcp::client/connect("https://mcp.example.com/mcp", info, null)
response ::mcp::client/session-request-stream(session, "tools/call", {name: "analyze", arguments: {}})
for-each(response.body, (frame) { println(frame.data) })
session-request-stream-with-tool
fn (session: ::mcp::types/Session, method: Str, params: Map?, tool: ::mcp::types/Tool?): ::hot::http/StreamingHttpResponse
Send a streaming MCP request with optional tool header metadata.
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))
params {name: tool.name, arguments: {}}
response ::mcp::client/session-request-stream-with-tool(session, "tools/call", params, tool)
for-each(response.body, (frame) { println(frame.data) })
session-request-with-input
fn (session: ::mcp::types/Session, method: Str, params: Map?, handler: Fn, max-rounds: Int): Map
Fulfill modern Multi Round-Trip Requests.
handler receives each requested server-to-client request and returns its
response. The original request is retried with a fresh JSON-RPC ID,
inputResponses, and the opaque requestState.
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}} }
params {name: "deploy", arguments: {}}
result ::mcp::client/session-request-with-input(session, "tools/call", params, ask, 3)
result.content
session-request-with-tool
fn (session: ::mcp::types/Session, method: Str, params: Map?, tool: ::mcp::types/Tool?): Map
Send an MCP request, optionally using a Tool definition for x-mcp-header mirroring.
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))
params {name: tool.name, arguments: {}}
result ::mcp::client/session-request-with-tool(session, "tools/call", params, tool)
result.content
session-request-with-tool-input
fn (session: ::mcp::types/Session, method: Str, params: Map?, tool: ::mcp::types/Tool, handler: Fn, max-rounds: Int): Map
MRTR request helper that also mirrors a tool's x-mcp-header
parameters.
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))
params {name: tool.name, arguments: {}}
result ::mcp::client/session-request-with-tool-input(session, "tools/call", params, tool, ask, 3)
result.content
tool-header-analysis
fn (tool: ::mcp::types/Tool): Map
Validate and collect statically reachable x-mcp-header annotations
from a tool.
Example
tool ::mcp::types/Tool({name: "search", input-schema: {
type: "object",
properties: {region: {type: "string", "x-mcp-header": "Region"}}
}})
analysis ::mcp::client/tool-header-analysis(tool)
analysis.valid // true
analysis.defs[0].suffix // "Region"
tool-parameter-headers
fn (tool: ::mcp::types/Tool, arguments: Map?): Map
Build Mcp-Param-* headers for a modern HTTP tool call.
Example
tool ::mcp::types/Tool({name: "search", input-schema: {
type: "object",
properties: {region: {type: "string", "x-mcp-header": "Region"}}
}})
::mcp::client/tool-parameter-headers(tool, {region: "us-east"})
// {"Mcp-Param-Region": "us-east"}
valid-tool-for-session
fn (session: ::mcp::types/Session, tool: ::mcp::types/Tool): Bool
Return whether a tool definition is valid for the session transport.
Example
session ::mcp::types/Session({
url: "https://mcp.example.com/mcp",
protocol-version: "2026-07-28",
server-info: ::mcp::types/ServerInfo({name: "server", version: "1"}),
server-capabilities: ::mcp::types/ServerCapabilities({tools: {listChanged: true}}),
headers: {},
era: "modern",
client-info: ::mcp::types/ClientInfo({name: "my-app", version: "1.0.0"})
})
bad ::mcp::types/Tool({name: "bad", input-schema: {type: "object", "x-mcp-header": "Bad"}})
::mcp::client/valid-tool-for-session(session, bad) // false