Agent / foldkit-agent-webmcp

Manage registration lifecycle and options

ts
registration.registered()  // capability names currently registered
await registration.refresh() // reconcile against the current Model
registration.unregister()  // stop following and abort every registration
OptionDefaultPurpose
agent—Bound AgentRuntime
modelContextpageModelContext()Target producer surface (pass a mock in tests)
followModeltrueReconcile tools when availability changes
signal—Unregister all tools when aborted
invocationIdcrypto.randomUUID()Generates protocol invocation IDs
onError—Handles background reconciliation errors
forms—Declarative form tools wired via formTool

Each registered tool holds its own registration AbortController, separate from the per-call execution AbortSignal forwarded to AgentRuntime as Invocation.signal.

How errors map to tool callers

Policy and validation refusals return clear messages to the calling agent (No such capability: ..., Capability "..." is not available right now, Not authorized to invoke "...", Invalid input for "...", Capability "..." failed unexpectedly), while internal host or adapter defects flatten to a generic message so application internals stay private.

Test without a browser

modelContext is the only browser seam. Pass a fake object implementing registerTool to inspect registered descriptors and invoke execute directly in unit tests:

ts
const tested = AgentWebMcp.register({
  agent: agentRuntime,
  modelContext: fakeModelContext,
})

await tested.refresh()

Choose an agent adapter

Where the agent runsAdapter
In the page beside the userfoldkit-agent-webmcp
External MCP client over stdio or HTTPfoldkit-agent-mcp
Another agent over A2Afoldkit-agent-a2a
An Agent Native hostfoldkit-agent-native

Isolate experimental WebMCP changes

Because the browser WebMCP specification is still evolving, keeping WebMCP registration in this adapter ensures upstream browser API changes stay isolated from your foldkit-agent contract and Foldkit Messages.

Next