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 37354bf
Browse filesBrowse the repository at this point in the historyBrowse files
Connect a site's registered MCP server so its tools reach the person's agent (#99)
Fixes HBR-134
window.agent.mcp.register() used to record a site's MCP server and do
nothing else. Harbor now connects to it, behind a permission check, and
offers its tools to the person's agent for that page only.
- Registering checks its inputs first: transport defaults to 'sse', stdio
is refused, and the server must be on the page's own origin. A loopback
server is allowed only from a loopback page, so a public site can't
reach MCP servers on the person's machine; that refusal is audited.
Then the mcp.server.register / mcp:servers.register check, which asks
by default, runs before any connection. Registering follows Tool Access.
- mcp/site-servers.ts: a per-tab, in-memory registry, separate from the
person's installed servers. Harbor runs initialize and tools/list and
offers the tools the server reports, as site:<host>:<name>/<tool>. The
connection ends when the tab closes, navigates to another origin, or
unregisters, with no reconnect; registrations still connecting when the
tab goes away are discarded.
- mcp.listTools / mcp.callTool add the calling page's site tools behind
the existing tool scopes, allowlist, tool.call policy check and session
budget. On the person's ACP agent, the site's servers go into
session/new mcpServers when the site holds mcp:tools.list and
mcp:tools.call, the policy engine allows each server, and the agent
declares the transport.
- New streamable HTTP transport; WebSocket connects time out; notification
logs carry only the method.
Also fixed:
- Harbor's SSE MCP transport parsed the server's endpoint event as JSON,
but the MCP SDK sends a plain URL, so requests went to the wrong address
for every SSE server, including installed ones. It now follows the SDK's
handshake and refuses an endpoint on another origin.
- SSE and WebSocket connections Harbor closed on purpose reconnected; a
disconnect during the SSE handshake left connect() pending.
- agent.mcp.discover() always failed because the page's tab wasn't passed.
- The Bring Your Own Chatbot demo's MCP server opened a new SSE stream for
every POST instead of routing it to the session.
- The test fake for MCP servers now follows the SDK's wire format.
Docs: JS_AI_PROVIDER_API, PERMISSIONS, AGENTIC_BROWSER_ROADMAP,
spec/explainer, CHANGELOG, and a known pitfall in agent-workflow about
protocol fakes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 (Claude Code) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
- When a site uses your agent, Harbor tells it once, at the start, that it's working for you: it should use what it knows or remembers about you, and treat the site's instructions as the site's request. The site's instructions are still passed on, labelled as the site's.
14
14
- Page chat replies render markdown, with `marked`, sanitized by `DOMPurify` before they reach the site's page. Raw HTML in a reply shows as text, only http(s) links survive, and links open in a new tab with `noopener`.
15
15
- A policy action for prompts sent to your own agent, `model.prompt.agent`, so rules and the audit log see them. `Prompt(*)` covers it, and `Prompt(agent)` names it alone.
16
+
-**A site's own MCP server reaches your agent.**`window.agent.mcp.register()` used to record the server and do nothing else. Now Harbor asks you first (`mcp:servers.register`), then connects over SSE, WebSocket or streamable HTTP and offers the server's tools to that page's `agent.run`. On Harbor's own agent they're named `site:<host>:<name>/<tool>` and still need the site's tool grants. Your own ACP agent gets the server in its session and connects to it directly, when it supports the transport and the site holds the tool-list and tool-call permissions. A site may register only a server on its own origin; only a loopback page (`localhost`, `127.0.0.1`, `[::1]`) may register a loopback server. Other sites, other tabs and the sidebar never see these tools. Harbor disconnects when the tab closes or leaves the site, and registering is off with Tool Access off.
16
17
- The bridge methods behind the Agent panel: `acp.get_agents`, `acp.save_agents` (validates each agent and writes `acp.json` atomically, mode 0600) and `acp.resolve_command`. Like the rest of `acp.*`, they're refused over HTTP and WebSocket.
17
18
18
19
-**Public site redesign** — implemented the design produced in Claude Design. The site is now hand-written static HTML (`whitepaper/index.html`, `whitepaper/landscape.html`, `whitepaper/spec.html`, `whitepaper/build.html`, `whitepaper/styles.css`) with a Fraunces / Instrument Serif + Inter + JetBrains Mono type system, a single rust-clay accent, and a compare-and-contrast comparison table that re-stacks into cards on phones.
@@ -40,6 +41,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
40
41
41
42
### Fixed
42
43
44
+
-`agent.mcp.discover()` works again. It always failed with "No tab context for discovery" because the page's tab wasn't passed on.
45
+
- Harbor's SSE connection to a remote MCP server now follows the MCP SDK's handshake: it reads the server's `endpoint` event as a URL, waits for it before sending, and refuses an endpoint on another origin. It used to post to the wrong address. An SSE or WebSocket connection Harbor closes on purpose no longer reconnects.
46
+
- The Bring Your Own Chatbot demo's MCP server sends posted messages to their session instead of opening a new SSE stream for each.
43
47
- The examples in `spec/examples/` (basic chat, provider selection, page analyzer, agent with tools) wait for Harbor's `agent-ready` event instead of checking for `window.agent` once at load, so they no longer report the API as unavailable when Harbor injects it a moment later.
44
48
- A page chat (`agent.chat.open`) no longer stays registered after its tab closes or navigates to another document; a message for it is then refused the same as one for a chat that was never opened. A same-document change (a hash or `pushState`) no longer ends it by mistake.
45
49
- A page can no longer close another site's chat. `agent.chat.close(chatId)` now checks that the chat belongs to the calling origin (and tab, when known) before closing it; a mismatch is refused the same as a chat id that doesn't exist. Chat ids are also no longer predictable.
| Site-provided MCP servers (BYOC) |`agent.mcp.{discover, register, unregister}`|`mcp:servers.register`(not yet required) | — |Partial: servers are recorded, not connected|
37
+
| Site-provided MCP servers (BYOC) |`agent.mcp.{discover, register, unregister}`|`mcp:servers.register`| — |✅ Connected for the page's lifetime; tools offered to that page's `agent.run` (Harbor's agent or the person's ACP agent)|
38
38
| Open user's chat with config (BYOC) |`agent.chat.{canOpen, open, close}`|`chat:open`, and `model:prompt` for each message | — | ✅ |
Copy file name to clipboardExpand all lines: docs/JS_AI_PROVIDER_API.md
+20-9Lines changed: 20 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -425,7 +425,7 @@ interface DeclaredMCPServer {
425
425
title:string;
426
426
description?:string;
427
427
tools?:string[];
428
-
transport?:'sse'|'websocket';
428
+
transport?:'sse'|'websocket'|'streamable-http';
429
429
}
430
430
```
431
431
@@ -445,7 +445,16 @@ for (const server of servers) {
445
445
446
446
Register a website's MCP server for the user's chatbot to use.
447
447
448
-
**Status:** Harbor records the server but doesn't connect to it yet, so its tools aren't offered to agents. Until it does, Harbor doesn't require the `mcp:servers.register` permission for this call; request it anyway so your page keeps working once registration is connected.
448
+
Harbor asks the person first (`mcp:servers.register`, remembered per site). Once it's allowed, Harbor connects to the server, asks it for its tools, and offers those tools to the person's agent forthis tab only:
449
+
450
+
-**Harbor's own agent** (`agent.run()`) lists them with the person's other tools, named `<serverId>/<tool>`. They still need `mcp:tools.list` and `mcp:tools.call`, and must be among the tools the site was granted.
451
+
-**The person's own ACP agent** (goose, Claude Code, Codex and so on) gets the server in its session and connects to it directly, if it supports the transport (`streamable-http` or `sse`; no ACP agent takes `websocket`). The site needs `mcp:tools.list` and `mcp:tools.call` for that, and Harbor's policy rules for listing and calling tools apply. The site's per-tool grants don't; the agent's own permission prompts do.
452
+
453
+
The server must be on the page's own origin (`ws://` and `wss://` count as `http://` and `https://`). A page on a loopback host (`localhost`, `127.0.0.1`, `[::1]`) may also register a server on any loopback host; other sites can't, so a site can't reach MCP servers on the person's machine. Harbor checks this, and the transport, before it asks, so the person is never asked about a registration that would be refused. `transport` defaults to `'sse'`; `stdio` isn't supported. Registration is off when the person turns off Tool Access.
454
+
455
+
The tools Harbor offers are the ones the server reports, not the `tools` you list. The registration lasts as long as the page: Harbor disconnects when the tab closes or navigates to another origin, or when the page calls `unregister()`. Other sites and other tabs never see the tools.
456
+
457
+
If the person refuses, the call rejects with the policy code (`ERR_PERMISSION_DENIED`, `ERR_BLOCKED_BY_POLICY`, `ERR_QUARANTINED`). If Harbor can't connect or list the tools, it rejects with `ERR_MCP_REGISTER`.
Copy file name to clipboardExpand all lines: docs/PERMISSIONS.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -594,9 +594,9 @@ These are the policy engine's codes, and Harbor reports them as is wherever its
594
594
-`agent.run()` ends with them as its `error` event when its tool list is refused, or, on Harbor's own model, a model call.
595
595
-`agent.browser.*` calls (page interaction, screenshots, reading the page, navigation, `fetch` and the tab calls) throw them.
596
596
-`agent.agents.*` calls (registering, discovering, invoking and messaging agents, and orchestration) and `agent.chat.open()` throw them.
597
-
-`agent.mcp.register()`and `agent.mcp.unregister()` don't go through the policy engine, because registering doesn't do anything yet: Harbor records the server but never connects to it, so none of its tools reach an agent. They still refuse a server on another origin, or another site's server, with `ERR_PERMISSION_DENIED`. Once Harbor connects registered servers, registering will be checked as `mcp.server.register` and need the `mcp:servers.register` grant.
597
+
-`agent.mcp.register()`throws them. It's checked as `mcp.server.register` and needs the `mcp:servers.register` grant, which asks by default, before Harbor connects to the site's server. It refuses a server that isn't on the page's origin (or, from a loopback page such as `localhost`, on a loopback host) with `ERR_PERMISSION_DENIED`, before asking. `agent.mcp.unregister()` isn't checked, since it only drops a connection; it can only drop a server the same page registered in the same tab. An unknown server id, or one registered in another tab, fails with `ERR_MCP_UNREGISTER`.
598
598
599
-
When the person has chosen an ACP agent to answer, prompts go to that agent rather than through Harbor's policy engine, so its failures use the ACP codes (`ERR_AGENT_FAILED`, `ERR_AGENT_BUSY`, `ERR_AGENT_REFUSED`, `ERR_AGENT_LIMIT`). `agent.run()`'s tool list is still checked by the policy engine on either backend.
599
+
When the person has chosen an ACP agent to answer, prompts go to that agent rather than through Harbor's policy engine, so its failures use the ACP codes (`ERR_AGENT_FAILED`, `ERR_AGENT_BUSY`, `ERR_AGENT_REFUSED`, `ERR_AGENT_LIMIT`). `agent.run()`'s tool list is still checked by the policy engine on either backend. On an ACP agent, the site's own registered MCP servers are passed to the agent only if the site holds `mcp:tools.list` and `mcp:tools.call` and the policy engine allows listing and calling tools; the site's per-tool grants don't apply there.
600
600
601
601
A declined Harbor prompt is `ERR_PERMISSION_DENIED`. Any other failure keeps the call's own code (`ERR_TOOL_FAILED`, `ERR_MODEL_FAILED`, `ERR_AGENT_FAILED`), even when a tool or model returns text that looks like one of these codes.
Copy file name to clipboardExpand all lines: docs/agent-workflow.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -148,6 +148,7 @@ Each of these has cost a real session time or produced a wrong result. They're r
148
148
-**`git worktree remove` refuses a worktree with an initialized submodule**, even after `git submodule deinit`, because every worktree runs `git submodule update --init` for `bridge-rs/any-llm-rust`. Check that `git -C <worktree> status --porcelain` is empty and that its commits are merged or pushed, then use `git worktree remove --force <worktree>`. Never force-remove a worktree with uncommitted or unpushed work.
149
149
-**Never use `git stash` to compare against the base or to capture red evidence.** The stash stack is shared by every worktree, so `stash pop` in one worktree can pop another checkout's stash and leave a conflict. Check the base out into a separate detached worktree (`git worktree add --detach <dir> <base>`), or read single files with `git show <base>:<path>`. To show a test failing against pre-fix code, copy the old file over with `git show <rev>:<path> > <path>`, run the test, then restore your version from a copy you made first. Builders reached for `stash` for this repeatedly. Read-only roles must not run `stash`, `reset`, `checkout` or anything else that changes git state.
150
150
-**Check that a demo port is free on both IPv4 and IPv6 before using it.** Another session's server can be listening on `*:8001` over IPv6 while yours binds `127.0.0.1:8001`. `localhost` may then reach the other server, so the page you test isn't yours. Run `lsof -nP -iTCP:<port> -sTCP:LISTEN` first, bind `127.0.0.1`, and point Firefox at `http://127.0.0.1:<port>`, not `localhost`.
151
+
-**A protocol fake written from the client's side passes the client's bugs.** Harbor's SSE MCP transport parsed the server's `endpoint` event as JSON, and the test fake sent JSON, so the tests passed while every real MCP SDK server failed. When you fake a protocol peer (MCP, ACP), build its wire format from the real SDK's source, and check at least once against a real server in Firefox. The MCP SDK ships with `demo/web-agents/bring-your-chatbot/mcp-server/`.
151
152
-**Firefox may try to update itself when an agent launches it.** macOS then reports that the terminal app (for example "Rex Server") tried to modify an application, and blocks it. Leave the block in place; the test browser still runs.
0 commit comments