Agent / foldkit-agent-webmcp
Manage registration lifecycle and options
registration.registered() // capability names currently registered
await registration.refresh() // reconcile against the current Model
registration.unregister() // stop following and abort every registration| Option | Default | Purpose |
|---|---|---|
agent | — | Bound AgentRuntime |
modelContext | pageModelContext() | Target producer surface (pass a mock in tests) |
followModel | true | Reconcile tools when availability changes |
signal | — | Unregister all tools when aborted |
invocationId | crypto.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:
const tested = AgentWebMcp.register({
agent: agentRuntime,
modelContext: fakeModelContext,
})
await tested.refresh()Choose an agent adapter
| Where the agent runs | Adapter |
|---|---|
| In the page beside the user | foldkit-agent-webmcp |
| External MCP client over stdio or HTTP | foldkit-agent-mcp |
| Another agent over A2A | foldkit-agent-a2a |
| An Agent Native host | foldkit-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
- Declare capabilities, completion contracts, and Parts:
foldkit-agent - Serve external clients over stdio or HTTP MCP:
foldkit-agent-mcp - Read the architecture guide: Agents guide