MCP tools with persisted approval
View SourceOrdinary MCP calls need no new options. To use a discovered tool with persisted continuation, give Client explicit, non-secret host identity references:
{:ok, client} = ExAgent.MCP.Client.start_link(
transport: :streamable_http,
url: "https://mcp.example.invalid/service",
headers_provider: &MyApp.MCPCredentials.headers/1,
continuation_binding: %{
endpoint: %{"id" => "inventory-service", "version" => "1"},
principal: %{"id" => "tenant-account-123", "version" => "1"}
}
)
{:ok, tools} = ExAgent.MCP.Client.tools(client)
agent = ExAgent.new(model: model, tools: tools)Implement the credential callback as in the local recipe.
Run/pause/get/decide/resume use the existing Continuation API and
host definition/policy/model refs and codecs. A committed approval is checked
against the currently reconstructed tools before new model/tool IO. A changed
endpoint, principal, transport, protocol or bound result schema rejects with
:continuation_tools_changed, leaving the approved record available to its
original trusted definition. An older approval without a schema keeps the
original text or image projection when the current catalogue advertises an
object schema. Resolve an uncertain effect through Continuation reconciliation.
HTTP binds the negotiated revision. To restore a recorded HTTP revision, set
the top-level protocol_version: on the client, rediscover the tools and
rebuild the agent. Modern form elicitation uses the same endpoint and principal
on every round. Answer a form
The host chooses identity. endpoint identifies an externally stable service
definition; principal identifies the authority under which remote tools execute,
not the human approving the call. Use explicit id/version strings and update the
reference when its semantics change. A reference does not authenticate a peer or
establish that credentials belong to that principal; the host must enforce those
associations. Never put secrets in these references, infer a principal from an
Authorization header, or strip the private Tool metadata.
To rotate credentials for the same principal, update the callback's credential source. Continue using the existing client and trusted tool definition. The callback returns the reference of the selected credential and ExAgent checks it against the binding before sending. If credentials now represent another principal, use its own binding and obtain a new approval under a new execution. Reconcile an uncertain call before resuming.
HTTP binds the effective public URL through SHA256 independently of the declared
endpoint reference. It normalizes URI host case, default ports and an empty path
to /, without DNS lookup or broader path equivalence. Binding rejects userinfo,
query and fragment before transport startup to keep URL credentials out of
authority. Move auth to headers for this mode. Ordinary unbound HTTP keeps its
existing query support. No URL literal, headers, secrets, Finch name, PID or session
ID enters the binding.
Stdio uses the same continuation_binding option. The host endpoint reference must
identify the command/arguments/environment's semantics because those values may
contain secrets and are not persisted. Stdio binds protocol revision
2025-06-18, or the protocol_version: given in the binding (2025-06-18,
2025-03-26 or 2024-11-05), requests it and requires it in the initialize
reply before completing the handshake. A mismatch returns
:mcp_protocol_binding_mismatch. This equality check does not authenticate the
executable. For HTTP, pass protocol_version: alongside :continuation_binding.
Records persisted by 2.x bound 2024-11-05. Restore them with a client whose
binding adds protocol_version: "2024-11-05"; new executions can use the default.
{:ok, legacy} = ExAgent.MCP.Client.start_link(
command: server_path,
args: server_args,
continuation_binding: %{
endpoint: %{"id" => "files-server", "version" => "1"},
principal: %{"id" => "tenant-42", "version" => "1"},
protocol_version: "2024-11-05"
}
)Discovered tools without a trusted reference remain usable for ordinary
calls; persisted selection fails :tool_continuation_binding_required before
model/tool IO. Initial Store create/claim may already have occurred, following
existing tool-selection order. Malformed explicit identity options raise
ArgumentError before transport startup. Local tools keep their existing
fingerprint rules.
Historical MCP approval rows did not identify the target/principal. They cannot be silently upgraded by assigning the current target: a bound tool has a different fingerprint. Start a new bound execution and obtain its explicit approval. Existing local snapshots/descriptors do not require migration. Tool schemas, descriptions, argument validation, permissions and effective-argument checks remain independent authority and are still revalidated on resume.
Binding validation does not authenticate the peer or establish your OAuth/TLS deployment. Verify those application transport boundaries separately. Use MCP for ordinary connections and Durability for persisted execution. For a deferred MCP task that the peer no longer knows, settle the original effect with independent evidence. Operator recovery