@dudko.dev/agent-web 0.0.40 → 0.0.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +305 -22
- package/dist/agent-web.js +169 -161
- package/dist/agent-web.js.map +1 -1
- package/dist/chunk-2MLHZ6LQ.js +510 -0
- package/dist/chunk-2MLHZ6LQ.js.map +1 -0
- package/dist/{chunk-TZITKUFW.js → chunk-DAREMCXF.js} +152 -20
- package/dist/chunk-DAREMCXF.js.map +1 -0
- package/dist/{chunk-V3JOK7EW.js → chunk-YPCHD6DV.js} +4 -2
- package/dist/chunk-YPCHD6DV.js.map +1 -0
- package/dist/chunk-ZSZSSJS4.js +973 -0
- package/dist/chunk-ZSZSSJS4.js.map +1 -0
- package/dist/elicitation-DS-84_bF.d.cts +680 -0
- package/dist/elicitation-DS-84_bF.d.ts +680 -0
- package/dist/index.cjs +1939 -225
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +692 -117
- package/dist/index.d.ts +692 -117
- package/dist/index.js +1325 -189
- package/dist/index.js.map +1 -1
- package/dist/mcp.cjs +2478 -49
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +291 -9
- package/dist/mcp.d.ts +291 -9
- package/dist/mcp.js +1578 -48
- package/dist/mcp.js.map +1 -1
- package/dist/{sandbox-KG6OUG24.js → sandbox-3VRX47UY.js} +21 -8
- package/dist/sandbox-3VRX47UY.js.map +1 -0
- package/dist/sandbox-worker.cjs +3 -1
- package/dist/sandbox-worker.cjs.map +1 -1
- package/dist/sandbox-worker.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-A6ZJALLU.js +0 -254
- package/dist/chunk-A6ZJALLU.js.map +0 -1
- package/dist/chunk-CTXDKSDD.js +0 -39
- package/dist/chunk-CTXDKSDD.js.map +0 -1
- package/dist/chunk-TZITKUFW.js.map +0 -1
- package/dist/chunk-V3JOK7EW.js.map +0 -1
- package/dist/sandbox-KG6OUG24.js.map +0 -1
- package/dist/vault-BatBaRQP.d.cts +0 -36
- package/dist/vault-BatBaRQP.d.ts +0 -36
package/README.md
CHANGED
|
@@ -214,11 +214,64 @@ enters your core bundle.
|
|
|
214
214
|
|
|
215
215
|
The MCP client is the official 2.x SDK, **`@modelcontextprotocol/client`** (an
|
|
216
216
|
optional peer: install it when you import `./mcp`; `@modelcontextprotocol/sdk`
|
|
217
|
-
1.x is no longer used — [what to change](#upgrading-to-the-2x-mcp-sdk)).
|
|
218
|
-
negotiates the 2025 protocol revisions with the unchanged
|
|
219
|
-
handshake, so servers see the same requests and the same headers
|
|
220
|
-
server that speaks **only** the 2026-07-28 revision fails to
|
|
221
|
-
with `Unsupported protocol version: 2025-11-25` in
|
|
217
|
+
1.x is no longer used — [what to change](#upgrading-to-the-2x-mcp-sdk)). By
|
|
218
|
+
default it negotiates the 2025 protocol revisions with the unchanged
|
|
219
|
+
`initialize` handshake, so servers see the same requests and the same headers
|
|
220
|
+
as before; a server that speaks **only** the 2026-07-28 revision then fails to
|
|
221
|
+
connect, at once, with `Unsupported protocol version: 2025-11-25` in
|
|
222
|
+
`results[].error`.
|
|
223
|
+
|
|
224
|
+
**The 2026-07-28 revision is a per-server opt-in**, `protocol`:
|
|
225
|
+
|
|
226
|
+
```ts
|
|
227
|
+
const mcp = await connectMcpHttp({
|
|
228
|
+
docs: { url: 'https://docs.example.com/mcp' }, // 'legacy', the default
|
|
229
|
+
crm: { url: 'https://crm.example.com/mcp', protocol: 'auto' },
|
|
230
|
+
files: { url: 'https://files.example.com/mcp', protocol: 'modern' },
|
|
231
|
+
})
|
|
232
|
+
mcp.protocols // [{ server: 'docs', version: '2025-11-25', era: 'legacy' }, { server: 'crm', version: '2026-07-28', era: 'modern' }, …]
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
| `protocol` | What is spoken | Against a server of the other kind |
|
|
236
|
+
| --- | --- | --- |
|
|
237
|
+
| `'legacy'` (default, same as leaving it out) | The 2025 revisions: exactly the requests and the request headers sent before the option existed (a test compares them with a recording made before it). | Only 2026-07-28: `Unsupported protocol version: 2025-11-25`, at once. |
|
|
238
|
+
| `'auto'` | The server is asked first (`server/discover`). One that answers with 2026-07-28 is spoken to that way; any other gets the 2025 handshake. | Works with both. An HTTP 5xx, an answer that is not JSON-RPC or no answer fails the connect: an outage is not read as "an old server". |
|
|
239
|
+
| `'modern'` | 2026-07-28 only. | A 2025 server: `the server did not offer pinned protocol version 2026-07-28 …`, at once. |
|
|
240
|
+
|
|
241
|
+
The revision is decided **once, at connect**; no tool call is ever sent again in
|
|
242
|
+
another revision. `protocols` says what each connected server negotiated, and
|
|
243
|
+
for a server with `protocol` set an `info` line goes to `onLog`
|
|
244
|
+
(`[mcp] crm: protocol 2026-07-28 (modern: …; configured 'auto')`).
|
|
245
|
+
|
|
246
|
+
On 2026-07-28: there is no session (`mcp-session-id`), no GET stream and no
|
|
247
|
+
`initialize`; `instructions`, `isError`, `structuredContent` and the
|
|
248
|
+
`outputSchema` note work as before; OAuth is unchanged. Three things differ:
|
|
249
|
+
|
|
250
|
+
- **CORS.** Every request carries `Mcp-Method` and `Mcp-Name`, and
|
|
251
|
+
`MCP-Protocol-Version` from the first one on: the server must allow them
|
|
252
|
+
([below](#cors-what-the-server-must-send)). A server that does not cannot be
|
|
253
|
+
reached that way from a page. `'modern'` then fails, and the error names the
|
|
254
|
+
missing headers. `'auto'` cannot tell a blocked probe from an old server (the
|
|
255
|
+
browser says nothing), so it falls back to the 2025 revisions and logs a
|
|
256
|
+
`warn` line that names the headers - or, when the server speaks only
|
|
257
|
+
2026-07-28, fails with that same explanation.
|
|
258
|
+
- **Tool list changes** arrive over a `subscriptions/listen` stream, which the
|
|
259
|
+
connector opens at connect when you pass `onToolsChanged` and the server
|
|
260
|
+
advertises `tools.listChanged`. When that stream ends while the connection is
|
|
261
|
+
open - dropped, or closed by the server with its result - it is **opened
|
|
262
|
+
again**, with backoff (at most 1 s, 2 s, 4 s, ... up to 60 s, less a random
|
|
263
|
+
share of up to half; the count starts over after a stream that stayed up a
|
|
264
|
+
minute), and once it is back `onToolsChanged(name)` fires once, exactly as
|
|
265
|
+
for a notice: a change made in the gap was announced to nobody. After 10
|
|
266
|
+
attempts in a row it gives up; a 401 / 403 / 404 / 405 (or `-32601`) stops
|
|
267
|
+
it at once. One `warn` per loss with the attempt and the delay, one `info`
|
|
268
|
+
when it is back, one `warn` on giving up. `close()` takes down a pending
|
|
269
|
+
retry and an attempt in flight. `refreshServer(name)` always works. No
|
|
270
|
+
setting: see [docs/design.md](docs/design.md#mcp-the-listen-stream-is-opened-again).
|
|
271
|
+
- **`input_required` needs `onElicitation`.** Without it, a tool that asks the
|
|
272
|
+
user something (elicitation), or asks for the call to be sent again with a
|
|
273
|
+
state, fails with `MCP tool "x" did not finish: the server asked for more
|
|
274
|
+
input …`; the call is not repeated. With it, see [Elicitation](#elicitation-a-server-asks-the-user).
|
|
222
275
|
|
|
223
276
|
Pass several servers at once — they connect concurrently, each with its own
|
|
224
277
|
deadline (`connectTimeoutMs`, default 30 s), every page of a paginated
|
|
@@ -243,19 +296,201 @@ SDK added — read `error.code` for the number. A paginated `tools/list` is
|
|
|
243
296
|
followed for up to 100 pages (a repeated cursor ends the walk; past the cap a
|
|
244
297
|
`warn` line says the rest is not mounted).
|
|
245
298
|
|
|
246
|
-
`connectMcpHttp` returns `{ tools, catalog, results, instructions, refreshServer, close }`.
|
|
299
|
+
`connectMcpHttp` returns `{ tools, catalog, results, instructions, protocols, refreshServer, close }`.
|
|
247
300
|
`tools` and `catalog` are mutated **in place** by `refreshServer(name)`, so an
|
|
248
301
|
agent built from them picks up a server's new tool list (react to it via the
|
|
249
302
|
`onToolsChanged` option) without being rebuilt. Filtering is plain object work:
|
|
250
303
|
delete the keys you don't want before merging.
|
|
251
304
|
|
|
305
|
+
### MCP skills (experimental): a server's instructions as skills
|
|
306
|
+
|
|
307
|
+
A server may serve **skills** (the [Skills extension](https://github.com/modelcontextprotocol/ext-skills),
|
|
308
|
+
`io.modelcontextprotocol/skills`, Beta, written against 2026-07-28): `SKILL.md` instruction files
|
|
309
|
+
and the files they bundle. Opt in per server - they come with its tools:
|
|
310
|
+
|
|
311
|
+
```ts
|
|
312
|
+
const mcp = await connectMcpHttp({
|
|
313
|
+
docs: { url: 'https://docs.example.com/mcp', protocol: 'auto', skills: true },
|
|
314
|
+
// a server you vetted: its skills load without a question
|
|
315
|
+
ours: { url: 'https://mcp.internal.example/mcp', protocol: 'auto', skills: { consent: 'never' } },
|
|
316
|
+
// a server you trust with its GENERATED skills (no checksums): read whole, that copy approved
|
|
317
|
+
gen: { url: 'https://gen.example.com/mcp', protocol: 'auto', skills: { dynamic: true } },
|
|
318
|
+
})
|
|
319
|
+
const agent = await createAgent({
|
|
320
|
+
model,
|
|
321
|
+
tools: { ...mcp.tools },
|
|
322
|
+
toolApproval: { onRequest: askThePerson }, // a request with `skill`: show it, then answer
|
|
323
|
+
})
|
|
324
|
+
agent.skills // [{ name: 'docs/pdf-processing', description: '… [from the MCP server "docs" - third-party]', server: 'docs' }, …]
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
| | |
|
|
328
|
+
| --- | --- |
|
|
329
|
+
| Off by default | Without `skills` (`true`, or `{ consent, dynamic }`) the extension is not declared and nothing of it is sent. It is declared only where 2026-07-28 may be spoken (`protocol: 'auto'` / `'modern'`); `'legacy'` (or none) logs a `warn` and asks nothing, an `'auto'` connection that ends on 2025 lists nothing. No agent-wide switch. |
|
|
330
|
+
| One catalog, namespaced | The server's skills join your `skills` and the agent's lessons as `<server>/<skill>` (the server by its key in `connectMcpHttp`, never its `serverInfo`). No other skill name can hold a `/`: a server cannot shadow yours, a lesson or another server's - your `git-workflow` keeps its name and the clash is logged. Same-named skills of one server are kept by their paths. |
|
|
331
|
+
| On demand, verified | The prompts carry the name, the description (one line, ≤ 300 characters) and the origin. Nothing is read at connect; `SKILL.md` is read when `load_skill` or the planner asks, a file when `read_skill_file` asks - each checked against the server's entry (size, SHA-256, and for `SKILL.md` the frontmatter): a mismatch is refused, nothing of it used. A file only from the skill's own server, only if its entry lists it, as text. |
|
|
332
|
+
| Knowledge, never policy | Loaded under a preamble saying it is third-party text that cannot grant permissions, approve a call or change the approval mode, widen egress or the sandbox, or make the agent run anything. Nothing of its frontmatter beyond `name` / `description` is read (`allowed-tools` grants nothing). While a run acts on an MCP skill, a tool that runs code (`run_js`, or yours marked with `markCodeExecution`) is always asked - whatever the mode or a rule say; with no `onRequest` it is refused. |
|
|
333
|
+
| Caps | 32 skills per server, 64 in all; 16 000 characters of instructions, 32 000 of a file - every cut said. Entries over the extension's limits (512 files, 16 MiB), `"dynamic"` ones (unless the server has `skills: { dynamic: true }`) and ones whose URI and frontmatter name disagree are refused with a `warn`. |
|
|
334
|
+
| Changes | Announced as a resource list change: `onToolsChanged(name)` fires (also for that notice), and `refreshServer(name)` lists the skills again. An agent built afterwards has the new ones. |
|
|
335
|
+
| Directories | `read_skill_file` with a directory of a skill (`templates/`, `.` for the root) lists it - `{ name, directory, files, directories, more?, notServed?, note? }`, the direct children by path, at most 64 - from the entry the skill was loaded and approved with, after the same consent as a file. When the server declared `directoryRead`, `resources/directory/read` goes to THAT server too (`skill://<path>/<dir>`, no trailing slash), only to see whether the skill changed there: what it lists beyond the entry is never shown - a fixed `note` says how many, a `warn` is logged (counts only) and `onToolsChanged(name)` fires once for that loaded skill; what the entry holds and the server no longer lists is kept and named in `notServed`. A failed directory read: the listing from the entry alone, and a log line. Without `directoryRead` the method is never called. A generated skill's directories are listed from its snapshot (below), the same way. |
|
|
336
|
+
| Generated skills (opt-in) | A `"dynamic"` entry - the server generates the skill and publishes no checksums - is declined unless THAT server has `skills: { dynamic: true }` (no agent-wide switch: you trust servers with this one by one). It joins the catalog like any other, its line ending `[from the MCP server "x" - third-party, no checksums]`. When it would enter the context - BEFORE anyone is asked - the agent reads all of it once: `SKILL.md` (frontmatter compared with the entry's) and, if the server declared `directoryRead`, its directory tree (direct children each time, only `inode/directory` children inside the skill, never twice) and every file found. Bounds: 512 files and 16 MiB read per skill (the extension's limits, counted on what is read), 64 directories, 8 levels deep, and 64 MiB held by all of one agent's copies (`MCP_SKILL_SNAPSHOTS_MAX_BYTES`) - past any of them it is declined: nobody is asked, the model is told why, a `warn` says it. The agent computes each file's size and SHA-256 itself; that copy (its "snapshot") is the skill's entry from then on: the consent request carries `dynamic: true` and the copy's size, files and text, a yes binds to the copy's digests (another copy that differs in one byte - after a refresh, in a new agent - is asked about again under `'once-per-skill'`; the same bytes are not), and the model gets that copy only: its body, and every file served from memory, never read from the server again. Without `directoryRead` the copy is `SKILL.md` alone (`noFileListing: true`; no other file can be read). Nothing of a copy is written to IndexedDB, a checkpoint, an event or a log: a resumed run in a new agent reads a new one. `'never'` works too (a vetted server). |
|
|
337
|
+
| A person sees it first | Before a server's skill enters the model's context (`load_skill`, the planner's pick, a resumed run, `read_skill_file`), its verified `SKILL.md` is put to `toolApproval.onRequest`: a request with `toolName: 'load_skill'` and `skill` (`McpSkillConsentView`: server, name, description, size, files, `byUri`, `nestedIn`, `consent`, and `body` - the very text the model would read). Yes lets it in; `remember: true` = "Always for this server" (nested skills excepted); no keeps all of it out and the model is told. Asked whatever the approval mode says - autopilot too; without `onRequest` it is not loaded. When: `skills: { consent }` per server, else `mcpSkills: { consent }` on the agent, else `'once-per-skill'` (the first time per skill in the agent's life, again if its files change); `'ask'` (every run); `'never'` (a vetted server). A nested skill is asked about on its own. |
|
|
338
|
+
| By URI | A skill the listing leaves out, named by URI in a server's text: `load_skill({ server, uri })` (its description says so). A `skill://…/SKILL.md` URI and a server whose skills are on - checked before any request - and room under the per-server cap; then `skills/get` to THAT server only (its `-32602` reaches the model), the same entry rules, verification, consent (`byUri`) and preamble. It stays in the catalog, under a name no other skill has. |
|
|
339
|
+
|
|
340
|
+
A server's skills come with its tools, like its instructions: a server whose tools are all
|
|
341
|
+
filtered out (or that has none) offers none. Details: [docs/capabilities.md](docs/capabilities.md#mcp-skills-experimental),
|
|
342
|
+
what a server's skill can and cannot do: [docs/security.md](docs/security.md#mcp-skills-third-party-instructions).
|
|
343
|
+
|
|
344
|
+
### Elicitation: a server asks the user
|
|
345
|
+
|
|
346
|
+
A tool may need something only the user has - a name to confirm, a choice, a
|
|
347
|
+
page to visit - and ask for it **in the middle of the call**. Off until you give
|
|
348
|
+
the connection a callback:
|
|
349
|
+
|
|
350
|
+
```ts
|
|
351
|
+
const pending = new Map<string, (r: McpElicitationResult) => void>()
|
|
352
|
+
|
|
353
|
+
const mcp = await connectMcpHttp(servers, {
|
|
354
|
+
// The HOST decides, never the model. `request` is the SERVER's text: show it as such.
|
|
355
|
+
onElicitation: (request, { signal }) =>
|
|
356
|
+
new Promise((resolve) => {
|
|
357
|
+
pending.set(request.id, resolve) // your UI resolves it: accept / decline / cancel
|
|
358
|
+
signal.addEventListener('abort', () => pending.delete(request.id)) // no longer wanted
|
|
359
|
+
}),
|
|
360
|
+
elicitation: { timeoutMs: 300_000, maxPerToolCall: 5, maxPerRun: 20 }, // the defaults
|
|
361
|
+
})
|
|
362
|
+
// later, from the form the user filled in:
|
|
363
|
+
pending.get(id)?.({ action: 'accept', content: { name: 'Ada' } })
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
- **Off = nothing changes.** Without `onElicitation` no capability is declared, a
|
|
367
|
+
server cannot ask, and every request is byte for byte what it was (no new
|
|
368
|
+
request header either: a server's CORS list needs nothing for this).
|
|
369
|
+
- **The request** (`McpElicitationRequest`): `id`, `server`, `tool` (the call
|
|
370
|
+
that asks), `mode: 'form' | 'url'`, `message`, and `requestedSchema` (a flat
|
|
371
|
+
form: strings, numbers, booleans, selects) or `url`. All of it is third-party
|
|
372
|
+
text, cleaned and capped; none of it reaches a prompt. A form that is not flat,
|
|
373
|
+
or too large, is declined without the callback being called.
|
|
374
|
+
- **The answer** is checked against the form before it is sent (types, limits,
|
|
375
|
+
required fields, no field the form did not ask for) and goes **only to the
|
|
376
|
+
server that asked**: not into the model's context, an event, a log or a run
|
|
377
|
+
checkpoint.
|
|
378
|
+
- **URL mode** is opt-in (`elicitation: { url: true }`). The link is only handed
|
|
379
|
+
to your callback: this package never fetches it and never calls
|
|
380
|
+
`window.open`. Only `https:` (or loopback `http:`) links get that far. Open it
|
|
381
|
+
from a user gesture, in a new tab, showing the host name first.
|
|
382
|
+
- **Nobody decided = the call fails.** A callback that throws or does not answer
|
|
383
|
+
within `timeoutMs`, an answer that does not fit, a cap: the question is
|
|
384
|
+
cancelled, the tool call fails with one sentence that says why, and nothing is
|
|
385
|
+
retried.
|
|
386
|
+
- **Subagents do not ask** unless the connection says so
|
|
387
|
+
(`elicitation: { subagents: true }`): a helper the model started, and a
|
|
388
|
+
subagent tool's child that was handed these tools, have their questions
|
|
389
|
+
cancelled without the callback being called.
|
|
390
|
+
- **Time.** A question waits `timeoutMs` (5 minutes) at most; `0` or
|
|
391
|
+
`Infinity` removes that limit (the question waits until the run is stopped),
|
|
392
|
+
and so does a value above 2^31 - 1 ms (about 24.8 days, the longest delay a
|
|
393
|
+
timer holds). A negative number or `NaN` fails the connect. The step it
|
|
394
|
+
belongs to does not run out of time meanwhile: `chatTimeoutMs` (default
|
|
395
|
+
120 s) **is stopped while a question waits** - like the `timeoutMs` of a
|
|
396
|
+
subagent the question holds up - and goes on with the time it had left. The
|
|
397
|
+
same holds while a person decides a tool approval (whose own bound is
|
|
398
|
+
`toolApproval.timeoutMs`, also 5 minutes by default). Stopping the run ends a
|
|
399
|
+
wait at once.
|
|
400
|
+
- **Events** inside a run: `mcp.elicitation-requested` and
|
|
401
|
+
`mcp.elicitation-answered` (field names, never a value).
|
|
402
|
+
|
|
403
|
+
The whole of it, with every guard: [docs/capabilities.md](docs/capabilities.md#mcp-elicitation-a-server-asks-the-user)
|
|
404
|
+
and [docs/security.md](docs/security.md#mcp-elicitation-a-server-asks-the-user-in-the-middle-of-a-tool-call).
|
|
405
|
+
|
|
406
|
+
### MCP Apps: a server's own interface for a tool
|
|
407
|
+
|
|
408
|
+
With [MCP Apps](https://github.com/modelcontextprotocol/ext-apps) (the stable extension
|
|
409
|
+
`io.modelcontextprotocol/ui`, revision 2026-01-26) a tool declares an HTML app
|
|
410
|
+
(`_meta.ui.resourceUri: 'ui://…'`) that shows its result - a flight list, a chart, a form. This
|
|
411
|
+
package is the host's data side: it reads the declaration, tells the run when such a tool
|
|
412
|
+
returned, reads the app from its server, and makes the calls the app asks for. **Drawing** the
|
|
413
|
+
app is the UI's job: the React package's `<AgentChat mcpApps>` does it in a sandboxed frame.
|
|
414
|
+
Off until you ask:
|
|
415
|
+
|
|
416
|
+
```ts
|
|
417
|
+
const mcp = await connectMcpHttp(servers, { apps: true })
|
|
418
|
+
const agent = await createAgent({ model, tools: mcp.tools })
|
|
419
|
+
|
|
420
|
+
agent.run(goal, {
|
|
421
|
+
onEvent: async (e) => {
|
|
422
|
+
if (e.type !== 'mcp.app') return
|
|
423
|
+
// e.server, e.tool / e.toolName, e.resourceUri, e.input, e.result: what the app is shown
|
|
424
|
+
const app = await mcp.apps!.readUiResource(e.server, e.resourceUri) // { html, csp, permissions, … }
|
|
425
|
+
// ... frame app.html with a policy built from app.csp (connectDomains / resourceDomains only)
|
|
426
|
+
},
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
// The app asks to call a tool of ITS server: consent first, then the call.
|
|
430
|
+
const tool = mcp.apps!.appTool('travel', 'flights.book') // undefined: not one an app may call
|
|
431
|
+
await agent.approveAppToolCall({ tool: tool!.key, toolName: 'flights.book', server: 'travel',
|
|
432
|
+
resourceUri, input: args, readOnly: tool!.readOnly }) // throws ToolDeniedError when refused
|
|
433
|
+
const result = await mcp.apps!.callAppTool('travel', 'flights.book', args)
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
- **Off = nothing changes.** Without `apps` no extension is declared, `_meta` is not read, every
|
|
437
|
+
tool is mounted as before and the wire is byte for byte what it was. On, the only difference on
|
|
438
|
+
the wire is the extension in the handshake (`capabilities.extensions`).
|
|
439
|
+
- **The HTML never reaches the model**: it is in no tool result, event, log or checkpoint. The
|
|
440
|
+
model's tool result is what it would be without apps. `mcp.app` carries the call's arguments
|
|
441
|
+
and the result for the app (`content`, `structuredContent`, `isError`, `_meta`; left out above
|
|
442
|
+
`MCP_APP_MAX_RESULT_CHARS`, 512 000).
|
|
443
|
+
- **An app is read only from the server that declared it**, and only a `ui://` URI that a tool of
|
|
444
|
+
THAT server declares in its current listing - nothing is asked of a server otherwise; checked
|
|
445
|
+
(the exact URI, the MIME type `text/html;profile=mcp-app`, at most 2 000 000 characters, `text`
|
|
446
|
+
or base64 `blob`) and cached per connection; a refused read is not kept. Its declared CSP is
|
|
447
|
+
cleaned to origins (`https://host`, `wss://…`, `https://*.example.com`, loopback `http`): a
|
|
448
|
+
keyword, a scheme, a path, `*` or a `;` never gets through. The permissions it asks for
|
|
449
|
+
(camera, microphone, …) are reported, never granted here. Each read logs the policy (`onLog`).
|
|
450
|
+
- **Who may call what** (`_meta.ui.visibility`): a tool for its app only (`['app']`) is not
|
|
451
|
+
mounted for the model; `appTool` / `callAppTool` refuse a tool whose visibility leaves out
|
|
452
|
+
`'app'`, or that the server does not list - before anything is sent.
|
|
453
|
+
- **Consent for an app's calls** - `agent.approveAppToolCall` - is the agent's own gate
|
|
454
|
+
(`toolApproval`: its rules, handler and timeout) with two differences: under `'autopilot'` a
|
|
455
|
+
write still asks (read-only tools run, as in `'ask-writes'`), and "always allow" given to an app
|
|
456
|
+
is remembered for apps only. The request carries `app: { server, tool, resourceUri }`.
|
|
457
|
+
`callAppTool` itself does not ask: call it after the consent.
|
|
458
|
+
|
|
459
|
+
- **One server's apps off**: `McpHttpServerConfig.apps: false` (over the connection's `apps`) -
|
|
460
|
+
that server is not told of apps, none of its apps is read, no `mcp.app` is told for it, and a
|
|
461
|
+
tool it marks for its app only is mounted for nobody; its other tools are plain tools. `apps:
|
|
462
|
+
true` turns them on for that server alone (`mcpAppsModeOf`: `'on' | 'declined' | 'off'`).
|
|
463
|
+
- **A file an app links to** (`ui/download-file` with a `resource_link`):
|
|
464
|
+
`mcp.apps.readResource(server, uri, { maxBytes })` - `resources/read` on that server only, never a
|
|
465
|
+
fetch of the URI; its bytes, at most `MCP_APP_MAX_DOWNLOAD_BYTES` (20 MB), not cached. It neither
|
|
466
|
+
asks the user nor judges the type: the UI does both before it saves anything.
|
|
467
|
+
- **A completion an app asks for** (`sampling/createMessage`) - `agent.sampleForApp({ server,
|
|
468
|
+
resourceUri, params }, { approve, signal?, onEvent?, sessionId? })`: checked (text; images only
|
|
469
|
+
for a model known to read them; no tools; 16 000 characters; `maxTokens` lowered to 1024), rate
|
|
470
|
+
limited per app (5 a minute, 30 in all), put to `approve` with exactly what the model will get,
|
|
471
|
+
then answered by the synthesizer's model with nothing of the agent's context. Its tokens count in
|
|
472
|
+
`agent.usage` (a `usage` event of phase `'app'`); the answer goes to the caller only - never into
|
|
473
|
+
memory, an event or a run. Caps: `config.appSampling` (`false` refuses every request).
|
|
474
|
+
|
|
475
|
+
```ts
|
|
476
|
+
const answer = await agent.sampleForApp(
|
|
477
|
+
{ server: 'demo', resourceUri: 'ui://demo/trip-board.html', params: request.params },
|
|
478
|
+
{ approve: (view) => askTheUser(view) }, // view: { messages, systemPrompt?, maxTokens, … }
|
|
479
|
+
) // { role: 'assistant', content: { type: 'text', text }, model, stopReason } - or AppSamplingError
|
|
480
|
+
```
|
|
481
|
+
|
|
482
|
+
Everything else an app may ask for - opening a link, putting a message in the chat, full screen,
|
|
483
|
+
saving a file - is the UI's to ask the user about. The whole of it: [docs/capabilities.md](docs/capabilities.md#mcp-apps-a-servers-interface-for-a-tool)
|
|
484
|
+
and [docs/security.md](docs/security.md#mcp-apps-a-servers-html-with-scripts).
|
|
485
|
+
|
|
252
486
|
### OAuth 2.1 + Dynamic Client Registration
|
|
253
487
|
|
|
254
488
|
A server behind OAuth needs more than a header: access tokens expire mid-run.
|
|
255
489
|
Pass an `authProvider` and the MCP SDK discovers the authorization server
|
|
256
|
-
(RFC 9728), registers this app dynamically (RFC 7591
|
|
257
|
-
|
|
258
|
-
|
|
490
|
+
(RFC 9728), registers this app — dynamically (RFC 7591) or by its client ID
|
|
491
|
+
metadata document (CIMD), automatically or one of them only (`registration`):
|
|
492
|
+
no client_id to pre-provision — runs PKCE, and **refreshes the access token on
|
|
493
|
+
any 401 and retries the request**.
|
|
259
494
|
|
|
260
495
|
```ts
|
|
261
496
|
import { BrowserOAuthProvider, connectMcpHttp, finishMcpOAuth, readOAuthCallback }
|
|
@@ -298,6 +533,25 @@ on `provider.authorizationUrl` and the app decides when to use it.
|
|
|
298
533
|
before, and a registration already in storage wins over both. The URL must be
|
|
299
534
|
https with a path (anything else throws in the constructor), and the document
|
|
300
535
|
must list the same `redirect_uris` as `redirectUrl`.
|
|
536
|
+
- **`registration`: how the client is registered** — `'auto'` (the default),
|
|
537
|
+
`'cimd'` or `'dcr'`; the Node package has the same option.
|
|
538
|
+
|
|
539
|
+
| value | the client | an authorization server without CIMD support |
|
|
540
|
+
|---|---|---|
|
|
541
|
+
| `'auto'` | the document where the server advertises `client_id_metadata_document_supported` (and `clientMetadataUrl` is set), a dynamic registration elsewhere; a stored client is used as it is | dynamic registration |
|
|
542
|
+
| `'cimd'` | the document only; needs `clientMetadataUrl` (the constructor throws without one) | **refused before anything is sent to its registration endpoint**: the connect fails with `… does not support client ID metadata documents (CIMD), which this connection requires (registration: 'cimd') - nothing was sent to its registration endpoint`, and what discovery found is dropped, so the next attempt reads the server's metadata again |
|
|
543
|
+
| `'dcr'` | a dynamic registration only, even with a `clientMetadataUrl` (the provider's `clientMetadataUrl` is then `undefined`: the SDK never sees the URL) | dynamic registration |
|
|
544
|
+
|
|
545
|
+
`await provider.registrationKind()` says how the stored client was made —
|
|
546
|
+
`'cimd'`, `'dcr'` (also a client you saved yourself), or `undefined` when
|
|
547
|
+
there is none this provider would use; `provider.registration` is the
|
|
548
|
+
setting. Under `'cimd'` / `'dcr'` **a stored client of the other kind is not
|
|
549
|
+
reused**: it is forgotten together with the tokens issued to it (a token
|
|
550
|
+
belongs to its client) before either is read, and the user signs in again.
|
|
551
|
+
The kind is stamped on the stored record when it is saved, so a later change
|
|
552
|
+
of `clientMetadataUrl` does not make an old document client look like a
|
|
553
|
+
dynamic one; a record saved before the stamp existed is CIMD when its
|
|
554
|
+
`client_id` is the document configured now.
|
|
301
555
|
- **Registration** describes a public PKCE client. `application_type` follows
|
|
302
556
|
the redirect URL: `'web'` for an https page, `'native'` for a loopback one
|
|
303
557
|
(local development). Change any field through `clientMetadata`.
|
|
@@ -434,11 +688,25 @@ HTTP server, the old and the new client send the same requests with the same
|
|
|
434
688
|
headers (`Accept`, `Content-Type`, then `mcp-session-id` and
|
|
435
689
|
`MCP-Protocol-Version` after `initialize`, `Authorization` and `Last-Event-ID`
|
|
436
690
|
when they apply), and the browser tests run against a server with exactly this
|
|
437
|
-
list.
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
691
|
+
list.
|
|
692
|
+
|
|
693
|
+
**For the 2026-07-28 revision** (a server connected with `protocol: 'auto'` or
|
|
694
|
+
`'modern'`) two more request headers are needed, and `MCP-Protocol-Version` is
|
|
695
|
+
on the very first request:
|
|
696
|
+
|
|
697
|
+
```
|
|
698
|
+
Access-Control-Allow-Headers: Content-Type, Authorization, MCP-Protocol-Version,
|
|
699
|
+
Mcp-Method, Mcp-Name
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
(`mcp-session-id` and `Last-Event-ID` are not sent in that revision, and no new
|
|
703
|
+
response header needs exposing; keep them all in one list if the server also
|
|
704
|
+
serves 2025 clients.) This package does **not** send `Mcp-Param-*` headers -
|
|
705
|
+
the mirror of tool arguments a tool may ask for with `x-mcp-header` - so the
|
|
706
|
+
list above is the whole requirement for it; another client may send them, and
|
|
707
|
+
their names come from the tools, so a server that uses the feature has to
|
|
708
|
+
allow them by pattern. Without `protocol`, none of these headers is sent and
|
|
709
|
+
the 2025 list is still enough.
|
|
442
710
|
|
|
443
711
|
Each line earns its place:
|
|
444
712
|
|
|
@@ -463,6 +731,16 @@ browser's silence: it re-probes the endpoint with a plain request and, if that
|
|
|
463
731
|
gets through, says which header is being refused. `diagnoseMcpCors(url)` is
|
|
464
732
|
exported so a UI can show the same sentence.
|
|
465
733
|
|
|
734
|
+
With `protocol: 'auto'` or `'modern'` it goes one step further, because the
|
|
735
|
+
browser will not say *which* header a preflight refused: it sends one request
|
|
736
|
+
per header (`MCP-Protocol-Version`, `Mcp-Method`, `Mcp-Name`, each alone) and
|
|
737
|
+
names the ones that were blocked - `… one carrying Mcp-Method / Mcp-Name was
|
|
738
|
+
blocked: the server's Access-Control-Allow-Headers does not list them …`. That
|
|
739
|
+
sentence is added to the connect error (`'modern'`, and `'auto'` against a
|
|
740
|
+
2026-only server) or logged at `warn` (`'auto'` that fell back to 2025). The
|
|
741
|
+
same from your own code: `diagnoseMcpCors(url, fetch, { protocol: 'modern' })`.
|
|
742
|
+
These extra requests are made only after a connect already failed or fell back.
|
|
743
|
+
|
|
466
744
|
## Optional: WebMCP — a page's tools, both ways
|
|
467
745
|
|
|
468
746
|
[WebMCP](https://webmachinelearning.github.io/webmcp/) lets a page register named, typed tools
|
|
@@ -509,7 +787,10 @@ const agent = await createAgent({
|
|
|
509
787
|
skills: [defineSkill({ name: 'triage', description: 'Triage a bug report', content: '…' })],
|
|
510
788
|
toolApproval: {
|
|
511
789
|
mode: 'ask-writes', // autopilot | ask-writes | ask-all | read-only
|
|
512
|
-
|
|
790
|
+
// `signal` aborts when the agent stops waiting (the bound, a stop): take your dialog down then
|
|
791
|
+
onRequest: async (req, { signal }) => askInADialog(`Allow ${req.toolName}?`, { signal }),
|
|
792
|
+
// no decision in 5 minutes (the default) -> deny; 0 or Infinity: wait until the run is stopped
|
|
793
|
+
timeoutMs: 300_000,
|
|
513
794
|
},
|
|
514
795
|
})
|
|
515
796
|
agent.setToolApprovalMode('autopilot') // flip the switch at any time
|
|
@@ -530,7 +811,7 @@ that run's limits. Give `persistence` a store
|
|
|
530
811
|
last checkpoint with `run('', { resumeFromRunId })` — the planner does not run again and
|
|
531
812
|
no finished step is repeated. `createRunControl()` steers a run that is going: `send()`
|
|
532
813
|
puts a message in front of the model at the next boundary (the replanner re-checks the plan
|
|
533
|
-
against it), `stopSubagent(id)` stops one subagent. `egress` (off by default) gives the model one safe `web_fetch` tool with allow / deny lists. `search` (off by default) adds `web_search` over a search API
|
|
814
|
+
against it), `stopSubagent(id)` stops one subagent. `egress` (off by default) gives the model one safe `web_fetch` tool with allow / deny lists. `search` (off by default) adds `web_search` over a function of yours (any search API — recipes for Tavily, Brave and SearXNG are in the docs) or the built-in Google Search through Gemini grounding, which needs only a Gemini key and spends its tokens — the key stays in the credential store. `sandbox` (off by default) gives the model `run_js`: the code it wrote runs in QuickJS-in-WebAssembly inside a Web Worker that is killed at the deadline, so "I ran it" is a tool call you can see. `media` (off by default) mounts `generate_image`, `generate_speech` and `transcribe_audio` — each only when you configure its model — writes what they make into the virtual file system instead of the context, and turns attached audio into text for a model that cannot listen. `learning` (off by default) lets the agent write down what it figured out as skills of its own — in memory, or in the file system across sessions. Details, defaults and events:
|
|
534
815
|
**[docs/capabilities.md](docs/capabilities.md)**.
|
|
535
816
|
|
|
536
817
|
## Pipelines: a graph of agents
|
|
@@ -598,14 +879,16 @@ Loading a definition someone else wrote: [docs/security.md](docs/security.md#pip
|
|
|
598
879
|
| `executorTiers` | off | `{ light?, standard?, strong? }`, each a model like `planner`: the planner rates every step low / medium / high and the executor runs it on that tier's model; a tier that is not configured falls back to the nearest one; the smallest window among them governs the run ([model tiers](docs/capabilities.md#model-tiers-and-escalation)) |
|
|
599
880
|
| `escalation` | on with tiers | `false`, or `{ maxPerStep?, maxPerRun? }` (1 / 3): a step that fails in a way a stronger model could fix is retried on the next stronger tier before the replanner is asked - continuing the step, never writing twice. Nothing without tiers |
|
|
600
881
|
| `credentials` | — | a `CredentialStore` for `credentialRef` keys |
|
|
601
|
-
| `tools` | `{}` | host tools (`defineTool`) |
|
|
882
|
+
| `tools` | `{}` | host tools (`defineTool`); mark a tool that runs code with `markCodeExecution` (always asked while a run acts on an MCP server's skill) |
|
|
602
883
|
| `availableTools` / `excludedTools` | — | whitelist / blacklist of tool names mounted from `tools` |
|
|
603
884
|
| `toolMode` | `'auto'` | `native` \| `prompted` \| `auto` (cloud→native, local→prompted) |
|
|
604
885
|
| `toolSelectionStrategy` | `'auto'` | `all` \| `plan-narrowed` \| `search` \| `auto` (search above `toolSearchThreshold`, 40, or once the definitions take ¼ of the window) |
|
|
605
|
-
| `
|
|
606
|
-
| `
|
|
886
|
+
| `appSampling` | on, with caps | the caps of `agent.sampleForApp` (an MCP App asking the model): `{ maxTokens: 1024, maxRequestsPerMinute: 5, maxRequests: 30, maxInputChars: 16000, reasoningTokens: 2048 }`, per app (`reasoningTokens`: room on top of an app's `maxTokens` for a model seen reasoning - its reasoning counts against the cap); `false` refuses every request. Nothing happens unless a host calls it, and every request goes to its `approve` first. See [An app asks the model](docs/capabilities.md#an-app-asks-the-model) |
|
|
887
|
+
| `toolApproval` | autopilot | consent policy: `{ mode, rules, onRequest, timeoutMs }`; `agent.setToolApprovalMode()`. A question waits `timeoutMs` for a decision, then is denied: default 300000 (`TOOL_APPROVAL_TIMEOUT_MS`), `0` or `Infinity` = until the run is stopped (as is a value above 2^31 - 1, the most a timer holds); negative or `NaN` fails `createAgent`. `onRequest(req, { signal })`: the signal aborts when the question ends without an answer (`TimeoutError` for the bound, `AbortError` for a stop). See [Tool consent](docs/capabilities.md#tool-consent-and-autopilot) |
|
|
888
|
+
| `skills` | — | SKILL.md bundles (`defineSkill` / `parseSkillMarkdown` / `loadSkillFromUrl`). An MCP server's skills come with its tools (`skills: true` or `{ consent, dynamic }` on the server of `connectMcpHttp`, experimental; `dynamic: true` also takes its generated skills, each read whole into a snapshot before anyone is asked) and join them as `<server>/<skill>` - see [MCP skills](#mcp-skills-experimental-a-servers-instructions-as-skills) |
|
|
889
|
+
| `mcpSkills` | `{ consent: 'once-per-skill' }` | experimental: when a person is asked (`toolApproval.onRequest`, a request with `skill`) before an MCP server's skill enters the model's context, for servers whose `skills: { consent }` does not say - `'once-per-skill'`, `'ask'` (every run) or `'never'` - see [MCP skills](#mcp-skills-experimental-a-servers-instructions-as-skills) |
|
|
607
890
|
| `egress` | off | what the **model** may fetch (`web_fetch`): `true` = any public host over https, or `{ allow, deny, protocols, allowPrivateNetwork, fetch, ... }`; a browser can't pin DNS, so prefer an `allow` list — see [Egress](docs/capabilities.md#egress-what-the-model-may-fetch) |
|
|
608
|
-
| `search` | off | the model may **search the web** (`web_search`: a short list of title / url / snippet): `{
|
|
891
|
+
| `search` | off | the model may **search the web** (`web_search`: a short list of title / url / snippet): `{ engine: fn }` - a search engine of yours, any API - or `{ provider: 'google', credentialRef, model, baseURL, maxResults, allowPrivateNetwork, readOnly, fetch }` - Google Search through Gemini grounding: one extra `generateContent` call per search on a Gemini key (default model `gemini-2.5-flash-lite`), which **spends model tokens** (`usage` phase `'search'`) and returns **Google redirect links**, not the pages' URLs. No key ships with the library and none is written in the config (`credentialRef` names it in `credentials`); the request reaches only that API; with `egress`, results the model could not fetch are left out. Recipes for Tavily / Brave / SearXNG as an `engine`, the free-tier models and what the redirect links mean — see [Search](docs/capabilities.md#search-finding-the-page-to-fetch) |
|
|
609
892
|
| `media` | off | image generation, speech and transcription as tools, each mounted only when its model is set: `{ imageModel, speechModel, transcriptionModel, maxCalls, timeoutMs, files, folder, voice, speechFormat, transcribeAttachments }`. A model is an AI SDK image / speech / transcription model object or a `ProviderModelSpec` (key by `credentialRef`). Generated files go to the virtual file system and the model gets a path, never the bytes; attached audio is transcribed to text; calls are counted in `usage.mediaCalls` (and the other media fields) and capped per run — see [Media](docs/capabilities.md#media-images-speech-and-transcription) |
|
|
610
893
|
| `decisionModel` | off | a **decision model** - answers a closed question with one option and a probability instead of writing text: `{ providerType: 'google', model: 'gemini-decision-1', credentialRef }` (the key stays in `credentials`; the request reaches only that API) or an object with `decide(question, { abortSignal })`. Where it is confident it replaces the replanner's continue / finish call and a pipeline node's route call; never consulted for tool approval or egress — see [Decision models](docs/capabilities.md#decision-models) |
|
|
611
894
|
| `decision` | `{}` | `{ confidenceThreshold, timeoutMs, replan, route }` (defaults 0.8, 5000 ms, on, on): below the threshold, on an error, a timeout or an answer that is not an option, the ordinary model call runs unchanged |
|
|
@@ -625,7 +908,7 @@ Loading a definition someone else wrote: [docs/security.md](docs/security.md#pip
|
|
|
625
908
|
| `sessionId` | — | names the stored conversation in `memory`, and the bucket `agent.sessionUsage()` counts into |
|
|
626
909
|
| `persistence` | — | checkpoint runs (`IndexedDBRunStore` / `MemoryRunStore`) so `run(goal, { resumeFromRunId })` continues after a reload — see [Resuming](docs/capabilities.md#resuming-an-interrupted-run) |
|
|
627
910
|
| `maxIterations` / `maxStepsPerTask` / `maxRevisions` | 8 / 4 / 2 | loop caps |
|
|
628
|
-
| `chatTimeoutMs` | 120000 | per-call watchdog |
|
|
911
|
+
| `chatTimeoutMs` | 120000 | per-call watchdog; for the executor, the whole step (its tool calls included). Stopped while a tool call waits for a person (an approval, an MCP question): the step goes on with the time it had left - see [Tool consent](docs/capabilities.md#tool-consent-and-autopilot) |
|
|
629
912
|
| `temperature` | provider default | sampling temperature for every stage |
|
|
630
913
|
| `budgets` | — | legacy per-phase output caps; `limits.perCall` wins, `0` = no cap, and the defaults are shares of the model's window (none for a phase that thinks) |
|
|
631
914
|
| `clientName` | — | sent as the openai-compatible provider name and the MCP client name |
|
|
@@ -686,7 +969,7 @@ If you do import it:
|
|
|
686
969
|
calls, where it used to fail the whole server at connect; a
|
|
687
970
|
`403 insufficient_scope` fails the call instead of starting an
|
|
688
971
|
authorization; a server that speaks only 2026-07-28 is refused with a clear
|
|
689
|
-
error.
|
|
972
|
+
error (unless you opt in: `protocol: 'auto'` or `'modern'` on that server).
|
|
690
973
|
|
|
691
974
|
## Docs
|
|
692
975
|
|