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
Copy file name to clipboardExpand all lines: docs/proposal.md
+20-46Lines changed: 20 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,34 +52,9 @@ Handling tool calls in the main thread with the option of delegating to workers
52
52
## API
53
53
54
54
### modelContext
55
-
The `window.navigator.modelContext` interface is introduced for the site to declare functionality that can be used by an AI Agent. Access to these tools is arbitrated by the browser. The `modelContext` object has a `provideContext` method that's used to update the context (currently just tools) available to these agents. The method takes an object with a `tools` property which is a list of tool descriptors. The tool descriptors look as shown in this example below, which aligns with the Prompt API's [tool use](https://github.com/webmachinelearning/prompt-api#tool-use) specification, and other libraries like the MCP SDK:
55
+
The `window.navigator.modelContext` interface is introduced for the site to declare functionality that can be used by an AI Agent. Access to these tools is arbitrated by the browser.
56
56
57
-
```js
58
-
// Declare tool schema and implementation functions.
59
-
window.navigator.modelContext.provideContext({
60
-
tools: [
61
-
{
62
-
name:"add-todo",
63
-
description:"Add a new todo item to the list",
64
-
inputSchema: {
65
-
type:"object",
66
-
properties: {
67
-
text: { type:"string", description:"The text of the todo item" }
68
-
},
69
-
required: ["text"]
70
-
},
71
-
execute: ({ text }, agent) => {
72
-
// Add todo item and update UI.
73
-
return/* structured content response */
74
-
}
75
-
}
76
-
]
77
-
});
78
-
```
79
-
80
-
The `provideContext` method can be called multiple times. Subsequent calls clear any pre-existing tools and other context before registering the new ones. This is useful for single-page web apps that frequently change UI state and could benefit from presenting different tools depending on which state the UI is currently in. For a list of tools passed to `provideContext`, each tool name in the list is expected to be unique.
81
-
82
-
Alternatively, the `registerTool`/`unregisterTool` APIs can be used to add/remove tools from the registered set without resetting the state entirely.
57
+
The `modelContext`'s `registerTool()` and `unregisterTool()` methods are used to add and remove tools from the agent's context.
The `agent` interface is introduced to represent an AI Agent using the functionality declared by the site through the `modelContext`. The lifetime of this interface is scoped to the execution of a tool. It is passed as a parameter when executing a tool's function. This interface provides the dependencies required by the site from the Agent.
106
82
@@ -246,30 +222,28 @@ function addStamp(stampName, stampDescription, stampYear, stampImageUrl) {
246
222
}
247
223
```
248
224
249
-
To let AI agents use this functionality, the author defines the available tools. The `agent` property on the `Window` is checked to ensure the browser supports WebMCP. If supported, the `provideContext()` method is called, passing in an array of tools with a single item, a definition for the new "Add Stamp" tool. The tool accepts as parameters the same set of fields that are present in the HTML form, since this tool and the form should be functionally equivalent.
225
+
To let AI agents use this functionality, the author defines the available tools. The `modelContext` property on the `Window` is checked to ensure the browser supports WebMCP. If supported, the `registerTool()` method is called with an object describing the new "Add Stamp" tool. The tool accepts as parameters the same set of fields that are present in the HTML form, since this tool and the form should be functionally equivalent.
250
226
251
227
```js
252
228
if ("modelContext"inwindow.navigator) {
253
-
window.navigator.modelContext.provideContext({
254
-
tools: [
255
-
{
256
-
name:"add-stamp",
257
-
description:"Add a new stamp to the collection",
258
-
inputSchema: {
259
-
type:"object",
260
-
properties: {
261
-
name: { type:"string", description:"The name of the stamp" },
262
-
description: { type:"string", description:"A brief description of the stamp" },
263
-
year: { type:"number", description:"The year the stamp was issued" },
264
-
imageUrl: { type:"string", description:"An optional image URL for the stamp" }
265
-
},
266
-
required: ["name", "description", "year"]
229
+
window.navigator.modelContext.registerTool({
230
+
{
231
+
name:"add-stamp",
232
+
description:"Add a new stamp to the collection",
233
+
inputSchema: {
234
+
type:"object",
235
+
properties: {
236
+
name: { type:"string", description:"The name of the stamp" },
237
+
description: { type:"string", description:"A brief description of the stamp" },
238
+
year: { type:"number", description:"The year the stamp was issued" },
239
+
imageUrl: { type:"string", description:"An optional image URL for the stamp" }
<p>Registers the provided context (tools) with the browser. This method clears any pre-existing tools and other context before registering the new ones.
<p>Registers a single tool without clearing the existing set of tools. The method throws an error, if a tool with the same name already exists, or if the {{ModelContextTool/inputSchema}} is invalid.
@@ -210,20 +198,6 @@ is a [=model context=] [=struct=] created alongside the {{ModelContext}}.
210
198
</dd>
211
199
</dl>
212
200
213
-
<div algorithm>
214
-
The <dfn method for=ModelContext>provideContext(<var ignore>options</var>)</dfn> method steps are:
215
-
216
-
1. TODO: fill this out.
217
-
218
-
</div>
219
-
220
-
<div algorithm>
221
-
The <dfn method for=ModelContext>clearContext()</dfn> method steps are:
222
-
223
-
1. TODO: fill this out.
224
-
225
-
</div>
226
-
227
201
228
202
<div algorithm>
229
203
The <dfn method for=ModelContext>registerTool(<var>tool</var>)</dfn> method steps are:
@@ -294,21 +268,6 @@ The <dfn method for=ModelContext>unregisterTool(<var>name</var>)</dfn> method st
0 commit comments