Skip to content

Commit f15fe17

Browse files
samuelcoleclaude
andauthored
Drop agent.tools.list() and call(), and sessions' direct tool calls, in favor of WebMCP (#140)
A page reaches its own tools through WebMCP (document.modelContext.getTools() and executeTool()). The person's installed tools now reach a site only through the person's agent, in agent.run() or agent.chat.open(). Neither window.agent nor a session can call them directly any more. Removed, with no alias: - window.agent.tools.list() and call(), their handlers and message types, and surfaces.tools in agent.capabilities(). - A session's callTool(), listAllowedTools(), tools capability and maxToolCalls budget, and its tool-call count in the sidebar. A tool.call action in requestCapabilities() now grants nothing. - ERR_TOOL_NOT_ALLOWED, ERR_TOOL_NOT_FOUND and ERR_BUDGET_EXCEEDED, which only those paths sent. Kept: the mcp:tools.list and mcp:tools.call scopes and the per-site tool allowlist, which the built-in agent.run() still checks; agent.run()'s own maxToolCalls; and the Tool access setting, which now covers agent.mcp.register(). The consent text for the two scopes and the Tool access card now say what they permit. The demos, spec example, test-harness mock and types, E2E tests, about 25 docs and the spec move to WebMCP or agent.run(). A new Firefox E2E checks that a page registers, lists and calls its own tool through document.modelContext, and that window.agent.tools is gone. Also fixed: - test-getting-started.mjs read Firefox's tab list before the page loaded, so it failed on main. It also expected a walkthrough step that's gone. - Docs said agent.run() sent ERR_BUDGET_EXCEEDED; a spent run stops calling tools and answers. - ARCHITECTURE.md described a rate limiter that doesn't exist. - spec/explainer.md's proposed capabilities() report exposed the person's installed tools, and its shipped signature said surfaces.ai instead of surfaces.languageModel. - spec/security-privacy.md cited a direct tool call and a deleted handler. - docs/agent-workflow.md records two test-setup pitfalls. Fixes HBR-183 Co-Authored-By: Claude Opus 5.5 (Claude Code) <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 (Claude Code) <noreply@anthropic.com>
1 parent bd3a316 commit f15fe17

82 files changed

Lines changed: 1011 additions & 2498 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎ARCHITECTURE.md‎

Lines changed: 7 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ await window.agent.requestPermissions({
5959
reason: 'Enable AI features'
6060
});
6161

62-
const tools = await window.agent.tools.list();
6362
for await (const event of window.agent.run({ task: 'Search for news' })) {
6463
console.log(event);
6564
}
@@ -118,7 +117,6 @@ For LLM inference and native MCP servers, Harbor uses a Rust native messaging br
118117
│ LanguageModel window.agent │
119118
│ ├── availability() ├── requestPermissions() │
120119
│ └── create() ├── capabilities() │
121-
│ ├── tools.list() / tools.call() │
122120
│ ├── browser.activeTab.* │
123121
│ ├── run({ task }) │
124122
│ ├── sessions.create() │
@@ -245,7 +243,7 @@ Every page-facing member exists and calls through regardless of these flags; a t
245243
|------|-------------|---------|
246244
| `textGeneration` | Gates `LanguageModel` (prompts and prompt streaming; `availability()` reports `"unavailable"` instead of refusing) | `true` |
247245
| `toolCalling` | Gates `agent.run()` for autonomous tasks | `true` |
248-
| `toolAccess` | Gates `agent.tools.list()` and `call()` | `true` |
246+
| `toolAccess` | Gates `agent.mcp.register()`, a site registering its own MCP server (`discover()` and `unregister()` aren't gated) | `true` |
249247
| `browserInteraction` | Gates click/fill/scroll on pages | `false` |
250248
| `browserControl` | Gates navigation and tab management | `false` |
251249
| `multiAgent` | Gates multi-agent orchestration | `false` |
@@ -356,12 +354,12 @@ Web Page Extension Bridge
356354
│ "Hello! How can I help?" │ │ │
357355
```
358356

359-
### 2. Tool Call Flow
357+
### 2. Tool Call Flow (inside an agent.run())
360358

361359
```
362360
Web Page Extension Bridge MCP Server
363361
│ │ │ │
364-
│ agent.tools.call(...) │ │ │
362+
│ agent.run({ task, tools })│ │ │
365363
├──────────────────────────►│ │ │
366364
│ │ ① Check permission │ │
367365
│ │ ② host_call_tool │ │
@@ -401,12 +399,12 @@ User: "Find my recent GitHub PRs and summarize them"
401399
"You have 3 open PRs: #123 fixes auth bug, #124 adds dark mode..."
402400
```
403401

404-
### 4. In-Browser Tool Call (WASM/JS)
402+
### 4. In-Browser Tool Call (WASM/JS, inside an agent.run())
405403

406404
```
407405
Web Page Extension WASM/JS Runtime
408406
│ │ │
409-
│ tools.call('time/now') │ │
407+
│ agent.run({ task: '…', tools: ['time/now'] }) │
410408
├──────────────────────────►│ │
411409
│ │ ① Check permission │
412410
│ │ ② Route to runtime │
@@ -802,8 +800,8 @@ Permissions are scoped per-origin with capability-based grants. Harbor holds the
802800
|-------|-------------|------------------|
803801
| `model:prompt` | Basic text generation | `LanguageModel.create()` (asked for by `create()` itself if missing) |
804802
| `model:tools` | AI with tool calling | `agent.run()` |
805-
| `mcp:tools.list` | List available tools | `agent.tools.list()` |
806-
| `mcp:tools.call` | Execute tools | `agent.tools.call()` |
803+
| `mcp:tools.list` | Let your agent see your installed tools | `agent.run()` |
804+
| `mcp:tools.call` | Let your agent use your installed tools | `agent.run()` |
807805
| `mcp:servers.register` | Register website MCP servers | `agent.mcp.register()` |
808806
| `browser:activeTab.read` | Read active tab | `agent.browser.activeTab.readability()` |
809807
| `chat:open` | Open browser chat UI | `agent.chat.open()` |
@@ -879,31 +877,6 @@ Tools available for invocation
879877

880878
---
881879

882-
## Rate Limiting
883-
884-
| Limit | Default | Purpose |
885-
|-------|---------|---------|
886-
| `maxCallsPerRun` | 5 | Prevent runaway agent loops |
887-
| `maxConcurrentPerOrigin` | 2 | Fair resource sharing |
888-
| `defaultTimeoutMs` | 30,000 | Prevent hanging calls |
889-
890-
### Budget Tracking
891-
892-
```typescript
893-
// Create a run with budget
894-
const run = rateLimiter.createRun(origin, 5);
895-
896-
// Each tool call decrements budget
897-
await rateLimiter.acquireCallSlot(origin, run.runId);
898-
// → Budget: 5 → 4
899-
900-
// Exceeding budget returns error
901-
await rateLimiter.acquireCallSlot(origin, run.runId);
902-
// → ERR_BUDGET_EXCEEDED
903-
```
904-
905-
---
906-
907880
## Server Lifecycle
908881

909882
```
@@ -960,13 +933,11 @@ A sample of the codes these layers return:
960933
| `ERR_TIMEOUT` | Request timed out |
961934
| `ERR_INVALID_REQUEST` | Invalid request format |
962935
| `ERR_PERMISSION_DENIED` | Permission denied by user or policy |
963-
| `ERR_TOOL_NOT_ALLOWED` | Tool not in allowlist |
964936
| `ERR_SESSION_NOT_FOUND` | Session not found |
965937
| `ERR_AGENT_NOT_FOUND` | Agent not found |
966938
| `ERR_TOOL_FAILED` | Tool execution failed |
967939
| `ERR_MODEL_FAILED` | Model/LLM execution failed |
968940
| `ERR_AGENT_NOT_ACCEPTING` | Agent not accepting requests |
969-
| `ERR_BUDGET_EXCEEDED` | Budget exceeded (tool calls, tokens, etc.) |
970941
| `ERR_INTERNAL` | Internal error |
971942

972943
See [docs/WEB_AGENTS_API.md#error-handling](docs/WEB_AGENTS_API.md#error-handling) for the full list.

‎CHANGELOG.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Changed
1111

1212
- **Firefox 128 or later is now required.** `"world": "MAIN"` in a manifest content script, which `injected.js` relies on, needs Firefox 128; an older Firefox would run it in the isolated world instead.
13-
- **`LanguageModel`, `window.agent` and `document.modelContext` now exist before a page's own scripts run, not just after the page has finished loading.** `injected.js` runs as a main-world content script at `document_start` (declared directly in the Firefox and Chrome manifests; registered at runtime with `scripting.registerContentScripts` on Safari), instead of a `<script src>` the old isolated-world content script inserted, which Firefox didn't run until the page's own parser had already finished. A turned-off feature flag no longer removes an API or any of its members — `agent.tools`, `agent.browser.*`, `agent.agents.*` and the rest always exist and call through; the background refuses the call (`ERR_FEATURE_DISABLED`) when its flag is off, same as it already did for a page calling the transport directly. `LanguageModel` itself is always defined unless a native one already exists, and `LanguageModel.availability()` resolves `"unavailable"` with Text Generation off rather than rejecting, matching the Prompt API's own contract that `availability()` never rejects. `agent.capabilities()` reports the flags synchronously, but can still read Harbor's defaults for a script that calls it before the first `agent-ready`, which fires once `DOMContentLoaded` has happened — confirmed even if `injected.js` starts after that already did, such as in a tab that was already open when Harbor installed or was enabled — and Harbor knows the person's real settings, whichever is later, then again, but only when a setting actually changes (never a repeat firing for the same six flags, which a flags delivery can otherwise carry more than once, including across a back/forward cache restore).
13+
- **`LanguageModel`, `window.agent` and `document.modelContext` now exist before a page's own scripts run, not just after the page has finished loading.** `injected.js` runs as a main-world content script at `document_start` (declared directly in the Firefox and Chrome manifests; registered at runtime with `scripting.registerContentScripts` on Safari), instead of a `<script src>` the old isolated-world content script inserted, which Firefox didn't run until the page's own parser had already finished. A turned-off feature flag no longer removes an API or any of its members — `agent.browser.*`, `agent.agents.*` and the rest always exist and call through; the background refuses the call (`ERR_FEATURE_DISABLED`) when its flag is off, same as it already did for a page calling the transport directly. `LanguageModel` itself is always defined unless a native one already exists, and `LanguageModel.availability()` resolves `"unavailable"` with Text Generation off rather than rejecting, matching the Prompt API's own contract that `availability()` never rejects. `agent.capabilities()` reports the flags synchronously, but can still read Harbor's defaults for a script that calls it before the first `agent-ready`, which fires once `DOMContentLoaded` has happened — confirmed even if `injected.js` starts after that already did, such as in a tab that was already open when Harbor installed or was enabled — and Harbor knows the person's real settings, whichever is later, then again, but only when a setting actually changes (never a repeat firing for the same six flags, which a flags delivery can otherwise carry more than once, including across a back/forward cache restore).
1414
- **`window.ai` is replaced by the Prompt API's `LanguageModel`.** Pages call `LanguageModel.availability()` and `LanguageModel.create()` (https://webmachinelearning.github.io/prompt-api/) instead of `window.ai.canCreateTextSession()` / `createTextSession()` / `languageModel.capabilities()` / `languageModel.create()`. `create()` asks you for the `model:prompt` grant itself if the site doesn't already have it, and rejects with `NotAllowedError` on Deny; `availability()` needs no grant. The `providers.*` calls and the `model:list` permission scope are removed, along with the `{ provider, model }` session option — you pick your model or agent in Harbor, not the page.
1515
- **`document.modelContext` now matches the current [WebMCP draft](https://webmachinelearning.github.io/webmcp/).** `registerTool()` keeps the same shape, but `document.modelContext` is now a full `ModelContext`: `getTools()` resolves to this document's own tools, sorted by name, each with a `title` (`""` if you didn't give one) and `annotations` (all four hints, defaulted, if you gave any at all — `null` if you didn't); `executeTool(tool, inputObject)` runs a tool the page itself registered, with no permission needed, accepts any object including arrays, and resolves to the JSON serialization of the result; `waitForToolsUntil(promise)` holds the agent-facing tool list for up to 10 seconds from your first call, a deadline later calls can't extend; and `toolchange`, `toolactivated` and `toolcancel` all fire on `document.modelContext` for a real execution, agent-called or your own `executeTool()` alike. `navigator.modelContext`, `addTool()`, `removeTool()` and the `tools` getter are removed, with no alias; unregister by aborting the `signal` passed to `registerTool()`'s options, and list tools with `getTools()`. `exposedTo` entries are validated (`SecurityError` for an invalid or non-trustworthy origin) but otherwise accepted with no effect, and a non-empty `fromOrigins` still adds nothing, because Harbor's polyfill injects into the top frame only. A document other than the page's own, such as one from `createHTMLDocument()`, gets its own `modelContext` whose methods all reject or throw `InvalidStateError`.
1616
- **Tool hints are the WebMCP draft's four, not MCP's seven.** A page tool's `annotations` keep only `readOnlyHint`, `untrustedContentHint`, `consequentialHint` and `debugging`. MCP's `destructiveHint`, `idempotentHint` and `openWorldHint` are no longer accepted, on the page, in the background, or in the text Harbor's built-in model is told about a tool.
17+
- **The tool permissions now say what they let a site do.** A site can no longer call your installed tools itself, so the prompt for `mcp:tools.list` and `mcp:tools.call` now asks whether your agent may see and use your installed tools while it works for that site ("Use your tools"). The sidebar's **Tool access** setting now covers a site registering its own tool server (`agent.mcp.register()`), the only page call it still controls.
1718

1819
### Added
1920

@@ -156,6 +157,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
156157

157158
### Removed
158159

160+
- `window.agent.tools.list()` and `agent.tools.call()`, with no alias. A page reaches its own tools through WebMCP (`document.modelContext.getTools()` and `executeTool()`). The person's installed tools are reachable only through their agent, inside `agent.run()` or `agent.chat.open()`.
161+
- A session's `callTool()`, `listAllowedTools()`, its `tools` capability, and its `maxToolCalls` limit. Sessions now carry LLM and browser capabilities only. To call a tool, start `agent.run()`, which keeps its own `maxToolCalls`.
162+
- The error codes only those calls sent: `ERR_TOOL_NOT_ALLOWED`, `ERR_TOOL_NOT_FOUND` and `ERR_BUDGET_EXCEEDED`. Several docs said `agent.run()` could send them; it never did. When a run spends its `maxToolCalls`, it stops calling tools and gives its answer.
159163
- Error codes Harbor documented but never sent: `ERR_USER_GESTURE_REQUIRED`, `ERR_SCOPE_REQUIRED`, `ERR_NOT_INSTALLED`, `ERR_TOOL_TIMEOUT`, `ERR_RATE_LIMITED` and a few MCP and bridge codes. They're gone from the docs and the spec. A missing scope is `ERR_PERMISSION_DENIED`, a page tool that times out is `ERR_TOOL_FAILED`, and a page without Harbor has no `window.agent` at all.
160164
- The sidebar's **Open Chat** button and the chat page bundled inside the extension. That page ran its own copy of `window.agent` with every permission treated as granted, so it skipped the permission checks and loop fixes that web pages get. To chat with tools, use the demo-site chat (`demo/web-agents/chat-poc/`), which goes through the same `agent.run` as any site. The extension also no longer exposes `demo/*` or `demo-bootstrap.js` to web pages.
161165
- The old Jekyll scaffolding under `whitepaper/` (`_config.yml`, `_layouts/`, `Gemfile`, `index.md`, `landscape.md`) — replaced by static HTML. `.nojekyll` added so GitHub Pages serves the files as authored.

‎QUICKSTART.md‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -260,23 +260,19 @@ const response = await session.prompt('What is JavaScript?');
260260
session.destroy();
261261
```
262262
263-
**List and Call Tools:**
263+
**Use Your Installed Tools (through your agent):**
264+
265+
A page never calls an installed tool directly. Ask the agent to, inside
266+
`agent.run()`:
267+
264268
```javascript
265269
await window.agent.requestPermissions({
266-
scopes: ['mcp:tools.list', 'mcp:tools.call']
267-
});
268-
269-
const tools = await window.agent.tools.list();
270-
const result = await window.agent.tools.call({
271-
tool: 'time-wasm/time.now',
272-
args: { timezone: 'America/New_York' }
270+
scopes: ['model:tools', 'mcp:tools.list', 'mcp:tools.call']
273271
});
274-
```
275272
276-
**Autonomous Agent:**
277-
```javascript
278273
for await (const event of window.agent.run({
279274
task: 'What is the current time in Tokyo?',
275+
tools: ['time-wasm/time.now'],
280276
maxToolCalls: 5
281277
})) {
282278
if (event.type === 'final') {
@@ -333,11 +329,15 @@ async function handleToolCall(toolName, args) {
333329
334330
### 4. Use Your Tool
335331
332+
Ask your agent to use it, inside `agent.run()`:
333+
336334
```javascript
337-
const result = await window.agent.tools.call({
338-
tool: 'my-tool/my_tool',
339-
args: { input: 'hello world' }
340-
});
335+
for await (const event of window.agent.run({
336+
task: 'Process this: hello world',
337+
tools: ['my-tool/my_tool'],
338+
})) {
339+
if (event.type === 'final') console.log(event.output);
340+
}
341341
```
342342
343343
→ **[MCP Authoring Guide](mcp-servers/AUTHORING_GUIDE.md)**

‎README.md‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,8 @@ The Web Agent API gives your web pages access to:
6767
| API | What It Does |
6868
|-----|--------------|
6969
| `LanguageModel.create()` | Chat with AI models (asks for consent itself, if needed) |
70-
| `window.agent.tools.list()` | List available MCP tools |
71-
| `window.agent.tools.call()` | Execute tools (search, files, databases) |
72-
| `window.agent.run()` | Run autonomous agent tasks |
70+
| `document.modelContext.registerTool()` | Register your page's own tools (WebMCP) |
71+
| `window.agent.run()` | Run autonomous agent tasks, including the person's installed tools (search, files, databases) |
7372
| `window.agent.browser.activeTab.readability()` | Read page content |
7473

7574
### Minimal Example

‎demo/web-agents/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ Basic Web Agent API demos for LLM and MCP server access.
1515

1616
- `LanguageModel.create()` - LLM sessions
1717
- `window.agent.requestPermissions()` - Permission management
18-
- `window.agent.tools.list()` - List MCP tools
19-
- `window.agent.run()` - Autonomous agent tasks
18+
- `window.agent.run()` - Autonomous agent tasks, including the person's installed MCP tools
19+
- `document.modelContext.registerTool()` / `getTools()` / `executeTool()` - A page's own tools (the WebMCP draft)
2020
- `window.agent.chat.open()` - Open your agent's chat on a page

0 commit comments

Comments
 (0)