You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f303c45
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: README.md
+70-3Lines changed: 70 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -326,7 +326,7 @@ By default, WebMCP is enabled in top-level `Window`s and its same-origin iframes
326
326
327
327
Calls to `document.modelContext.registerTool()` will return a promise rejected with `NotAllowedError` DOMException when the permission is disabled, whether by the `allow` attribute or the `Permissions-Policy: tools=()` header. Handling of declarative tool registration errors, including when the permission is disabled is TBD; see [Issue #182](https://github.com/webmachinelearning/webmcp/issues/182).
328
328
329
-
#### Cross-origin iframe exposure: `exposedTo`
329
+
#### Cross-origin iframe exposure: `registerTool() and `exposedTo`
330
330
331
331
By default, tools registered by a document are only exposed to itself, same-origin documents in the same tree, and built-in browser agents (see this <ahref=#built-in-agent-default-exposure>discussion</a>). To support author-provided agents running in frames, developers can selectively share tools with secure origins of their choice, `exposedTo` option during registration:
332
332
@@ -343,9 +343,76 @@ Any document in the tree matching these origins (and allowed to use `tools` perm
343
343
- Receive the `toolchange` event on its `document.modelContext` when the tool is registered or unregistered.
344
344
- Be able to discover and run the tools
345
345
346
-
#### Discovering and running tools
346
+
#### Discovering and running tools: `getTools()` and `executeTool()`
347
347
348
-
TODO: Spec and describe the `modelContext.getTools()` and `modelContext.executeTool()` APIs.
348
+
Once tools are registered, in-page agents can discover and invoke them using `getTools()` and `executeTool()`.
349
+
350
+
Calling `document.modelContext.getTools()` returns a promise that resolves with an array of `RegisteredTool` dictionary objects. Each object contains the tool's `name`, `description`, `inputSchema`, `origin`, and owner `window`:
351
+
352
+
```js
353
+
// Discover tools exposed by same-origin frames in the tree (default)
An agent executes a discovered `RegisteredTool` by passing the tool dictionary and input arguments along to `document.modelContext.executeTool()`. The browser securely mediates the execution, ensuring the [`exposedTo`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextregistertooloptions-exposedto) and [`fromOrigins`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextgettooloptions-fromorigins) agree, and the tool runs in the tool owner's execution context:
Tool invocations can be cancelled mid-execution (e.g., if the user aborts an ongoing request, as they might with the "stop button" that's present in most agent UIs) by passing an `AbortSignal`:
The tool's [execution callback](https://webmachinelearning.github.io/webmcp/#callbackdef-toolexecutecallback) receives this signal via its [`options.signal`](https://webmachinelearning.github.io/webmcp/#dom-modelcontextexecutetooloptions-signal) parameter, allowing it to abort underlying network requests or asynchronous tasks cleanly.
405
+
406
+
##### Responding to dynamic tool updates: the `toolchange` event
407
+
408
+
When tools are added, removed, or updated dynamically (such as when user interactions result in new tools being registered), `document.modelContext` fires a `toolchange` event:
0 commit comments