Skip to content

Commit fe84c67

Browse files
authored
Remove provideContext() and clearContext() (#132)
1 parent 3da78ad commit fe84c67

2 files changed

Lines changed: 20 additions & 87 deletions

File tree

docs/proposal.md

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,9 @@ Handling tool calls in the main thread with the option of delegating to workers
5252
## API
5353

5454
### 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.
5656

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.
8358

8459
```js
8560
window.navigator.modelContext.registerTool({
@@ -101,6 +76,7 @@ window.navigator.modelContext.registerTool({
10176

10277
window.navigator.modelContext.unregisterTool("add-todo");
10378
```
79+
10480
### agent
10581
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.
10682

@@ -246,30 +222,28 @@ function addStamp(stampName, stampDescription, stampYear, stampImageUrl) {
246222
}
247223
```
248224

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.
250226

251227
```js
252228
if ("modelContext" in window.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" }
267240
},
268-
execute({ name, description, year, imageUrl }, agent) {
269-
// TODO
270-
}
241+
required: ["name", "description", "year"]
242+
},
243+
execute({ name, description, year, imageUrl }, agent) {
244+
// TODO
271245
}
272-
]
246+
}
273247
});
274248
}
275249
```

index.bs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,6 @@ The {{ModelContext}} interface provides methods for web applications to register
177177
<xmp class="idl">
178178
[Exposed=Window, SecureContext]
179179
interface ModelContext {
180-
undefined provideContext(optional ModelContextOptions options = {});
181-
undefined clearContext();
182180
undefined registerTool(ModelContextTool tool);
183181
undefined unregisterTool(DOMString name);
184182
};
@@ -189,16 +187,6 @@ is a [=model context=] [=struct=] created alongside the {{ModelContext}}.
189187

190188

191189
<dl class="domintro">
192-
<dt><code><var ignore>navigator</var>.{{Navigator/modelContext}}.{{ModelContext/provideContext(options)}}</code></dt>
193-
<dd>
194-
<p>Registers the provided context (tools) with the browser. This method clears any pre-existing tools and other context before registering the new ones.
195-
</dd>
196-
197-
<dt><code><var ignore>navigator</var>.{{Navigator/modelContext}}.{{ModelContext/clearContext()}}</code></dt>
198-
<dd>
199-
<p>Unregisters all context (tools) with the browser.
200-
</dd>
201-
202190
<dt><code><var ignore>navigator</var>.{{Navigator/modelContext}}.{{ModelContext/registerTool(tool)}}</code></dt>
203191
<dd>
204192
<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}}.
210198
</dd>
211199
</dl>
212200

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-
227201

228202
<div algorithm>
229203
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
294268

295269
</div>
296270

297-
<h4 id="model-context-options">ModelContextOptions Dictionary</h4>
298-
299-
<xmp class="idl">
300-
dictionary ModelContextOptions {
301-
sequence<ModelContextTool> tools = [];
302-
};
303-
</xmp>
304-
305-
<dl class="domintro">
306-
<dt><code><var ignore>options</var>["{{ModelContextOptions/tools}}"]</code></dt>
307-
<dd>
308-
<p>A list of {{ModelContextOptions/tools}} to register with the browser. Each tool name in the list is expected to be unique.
309-
</dd>
310-
</dl>
311-
312271
<h4 id="model-context-tool">ModelContextTool Dictionary</h4>
313272

314273
The {{ModelContextTool}} dictionary describes a tool that can be invoked by [=agents=].

0 commit comments

Comments
 (0)