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

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.cjs CHANGED
@@ -31,10 +31,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var mcp_exports = {};
32
32
  __export(mcp_exports, {
33
33
  claimOAuthCallback: () => claimOAuthCallback,
34
+ createElicitationQueue: () => createElicitationQueue,
34
35
  describeMcpResult: () => describeMcpResult,
36
+ elicitationConnectOptions: () => elicitationConnectOptions,
37
+ elicitationSettings: () => elicitationSettings,
38
+ elicitationTimeoutOf: () => elicitationTimeoutOf,
35
39
  isUnauthorizedError: () => isUnauthorizedError,
40
+ mcpAppsRouter: () => mcpAppsRouter,
36
41
  mcpInstructionsOf: () => mcpInstructionsOf,
42
+ mcpOAuthOptionsOfRecord: () => mcpOAuthOptionsOfRecord,
37
43
  mcpOAuthProviderOptions: () => mcpOAuthProviderOptions,
44
+ mcpOAuthRecordOf: () => mcpOAuthRecordOf,
45
+ mcpOAuthRegistrationOf: () => mcpOAuthRegistrationOf,
46
+ mcpProtocolOf: () => mcpProtocolOf,
47
+ mcpSkillsSettingOf: () => mcpSkillsSettingOf,
48
+ newMcpOAuthProvider: () => newMcpOAuthProvider,
38
49
  readCallbackParams: () => readCallbackParams,
39
50
  stripOAuthParams: () => stripOAuthParams,
40
51
  useMcp: () => useMcp,
@@ -44,11 +55,162 @@ module.exports = __toCommonJS(mcp_exports);
44
55
 
45
56
  // src/hooks/use-mcp.ts
46
57
  var import_react = require("react");
58
+
59
+ // src/elicitation.ts
60
+ var ELICITATION_TIMEOUT_MS = 3e5;
61
+ var elicitationSettings = (option) => {
62
+ if (option === true) return {};
63
+ if (typeof option === "object" && option !== null) return { ...option };
64
+ return void 0;
65
+ };
66
+ var elicitationConnectOptions = (option, handler) => {
67
+ const settings = elicitationSettings(option);
68
+ return settings ? { onElicitation: handler, elicitation: settings } : {};
69
+ };
70
+ var TIMER_MAX_MS = 2147483647;
71
+ var elicitationTimeoutOf = (settings) => {
72
+ const raw = settings.timeoutMs;
73
+ if (raw === void 0 || raw === null) return ELICITATION_TIMEOUT_MS;
74
+ if (typeof raw !== "number" || !(raw > 0) || raw > TIMER_MAX_MS) return void 0;
75
+ return Math.max(1, Math.floor(raw));
76
+ };
77
+ var createElicitationQueue = (options = {}) => {
78
+ const now = options.now ?? Date.now;
79
+ const waiting = /* @__PURE__ */ new Map();
80
+ let disposed = false;
81
+ const list = () => [...waiting.values()].map((w) => w.request);
82
+ const changed = () => {
83
+ if (!disposed) options.onChange?.(list());
84
+ };
85
+ const handler = (request, ctx) => new Promise((resolve) => {
86
+ const signal = ctx?.signal;
87
+ if (disposed || signal?.aborted || waiting.has(request.id)) {
88
+ resolve({ action: "cancel" });
89
+ return;
90
+ }
91
+ const onAbort = () => {
92
+ if (waiting.get(request.id)?.settle !== settle) return;
93
+ settle({ action: "cancel" });
94
+ changed();
95
+ };
96
+ const settle = (result) => {
97
+ if (waiting.get(request.id)?.settle !== settle) return;
98
+ waiting.delete(request.id);
99
+ signal?.removeEventListener("abort", onAbort);
100
+ resolve(result);
101
+ };
102
+ signal?.addEventListener("abort", onAbort, { once: true });
103
+ const timeoutMs = typeof options.timeoutMs === "function" ? options.timeoutMs() : options.timeoutMs;
104
+ waiting.set(request.id, {
105
+ request: {
106
+ ...request,
107
+ ...timeoutMs !== void 0 ? { expiresAt: now() + timeoutMs } : {}
108
+ },
109
+ settle
110
+ });
111
+ changed();
112
+ });
113
+ return {
114
+ handler,
115
+ pending: list,
116
+ answer: (id, result) => {
117
+ const entry = waiting.get(id);
118
+ if (!entry) return false;
119
+ entry.settle(result);
120
+ changed();
121
+ return true;
122
+ },
123
+ cancel: (match) => {
124
+ let any = false;
125
+ for (const entry of [...waiting.values()]) {
126
+ if (match && !match(entry.request)) continue;
127
+ entry.settle({ action: "cancel" });
128
+ any = true;
129
+ }
130
+ if (any) changed();
131
+ },
132
+ dispose: () => {
133
+ disposed = true;
134
+ for (const entry of [...waiting.values()]) entry.settle({ action: "cancel" });
135
+ }
136
+ };
137
+ };
138
+
139
+ // src/hooks/use-mcp.ts
140
+ var mcpSkillsSettingOf = (value) => {
141
+ if (value === true) return true;
142
+ if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
143
+ const consent = value.consent;
144
+ return consent === "ask" || consent === "once-per-skill" || consent === "never" ? { consent } : consent === void 0 ? true : void 0;
145
+ };
146
+ var mcpAppsRouter = (connectionOf) => {
147
+ const appsOf = (server) => connectionOf(server)?.apps;
148
+ const notConnected = (server) => new Error(`the server \u201C${server}\u201D is not connected`);
149
+ return {
150
+ readUiResource: (server, uri, options) => {
151
+ const apps = appsOf(server);
152
+ return apps ? apps.readUiResource(server, uri, options) : Promise.reject(notConnected(server));
153
+ },
154
+ appTool: (server, name) => appsOf(server)?.appTool(server, name),
155
+ readResource: (server, uri, options) => {
156
+ const apps = appsOf(server);
157
+ if (!apps) return Promise.reject(notConnected(server));
158
+ if (!apps.readResource) {
159
+ return Promise.reject(new Error("this version of the core cannot read a linked file"));
160
+ }
161
+ return apps.readResource(server, uri, options);
162
+ },
163
+ callAppTool: (server, name, args, options) => {
164
+ const apps = appsOf(server);
165
+ return apps ? apps.callAppTool(server, name, args, options) : Promise.reject(notConnected(server));
166
+ }
167
+ };
168
+ };
47
169
  var mcpInstructionsOf = (connection, name) => {
48
170
  const list = Array.isArray(connection.instructions) ? connection.instructions : [];
49
171
  const text = list.find((i) => i?.server === name)?.instructions;
50
172
  return typeof text === "string" && text.trim() ? text : void 0;
51
173
  };
174
+ var mcpProtocolOf = (connection, name) => {
175
+ const list = Array.isArray(connection.protocols) ? connection.protocols : [];
176
+ const found = list.find((p) => p?.server === name);
177
+ return found && typeof found.version === "string" ? { server: name, version: found.version, era: found.era } : void 0;
178
+ };
179
+ var useElicitationQueue = (optionsRef) => {
180
+ const [pendingElicitations, setPending] = (0, import_react.useState)([]);
181
+ const mountedRef = (0, import_react.useRef)(true);
182
+ const queueRef = (0, import_react.useRef)(void 0);
183
+ queueRef.current ??= createElicitationQueue({
184
+ timeoutMs: () => {
185
+ const settings = elicitationSettings(optionsRef.current.elicitation);
186
+ return settings ? elicitationTimeoutOf(settings) : void 0;
187
+ },
188
+ onChange: (pending) => {
189
+ if (mountedRef.current) setPending(pending);
190
+ }
191
+ });
192
+ const queue = queueRef.current;
193
+ const handler = (0, import_react.useCallback)(
194
+ (request, ctx) => mountedRef.current ? queue.handler(request, ctx) : { action: "cancel" },
195
+ [queue]
196
+ );
197
+ const answerElicitation = (0, import_react.useCallback)(
198
+ (id, result) => queue.answer(id, result),
199
+ [queue]
200
+ );
201
+ const cancel = (0, import_react.useCallback)(
202
+ (server) => queue.cancel(server === void 0 ? void 0 : (request) => request.server === server),
203
+ [queue]
204
+ );
205
+ (0, import_react.useEffect)(() => {
206
+ mountedRef.current = true;
207
+ return () => {
208
+ mountedRef.current = false;
209
+ queue.cancel();
210
+ };
211
+ }, [queue]);
212
+ return { pendingElicitations, answerElicitation, handler, cancel };
213
+ };
52
214
  var OAUTH_UNSUPPORTED = "The installed @dudko.dev/agent-web has no MCP OAuth support. Upgrade the core to a version exporting BrowserOAuthProvider, or use a static Authorization header.";
53
215
  var PENDING_KEY = "agent-web-react:mcp:pending";
54
216
  var OAUTH_KEY = "agent-web-react:mcp:oauth";
@@ -142,9 +304,44 @@ var mcpOAuthProviderOptions = (serverUrl, oauth = {}, defaults = {}) => {
142
304
  clientName: oauth.clientName ?? defaults.clientName,
143
305
  scope: oauth.scope,
144
306
  // Left out when unset: a provider built without it keeps registering dynamically.
145
- ...clientMetadataUrl !== void 0 ? { clientMetadataUrl } : {}
307
+ ...clientMetadataUrl !== void 0 ? { clientMetadataUrl } : {},
308
+ // Left out when unset, too: the core's default is 'auto'.
309
+ ...oauth.registration !== void 0 ? { registration: oauth.registration } : {}
146
310
  };
147
311
  };
312
+ var mcpOAuthRecordOf = (resolved) => ({
313
+ redirectUrl: resolved.redirectUrl,
314
+ scope: resolved.scope,
315
+ clientName: resolved.clientName,
316
+ clientMetadataUrl: resolved.clientMetadataUrl,
317
+ ...resolved.registration !== void 0 ? { registration: resolved.registration } : {}
318
+ });
319
+ var mcpOAuthOptionsOfRecord = (record) => ({
320
+ redirectUrl: record.redirectUrl,
321
+ scope: record.scope,
322
+ clientName: record.clientName,
323
+ clientMetadataUrl: record.clientMetadataUrl,
324
+ ...record.registration !== void 0 ? { registration: record.registration } : {}
325
+ });
326
+ var registrationUnsupported = (registration) => `The installed @dudko.dev/agent-web does not support oauth.registration ('${registration}'): it would register as it always did. Upgrade the core, or leave registration out.`;
327
+ var newMcpOAuthProvider = (mod, options) => {
328
+ if (!mod.BrowserOAuthProvider) throw new Error(OAUTH_UNSUPPORTED);
329
+ const provider = new mod.BrowserOAuthProvider(options);
330
+ const asked = options.registration;
331
+ if (asked !== void 0 && asked !== "auto" && provider.registration !== asked) {
332
+ throw new Error(registrationUnsupported(asked));
333
+ }
334
+ return provider;
335
+ };
336
+ var mcpOAuthRegistrationOf = async (provider) => {
337
+ if (typeof provider?.registrationKind !== "function") return void 0;
338
+ try {
339
+ const kind = await provider.registrationKind();
340
+ return kind === "cimd" || kind === "dcr" ? kind : void 0;
341
+ } catch {
342
+ return void 0;
343
+ }
344
+ };
148
345
  var isUnauthorizedError = (err, mod) => {
149
346
  if (!(err instanceof Error)) return false;
150
347
  if (mod?.UnauthorizedError && err instanceof mod.UnauthorizedError) return true;
@@ -180,8 +377,12 @@ var useMcp = (options = {}) => {
180
377
  const [tools, setTools] = (0, import_react.useState)(void 0);
181
378
  const [catalog, setCatalog] = (0, import_react.useState)([]);
182
379
  const [instructions, setInstructions] = (0, import_react.useState)(void 0);
380
+ const [protocol, setProtocol] = (0, import_react.useState)(void 0);
183
381
  const [error, setError] = (0, import_react.useState)(void 0);
184
382
  const [authorizationUrl, setAuthorizationUrl] = (0, import_react.useState)(void 0);
383
+ const [oauthRegistration, setOauthRegistration] = (0, import_react.useState)(
384
+ void 0
385
+ );
185
386
  const [oauthSupported, setOauthSupported] = (0, import_react.useState)(void 0);
186
387
  const [completingAuthorization, setCompletingAuthorization] = (0, import_react.useState)(
187
388
  () => readCallbackParams() !== void 0
@@ -191,12 +392,15 @@ var useMcp = (options = {}) => {
191
392
  const epochRef = (0, import_react.useRef)(0);
192
393
  const optionsRef = (0, import_react.useRef)(options);
193
394
  optionsRef.current = options;
395
+ const elicitation = useElicitationQueue(optionsRef);
396
+ const cancelElicitations = elicitation.cancel;
194
397
  const closeConnection = (0, import_react.useCallback)(async () => {
195
398
  const open = connectionRef.current;
196
399
  connectionRef.current = void 0;
400
+ cancelElicitations();
197
401
  if (open) await open.close().catch(() => {
198
402
  });
199
- }, []);
403
+ }, [cancelElicitations]);
200
404
  const checkOAuthSupport = (0, import_react.useCallback)(async () => {
201
405
  try {
202
406
  const mod = await loadMcp();
@@ -217,9 +421,11 @@ var useMcp = (options = {}) => {
217
421
  setStatus("connecting");
218
422
  setError(void 0);
219
423
  setAuthorizationUrl(void 0);
424
+ setOauthRegistration(void 0);
220
425
  setTools(void 0);
221
426
  setCatalog([]);
222
427
  setInstructions(void 0);
428
+ setProtocol(void 0);
223
429
  try {
224
430
  const mod = await loadMcp();
225
431
  setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
@@ -235,13 +441,12 @@ var useMcp = (options = {}) => {
235
441
  const record = {
236
442
  url: opts.url,
237
443
  name,
238
- redirectUrl: providerOptions.redirectUrl,
239
- scope: providerOptions.scope,
240
- clientName: providerOptions.clientName,
241
- clientMetadataUrl: providerOptions.clientMetadataUrl,
444
+ ...mcpOAuthRecordOf(providerOptions),
445
+ ...opts.protocol ? { protocol: opts.protocol } : {},
446
+ ...mcpSkillsSettingOf(opts.skills) ? { skills: mcpSkillsSettingOf(opts.skills) } : {},
242
447
  startedAt: Date.now()
243
448
  };
244
- authProvider = new mod.BrowserOAuthProvider(providerOptions);
449
+ authProvider = newMcpOAuthProvider(mod, providerOptions);
245
450
  providerRef.current = authProvider;
246
451
  writeRecord(PENDING_KEY, record);
247
452
  writeRecord(OAUTH_KEY, record);
@@ -253,10 +458,19 @@ var useMcp = (options = {}) => {
253
458
  [name]: {
254
459
  url: opts.url,
255
460
  headers: opts.oauth ? void 0 : opts.headers,
256
- authProvider
461
+ authProvider,
462
+ // Only when asked for: without it the connection is built as it always was.
463
+ ...opts.protocol ? { protocol: opts.protocol } : {},
464
+ ...mcpSkillsSettingOf(opts.skills) ? { skills: mcpSkillsSettingOf(opts.skills) } : {}
257
465
  }
258
466
  },
259
- { clientName: optionsRef.current.clientName, onLog: optionsRef.current.onLog }
467
+ {
468
+ clientName: optionsRef.current.clientName,
469
+ onLog: optionsRef.current.onLog,
470
+ ...optionsRef.current.apps ? { apps: true } : {},
471
+ // Off: neither key is passed, so the core declares no capability.
472
+ ...elicitationConnectOptions(optionsRef.current.elicitation, elicitation.handler)
473
+ }
260
474
  );
261
475
  if (!current()) {
262
476
  await connection.close().catch(() => {
@@ -287,6 +501,10 @@ var useMcp = (options = {}) => {
287
501
  );
288
502
  setCatalog(connection.catalog);
289
503
  setInstructions(mcpInstructionsOf(connection, name));
504
+ setProtocol(mcpProtocolOf(connection, name));
505
+ const registered = await mcpOAuthRegistrationOf(authProvider);
506
+ if (!current()) return;
507
+ setOauthRegistration(registered);
290
508
  setStatus("connected");
291
509
  } catch (err) {
292
510
  if (!current()) return;
@@ -294,7 +512,7 @@ var useMcp = (options = {}) => {
294
512
  setStatus("error");
295
513
  }
296
514
  },
297
- [closeConnection]
515
+ [closeConnection, elicitation.handler]
298
516
  );
299
517
  const disconnect = (0, import_react.useCallback)(async () => {
300
518
  epochRef.current++;
@@ -302,7 +520,9 @@ var useMcp = (options = {}) => {
302
520
  setTools(void 0);
303
521
  setCatalog([]);
304
522
  setInstructions(void 0);
523
+ setProtocol(void 0);
305
524
  setAuthorizationUrl(void 0);
525
+ setOauthRegistration(void 0);
306
526
  setError(void 0);
307
527
  setStatus("idle");
308
528
  }, [closeConnection]);
@@ -355,7 +575,8 @@ var useMcp = (options = {}) => {
355
575
  const mod = await loadMcp();
356
576
  setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
357
577
  if (!mod.BrowserOAuthProvider || !mod.finishMcpOAuth) throw new Error(OAUTH_UNSUPPORTED);
358
- const provider = new mod.BrowserOAuthProvider(mcpOAuthProviderOptions(pending.url, pending));
578
+ const oauth = mcpOAuthOptionsOfRecord(pending);
579
+ const provider = newMcpOAuthProvider(mod, mcpOAuthProviderOptions(pending.url, oauth));
359
580
  providerRef.current = provider;
360
581
  await mod.finishMcpOAuth(provider, callback);
361
582
  writeRecord(PENDING_KEY, void 0);
@@ -363,12 +584,9 @@ var useMcp = (options = {}) => {
363
584
  await connect({
364
585
  url: pending.url,
365
586
  name: pending.name,
366
- oauth: {
367
- redirectUrl: pending.redirectUrl,
368
- scope: pending.scope,
369
- clientName: pending.clientName,
370
- clientMetadataUrl: pending.clientMetadataUrl
371
- }
587
+ oauth,
588
+ ...pending.protocol ? { protocol: pending.protocol } : {},
589
+ ...mcpSkillsSettingOf(pending.skills) ? { skills: mcpSkillsSettingOf(pending.skills) } : {}
372
590
  });
373
591
  } catch (err) {
374
592
  writeRecord(PENDING_KEY, void 0);
@@ -386,15 +604,25 @@ var useMcp = (options = {}) => {
386
604
  },
387
605
  [closeConnection]
388
606
  );
607
+ const appsOn = options.apps === true;
608
+ const apps = (0, import_react.useMemo)(
609
+ () => appsOn ? mcpAppsRouter(() => connectionRef.current) : void 0,
610
+ [appsOn]
611
+ );
389
612
  return {
613
+ apps,
390
614
  status,
391
615
  tools,
392
616
  catalog,
393
617
  instructions,
618
+ protocol,
394
619
  error,
395
620
  authorizationUrl,
621
+ oauthRegistration,
396
622
  oauthSupported,
397
623
  completingAuthorization,
624
+ pendingElicitations: elicitation.pendingElicitations,
625
+ answerElicitation: elicitation.answerElicitation,
398
626
  connect,
399
627
  disconnect,
400
628
  authorize,
@@ -407,10 +635,14 @@ var useMcp = (options = {}) => {
407
635
  var import_react2 = require("react");
408
636
  var DEFAULT_KEY = "agent-web-react:mcp-servers";
409
637
  var sanitize = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 32) || "mcp";
638
+ var isProtocolMode = (value) => value === "legacy" || value === "auto" || value === "modern";
410
639
  var view = (s, patch = {}) => ({
411
640
  name: s.name,
412
641
  url: s.url,
413
642
  auth: s.auth,
643
+ ...isProtocolMode(s.protocol) ? { protocolMode: s.protocol } : {},
644
+ ...mcpSkillsSettingOf(s.skills) ? { skills: mcpSkillsSettingOf(s.skills) } : {},
645
+ ...typeof s.apps === "boolean" ? { apps: s.apps } : {},
414
646
  status: "idle",
415
647
  catalog: [],
416
648
  ...patch
@@ -437,13 +669,18 @@ var useMcpServers = (options = {}) => {
437
669
  name: s.name,
438
670
  url: s.url,
439
671
  auth: s.auth,
440
- ...oauth && typeof oauth === "object" ? { oauth } : {}
672
+ ...oauth && typeof oauth === "object" ? { oauth } : {},
673
+ ...s.protocolMode ? { protocol: s.protocolMode } : {},
674
+ ...mcpSkillsSettingOf(s.skills) ? { skills: mcpSkillsSettingOf(s.skills) } : {},
675
+ ...typeof s.apps === "boolean" ? { apps: s.apps } : {}
441
676
  });
442
677
  }
443
678
  }
444
679
  const optionsRef = (0, import_react2.useRef)(options);
445
680
  optionsRef.current = options;
446
681
  const unmountedRef = (0, import_react2.useRef)(false);
682
+ const elicitation = useElicitationQueue(optionsRef);
683
+ const cancelElicitations = elicitation.cancel;
447
684
  const saveList = (0, import_react2.useCallback)(() => {
448
685
  if (!persist) return;
449
686
  writeRecord(storageKey, [...specsRef.current.values()]);
@@ -470,15 +707,11 @@ var useMcpServers = (options = {}) => {
470
707
  l.tools = void 0;
471
708
  setToolsVersion((v) => v + 1);
472
709
  }
710
+ cancelElicitations(name);
473
711
  if (open) await open.close().catch(() => {
474
712
  });
475
713
  }, []);
476
- const providerFor = (mod, spec) => {
477
- if (!mod.BrowserOAuthProvider) throw new Error(OAUTH_UNSUPPORTED);
478
- return new mod.BrowserOAuthProvider(
479
- mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current)
480
- );
481
- };
714
+ const providerFor = (mod, spec) => newMcpOAuthProvider(mod, mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current));
482
715
  const connectServer = (0, import_react2.useCallback)(
483
716
  async (name) => {
484
717
  const spec = specsRef.current.get(name);
@@ -495,8 +728,10 @@ var useMcpServers = (options = {}) => {
495
728
  status: "connecting",
496
729
  error: void 0,
497
730
  authorizationUrl: void 0,
731
+ oauthRegistration: void 0,
498
732
  catalog: [],
499
- instructions: void 0
733
+ instructions: void 0,
734
+ protocol: void 0
500
735
  });
501
736
  try {
502
737
  const mod = await loadMcp();
@@ -512,13 +747,21 @@ var useMcpServers = (options = {}) => {
512
747
  url: spec.url,
513
748
  headers: spec.auth === "bearer" && l.token ? { Authorization: `Bearer ${l.token}` } : void 0,
514
749
  authProvider: provider,
515
- connectTimeoutMs: optionsRef.current.connectTimeoutMs
750
+ connectTimeoutMs: optionsRef.current.connectTimeoutMs,
751
+ // Only when asked for: without it the connection is built as it always was.
752
+ ...spec.protocol ? { protocol: spec.protocol } : {},
753
+ ...mcpSkillsSettingOf(spec.skills) ? { skills: mcpSkillsSettingOf(spec.skills) } : {},
754
+ // Only when given: without it the hook's `apps` decides, as before.
755
+ ...typeof spec.apps === "boolean" ? { apps: spec.apps } : {}
516
756
  }
517
757
  },
518
758
  {
519
759
  clientName: optionsRef.current.clientName,
520
760
  onLog: optionsRef.current.onLog,
521
- connectTimeoutMs: optionsRef.current.connectTimeoutMs
761
+ connectTimeoutMs: optionsRef.current.connectTimeoutMs,
762
+ ...optionsRef.current.apps ? { apps: true } : {},
763
+ // Off: neither key is passed, so the core declares no capability.
764
+ ...elicitationConnectOptions(optionsRef.current.elicitation, elicitation.handler)
522
765
  }
523
766
  );
524
767
  if (!current()) {
@@ -550,10 +793,15 @@ var useMcpServers = (options = {}) => {
550
793
  });
551
794
  });
552
795
  setToolsVersion((v) => v + 1);
796
+ const negotiated = mcpProtocolOf(connection, name);
797
+ const oauthRegistration = await mcpOAuthRegistrationOf(provider);
798
+ if (!current()) return;
553
799
  patch(name, {
554
800
  status: "connected",
801
+ oauthRegistration,
555
802
  catalog: connection.catalog,
556
- instructions: mcpInstructionsOf(connection, name)
803
+ instructions: mcpInstructionsOf(connection, name),
804
+ protocol: negotiated ? { version: negotiated.version, era: negotiated.era } : void 0
557
805
  });
558
806
  } catch (err) {
559
807
  if (!current()) return;
@@ -576,7 +824,10 @@ var useMcpServers = (options = {}) => {
576
824
  name,
577
825
  url: input.url,
578
826
  auth: input.auth ?? "none",
579
- ...input.oauth ? { oauth: input.oauth } : {}
827
+ ...input.oauth ? { oauth: input.oauth } : {},
828
+ ...isProtocolMode(input.protocol) ? { protocol: input.protocol } : {},
829
+ ...mcpSkillsSettingOf(input.skills) ? { skills: mcpSkillsSettingOf(input.skills) } : {},
830
+ ...typeof input.apps === "boolean" ? { apps: input.apps } : {}
580
831
  };
581
832
  specsRef.current.set(name, spec);
582
833
  live(name).token = input.auth === "bearer" ? input.token : void 0;
@@ -614,10 +865,7 @@ var useMcpServers = (options = {}) => {
614
865
  const pending = {
615
866
  name,
616
867
  url: spec.url,
617
- redirectUrl: spec.oauth?.redirectUrl ?? defaultRedirectUrl(),
618
- scope: spec.oauth?.scope,
619
- clientName: spec.oauth?.clientName ?? optionsRef.current.clientName,
620
- clientMetadataUrl: spec.oauth?.clientMetadataUrl ?? optionsRef.current.clientMetadataUrl,
868
+ ...mcpOAuthRecordOf(mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current)),
621
869
  startedAt: Date.now()
622
870
  };
623
871
  writeRecord(pendingKey, pending);
@@ -648,8 +896,10 @@ var useMcpServers = (options = {}) => {
648
896
  patch(name, {
649
897
  status: "idle",
650
898
  authorizationUrl: void 0,
899
+ oauthRegistration: void 0,
651
900
  catalog: [],
652
901
  instructions: void 0,
902
+ protocol: void 0,
653
903
  error: void 0
654
904
  });
655
905
  },
@@ -694,15 +944,7 @@ var useMcpServers = (options = {}) => {
694
944
  setServers((list) => [...list, view(spec)]);
695
945
  saveList();
696
946
  }
697
- const provider = providerFor(mod, {
698
- ...spec,
699
- oauth: {
700
- redirectUrl: pending.redirectUrl,
701
- scope: pending.scope,
702
- clientName: pending.clientName,
703
- clientMetadataUrl: pending.clientMetadataUrl
704
- }
705
- });
947
+ const provider = providerFor(mod, { ...spec, oauth: mcpOAuthOptionsOfRecord(pending) });
706
948
  live(spec.name).provider = provider;
707
949
  await mod.finishMcpOAuth(provider, callback);
708
950
  writeRecord(pendingKey, void 0);
@@ -735,10 +977,30 @@ var useMcpServers = (options = {}) => {
735
977
  () => servers.filter((s) => s.status === "connected").flatMap((s) => s.catalog),
736
978
  [servers]
737
979
  );
980
+ const appsOn = options.apps === true || servers.some((s) => s.apps === true);
981
+ const hookApps = options.apps === true;
982
+ const apps = (0, import_react2.useMemo)(
983
+ () => appsOn ? mcpAppsRouter((server) => {
984
+ const spec = specsRef.current.get(server);
985
+ if (!spec || (spec.apps ?? hookApps) !== true) return void 0;
986
+ return liveRef.current.get(server)?.connection;
987
+ }) : void 0,
988
+ [appsOn, hookApps]
989
+ );
990
+ const protocols = (0, import_react2.useMemo)(
991
+ () => servers.flatMap(
992
+ (s) => s.status === "connected" && s.protocol ? [{ server: s.name, ...s.protocol }] : []
993
+ ),
994
+ [servers]
995
+ );
738
996
  return {
997
+ apps,
739
998
  servers,
740
999
  tools,
741
1000
  catalog,
1001
+ protocols,
1002
+ pendingElicitations: elicitation.pendingElicitations,
1003
+ answerElicitation: elicitation.answerElicitation,
742
1004
  connectedCount: servers.filter((s) => s.status === "connected").length,
743
1005
  completingAuthorization,
744
1006
  oauthSupported,
@@ -753,10 +1015,21 @@ var useMcpServers = (options = {}) => {
753
1015
  // Annotate the CommonJS export names for ESM import in node:
754
1016
  0 && (module.exports = {
755
1017
  claimOAuthCallback,
1018
+ createElicitationQueue,
756
1019
  describeMcpResult,
1020
+ elicitationConnectOptions,
1021
+ elicitationSettings,
1022
+ elicitationTimeoutOf,
757
1023
  isUnauthorizedError,
1024
+ mcpAppsRouter,
758
1025
  mcpInstructionsOf,
1026
+ mcpOAuthOptionsOfRecord,
759
1027
  mcpOAuthProviderOptions,
1028
+ mcpOAuthRecordOf,
1029
+ mcpOAuthRegistrationOf,
1030
+ mcpProtocolOf,
1031
+ mcpSkillsSettingOf,
1032
+ newMcpOAuthProvider,
760
1033
  readCallbackParams,
761
1034
  stripOAuthParams,
762
1035
  useMcp,