@dudko.dev/agent-web-react 0.0.29 → 0.0.31

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/dist/mcp.d.ts CHANGED
@@ -1,94 +1,7 @@
1
- import { AgentToolSet } from '@dudko.dev/agent-web';
2
-
3
- /**
4
- * Structural types for the core's OPTIONAL `@dudko.dev/agent-web/mcp` subpath.
5
- *
6
- * The subpath is loaded with a dynamic import and typed here rather than
7
- * imported, for two reasons: it drags in `@modelcontextprotocol/client` (an
8
- * optional peer of the core, which apps without MCP must not have to install),
9
- * and the OAuth half only exists in newer cores while this package supports
10
- * `@dudko.dev/agent-web >= 0.0.6`. `useMcp` feature-detects at runtime and
11
- * reports `oauthSupported: false` on an older core instead of crashing.
12
- */
13
- interface McpCatalogEntry {
14
- name: string;
15
- description: string;
16
- server: string;
17
- /** The server marked the tool read-only (newer cores). */
18
- readOnly?: boolean;
19
- }
20
- interface McpServerResult {
21
- name: string;
22
- connected: boolean;
23
- error?: string;
24
- needsAuthorization?: boolean;
25
- }
26
- /** The `instructions` one connected server returned in its `initialize` result. */
27
- interface McpServerInstructions {
28
- /** The server's name: its key in the configuration. */
29
- server: string;
30
- instructions: string;
31
- }
32
- interface ConnectedMcp {
33
- tools: AgentToolSet;
34
- catalog: McpCatalogEntry[];
35
- results: McpServerResult[];
36
- /**
37
- * What each connected server told the agent in its handshake (newer cores; absent on older
38
- * ones). THIRD-PARTY text: the core puts it in the system prompt of an agent that uses the
39
- * server's tools, so a host should let the user see it.
40
- */
41
- instructions?: McpServerInstructions[];
42
- refreshServer?: (name: string) => Promise<void>;
43
- close: () => Promise<void>;
44
- }
45
- interface McpHttpServerConfig {
46
- url: string;
47
- headers?: Record<string, string>;
48
- authProvider?: unknown;
49
- /** Per-server connect deadline (newer cores; ignored by older ones). */
50
- connectTimeoutMs?: number;
51
- }
52
- interface McpOAuthCallback {
53
- code?: string;
54
- state?: string;
55
- /** The `iss` parameter of the response (RFC 9207); the core checks it. */
56
- iss?: string;
57
- error?: string;
58
- errorDescription?: string;
59
- }
60
- interface BrowserOAuthProvider {
61
- serverUrl: string;
62
- authorizationUrl?: URL;
63
- isAuthorized(): Promise<boolean>;
64
- reset(): Promise<void>;
65
- }
66
- interface BrowserOAuthProviderOptions {
67
- serverUrl: string;
68
- redirectUrl: string;
69
- clientName?: string;
70
- scope?: string;
71
- /** Client ID metadata document URL (CIMD). Cores without it ignore the field. */
72
- clientMetadataUrl?: string;
73
- }
74
- /** The shape of the subpath module, as far as this package uses it. */
75
- interface McpModule {
76
- connectMcpHttp: (servers: Record<string, McpHttpServerConfig>, opts?: {
77
- clientName?: string;
78
- onLog?: (level: string, message: string) => void;
79
- connectTimeoutMs?: number;
80
- }) => Promise<ConnectedMcp>;
81
- BrowserOAuthProvider?: new (opts: BrowserOAuthProviderOptions) => BrowserOAuthProvider;
82
- readOAuthCallback?: (input?: string | URL) => McpOAuthCallback | undefined;
83
- finishMcpOAuth?: (provider: BrowserOAuthProvider, callback: McpOAuthCallback) => Promise<void>;
84
- /**
85
- * The SDK's error class, re-exported by the core so an authorization failure
86
- * can be recognised by identity (`@modelcontextprotocol/client` on a core on
87
- * the 2.x MCP SDK, `@modelcontextprotocol/sdk` before). Absent on cores older
88
- * than 0.0.12.
89
- */
90
- UnauthorizedError?: new (message?: string) => Error;
91
- }
1
+ import { McpSkillConsent, AgentToolSet } from '@dudko.dev/agent-web';
2
+ import { aW as McpOAuthRegistration, aX as McpProtocolMode, P as PendingElicitation, f as McpElicitationResult, aY as McpElicitationOptions, aZ as McpCatalogEntry, a_ as McpServerProtocol, a$ as McpOAuthRegistrationKind, b0 as McpOAuthCallback, b1 as McpServerResult, b2 as McpModule, b3 as ConnectedMcp, b4 as BrowserOAuthProviderOptions, b5 as BrowserOAuthProvider } from './elicitation-DbW6QKxS.js';
3
+ import { McpAppsConnectionLike } from './index.js';
4
+ export { b6 as ElicitationQueue, b7 as ElicitationQueueOptions, an as McpElicitationFieldSchema, b8 as McpElicitationHandler, ao as McpElicitationRequest, ap as McpElicitationSchema, b9 as McpServerInstructions, ba as createElicitationQueue, bb as elicitationConnectOptions, bc as elicitationSettings, bd as elicitationTimeoutOf } from './elicitation-DbW6QKxS.js';
92
5
 
93
6
  type McpStatus = 'idle' | 'connecting' | 'connected' | 'needs-authorization' | 'error';
94
7
  /** The OAuth details of one server. Everything is optional. */
@@ -110,6 +23,19 @@ interface McpOAuthOptions {
110
23
  * ignores it and registers dynamically.
111
24
  */
112
25
  clientMetadataUrl?: string;
26
+ /**
27
+ * How the client is registered with the server's authorization server:
28
+ * `'auto'` (the default - the document where the server supports it, dynamic
29
+ * registration otherwise), `'cimd'` (the document only: needs a
30
+ * `clientMetadataUrl`, and a server without support ends in `status: 'error'`
31
+ * before anything is sent to its registration endpoint) or `'dcr'` (dynamic
32
+ * registration only, even with a `clientMetadataUrl`). Kept across the
33
+ * redirect, and with the server list of `useMcpServers`. Left out, nothing is
34
+ * passed. A core that does not know the option is refused for `'cimd'` /
35
+ * `'dcr'` (it would register as it always did). Which way was taken is in
36
+ * `oauthRegistration`.
37
+ */
38
+ registration?: McpOAuthRegistration;
113
39
  }
114
40
  interface McpConnectOptions {
115
41
  /** The server's StreamableHTTP endpoint. */
@@ -123,7 +49,41 @@ interface McpConnectOptions {
123
49
  * that ships the OAuth provider; check `oauthSupported` before offering it.
124
50
  */
125
51
  oauth?: boolean | McpOAuthOptions;
52
+ /**
53
+ * The MCP protocol revisions this connection may use: `'legacy'` the 2025 revisions,
54
+ * `'auto'` 2026-07-28 when the server offers it and the 2025 ones otherwise (one probe
55
+ * request; from a page the server's CORS must allow `Mcp-Method` and `Mcp-Name`, or the
56
+ * probe is blocked and the connection falls back with a warning), `'modern'` 2026-07-28 only.
57
+ * Left out, nothing is passed and the core decides (`'legacy'`). What was negotiated is in
58
+ * the hook's `protocol`.
59
+ */
60
+ protocol?: McpProtocolMode;
61
+ /**
62
+ * EXPERIMENTAL (the MCP Skills extension is Beta): load the skills the server serves into the
63
+ * agent's skills catalog, as `<server>/<skill>` - they come with `tools`, so nothing else is
64
+ * wired. Needs `protocol: 'auto'` or `'modern'`. Third-party text: the core loads it as
65
+ * knowledge only, never policy, and - unless `{ consent: 'never' }` - only after a person
66
+ * allowed it (`useAgent().pendingApprovals`, a request with `skill`). `true` or `{ consent }`
67
+ * (see `McpSkillsSetting`). Left out, nothing is passed (off).
68
+ */
69
+ skills?: McpSkillsSetting;
126
70
  }
71
+ /**
72
+ * `skills` on a server, as the hooks pass it on and remember it: `true`, or `{ consent, dynamic }`
73
+ * - `consent`: `'once-per-skill'` (the core's default), `'ask'` or `'never'`; `dynamic: true`: also
74
+ * the server's generated skills (no checksums - each read whole into a snapshot before anyone is
75
+ * asked, approved and used as that copy only; see the core's `McpHttpServerConfig.skills`).
76
+ */
77
+ type McpSkillsSetting = true | {
78
+ consent?: McpSkillConsent;
79
+ dynamic?: boolean;
80
+ };
81
+ /**
82
+ * A `skills` value as the hooks take it - also from storage, so anything else is dropped: `true`,
83
+ * an object with a known `consent` (or none) and a boolean `dynamic` (or none) - `{ dynamic: true }`
84
+ * kept, `false` dropped; neither left: `true` -, else `undefined` (off).
85
+ */
86
+ declare const mcpSkillsSettingOf: (value: unknown) => McpSkillsSetting | undefined;
127
87
  interface UseMcpOptions {
128
88
  /** Client name reported to the MCP server during initialize. */
129
89
  clientName?: string;
@@ -135,8 +95,45 @@ interface UseMcpOptions {
135
95
  clientMetadataUrl?: string;
136
96
  /** Called with connector log lines — handy while debugging a server. */
137
97
  onLog?: (level: string, message: string) => void;
98
+ /**
99
+ * MCP Apps: declare the extension and read the tools' apps (default false). The hook then
100
+ * returns `apps` - pass it to `<AgentChat mcpApps>` - and a tool's results come with an app.
101
+ * A tool for its app only is then not in `tools`. Needs a core with MCP Apps.
102
+ */
103
+ apps?: boolean;
104
+ /**
105
+ * MCP elicitation: let a server ask the USER for input in the middle of a tool call - a
106
+ * form, or (with `url: true`) a link to open. Off by default, and then nothing is passed to
107
+ * the core: no capability is declared and the wire is what it was. `true` turns it on with
108
+ * the core's defaults; an object is the core's `elicitation` settings (`url`, `timeoutMs`,
109
+ * `maxPerToolCall`, `maxPerRun`, `subagents`). Questions land in `pendingElicitations`; show
110
+ * them (`<ElicitationPrompt>`, or `<AgentChat elicitations>`) and answer with
111
+ * `answerElicitation`. Read when a server connects: changing it takes a reconnect.
112
+ */
113
+ elicitation?: boolean | McpElicitationOptions;
138
114
  }
139
- interface UseMcpReturn {
115
+ /**
116
+ * A stable `McpAppsConnectionLike` for the hooks: each call reaches the connection the server is
117
+ * on NOW (or says it is not connected), so it can be handed to `<AgentChat>` once.
118
+ */
119
+ declare const mcpAppsRouter: (connectionOf: (server: string) => ConnectedMcp | undefined) => McpAppsConnectionLike;
120
+ /** What both MCP hooks return for elicitation. */
121
+ interface McpElicitationControls {
122
+ /**
123
+ * Questions servers are waiting on, oldest first (empty unless `elicitation` is on). Every
124
+ * string in a request is the SERVER's text. A question leaves the list when it is answered,
125
+ * when the core stops waiting (its time ran out, the run stopped), when its server is
126
+ * disconnected and when the component unmounts - the last three answer `cancel`.
127
+ */
128
+ pendingElicitations: PendingElicitation[];
129
+ /**
130
+ * Answer a pending question: `{ action: 'accept', content }` (a form's values; no content
131
+ * for a link), `{ action: 'decline' }` or `{ action: 'cancel' }`. The answer is handed to
132
+ * the core and kept nowhere. False when no such question is waiting any more.
133
+ */
134
+ answerElicitation: (id: string, result: McpElicitationResult) => boolean;
135
+ }
136
+ interface UseMcpReturn extends McpElicitationControls {
140
137
  status: McpStatus;
141
138
  /** Merge into `BrowserAgentConfig.tools` once `status === 'connected'`. */
142
139
  tools?: AgentToolSet;
@@ -147,9 +144,20 @@ interface UseMcpReturn {
147
144
  * user as the server's words, never as your own.
148
145
  */
149
146
  instructions?: string;
147
+ /**
148
+ * The protocol revision negotiated with the connected server (`version`, `era`); absent
149
+ * until it is connected, and on a core that does not report it.
150
+ */
151
+ protocol?: McpServerProtocol;
150
152
  error?: string;
151
153
  /** Where to send the user when `status === 'needs-authorization'`. */
152
154
  authorizationUrl?: string;
155
+ /**
156
+ * How the OAuth client of the connected server was registered - `'cimd'`
157
+ * (its client ID metadata document) or `'dcr'` (dynamic registration) - once
158
+ * it is connected with OAuth, on a core that reports it.
159
+ */
160
+ oauthRegistration?: McpOAuthRegistrationKind;
153
161
  /**
154
162
  * Whether the installed core exposes the OAuth API. `undefined` until the
155
163
  * optional subpath has been loaded once — call `checkOAuthSupport()` to
@@ -166,12 +174,28 @@ interface UseMcpReturn {
166
174
  forgetAuthorization: () => Promise<void>;
167
175
  /** Load the optional subpath and report whether it can do OAuth. */
168
176
  checkOAuthSupport: () => Promise<boolean>;
177
+ /** MCP Apps of the connected server (with `apps: true`): pass it to `<AgentChat mcpApps>`. */
178
+ apps?: McpAppsConnectionLike;
169
179
  }
170
180
  /**
171
181
  * The instructions the server `name` sent, or undefined when it sent none (or the core is too
172
182
  * old to report them). The text is the server's, not the host's: show it as such.
173
183
  */
174
184
  declare const mcpInstructionsOf: (connection: Pick<ConnectedMcp, "instructions">, name: string) => string | undefined;
185
+ /** What was negotiated with the server `name`, or undefined (not connected, or an older core). */
186
+ declare const mcpProtocolOf: (connection: Pick<ConnectedMcp, "protocols">, name: string) => McpServerProtocol | undefined;
187
+ /**
188
+ * The OAuth details a redirect record keeps for one server - both hooks write one before the
189
+ * user leaves for the authorization server, and build the provider and the reconnect from it
190
+ * on the way back, so the client is the same both times.
191
+ */
192
+ interface McpOAuthRecord {
193
+ redirectUrl: string;
194
+ scope?: string;
195
+ clientName?: string;
196
+ clientMetadataUrl?: string;
197
+ registration?: McpOAuthRegistration;
198
+ }
175
199
  /** Map a single server's connect outcome onto the hook's status. Pure. */
176
200
  declare const describeMcpResult: (result: McpServerResult | undefined) => {
177
201
  status: McpStatus;
@@ -205,6 +229,29 @@ declare const claimOAuthCallback: (callback: McpOAuthCallback) => boolean;
205
229
  * when forgetting, so the three always describe the same client.
206
230
  */
207
231
  declare const mcpOAuthProviderOptions: (serverUrl: string, oauth?: McpOAuthOptions, defaults?: Pick<McpOAuthOptions, "clientName" | "clientMetadataUrl">) => BrowserOAuthProviderOptions;
232
+ /**
233
+ * What a redirect record keeps of the options `mcpOAuthProviderOptions` resolved (the server's
234
+ * URL is kept beside it). Pure; written as JSON, so an unset field is simply absent.
235
+ */
236
+ declare const mcpOAuthRecordOf: (resolved: BrowserOAuthProviderOptions) => McpOAuthRecord;
237
+ /**
238
+ * The OAuth details read back from a redirect record on the way in: what the provider and the
239
+ * reconnect are built with. Pure. `registration` is passed on as it was stored - a value the
240
+ * core does not know is refused by the core, never read as "auto".
241
+ */
242
+ declare const mcpOAuthOptionsOfRecord: (record: McpOAuthRecord) => McpOAuthOptions;
243
+ /**
244
+ * The core's OAuth provider for one server. A `registration` other than `'auto'` needs a core
245
+ * that knows it - an older one would ignore it and register the old way (a document under
246
+ * `'dcr'`, a dynamic registration under `'cimd'`) - so that is refused here, before any request.
247
+ */
248
+ declare const newMcpOAuthProvider: (mod: McpModule, options: BrowserOAuthProviderOptions) => BrowserOAuthProvider;
249
+ /**
250
+ * How the provider's stored client was registered (`'cimd'` / `'dcr'`), read after a sign-in;
251
+ * undefined without a provider, on a core that does not report it, or when the read fails.
252
+ * Never throws: it is what the UI shows, not a check.
253
+ */
254
+ declare const mcpOAuthRegistrationOf: (provider: BrowserOAuthProvider | undefined) => Promise<McpOAuthRegistrationKind | undefined>;
208
255
  /**
209
256
  * Did this error come from the server refusing our authorization?
210
257
  *
@@ -253,18 +300,53 @@ interface McpServerSpec {
253
300
  auth?: McpAuthMode;
254
301
  /** Bearer token for `auth: 'bearer'` — kept in memory only, never persisted. */
255
302
  token?: string;
256
- /** OAuth details for `auth: 'oauth'` (`clientMetadataUrl` for CIMD among them). */
303
+ /**
304
+ * OAuth details for `auth: 'oauth'` (`clientMetadataUrl` for CIMD and `registration` among
305
+ * them). Remembered with the server.
306
+ */
257
307
  oauth?: McpOAuthOptions;
308
+ /**
309
+ * The MCP protocol revisions this connection may use (`'legacy'` / `'auto'` / `'modern'`,
310
+ * see `McpConnectOptions.protocol`). Remembered with the server. Left out, nothing is passed
311
+ * and the core decides (`'legacy'`).
312
+ */
313
+ protocol?: McpProtocolMode;
314
+ /**
315
+ * EXPERIMENTAL: load the server's skills into the agent's catalog, as `<server>/<skill>` (see
316
+ * `McpConnectOptions.skills`; needs `protocol: 'auto'` or `'modern'`): `true`, or
317
+ * `{ consent }`. Remembered with the server. Left out, nothing is passed (off).
318
+ */
319
+ skills?: McpSkillsSetting;
320
+ /**
321
+ * MCP Apps for this server: `false` keeps its apps off while other servers' are shown (nothing
322
+ * is declared to it, no app of it is read, its app-only tools are hidden from everyone and its
323
+ * other tools are the model's, as plain tools); `true` shows them even when the hook's `apps`
324
+ * is off. Remembered with the server. Left out, the hook's `apps` decides.
325
+ */
326
+ apps?: boolean;
258
327
  }
259
328
  /** A server's live state. */
260
329
  interface McpServerView {
261
330
  name: string;
262
331
  url: string;
263
332
  auth: McpAuthMode;
333
+ /** The protocol revisions the server was added with, when it was given any. */
334
+ protocolMode?: McpProtocolMode;
335
+ /** It was added with `skills` (as given): its skills (if it serves any) are in the catalog. */
336
+ skills?: McpSkillsSetting;
337
+ /** It was added with `apps` set (`false`: its apps are off; absent: the hook's `apps`). */
338
+ apps?: boolean;
339
+ /** What was negotiated (`version`, `era`), while it is connected and the core reports it. */
340
+ protocol?: Omit<McpServerProtocol, 'server'>;
264
341
  status: McpStatus;
265
342
  error?: string;
266
343
  /** Where to send the user when `status === 'needs-authorization'`. */
267
344
  authorizationUrl?: string;
345
+ /**
346
+ * How its OAuth client was registered - `'cimd'` (the client ID metadata document) or `'dcr'`
347
+ * (dynamic registration) - while it is connected with OAuth, on a core that reports it.
348
+ */
349
+ oauthRegistration?: McpOAuthRegistrationKind;
268
350
  catalog: McpCatalogEntry[];
269
351
  /**
270
352
  * What the server told the agent in its handshake (its MCP `instructions`), while it is
@@ -286,12 +368,14 @@ interface UseMcpServersOptions extends UseMcpOptions {
286
368
  /** Per-server connect deadline in ms (default: the core's, 30 s). */
287
369
  connectTimeoutMs?: number;
288
370
  }
289
- interface UseMcpServersReturn {
371
+ interface UseMcpServersReturn extends McpElicitationControls {
290
372
  servers: McpServerView[];
291
373
  /** Tools of every connected server, merged — pass to `BrowserAgentConfig.tools`. */
292
374
  tools: AgentToolSet;
293
375
  /** Catalogue of every connected server, merged. */
294
376
  catalog: McpCatalogEntry[];
377
+ /** The protocol revision negotiated with each connected server (cores that report it). */
378
+ protocols: McpServerProtocol[];
295
379
  connectedCount: number;
296
380
  /** True while an OAuth redirect is being finished on mount. */
297
381
  completingAuthorization: boolean;
@@ -308,6 +392,11 @@ interface UseMcpServersReturn {
308
392
  authorize: (name: string) => void;
309
393
  /** Drop a server's stored OAuth tokens and registration. */
310
394
  forgetAuthorization: (name: string) => Promise<void>;
395
+ /**
396
+ * MCP Apps of every connected server (with `apps: true`): pass it to `<AgentChat mcpApps>`.
397
+ * Each call goes to the server it names, on the connection it has now.
398
+ */
399
+ apps?: McpAppsConnectionLike;
311
400
  }
312
401
  /**
313
402
  * Connect the browser agent to SEVERAL remote MCP servers at once, each with
@@ -329,5 +418,5 @@ interface UseMcpServersReturn {
329
418
  */
330
419
  declare const useMcpServers: (options?: UseMcpServersOptions) => UseMcpServersReturn;
331
420
 
332
- export { claimOAuthCallback, describeMcpResult, isUnauthorizedError, mcpInstructionsOf, mcpOAuthProviderOptions, readCallbackParams, stripOAuthParams, useMcp, useMcpServers };
333
- export type { BrowserOAuthProviderOptions, ConnectedMcp, McpAuthMode, McpCatalogEntry, McpConnectOptions, McpModule, McpOAuthCallback, McpOAuthOptions, McpServerInstructions, McpServerResult, McpServerSpec, McpServerView, McpStatus, UseMcpOptions, UseMcpReturn, UseMcpServersOptions, UseMcpServersReturn };
421
+ export { BrowserOAuthProvider, BrowserOAuthProviderOptions, ConnectedMcp, McpCatalogEntry, McpElicitationOptions, McpElicitationResult, McpModule, McpOAuthCallback, McpOAuthRegistration, McpOAuthRegistrationKind, McpProtocolMode, McpServerProtocol, McpServerResult, PendingElicitation, claimOAuthCallback, describeMcpResult, isUnauthorizedError, mcpAppsRouter, mcpInstructionsOf, mcpOAuthOptionsOfRecord, mcpOAuthProviderOptions, mcpOAuthRecordOf, mcpOAuthRegistrationOf, mcpProtocolOf, mcpSkillsSettingOf, newMcpOAuthProvider, readCallbackParams, stripOAuthParams, useMcp, useMcpServers };
422
+ export type { McpAuthMode, McpConnectOptions, McpElicitationControls, McpOAuthOptions, McpOAuthRecord, McpServerSpec, McpServerView, McpSkillsSetting, McpStatus, UseMcpOptions, UseMcpReturn, UseMcpServersOptions, UseMcpServersReturn };