@dudko.dev/agent-web 0.0.43 → 0.0.45

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.
Files changed (34) hide show
  1. package/README.md +56 -3
  2. package/dist/agent-web.js +167 -161
  3. package/dist/agent-web.js.map +1 -1
  4. package/dist/{chunk-DAREMCXF.js → chunk-236RCVAZ.js} +40 -8
  5. package/dist/chunk-236RCVAZ.js.map +1 -0
  6. package/dist/{chunk-2MLHZ6LQ.js → chunk-Y4MIIBPB.js} +2 -2
  7. package/dist/{chunk-ZSZSSJS4.js → chunk-Y6CD3WOK.js} +176 -10
  8. package/dist/chunk-Y6CD3WOK.js.map +1 -0
  9. package/dist/{chunk-YPCHD6DV.js → chunk-YGWIOO27.js} +31 -12
  10. package/dist/chunk-YGWIOO27.js.map +1 -0
  11. package/dist/index.cjs +1300 -171
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +1794 -1466
  14. package/dist/index.d.ts +1794 -1466
  15. package/dist/index.js +1044 -145
  16. package/dist/index.js.map +1 -1
  17. package/dist/mcp.cjs +136 -5
  18. package/dist/mcp.cjs.map +1 -1
  19. package/dist/mcp.d.cts +5 -2
  20. package/dist/mcp.d.ts +5 -2
  21. package/dist/mcp.js +19 -8
  22. package/dist/mcp.js.map +1 -1
  23. package/dist/{sandbox-3VRX47UY.js → sandbox-7CGSIIIZ.js} +4 -4
  24. package/dist/sandbox-worker.cjs +30 -11
  25. package/dist/sandbox-worker.cjs.map +1 -1
  26. package/dist/sandbox-worker.js +1 -1
  27. package/dist/{elicitation-DS-84_bF.d.cts → vault-Mar2CY0J.d.cts} +526 -526
  28. package/dist/{elicitation-DS-84_bF.d.ts → vault-Mar2CY0J.d.ts} +526 -526
  29. package/package.json +1 -1
  30. package/dist/chunk-DAREMCXF.js.map +0 -1
  31. package/dist/chunk-YPCHD6DV.js.map +0 -1
  32. package/dist/chunk-ZSZSSJS4.js.map +0 -1
  33. /package/dist/{chunk-2MLHZ6LQ.js.map → chunk-Y4MIIBPB.js.map} +0 -0
  34. /package/dist/{sandbox-3VRX47UY.js.map → sandbox-7CGSIIIZ.js.map} +0 -0
@@ -1,155 +1,435 @@
1
- interface VaultOptions {
2
- /** Database name, forwarded to the shared IDB owner (default 'agent-web'). */
3
- dbName?: string;
4
- }
5
1
  /**
6
- * Encrypted key/value secret store backed by IndexedDB. Values are encrypted at
7
- * rest with the non-extractable AES-GCM vault key (see crypto.ts).
2
+ * MCP Apps (the `io.modelcontextprotocol/ui` extension, stable revision 2026-01-26): a tool of an
3
+ * MCP server declares an HTML user interface (`_meta.ui.resourceUri`, a `ui://` resource), the
4
+ * host reads it with `resources/read` and shows it next to the tool's result in a sandboxed frame.
8
5
  *
9
- * ── THREAT MODEL (read before shipping any app-owned key to a browser) ──
10
- * This vault PROTECTS secrets **at rest** — an IndexedDB / disk dump yields
11
- * only ciphertext — and against **casual DevTools inspection** — no plaintext
12
- * key is stored, and the AES key cannot be exported even by in-page script.
6
+ * Pure, no imports: what this package accepts of the server's declarations, before anything is
7
+ * shown. Everything here is third-party data from the server, so every function is a guard:
13
8
  *
14
- * It does **NOT** defend against **active XSS on your origin**: any script that
15
- * already runs on the page can call `getSecret()`, or use the live `CryptoKey`
16
- * to decrypt. Browser storage is not a secrets manager.
9
+ * - `mcpAppToolMeta`: the tool's link to its app - a `ui://` URI or nothing - and who may call
10
+ * it (`visibility`: the model, the app, or both).
11
+ * - `mcpAppResourceOf`: the `resources/read` answer - the right URI, the extension's MIME type,
12
+ * a size cap, `text` or base64 `blob` - and the resource's metadata cleaned: CSP origins that
13
+ * are origins and nothing else, the permissions it asks for (reported, never granted here).
14
+ * - `mcpAppToolResultOf`: what of a tool's result is handed to the app, capped.
17
15
  *
18
- * Therefore this vault is for the **end user's OWN key on their OWN device**
19
- * (bring-your-own-key). A shared, app-owned key must NEVER reach the client —
20
- * put it behind a server proxy (`ProviderModelSpec.baseURL`) or the Vercel AI
21
- * Gateway instead.
16
+ * The HTML itself never reaches the model: it is not part of a tool result, an event or a log.
22
17
  */
23
- declare class IndexedDBVault {
24
- private readonly dbName?;
25
- constructor(opts?: VaultOptions);
26
- private key;
27
- /** Encrypt and store a secret string under `id`. */
28
- setSecret(id: string, value: string): Promise<void>;
29
- /** Fetch and decrypt a secret, or undefined if absent. */
30
- getSecret(id: string): Promise<string | undefined>;
31
- deleteSecret(id: string): Promise<void>;
32
- listSecretIds(): Promise<string[]>;
33
- }
34
-
18
+ /** The extension's identifier: declared under `capabilities.extensions` in the handshake. */
19
+ declare const MCP_APPS_EXTENSION = "io.modelcontextprotocol/ui";
20
+ /** The one content type of the stable revision (`text/html` with the `mcp-app` profile). */
21
+ declare const MCP_APP_MIME_TYPE = "text/html;profile=mcp-app";
22
+ /** An app's HTML above this many characters is refused (a bundled single-file app is ~1 MB). */
23
+ declare const MCP_APP_MAX_HTML_CHARS = 2000000;
24
+ /** A tool result above this many characters (as JSON) is not handed to its app. */
25
+ declare const MCP_APP_MAX_RESULT_CHARS = 512000;
26
+ /** At most this many origins per CSP list of a resource; the rest are refused. */
27
+ declare const MCP_APP_MAX_DOMAINS = 32;
28
+ /** Who may call a tool: the model (it is in the agent's toolbox), an app of its server, or both. */
29
+ type McpAppVisibility = 'model' | 'app';
30
+ /** The specification's default when a tool says nothing. */
31
+ declare const MCP_APP_DEFAULT_VISIBILITY: readonly McpAppVisibility[];
35
32
  /**
36
- * MCP Skills (the `io.modelcontextprotocol/skills` extension, SEP-2640, Beta; written against
37
- * base revision 2026-07-28): what the two agent packages share about a server's skills. The
38
- * rules on a server's entries (`mcpSkillEntryRefusal`), the names a skill gets in the agent's
39
- * catalog (`assignMcpSkillNames`: namespaced by the host's label of the server), the caps
40
- * (`selectMcpSkills`), the files of a loaded skill the model may read (`resolveMcpSkillFile`),
41
- * the preamble a skill's text is loaded under, the mark that carries a server's skills on its
42
- * tools (`markMcpSkills` / `collectMcpSkillSources`), a skill the model names by URI
43
- * (`mcpSkillUriRefusal`, `resolveMcpSkillServer`: `skills/get` to that one server only), the
44
- * person's consent before a skill's text enters the model's context (`decideMcpSkillConsent`,
45
- * `mcpSkillConsentView`) and a directory of a skill (`skillDirectoryOf`, `resolveMcpSkillPath`,
46
- * `skillDirectoryListing` - for every kind of skill - and, for a server that serves
47
- * `resources/directory/read`, `compareMcpSkillDirectory`) and, for a server the host trusts with
48
- * its generated skills (`skills: { dynamic: true }`), the snapshot such a skill is read into
49
- * before anyone is asked (`startMcpSkillWalk`, `takeMcpSkillWalkListing`,
50
- * `mcpSkillSnapshotBytesRefusal`, `mcpSkillSnapshotEntry`). Pure, no imports (a digest is
51
- * computed with the platform's WebCrypto, `globalThis.crypto.subtle`, or a function passed in).
52
- *
53
- * A server's skills are third-party text. They reach the model only as knowledge, under
54
- * `mcpSkillPreamble`, and - unless the host vetted the server (`consent: 'never'`) - only after a
55
- * person saw them and said yes; nothing here (or anywhere) reads a skill's frontmatter beyond its
56
- * `name` and `description` - `allowed-tools` included - and a file a skill bundles is read as
57
- * text, never run.
58
- *
59
- * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-skills.ts`) and
60
- * `@dudko.dev/agent-web` (`src/mcp/skills.ts`): change both. The Node package's
61
- * `tests/mcp-skills-shared.test.ts` compares the two files and tests every rule and cap here.
33
+ * The origins an app's resource declared, after cleaning: each entry an origin
34
+ * (`https://host[:port]`, `wss://…`, `https://*.example.com`, or `http(s)/ws(s)` on loopback),
35
+ * nothing else. An empty list means "none": the frame gets no network for that kind.
62
36
  */
63
- /** The extension's identifier, in the client's and the server's `extensions` capability. */
64
- declare const MCP_SKILLS_EXTENSION = "io.modelcontextprotocol/skills";
65
- /** The specification's limits (Limits): files per skill, `SKILL.md` included. */
66
- declare const MCP_SKILL_MAX_RESOURCES = 512;
67
- /** The specification's limits (Limits): the sum of `size` over a skill's files, in bytes. */
68
- declare const MCP_SKILL_MAX_TOTAL_BYTES: number;
69
- /** The most skills one server puts in the agent's catalog. */
70
- declare const MCP_SKILLS_MAX_PER_SERVER = 32;
71
- /** The most skills all servers put in the agent's catalog together. */
72
- declare const MCP_SKILLS_MAX_TOTAL = 64;
73
- /** The most a catalog entry (the description and its origin tag) takes, in characters. */
74
- declare const MCP_SKILL_DESCRIPTION_MAX_CHARS = 300;
75
- /** The most of a skill's instructions (its `SKILL.md` body) the model is given, in characters. */
76
- declare const MCP_SKILL_BODY_MAX_CHARS = 16000;
77
- /** The most of one file of a skill the model is given, in characters. */
78
- declare const MCP_SKILL_FILE_MAX_CHARS = 32000;
79
- /** One file of a skill, as its entry lists it. */
80
- interface McpSkillResourceLike {
81
- uri: string;
82
- digest: string;
83
- size: number;
37
+ interface McpAppCsp {
38
+ /** `fetch` / XHR / WebSocket (`connect-src`). */
39
+ connectDomains: string[];
40
+ /** Scripts, styles, images, fonts, media (`script-src`, `style-src`, …). */
41
+ resourceDomains: string[];
42
+ /** Nested frames (`frame-src`). */
43
+ frameDomains: string[];
44
+ /** `<base href>` (`base-uri`). */
45
+ baseUriDomains: string[];
84
46
  }
85
- /** A `skills/list` / `skills/get` entry (the extension's `Skill`), as far as this file reads it. */
86
- interface McpSkillEntryLike {
47
+ /** Browser features the resource asks for. Reported to the host; this package grants none. */
48
+ interface McpAppPermissions {
49
+ camera?: true;
50
+ microphone?: true;
51
+ geolocation?: true;
52
+ clipboardWrite?: true;
53
+ }
54
+ /** An app's document, read from the server that declared it and checked. */
55
+ interface McpAppResource {
56
+ /** The server it was read from (the one whose tool declared it). */
57
+ server: string;
87
58
  uri: string;
88
- frontmatter: {
89
- name: string;
90
- description: string;
91
- [key: string]: unknown;
92
- };
93
- resources: McpSkillResourceLike[] | 'dynamic';
59
+ /** The app's HTML. Third-party code: frame it, never put it in a page or a model's context. */
60
+ html: string;
61
+ /** The origins it declared, cleaned (see `McpAppCsp`). */
62
+ csp: McpAppCsp;
63
+ /** Declared entries that are not origins this package accepts - left out of `csp`. */
64
+ refusedDomains: string[];
65
+ /** What it asked for; not granted by this package. */
66
+ permissions: McpAppPermissions;
67
+ /** Its wish for a visible border; the host decides. */
68
+ prefersBorder?: boolean;
69
+ /** The dedicated origin it asked for; a page-based host cannot give one, so it is only reported. */
70
+ domain?: string;
71
+ }
72
+ /** A tool's result as handed to its app: the MCP `CallToolResult`, unchanged but for unknown keys. */
73
+ interface McpAppToolResult {
74
+ content?: unknown[];
75
+ structuredContent?: Record<string, unknown>;
76
+ isError?: boolean;
77
+ _meta?: Record<string, unknown>;
78
+ }
79
+ /** What a tool declares about apps. */
80
+ interface McpAppToolMeta {
81
+ /** Its app (`ui://…`), when it declares a valid one. */
82
+ resourceUri?: string;
83
+ visibility: McpAppVisibility[];
84
+ /** A declared app URI that was refused (not `ui://`, too long, not text) - for the log. */
85
+ refusedUri?: string;
94
86
  }
87
+ /** A `ui://` URI this package will read: text, short, no control characters. */
88
+ declare const isMcpAppUri: (value: unknown) => value is string;
95
89
  /**
96
- * Why the agent does not take a skill entry from a server, or `undefined` when it does. The
97
- * specification's rules on an entry, checked before anything of the skill is read:
98
- *
99
- * - its `uri` is a `SKILL.md` inside a named directory, whose last segment is the skill's
100
- * frontmatter `name` (Resource Mapping; Frontmatter), and that name follows the Agent Skills
101
- * naming rules;
102
- * - a description to show in the catalog;
103
- * - `resources` is the complete list of its files (Resources): `"dynamic"` content is declined
104
- * (a host MAY: there is nothing to verify it against, and a consent could not bind to its
105
- * content) - unless `options.dynamic` (the server's `skills: { dynamic: true }`: the host
106
- * trusts that server with its generated skills, which are then read into a snapshot before
107
- * anyone is asked, see {@link mcpSkillSnapshotEntry}); anything else is invalid;
108
- * - every file is `SKILL.md` or a file inside the skill's directory, listed once, with a
109
- * `sha256:` digest and a byte size, and `SKILL.md` is listed;
110
- * - at most {@link MCP_SKILL_MAX_RESOURCES} files and {@link MCP_SKILL_MAX_TOTAL_BYTES} bytes
111
- * (Limits: "both limits are checkable from the entry alone"; a generated skill's are counted
112
- * on what its snapshot reads).
90
+ * The tool's app and who may call it. `_meta.ui.resourceUri` wins over the deprecated flat
91
+ * `_meta["ui/resourceUri"]`. `visibility` defaults to both; unknown entries are dropped; a list
92
+ * that names nothing known is the default.
113
93
  */
114
- declare const mcpSkillEntryRefusal: (entry: unknown, options?: {
115
- dynamic?: boolean;
116
- }) => string | undefined;
117
- /** One skill of a server, as the agent's catalog holds it (the entry stays with the connection). */
118
- interface McpSkillRecord {
119
- /** The `SKILL.md` URI: with the server, the skill's identity. */
120
- uri: string;
121
- /** The frontmatter `name` (a label: two skills of one server may share it). */
122
- name: string;
123
- /** The description, cleaned to one line (not yet capped). */
124
- description: string;
125
- /** The skill's path (`acme/billing/refunds`), as segments. */
126
- path: string[];
127
- /** Its files other than `SKILL.md`, by their path inside the skill, sorted. */
128
- files: string[];
129
- /**
130
- * Generated by the server (`"resources": "dynamic"`, taken with `skills: { dynamic: true }`):
131
- * no files are known until its snapshot is read, and there are no checksums.
132
- */
133
- dynamic?: true;
94
+ declare const mcpAppToolMeta: (tool: {
95
+ _meta?: unknown;
96
+ }) => McpAppToolMeta;
97
+ /**
98
+ * Whether a content type is the extension's: `text/html` with `profile=mcp-app`, in any case,
99
+ * with or without spaces or quotes; `charset=utf-8` may come along, nothing else.
100
+ */
101
+ declare const isMcpAppMimeType: (value: unknown) => boolean;
102
+ /**
103
+ * One declared CSP entry as a source expression this package puts in a policy, or `undefined`.
104
+ * Only an origin: `https://` / `wss://` (a `*.` subdomain wildcard over at least two labels),
105
+ * or `http://` / `ws://` on loopback. No path, no keyword (`'unsafe-eval'`), no bare scheme, no
106
+ * `*`, no separator (`;` `,` space) that could add a directive of its own.
107
+ */
108
+ declare const mcpAppOrigin: (entry: unknown) => string | undefined;
109
+ /** The resource's declared CSP, cleaned: origins kept, everything else in `refused`. */
110
+ declare const mcpAppCspOf: (raw: unknown) => {
111
+ csp: McpAppCsp;
112
+ refused: string[];
113
+ };
114
+ /** The permissions a resource asks for: the four the specification names, nothing else. */
115
+ declare const mcpAppPermissionsOf: (raw: unknown) => McpAppPermissions;
116
+ /** Why a `resources/read` answer is not an app this package shows. */
117
+ declare class McpAppResourceError extends Error {
118
+ constructor(message: string);
134
119
  }
135
120
  /**
136
- * How a skill of a server is introduced wherever its text is shown to the model (its
137
- * instructions, and each file of it): third-party knowledge that cannot change the rules. The
138
- * wording is the guard.
121
+ * The app in a `resources/read` answer for `uri`: the entry with exactly that URI, the
122
+ * extension's MIME type, `text` (or base64 `blob`) under `maxChars`, metadata cleaned. Throws
123
+ * {@link McpAppResourceError} otherwise - nothing of a refused answer is shown.
139
124
  */
140
- declare const mcpSkillPreamble: (server: string, uri: string) => string;
125
+ declare const mcpAppResourceOf: (server: string, uri: string, result: unknown, maxChars?: number) => McpAppResource;
141
126
  /**
142
- * The most entries of one `resources/directory/read` answer looked at: the specification's 512
143
- * files per skill, and room for the directories among them. The rest are not looked at.
127
+ * The parts of a tool result an app is given (`content`, `structuredContent`, `isError`,
128
+ * `_meta`), or `undefined` when they are more than `maxChars` as JSON or not a result at all.
144
129
  */
145
- declare const MCP_SKILL_DIRECTORY_ENTRIES_MAX: number;
130
+ declare const mcpAppToolResultOf: (result: unknown, maxChars?: number) => McpAppToolResult | undefined;
146
131
  /**
147
- * What a server's live view of a directory says against the entry a skill was loaded with
148
- * ({@link compareMcpSkillDirectory}): a count and paths of that entry - nothing of the server's
149
- * own listing.
132
+ * What MCP Apps are for ONE server, from its own setting (`McpHttpServerConfig.apps`) and the
133
+ * connection's (`ConnectMcpOptions.apps`); the server's wins when it has one:
134
+ *
135
+ * - `'on'`: the extension declared, `_meta.ui` read, the server's apps shown.
136
+ * - `'declined'` (the server's `apps: false`): its apps are not shown here. Nothing is declared,
137
+ * no app is read and no `mcp.app` event is told, and a tool marked for its app only
138
+ * (`visibility` without `'model'`) is not mounted - it is for an app that will never run.
139
+ * Every other tool is the model's, as a plain tool.
140
+ * - `'off'` (neither set): MCP Apps unknown - nothing declared, `_meta` not read, every tool
141
+ * mounted: the wire and the tools are what they were before the extension.
150
142
  */
151
- interface McpSkillDirectoryDrift {
152
- /** Children the server lists that the entry does not hold: counted, never named. */
143
+ type McpAppsMode = 'on' | 'declined' | 'off';
144
+ declare const mcpAppsModeOf: (server: boolean | undefined, connection: boolean | undefined) => McpAppsMode;
145
+ /** A file an app asks the host to save, at most this many bytes (`readResource`'s default cap). */
146
+ declare const MCP_APP_MAX_DOWNLOAD_BYTES: number;
147
+ /** A resource read for a download (`McpAppsConnection.readResource`): its bytes, as sent. */
148
+ interface McpAppDownloadResource {
149
+ uri: string;
150
+ /** The type the server gave it, if any (third-party: the host judges it). */
151
+ mimeType?: string;
152
+ bytes: Uint8Array;
153
+ }
154
+ /**
155
+ * The bytes of a `resources/read` answer for `uri`, for a file the user is about to be asked to
156
+ * save: the entry with exactly that URI, `text` (as UTF-8) or base64 `blob`, at most `maxBytes`.
157
+ * Any MIME type (the host decides what it saves). Throws {@link McpAppResourceError} otherwise.
158
+ */
159
+ declare const mcpAppDownloadOf: (uri: string, result: unknown, maxBytes?: number) => McpAppDownloadResource;
160
+
161
+ /**
162
+ * MCP elicitation, the part the two agent packages share: a server asks the user for input in
163
+ * the middle of a tool call, the HOST answers through a callback, and the call goes on. Pure, no
164
+ * imports: the limits, what a request must look like before a host sees it, what an answer must
165
+ * look like before a server sees it, the one function that asks, and the two ways a tool call
166
+ * with questions is driven (`elicitation/create` requests on the 2025 revisions, `input_required`
167
+ * results on 2026-07-28).
168
+ *
169
+ * A consent boundary. The server's text is third-party data: cleaned and capped here, shown only
170
+ * to the host's callback and in the `mcp.elicitation-requested` event, never put into a prompt.
171
+ * The answer goes to the server that asked and nowhere else: nothing in this file logs, emits or
172
+ * returns a value the user entered - events and errors carry field NAMES only.
173
+ *
174
+ * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-elicitation.ts`) and
175
+ * `@dudko.dev/agent-web` (`src/mcp/elicitation.ts`): change both. The Node package's
176
+ * `tests/mcp-elicitation-shared.test.ts` compares the two files and tests every guard here; each
177
+ * needs a mutation check.
178
+ */
179
+ /** How long one question waits for the host's answer, by default: a human is reading it. */
180
+ declare const MCP_ELICITATION_TIMEOUT_MS = 300000;
181
+ /** The most questions one tool call may ask, by default. */
182
+ declare const MCP_ELICITATION_MAX_PER_TOOL_CALL = 5;
183
+ /** The most questions one run may be asked, by default (its helpers' calls included). */
184
+ declare const MCP_ELICITATION_MAX_PER_RUN = 20;
185
+ /** One field of a form: the flat subset of JSON Schema the specification allows, nothing else. */
186
+ interface McpElicitationFieldSchema {
187
+ type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
188
+ title?: string;
189
+ description?: string;
190
+ default?: string | number | boolean | string[];
191
+ /** string */
192
+ minLength?: number;
193
+ maxLength?: number;
194
+ format?: 'email' | 'uri' | 'date' | 'date-time';
195
+ /** string: single-select, plain (`enumNames`: the older titled form). */
196
+ enum?: string[];
197
+ enumNames?: string[];
198
+ /** string: single-select with titles. */
199
+ oneOf?: {
200
+ const: string;
201
+ title: string;
202
+ }[];
203
+ /** number / integer */
204
+ minimum?: number;
205
+ maximum?: number;
206
+ /** array: multi-select. */
207
+ minItems?: number;
208
+ maxItems?: number;
209
+ items?: {
210
+ type?: 'string';
211
+ enum?: string[];
212
+ anyOf?: {
213
+ const: string;
214
+ title: string;
215
+ }[];
216
+ };
217
+ }
218
+ /** The form a server asks for, as a host is shown it: checked, cleaned and capped. */
219
+ interface McpElicitationSchema {
220
+ type: 'object';
221
+ properties: Record<string, McpElicitationFieldSchema>;
222
+ required?: string[];
223
+ }
224
+ /** What the host's callback is given. Every string in it is third-party text. */
225
+ interface McpElicitationRequest {
226
+ /** Unique per question; the same id is in the two events. */
227
+ id: string;
228
+ /** The server that asks: its key in the host's configuration. */
229
+ server: string;
230
+ /** The tool call during which it asks: the tool's name as the model called it. */
231
+ tool: string;
232
+ mode: 'form' | 'url';
233
+ /** The server's words, cleaned and capped (MCP_ELICITATION_MESSAGE_MAX_CHARS). */
234
+ message: string;
235
+ /** Form mode: the fields to fill in. */
236
+ requestedSchema?: McpElicitationSchema;
237
+ /**
238
+ * URL mode: the link the server wants the user to open. It is only handed over: nothing in
239
+ * these packages fetches or opens it. https, or http on a loopback host.
240
+ */
241
+ url?: string;
242
+ /** URL mode on the 2025 revisions: the server's id for this interaction. */
243
+ elicitationId?: string;
244
+ runId?: string;
245
+ /** Set when a helper the model started is the one whose call asks (`elicitation.subagents`). */
246
+ subagent?: {
247
+ id: string;
248
+ depth: number;
249
+ };
250
+ }
251
+ type McpElicitationContent = Record<string, string | number | boolean | string[]>;
252
+ /**
253
+ * The host's answer. `accept` carries the form's values (form mode) or nothing (URL mode: it
254
+ * says the user agreed to open the link); `decline` is a no; `cancel` is "dismissed".
255
+ */
256
+ type McpElicitationResult = {
257
+ action: 'accept';
258
+ content?: McpElicitationContent;
259
+ } | {
260
+ action: 'decline';
261
+ } | {
262
+ action: 'cancel';
263
+ };
264
+ interface McpElicitationContext {
265
+ /** Aborted when the answer is no longer wanted: the run stopped, or the time ran out. */
266
+ signal: AbortSignal;
267
+ }
268
+ /** `onElicitation`: the host decides, never the model. */
269
+ type McpElicitationHandler = (request: McpElicitationRequest, ctx: McpElicitationContext) => McpElicitationResult | Promise<McpElicitationResult>;
270
+ /** The `elicitation` settings beside `onElicitation`. */
271
+ interface McpElicitationOptions {
272
+ /**
273
+ * How long one question waits for an answer. Default 300 000. `0` or `Infinity` = no limit of
274
+ * its own (the question waits until the run is stopped), and so is a value above 2^31 - 1 (about
275
+ * 24.8 days, the most a timer holds). Negative or NaN: a configuration error.
276
+ */
277
+ timeoutMs?: number;
278
+ /** Questions one tool call may ask. Default 5. */
279
+ maxPerToolCall?: number;
280
+ /** Questions one run may be asked. Default 20. */
281
+ maxPerRun?: number;
282
+ /** Also accept URL mode (a link to open). Default false: only forms are declared. */
283
+ url?: boolean;
284
+ /**
285
+ * Let a tool call made by a helper (a subagent) ask the user too. Default false: such a
286
+ * question is cancelled without the callback being called.
287
+ */
288
+ subagents?: boolean;
289
+ }
290
+ /** Why a question was answered without the host deciding. */
291
+ type McpElicitationReason = 'unsupported-schema' | 'unsupported-mode' | 'insecure-url' | 'invalid-request' | 'subagent' | 'cap-per-call' | 'cap-per-run' | 'handler-error' | 'timeout' | 'invalid-answer' | 'aborted' | 'step-timeout' | 'after-failure' | 'no-tool-call';
292
+ type Checked<T> = {
293
+ ok: true;
294
+ value: T;
295
+ } | {
296
+ ok: false;
297
+ reason: string;
298
+ };
299
+ /**
300
+ * The form a server asked for, reduced to what the specification allows a form to be: a flat
301
+ * object of strings, numbers, booleans and selects. Anything else - a nested object, a list of
302
+ * objects, a type union, an unknown format, too many fields or options, a name that could not
303
+ * be sent back verbatim - is refused with a reason (the caller declines the request). Keywords
304
+ * outside the subset are dropped; titles and descriptions are cleaned and capped.
305
+ */
306
+ declare const normalizeMcpElicitationSchema: (raw: unknown) => Checked<McpElicitationSchema>;
307
+ /**
308
+ * An accepted form, checked against the schema it answers: every value of the type and within
309
+ * the limits its field states, every required field there, and NO field the form did not ask
310
+ * for (what the server did not request is not sent to it). The result is a fresh object holding
311
+ * only the form's own fields. A refusal names the field and the rule, never the value.
312
+ */
313
+ declare const validateMcpElicitationContent: (schema: McpElicitationSchema, content: unknown) => Checked<McpElicitationContent>;
314
+
315
+ /**
316
+ * MCP Skills (the `io.modelcontextprotocol/skills` extension, SEP-2640, Beta; written against
317
+ * base revision 2026-07-28): what the two agent packages share about a server's skills. The
318
+ * rules on a server's entries (`mcpSkillEntryRefusal`), the names a skill gets in the agent's
319
+ * catalog (`assignMcpSkillNames`: namespaced by the host's label of the server), the caps
320
+ * (`selectMcpSkills`), the files of a loaded skill the model may read (`resolveMcpSkillFile`),
321
+ * the preamble a skill's text is loaded under, the mark that carries a server's skills on its
322
+ * tools (`markMcpSkills` / `collectMcpSkillSources`), a skill the model names by URI
323
+ * (`mcpSkillUriRefusal`, `resolveMcpSkillServer`: `skills/get` to that one server only), the
324
+ * person's consent before a skill's text enters the model's context (`decideMcpSkillConsent`,
325
+ * `mcpSkillConsentView`) and a directory of a skill (`skillDirectoryOf`, `resolveMcpSkillPath`,
326
+ * `skillDirectoryListing` - for every kind of skill - and, for a server that serves
327
+ * `resources/directory/read`, `compareMcpSkillDirectory`) and, for a server the host trusts with
328
+ * its generated skills (`skills: { dynamic: true }`), the snapshot such a skill is read into
329
+ * before anyone is asked (`startMcpSkillWalk`, `takeMcpSkillWalkListing`,
330
+ * `mcpSkillSnapshotBytesRefusal`, `mcpSkillSnapshotEntry`). Pure, no imports (a digest is
331
+ * computed with the platform's WebCrypto, `globalThis.crypto.subtle`, or a function passed in).
332
+ *
333
+ * A server's skills are third-party text. They reach the model only as knowledge, under
334
+ * `mcpSkillPreamble`, and - unless the host vetted the server (`consent: 'never'`) - only after a
335
+ * person saw them and said yes; nothing here (or anywhere) reads a skill's frontmatter beyond its
336
+ * `name` and `description` - `allowed-tools` included - and a file a skill bundles is read as
337
+ * text, never run.
338
+ *
339
+ * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-skills.ts`) and
340
+ * `@dudko.dev/agent-web` (`src/mcp/skills.ts`): change both. The Node package's
341
+ * `tests/mcp-skills-shared.test.ts` compares the two files and tests every rule and cap here.
342
+ */
343
+ /** The extension's identifier, in the client's and the server's `extensions` capability. */
344
+ declare const MCP_SKILLS_EXTENSION = "io.modelcontextprotocol/skills";
345
+ /** The specification's limits (Limits): files per skill, `SKILL.md` included. */
346
+ declare const MCP_SKILL_MAX_RESOURCES = 512;
347
+ /** The specification's limits (Limits): the sum of `size` over a skill's files, in bytes. */
348
+ declare const MCP_SKILL_MAX_TOTAL_BYTES: number;
349
+ /** The most skills one server puts in the agent's catalog. */
350
+ declare const MCP_SKILLS_MAX_PER_SERVER = 32;
351
+ /** The most skills all servers put in the agent's catalog together. */
352
+ declare const MCP_SKILLS_MAX_TOTAL = 64;
353
+ /** The most a catalog entry (the description and its origin tag) takes, in characters. */
354
+ declare const MCP_SKILL_DESCRIPTION_MAX_CHARS = 300;
355
+ /** The most of a skill's instructions (its `SKILL.md` body) the model is given, in characters. */
356
+ declare const MCP_SKILL_BODY_MAX_CHARS = 16000;
357
+ /** The most of one file of a skill the model is given, in characters. */
358
+ declare const MCP_SKILL_FILE_MAX_CHARS = 32000;
359
+ /** One file of a skill, as its entry lists it. */
360
+ interface McpSkillResourceLike {
361
+ uri: string;
362
+ digest: string;
363
+ size: number;
364
+ }
365
+ /** A `skills/list` / `skills/get` entry (the extension's `Skill`), as far as this file reads it. */
366
+ interface McpSkillEntryLike {
367
+ uri: string;
368
+ frontmatter: {
369
+ name: string;
370
+ description: string;
371
+ [key: string]: unknown;
372
+ };
373
+ resources: McpSkillResourceLike[] | 'dynamic';
374
+ }
375
+ /**
376
+ * Why the agent does not take a skill entry from a server, or `undefined` when it does. The
377
+ * specification's rules on an entry, checked before anything of the skill is read:
378
+ *
379
+ * - its `uri` is a `SKILL.md` inside a named directory, whose last segment is the skill's
380
+ * frontmatter `name` (Resource Mapping; Frontmatter), and that name follows the Agent Skills
381
+ * naming rules;
382
+ * - a description to show in the catalog;
383
+ * - `resources` is the complete list of its files (Resources): `"dynamic"` content is declined
384
+ * (a host MAY: there is nothing to verify it against, and a consent could not bind to its
385
+ * content) - unless `options.dynamic` (the server's `skills: { dynamic: true }`: the host
386
+ * trusts that server with its generated skills, which are then read into a snapshot before
387
+ * anyone is asked, see {@link mcpSkillSnapshotEntry}); anything else is invalid;
388
+ * - every file is `SKILL.md` or a file inside the skill's directory, listed once, with a
389
+ * `sha256:` digest and a byte size, and `SKILL.md` is listed;
390
+ * - at most {@link MCP_SKILL_MAX_RESOURCES} files and {@link MCP_SKILL_MAX_TOTAL_BYTES} bytes
391
+ * (Limits: "both limits are checkable from the entry alone"; a generated skill's are counted
392
+ * on what its snapshot reads).
393
+ */
394
+ declare const mcpSkillEntryRefusal: (entry: unknown, options?: {
395
+ dynamic?: boolean;
396
+ }) => string | undefined;
397
+ /** One skill of a server, as the agent's catalog holds it (the entry stays with the connection). */
398
+ interface McpSkillRecord {
399
+ /** The `SKILL.md` URI: with the server, the skill's identity. */
400
+ uri: string;
401
+ /** The frontmatter `name` (a label: two skills of one server may share it). */
402
+ name: string;
403
+ /** The description, cleaned to one line (not yet capped). */
404
+ description: string;
405
+ /** The skill's path (`acme/billing/refunds`), as segments. */
406
+ path: string[];
407
+ /** Its files other than `SKILL.md`, by their path inside the skill, sorted. */
408
+ files: string[];
409
+ /**
410
+ * Generated by the server (`"resources": "dynamic"`, taken with `skills: { dynamic: true }`):
411
+ * no files are known until its snapshot is read, and there are no checksums.
412
+ */
413
+ dynamic?: true;
414
+ }
415
+ /**
416
+ * How a skill of a server is introduced wherever its text is shown to the model (its
417
+ * instructions, and each file of it): third-party knowledge that cannot change the rules. The
418
+ * wording is the guard.
419
+ */
420
+ declare const mcpSkillPreamble: (server: string, uri: string) => string;
421
+ /**
422
+ * The most entries of one `resources/directory/read` answer looked at: the specification's 512
423
+ * files per skill, and room for the directories among them. The rest are not looked at.
424
+ */
425
+ declare const MCP_SKILL_DIRECTORY_ENTRIES_MAX: number;
426
+ /**
427
+ * What a server's live view of a directory says against the entry a skill was loaded with
428
+ * ({@link compareMcpSkillDirectory}): a count and paths of that entry - nothing of the server's
429
+ * own listing.
430
+ */
431
+ interface McpSkillDirectoryDrift {
432
+ /** Children the server lists that the entry does not hold: counted, never named. */
153
433
  extra: number;
154
434
  /** Children the entry holds (paths inside the skill) that the server does not list, sorted. */
155
435
  notServed: string[];
@@ -266,415 +546,135 @@ interface McpSkillConsentView {
266
546
  * there are no checksums. The size, the files and the text are those of the copy the agent just
267
547
  * read (its snapshot), and only that copy is used - say so.
268
548
  */
269
- dynamic?: true;
270
- /**
271
- * (with `dynamic`) The server cannot list the skill's files (no `resources/directory/read`): the
272
- * copy is its `SKILL.md` alone, and no other file of it can be read.
273
- */
274
- noFileListing?: true;
275
- /** Asked for this run only (`'ask'`) or, on a yes, for the agent's life (`'once-per-skill'`). */
276
- consent: Exclude<McpSkillConsent, 'never'>;
277
- }
278
- /**
279
- * The most directories one snapshot reads (`resources/directory/read`, the skill's root
280
- * included). One read is one directory, its pages walked by the SDK (bounded by its own page cap).
281
- */
282
- declare const MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES = 64;
283
- /** The deepest directory of a skill a snapshot reads: its root is 0, `templates` 1, ... */
284
- declare const MCP_SKILL_SNAPSHOT_MAX_DEPTH = 8;
285
- /** The most bytes the snapshots of one agent hold in memory together. */
286
- declare const MCP_SKILL_SNAPSHOTS_MAX_BYTES: number;
287
- /** What the snapshots of one agent hold in memory, in bytes ({@link MCP_SKILL_SNAPSHOTS_MAX_BYTES}). */
288
- interface McpSkillSnapshotMemory {
289
- used: number;
290
- }
291
- /** A loaded skill: its instructions, and the entry its files are read against (opaque). */
292
- interface McpSkillLoaded {
293
- readonly uri: string;
294
- /** The `SKILL.md` body (after its frontmatter), verified - not yet cleaned or capped. */
295
- readonly body: string;
296
- /** Its files other than `SKILL.md`, as the entry it was loaded with lists them. */
297
- readonly files: readonly string[];
298
- /** The entry it was loaded with (the "held entry"): what a consent is bound to and shows. */
299
- readonly entry: McpSkillEntryLike;
300
- /**
301
- * A generated skill's snapshot: `entry` is the manifest of the copy the agent read, which is
302
- * held in memory and the only one used. `bytes`: what it holds (counted against the agent's
303
- * {@link McpSkillSnapshotMemory}); `listed`: the server listed its files (`directoryRead`) -
304
- * without, the copy is `SKILL.md` alone.
305
- */
306
- readonly snapshot?: {
307
- readonly bytes: number;
308
- readonly listed: boolean;
309
- };
310
- }
311
- /**
312
- * The skills of one connected server, for the agent (a connection with `skills` on, to a server
313
- * that offers the extension). `skills` and `added` are live: a refresh of the server replaces
314
- * `skills`; `get` adds to `added`.
315
- */
316
- interface McpSkillSource {
317
- /** The host's label of the server: its key in the configuration. */
318
- readonly server: string;
319
- /** The skills its listing (`skills/list`) gave, the rules passed. */
320
- readonly skills: readonly McpSkillRecord[];
321
- /** Skills it gave by URI (`get`, `skills/get`) that its listing does not hold. */
322
- readonly added?: readonly McpSkillRecord[];
323
- /** The consent the server's config names (`skills: { consent }`); absent: the agent's decides. */
324
- readonly consent?: McpSkillConsent;
325
- /**
326
- * Ask the server - this one only - for the skill whose `SKILL.md` is at `uri` (`skills/get`):
327
- * its entry passes the same rules as a listed one and joins `added`. Throws when the URI is not
328
- * one to send ({@link mcpSkillUriRefusal}), the server does not serve it (`-32602`) or the entry
329
- * is refused.
330
- */
331
- get?: (uri: string, options?: {
332
- signal?: AbortSignal;
333
- }) => Promise<McpSkillRecord>;
334
- /**
335
- * Read the skill's `SKILL.md` and verify it against its entry (size, digest, frontmatter);
336
- * throws - and gives nothing - when it does not match. A generated skill (`dynamic`) is read
337
- * into a snapshot instead (see {@link mcpSkillSnapshotEntry}), its bytes counted against
338
- * `options.memory` (the agent's; a fresh one without); throws - logged - when it passes a bound.
339
- */
340
- load: (uri: string, options?: {
341
- signal?: AbortSignal;
342
- memory?: McpSkillSnapshotMemory;
343
- }) => Promise<McpSkillLoaded>;
344
- /**
345
- * Read one file of a loaded skill - a path its entry lists - and verify it against the entry
346
- * the skill was loaded with; a snapshot's file is served from the snapshot, never read again.
347
- * Text only; throws for anything else.
348
- */
349
- readFile: (loaded: McpSkillLoaded, path: string, options?: {
350
- signal?: AbortSignal;
351
- }) => Promise<string>;
352
- /**
353
- * Only for a server that declared `directoryRead`: its live view of a directory of a loaded
354
- * skill (`resources/directory/read` to THIS server, of the skill's root or `<root>/<dir>`),
355
- * compared with the entry the skill was loaded with ({@link compareMcpSkillDirectory}) - a
356
- * count and paths of that entry, nothing of the server's listing. `undefined` when the read
357
- * failed (logged): the directory is then listed from the entry alone. Throws when `dir` is no
358
- * directory of that entry (before any request), or when `options.signal` aborted the read.
359
- */
360
- readDirectory?: (loaded: McpSkillLoaded, dir: string, options?: {
361
- signal?: AbortSignal;
362
- }) => Promise<McpSkillDirectoryDrift | undefined>;
363
- }
364
-
365
- /**
366
- * MCP Apps (the `io.modelcontextprotocol/ui` extension, stable revision 2026-01-26): a tool of an
367
- * MCP server declares an HTML user interface (`_meta.ui.resourceUri`, a `ui://` resource), the
368
- * host reads it with `resources/read` and shows it next to the tool's result in a sandboxed frame.
369
- *
370
- * Pure, no imports: what this package accepts of the server's declarations, before anything is
371
- * shown. Everything here is third-party data from the server, so every function is a guard:
372
- *
373
- * - `mcpAppToolMeta`: the tool's link to its app - a `ui://` URI or nothing - and who may call
374
- * it (`visibility`: the model, the app, or both).
375
- * - `mcpAppResourceOf`: the `resources/read` answer - the right URI, the extension's MIME type,
376
- * a size cap, `text` or base64 `blob` - and the resource's metadata cleaned: CSP origins that
377
- * are origins and nothing else, the permissions it asks for (reported, never granted here).
378
- * - `mcpAppToolResultOf`: what of a tool's result is handed to the app, capped.
379
- *
380
- * The HTML itself never reaches the model: it is not part of a tool result, an event or a log.
381
- */
382
- /** The extension's identifier: declared under `capabilities.extensions` in the handshake. */
383
- declare const MCP_APPS_EXTENSION = "io.modelcontextprotocol/ui";
384
- /** The one content type of the stable revision (`text/html` with the `mcp-app` profile). */
385
- declare const MCP_APP_MIME_TYPE = "text/html;profile=mcp-app";
386
- /** An app's HTML above this many characters is refused (a bundled single-file app is ~1 MB). */
387
- declare const MCP_APP_MAX_HTML_CHARS = 2000000;
388
- /** A tool result above this many characters (as JSON) is not handed to its app. */
389
- declare const MCP_APP_MAX_RESULT_CHARS = 512000;
390
- /** At most this many origins per CSP list of a resource; the rest are refused. */
391
- declare const MCP_APP_MAX_DOMAINS = 32;
392
- /** Who may call a tool: the model (it is in the agent's toolbox), an app of its server, or both. */
393
- type McpAppVisibility = 'model' | 'app';
394
- /** The specification's default when a tool says nothing. */
395
- declare const MCP_APP_DEFAULT_VISIBILITY: readonly McpAppVisibility[];
396
- /**
397
- * The origins an app's resource declared, after cleaning: each entry an origin
398
- * (`https://host[:port]`, `wss://…`, `https://*.example.com`, or `http(s)/ws(s)` on loopback),
399
- * nothing else. An empty list means "none": the frame gets no network for that kind.
400
- */
401
- interface McpAppCsp {
402
- /** `fetch` / XHR / WebSocket (`connect-src`). */
403
- connectDomains: string[];
404
- /** Scripts, styles, images, fonts, media (`script-src`, `style-src`, …). */
405
- resourceDomains: string[];
406
- /** Nested frames (`frame-src`). */
407
- frameDomains: string[];
408
- /** `<base href>` (`base-uri`). */
409
- baseUriDomains: string[];
410
- }
411
- /** Browser features the resource asks for. Reported to the host; this package grants none. */
412
- interface McpAppPermissions {
413
- camera?: true;
414
- microphone?: true;
415
- geolocation?: true;
416
- clipboardWrite?: true;
417
- }
418
- /** An app's document, read from the server that declared it and checked. */
419
- interface McpAppResource {
420
- /** The server it was read from (the one whose tool declared it). */
421
- server: string;
422
- uri: string;
423
- /** The app's HTML. Third-party code: frame it, never put it in a page or a model's context. */
424
- html: string;
425
- /** The origins it declared, cleaned (see `McpAppCsp`). */
426
- csp: McpAppCsp;
427
- /** Declared entries that are not origins this package accepts - left out of `csp`. */
428
- refusedDomains: string[];
429
- /** What it asked for; not granted by this package. */
430
- permissions: McpAppPermissions;
431
- /** Its wish for a visible border; the host decides. */
432
- prefersBorder?: boolean;
433
- /** The dedicated origin it asked for; a page-based host cannot give one, so it is only reported. */
434
- domain?: string;
435
- }
436
- /** A tool's result as handed to its app: the MCP `CallToolResult`, unchanged but for unknown keys. */
437
- interface McpAppToolResult {
438
- content?: unknown[];
439
- structuredContent?: Record<string, unknown>;
440
- isError?: boolean;
441
- _meta?: Record<string, unknown>;
442
- }
443
- /** What a tool declares about apps. */
444
- interface McpAppToolMeta {
445
- /** Its app (`ui://…`), when it declares a valid one. */
446
- resourceUri?: string;
447
- visibility: McpAppVisibility[];
448
- /** A declared app URI that was refused (not `ui://`, too long, not text) - for the log. */
449
- refusedUri?: string;
450
- }
451
- /** A `ui://` URI this package will read: text, short, no control characters. */
452
- declare const isMcpAppUri: (value: unknown) => value is string;
453
- /**
454
- * The tool's app and who may call it. `_meta.ui.resourceUri` wins over the deprecated flat
455
- * `_meta["ui/resourceUri"]`. `visibility` defaults to both; unknown entries are dropped; a list
456
- * that names nothing known is the default.
457
- */
458
- declare const mcpAppToolMeta: (tool: {
459
- _meta?: unknown;
460
- }) => McpAppToolMeta;
461
- /**
462
- * Whether a content type is the extension's: `text/html` with `profile=mcp-app`, in any case,
463
- * with or without spaces or quotes; `charset=utf-8` may come along, nothing else.
464
- */
465
- declare const isMcpAppMimeType: (value: unknown) => boolean;
466
- /**
467
- * One declared CSP entry as a source expression this package puts in a policy, or `undefined`.
468
- * Only an origin: `https://` / `wss://` (a `*.` subdomain wildcard over at least two labels),
469
- * or `http://` / `ws://` on loopback. No path, no keyword (`'unsafe-eval'`), no bare scheme, no
470
- * `*`, no separator (`;` `,` space) that could add a directive of its own.
471
- */
472
- declare const mcpAppOrigin: (entry: unknown) => string | undefined;
473
- /** The resource's declared CSP, cleaned: origins kept, everything else in `refused`. */
474
- declare const mcpAppCspOf: (raw: unknown) => {
475
- csp: McpAppCsp;
476
- refused: string[];
477
- };
478
- /** The permissions a resource asks for: the four the specification names, nothing else. */
479
- declare const mcpAppPermissionsOf: (raw: unknown) => McpAppPermissions;
480
- /** Why a `resources/read` answer is not an app this package shows. */
481
- declare class McpAppResourceError extends Error {
482
- constructor(message: string);
483
- }
484
- /**
485
- * The app in a `resources/read` answer for `uri`: the entry with exactly that URI, the
486
- * extension's MIME type, `text` (or base64 `blob`) under `maxChars`, metadata cleaned. Throws
487
- * {@link McpAppResourceError} otherwise - nothing of a refused answer is shown.
488
- */
489
- declare const mcpAppResourceOf: (server: string, uri: string, result: unknown, maxChars?: number) => McpAppResource;
490
- /**
491
- * The parts of a tool result an app is given (`content`, `structuredContent`, `isError`,
492
- * `_meta`), or `undefined` when they are more than `maxChars` as JSON or not a result at all.
493
- */
494
- declare const mcpAppToolResultOf: (result: unknown, maxChars?: number) => McpAppToolResult | undefined;
495
- /**
496
- * What MCP Apps are for ONE server, from its own setting (`McpHttpServerConfig.apps`) and the
497
- * connection's (`ConnectMcpOptions.apps`); the server's wins when it has one:
498
- *
499
- * - `'on'`: the extension declared, `_meta.ui` read, the server's apps shown.
500
- * - `'declined'` (the server's `apps: false`): its apps are not shown here. Nothing is declared,
501
- * no app is read and no `mcp.app` event is told, and a tool marked for its app only
502
- * (`visibility` without `'model'`) is not mounted - it is for an app that will never run.
503
- * Every other tool is the model's, as a plain tool.
504
- * - `'off'` (neither set): MCP Apps unknown - nothing declared, `_meta` not read, every tool
505
- * mounted: the wire and the tools are what they were before the extension.
506
- */
507
- type McpAppsMode = 'on' | 'declined' | 'off';
508
- declare const mcpAppsModeOf: (server: boolean | undefined, connection: boolean | undefined) => McpAppsMode;
509
- /** A file an app asks the host to save, at most this many bytes (`readResource`'s default cap). */
510
- declare const MCP_APP_MAX_DOWNLOAD_BYTES: number;
511
- /** A resource read for a download (`McpAppsConnection.readResource`): its bytes, as sent. */
512
- interface McpAppDownloadResource {
513
- uri: string;
514
- /** The type the server gave it, if any (third-party: the host judges it). */
515
- mimeType?: string;
516
- bytes: Uint8Array;
549
+ dynamic?: true;
550
+ /**
551
+ * (with `dynamic`) The server cannot list the skill's files (no `resources/directory/read`): the
552
+ * copy is its `SKILL.md` alone, and no other file of it can be read.
553
+ */
554
+ noFileListing?: true;
555
+ /** Asked for this run only (`'ask'`) or, on a yes, for the agent's life (`'once-per-skill'`). */
556
+ consent: Exclude<McpSkillConsent, 'never'>;
517
557
  }
518
558
  /**
519
- * The bytes of a `resources/read` answer for `uri`, for a file the user is about to be asked to
520
- * save: the entry with exactly that URI, `text` (as UTF-8) or base64 `blob`, at most `maxBytes`.
521
- * Any MIME type (the host decides what it saves). Throws {@link McpAppResourceError} otherwise.
522
- */
523
- declare const mcpAppDownloadOf: (uri: string, result: unknown, maxBytes?: number) => McpAppDownloadResource;
524
-
525
- /**
526
- * MCP elicitation, the part the two agent packages share: a server asks the user for input in
527
- * the middle of a tool call, the HOST answers through a callback, and the call goes on. Pure, no
528
- * imports: the limits, what a request must look like before a host sees it, what an answer must
529
- * look like before a server sees it, the one function that asks, and the two ways a tool call
530
- * with questions is driven (`elicitation/create` requests on the 2025 revisions, `input_required`
531
- * results on 2026-07-28).
532
- *
533
- * A consent boundary. The server's text is third-party data: cleaned and capped here, shown only
534
- * to the host's callback and in the `mcp.elicitation-requested` event, never put into a prompt.
535
- * The answer goes to the server that asked and nowhere else: nothing in this file logs, emits or
536
- * returns a value the user entered - events and errors carry field NAMES only.
537
- *
538
- * This file is a COPY, byte for byte, in `@dudko.dev/agent` (`src/mcp-elicitation.ts`) and
539
- * `@dudko.dev/agent-web` (`src/mcp/elicitation.ts`): change both. The Node package's
540
- * `tests/mcp-elicitation-shared.test.ts` compares the two files and tests every guard here; each
541
- * needs a mutation check.
559
+ * The most directories one snapshot reads (`resources/directory/read`, the skill's root
560
+ * included). One read is one directory, its pages walked by the SDK (bounded by its own page cap).
542
561
  */
543
- /** How long one question waits for the host's answer, by default: a human is reading it. */
544
- declare const MCP_ELICITATION_TIMEOUT_MS = 300000;
545
- /** The most questions one tool call may ask, by default. */
546
- declare const MCP_ELICITATION_MAX_PER_TOOL_CALL = 5;
547
- /** The most questions one run may be asked, by default (its helpers' calls included). */
548
- declare const MCP_ELICITATION_MAX_PER_RUN = 20;
549
- /** One field of a form: the flat subset of JSON Schema the specification allows, nothing else. */
550
- interface McpElicitationFieldSchema {
551
- type: 'string' | 'number' | 'integer' | 'boolean' | 'array';
552
- title?: string;
553
- description?: string;
554
- default?: string | number | boolean | string[];
555
- /** string */
556
- minLength?: number;
557
- maxLength?: number;
558
- format?: 'email' | 'uri' | 'date' | 'date-time';
559
- /** string: single-select, plain (`enumNames`: the older titled form). */
560
- enum?: string[];
561
- enumNames?: string[];
562
- /** string: single-select with titles. */
563
- oneOf?: {
564
- const: string;
565
- title: string;
566
- }[];
567
- /** number / integer */
568
- minimum?: number;
569
- maximum?: number;
570
- /** array: multi-select. */
571
- minItems?: number;
572
- maxItems?: number;
573
- items?: {
574
- type?: 'string';
575
- enum?: string[];
576
- anyOf?: {
577
- const: string;
578
- title: string;
579
- }[];
580
- };
581
- }
582
- /** The form a server asks for, as a host is shown it: checked, cleaned and capped. */
583
- interface McpElicitationSchema {
584
- type: 'object';
585
- properties: Record<string, McpElicitationFieldSchema>;
586
- required?: string[];
562
+ declare const MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES = 64;
563
+ /** The deepest directory of a skill a snapshot reads: its root is 0, `templates` 1, ... */
564
+ declare const MCP_SKILL_SNAPSHOT_MAX_DEPTH = 8;
565
+ /** The most bytes the snapshots of one agent hold in memory together. */
566
+ declare const MCP_SKILL_SNAPSHOTS_MAX_BYTES: number;
567
+ /** What the snapshots of one agent hold in memory, in bytes ({@link MCP_SKILL_SNAPSHOTS_MAX_BYTES}). */
568
+ interface McpSkillSnapshotMemory {
569
+ used: number;
587
570
  }
588
- /** What the host's callback is given. Every string in it is third-party text. */
589
- interface McpElicitationRequest {
590
- /** Unique per question; the same id is in the two events. */
591
- id: string;
592
- /** The server that asks: its key in the host's configuration. */
593
- server: string;
594
- /** The tool call during which it asks: the tool's name as the model called it. */
595
- tool: string;
596
- mode: 'form' | 'url';
597
- /** The server's words, cleaned and capped (MCP_ELICITATION_MESSAGE_MAX_CHARS). */
598
- message: string;
599
- /** Form mode: the fields to fill in. */
600
- requestedSchema?: McpElicitationSchema;
571
+ /** A loaded skill: its instructions, and the entry its files are read against (opaque). */
572
+ interface McpSkillLoaded {
573
+ readonly uri: string;
574
+ /** The `SKILL.md` body (after its frontmatter), verified - not yet cleaned or capped. */
575
+ readonly body: string;
576
+ /** Its files other than `SKILL.md`, as the entry it was loaded with lists them. */
577
+ readonly files: readonly string[];
578
+ /** The entry it was loaded with (the "held entry"): what a consent is bound to and shows. */
579
+ readonly entry: McpSkillEntryLike;
601
580
  /**
602
- * URL mode: the link the server wants the user to open. It is only handed over: nothing in
603
- * these packages fetches or opens it. https, or http on a loopback host.
581
+ * A generated skill's snapshot: `entry` is the manifest of the copy the agent read, which is
582
+ * held in memory and the only one used. `bytes`: what it holds (counted against the agent's
583
+ * {@link McpSkillSnapshotMemory}); `listed`: the server listed its files (`directoryRead`) -
584
+ * without, the copy is `SKILL.md` alone.
604
585
  */
605
- url?: string;
606
- /** URL mode on the 2025 revisions: the server's id for this interaction. */
607
- elicitationId?: string;
608
- runId?: string;
609
- /** Set when a helper the model started is the one whose call asks (`elicitation.subagents`). */
610
- subagent?: {
611
- id: string;
612
- depth: number;
586
+ readonly snapshot?: {
587
+ readonly bytes: number;
588
+ readonly listed: boolean;
613
589
  };
614
590
  }
615
- type McpElicitationContent = Record<string, string | number | boolean | string[]>;
616
591
  /**
617
- * The host's answer. `accept` carries the form's values (form mode) or nothing (URL mode: it
618
- * says the user agreed to open the link); `decline` is a no; `cancel` is "dismissed".
592
+ * The skills of one connected server, for the agent (a connection with `skills` on, to a server
593
+ * that offers the extension). `skills` and `added` are live: a refresh of the server replaces
594
+ * `skills`; `get` adds to `added`.
619
595
  */
620
- type McpElicitationResult = {
621
- action: 'accept';
622
- content?: McpElicitationContent;
623
- } | {
624
- action: 'decline';
625
- } | {
626
- action: 'cancel';
627
- };
628
- interface McpElicitationContext {
629
- /** Aborted when the answer is no longer wanted: the run stopped, or the time ran out. */
630
- signal: AbortSignal;
631
- }
632
- /** `onElicitation`: the host decides, never the model. */
633
- type McpElicitationHandler = (request: McpElicitationRequest, ctx: McpElicitationContext) => McpElicitationResult | Promise<McpElicitationResult>;
634
- /** The `elicitation` settings beside `onElicitation`. */
635
- interface McpElicitationOptions {
596
+ interface McpSkillSource {
597
+ /** The host's label of the server: its key in the configuration. */
598
+ readonly server: string;
599
+ /** The skills its listing (`skills/list`) gave, the rules passed. */
600
+ readonly skills: readonly McpSkillRecord[];
601
+ /** Skills it gave by URI (`get`, `skills/get`) that its listing does not hold. */
602
+ readonly added?: readonly McpSkillRecord[];
603
+ /** The consent the server's config names (`skills: { consent }`); absent: the agent's decides. */
604
+ readonly consent?: McpSkillConsent;
636
605
  /**
637
- * How long one question waits for an answer. Default 300 000. `0` or `Infinity` = no limit of
638
- * its own (the question waits until the run is stopped), and so is a value above 2^31 - 1 (about
639
- * 24.8 days, the most a timer holds). Negative or NaN: a configuration error.
606
+ * Ask the server - this one only - for the skill whose `SKILL.md` is at `uri` (`skills/get`):
607
+ * its entry passes the same rules as a listed one and joins `added`. Throws when the URI is not
608
+ * one to send ({@link mcpSkillUriRefusal}), the server does not serve it (`-32602`) or the entry
609
+ * is refused.
640
610
  */
641
- timeoutMs?: number;
642
- /** Questions one tool call may ask. Default 5. */
643
- maxPerToolCall?: number;
644
- /** Questions one run may be asked. Default 20. */
645
- maxPerRun?: number;
646
- /** Also accept URL mode (a link to open). Default false: only forms are declared. */
647
- url?: boolean;
611
+ get?: (uri: string, options?: {
612
+ signal?: AbortSignal;
613
+ }) => Promise<McpSkillRecord>;
648
614
  /**
649
- * Let a tool call made by a helper (a subagent) ask the user too. Default false: such a
650
- * question is cancelled without the callback being called.
615
+ * Read the skill's `SKILL.md` and verify it against its entry (size, digest, frontmatter);
616
+ * throws - and gives nothing - when it does not match. A generated skill (`dynamic`) is read
617
+ * into a snapshot instead (see {@link mcpSkillSnapshotEntry}), its bytes counted against
618
+ * `options.memory` (the agent's; a fresh one without); throws - logged - when it passes a bound.
651
619
  */
652
- subagents?: boolean;
620
+ load: (uri: string, options?: {
621
+ signal?: AbortSignal;
622
+ memory?: McpSkillSnapshotMemory;
623
+ }) => Promise<McpSkillLoaded>;
624
+ /**
625
+ * Read one file of a loaded skill - a path its entry lists - and verify it against the entry
626
+ * the skill was loaded with; a snapshot's file is served from the snapshot, never read again.
627
+ * Text only; throws for anything else.
628
+ */
629
+ readFile: (loaded: McpSkillLoaded, path: string, options?: {
630
+ signal?: AbortSignal;
631
+ }) => Promise<string>;
632
+ /**
633
+ * Only for a server that declared `directoryRead`: its live view of a directory of a loaded
634
+ * skill (`resources/directory/read` to THIS server, of the skill's root or `<root>/<dir>`),
635
+ * compared with the entry the skill was loaded with ({@link compareMcpSkillDirectory}) - a
636
+ * count and paths of that entry, nothing of the server's listing. `undefined` when the read
637
+ * failed (logged): the directory is then listed from the entry alone. Throws when `dir` is no
638
+ * directory of that entry (before any request), or when `options.signal` aborted the read.
639
+ */
640
+ readDirectory?: (loaded: McpSkillLoaded, dir: string, options?: {
641
+ signal?: AbortSignal;
642
+ }) => Promise<McpSkillDirectoryDrift | undefined>;
643
+ }
644
+
645
+ interface VaultOptions {
646
+ /** Database name, forwarded to the shared IDB owner (default 'agent-web'). */
647
+ dbName?: string;
653
648
  }
654
- /** Why a question was answered without the host deciding. */
655
- type McpElicitationReason = 'unsupported-schema' | 'unsupported-mode' | 'insecure-url' | 'invalid-request' | 'subagent' | 'cap-per-call' | 'cap-per-run' | 'handler-error' | 'timeout' | 'invalid-answer' | 'aborted' | 'step-timeout' | 'after-failure' | 'no-tool-call';
656
- type Checked<T> = {
657
- ok: true;
658
- value: T;
659
- } | {
660
- ok: false;
661
- reason: string;
662
- };
663
- /**
664
- * The form a server asked for, reduced to what the specification allows a form to be: a flat
665
- * object of strings, numbers, booleans and selects. Anything else - a nested object, a list of
666
- * objects, a type union, an unknown format, too many fields or options, a name that could not
667
- * be sent back verbatim - is refused with a reason (the caller declines the request). Keywords
668
- * outside the subset are dropped; titles and descriptions are cleaned and capped.
669
- */
670
- declare const normalizeMcpElicitationSchema: (raw: unknown) => Checked<McpElicitationSchema>;
671
649
  /**
672
- * An accepted form, checked against the schema it answers: every value of the type and within
673
- * the limits its field states, every required field there, and NO field the form did not ask
674
- * for (what the server did not request is not sent to it). The result is a fresh object holding
675
- * only the form's own fields. A refusal names the field and the rule, never the value.
650
+ * Encrypted key/value secret store backed by IndexedDB. Values are encrypted at
651
+ * rest with the non-extractable AES-GCM vault key (see crypto.ts).
652
+ *
653
+ * ── THREAT MODEL (read before shipping any app-owned key to a browser) ──
654
+ * This vault PROTECTS secrets **at rest** — an IndexedDB / disk dump yields
655
+ * only ciphertext — and against **casual DevTools inspection** — no plaintext
656
+ * key is stored, and the AES key cannot be exported even by in-page script.
657
+ *
658
+ * It does **NOT** defend against **active XSS on your origin**: any script that
659
+ * already runs on the page can call `getSecret()`, or use the live `CryptoKey`
660
+ * to decrypt. Browser storage is not a secrets manager.
661
+ *
662
+ * Therefore this vault is for the **end user's OWN key on their OWN device**
663
+ * (bring-your-own-key). A shared, app-owned key must NEVER reach the client —
664
+ * put it behind a server proxy (`ProviderModelSpec.baseURL`) or the Vercel AI
665
+ * Gateway instead.
676
666
  */
677
- declare const validateMcpElicitationContent: (schema: McpElicitationSchema, content: unknown) => Checked<McpElicitationContent>;
667
+ declare class IndexedDBVault {
668
+ private readonly dbName?;
669
+ constructor(opts?: VaultOptions);
670
+ private key;
671
+ /** Encrypt and store a secret string under `id`. */
672
+ setSecret(id: string, value: string): Promise<void>;
673
+ /** Fetch and decrypt a secret, or undefined if absent. */
674
+ getSecret(id: string): Promise<string | undefined>;
675
+ deleteSecret(id: string): Promise<void>;
676
+ listSecretIds(): Promise<string[]>;
677
+ }
678
678
 
679
679
  export { MCP_SKILL_URI_MAX_CHARS as A, IndexedDBVault as I, mcpAppOrigin as J, mcpSkillEntryRefusal as K, mcpSkillPreamble as L, mcpSkillUriRefusal as N, MCP_APP_DEFAULT_VISIBILITY as R, MCP_APP_MAX_DOMAINS as T, MCP_APP_MAX_DOWNLOAD_BYTES as U, MCP_ELICITATION_MAX_PER_RUN as W, MCP_ELICITATION_MAX_PER_TOOL_CALL as X, MCP_ELICITATION_TIMEOUT_MS as Y, McpAppResourceError as Z, isMcpAppMimeType as a4, isMcpAppUri as a5, mcpAppCspOf as a6, mcpAppDownloadOf as a7, mcpAppPermissionsOf as a8, mcpAppResourceOf as a9, mcpAppToolMeta as aa, mcpAppToolResultOf as ab, mcpAppsModeOf as ac, normalizeMcpElicitationSchema as ad, validateMcpElicitationContent as ae, MCP_APPS_EXTENSION as i, MCP_APP_MAX_HTML_CHARS as j, MCP_APP_MAX_RESULT_CHARS as k, MCP_APP_MIME_TYPE as l, MCP_SKILLS_EXTENSION as m, MCP_SKILLS_MAX_PER_SERVER as n, MCP_SKILLS_MAX_TOTAL as o, MCP_SKILL_BODY_MAX_CHARS as p, MCP_SKILL_CONSENTS as q, MCP_SKILL_CONSENT_DEFAULT as r, MCP_SKILL_DESCRIPTION_MAX_CHARS as s, MCP_SKILL_DIRECTORY_ENTRIES_MAX as t, MCP_SKILL_FILE_MAX_CHARS as u, MCP_SKILL_MAX_RESOURCES as v, MCP_SKILL_MAX_TOTAL_BYTES as w, MCP_SKILL_SNAPSHOTS_MAX_BYTES as x, MCP_SKILL_SNAPSHOT_MAX_DEPTH as y, MCP_SKILL_SNAPSHOT_MAX_DIRECTORIES as z };
680
- export type { McpAppsMode as $, McpAppCsp as B, McpAppPermissions as C, McpAppResource as D, McpAppVisibility as E, McpElicitationFieldSchema as F, McpSkillsOptions as G, McpSkillsSetting as H, McpSkillSource as M, McpElicitationHandler as O, McpElicitationOptions as P, McpAppDownloadResource as Q, SkillDirectoryListing as S, VaultOptions as V, McpAppToolMeta as _, McpSkillConsent as a, McpElicitationContent as a0, McpElicitationContext as a1, McpElicitationRequest as a2, McpElicitationResult as a3, McpSkillGrants as b, McpSkillRunConsent as c, McpSkillConsentView as d, McpSkillSnapshotMemory as e, McpElicitationSchema as f, McpElicitationReason as g, McpAppToolResult as h };
680
+ export type { McpAppsMode as $, McpAppCsp as B, McpAppPermissions as C, McpAppResource as D, McpAppVisibility as E, McpElicitationFieldSchema as F, McpSkillsOptions as G, McpSkillsSetting as H, McpSkillConsentView as M, McpElicitationHandler as O, McpElicitationOptions as P, McpAppDownloadResource as Q, SkillDirectoryListing as S, VaultOptions as V, McpAppToolMeta as _, McpElicitationSchema as a, McpElicitationContent as a0, McpElicitationContext as a1, McpElicitationRequest as a2, McpElicitationResult as a3, McpElicitationReason as b, McpAppToolResult as c, McpSkillSource as d, McpSkillConsent as e, McpSkillGrants as f, McpSkillRunConsent as g, McpSkillSnapshotMemory as h };