@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/README.md +345 -19
- package/dist/{chunk-UUB7CE6N.js → chunk-EMF7DTGS.js} +69 -1
- package/dist/chunk-EMF7DTGS.js.map +1 -0
- package/dist/chunk-FXHQXIOU.js +94 -0
- package/dist/chunk-FXHQXIOU.js.map +1 -0
- package/dist/chunk-VMCWL6VH.js +294 -0
- package/dist/chunk-VMCWL6VH.js.map +1 -0
- package/dist/elicitation-CcZe5-EK.d.cts +1535 -0
- package/dist/elicitation-CcZe5-EK.d.ts +1535 -0
- package/dist/index.cjs +4360 -618
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +705 -433
- package/dist/index.d.ts +705 -433
- package/dist/index.js +4029 -628
- package/dist/index.js.map +1 -1
- package/dist/mcp-app-policy-DIUmGPJP.d.cts +55 -0
- package/dist/mcp-app-policy-DIUmGPJP.d.ts +55 -0
- package/dist/mcp-app-sandbox.cjs +313 -0
- package/dist/mcp-app-sandbox.cjs.map +1 -0
- package/dist/mcp-app-sandbox.d.cts +65 -0
- package/dist/mcp-app-sandbox.d.ts +65 -0
- package/dist/mcp-app-sandbox.js +201 -0
- package/dist/mcp-app-sandbox.js.map +1 -0
- package/dist/mcp.cjs +315 -42
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +182 -96
- package/dist/mcp.d.ts +182 -96
- package/dist/mcp.js +233 -46
- package/dist/mcp.js.map +1 -1
- package/dist/pipeline.cjs.map +1 -1
- package/dist/pipeline.js +1 -1
- package/dist/styles.css +1139 -0
- package/package.json +13 -3
- package/dist/chunk-UUB7CE6N.js.map +0 -1
package/dist/mcp.js
CHANGED
|
@@ -1,10 +1,86 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createElicitationQueue,
|
|
3
|
+
elicitationConnectOptions,
|
|
4
|
+
elicitationSettings,
|
|
5
|
+
elicitationTimeoutOf
|
|
6
|
+
} from "./chunk-VMCWL6VH.js";
|
|
7
|
+
|
|
1
8
|
// src/hooks/use-mcp.ts
|
|
2
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
9
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
10
|
+
var mcpSkillsSettingOf = (value) => {
|
|
11
|
+
if (value === true) return true;
|
|
12
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return void 0;
|
|
13
|
+
const consent = value.consent;
|
|
14
|
+
return consent === "ask" || consent === "once-per-skill" || consent === "never" ? { consent } : consent === void 0 ? true : void 0;
|
|
15
|
+
};
|
|
16
|
+
var mcpAppsRouter = (connectionOf) => {
|
|
17
|
+
const appsOf = (server) => connectionOf(server)?.apps;
|
|
18
|
+
const notConnected = (server) => new Error(`the server \u201C${server}\u201D is not connected`);
|
|
19
|
+
return {
|
|
20
|
+
readUiResource: (server, uri, options) => {
|
|
21
|
+
const apps = appsOf(server);
|
|
22
|
+
return apps ? apps.readUiResource(server, uri, options) : Promise.reject(notConnected(server));
|
|
23
|
+
},
|
|
24
|
+
appTool: (server, name) => appsOf(server)?.appTool(server, name),
|
|
25
|
+
readResource: (server, uri, options) => {
|
|
26
|
+
const apps = appsOf(server);
|
|
27
|
+
if (!apps) return Promise.reject(notConnected(server));
|
|
28
|
+
if (!apps.readResource) {
|
|
29
|
+
return Promise.reject(new Error("this version of the core cannot read a linked file"));
|
|
30
|
+
}
|
|
31
|
+
return apps.readResource(server, uri, options);
|
|
32
|
+
},
|
|
33
|
+
callAppTool: (server, name, args, options) => {
|
|
34
|
+
const apps = appsOf(server);
|
|
35
|
+
return apps ? apps.callAppTool(server, name, args, options) : Promise.reject(notConnected(server));
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
3
39
|
var mcpInstructionsOf = (connection, name) => {
|
|
4
40
|
const list = Array.isArray(connection.instructions) ? connection.instructions : [];
|
|
5
41
|
const text = list.find((i) => i?.server === name)?.instructions;
|
|
6
42
|
return typeof text === "string" && text.trim() ? text : void 0;
|
|
7
43
|
};
|
|
44
|
+
var mcpProtocolOf = (connection, name) => {
|
|
45
|
+
const list = Array.isArray(connection.protocols) ? connection.protocols : [];
|
|
46
|
+
const found = list.find((p) => p?.server === name);
|
|
47
|
+
return found && typeof found.version === "string" ? { server: name, version: found.version, era: found.era } : void 0;
|
|
48
|
+
};
|
|
49
|
+
var useElicitationQueue = (optionsRef) => {
|
|
50
|
+
const [pendingElicitations, setPending] = useState([]);
|
|
51
|
+
const mountedRef = useRef(true);
|
|
52
|
+
const queueRef = useRef(void 0);
|
|
53
|
+
queueRef.current ??= createElicitationQueue({
|
|
54
|
+
timeoutMs: () => {
|
|
55
|
+
const settings = elicitationSettings(optionsRef.current.elicitation);
|
|
56
|
+
return settings ? elicitationTimeoutOf(settings) : void 0;
|
|
57
|
+
},
|
|
58
|
+
onChange: (pending) => {
|
|
59
|
+
if (mountedRef.current) setPending(pending);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
const queue = queueRef.current;
|
|
63
|
+
const handler = useCallback(
|
|
64
|
+
(request, ctx) => mountedRef.current ? queue.handler(request, ctx) : { action: "cancel" },
|
|
65
|
+
[queue]
|
|
66
|
+
);
|
|
67
|
+
const answerElicitation = useCallback(
|
|
68
|
+
(id, result) => queue.answer(id, result),
|
|
69
|
+
[queue]
|
|
70
|
+
);
|
|
71
|
+
const cancel = useCallback(
|
|
72
|
+
(server) => queue.cancel(server === void 0 ? void 0 : (request) => request.server === server),
|
|
73
|
+
[queue]
|
|
74
|
+
);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
mountedRef.current = true;
|
|
77
|
+
return () => {
|
|
78
|
+
mountedRef.current = false;
|
|
79
|
+
queue.cancel();
|
|
80
|
+
};
|
|
81
|
+
}, [queue]);
|
|
82
|
+
return { pendingElicitations, answerElicitation, handler, cancel };
|
|
83
|
+
};
|
|
8
84
|
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.";
|
|
9
85
|
var PENDING_KEY = "agent-web-react:mcp:pending";
|
|
10
86
|
var OAUTH_KEY = "agent-web-react:mcp:oauth";
|
|
@@ -98,9 +174,44 @@ var mcpOAuthProviderOptions = (serverUrl, oauth = {}, defaults = {}) => {
|
|
|
98
174
|
clientName: oauth.clientName ?? defaults.clientName,
|
|
99
175
|
scope: oauth.scope,
|
|
100
176
|
// Left out when unset: a provider built without it keeps registering dynamically.
|
|
101
|
-
...clientMetadataUrl !== void 0 ? { clientMetadataUrl } : {}
|
|
177
|
+
...clientMetadataUrl !== void 0 ? { clientMetadataUrl } : {},
|
|
178
|
+
// Left out when unset, too: the core's default is 'auto'.
|
|
179
|
+
...oauth.registration !== void 0 ? { registration: oauth.registration } : {}
|
|
102
180
|
};
|
|
103
181
|
};
|
|
182
|
+
var mcpOAuthRecordOf = (resolved) => ({
|
|
183
|
+
redirectUrl: resolved.redirectUrl,
|
|
184
|
+
scope: resolved.scope,
|
|
185
|
+
clientName: resolved.clientName,
|
|
186
|
+
clientMetadataUrl: resolved.clientMetadataUrl,
|
|
187
|
+
...resolved.registration !== void 0 ? { registration: resolved.registration } : {}
|
|
188
|
+
});
|
|
189
|
+
var mcpOAuthOptionsOfRecord = (record) => ({
|
|
190
|
+
redirectUrl: record.redirectUrl,
|
|
191
|
+
scope: record.scope,
|
|
192
|
+
clientName: record.clientName,
|
|
193
|
+
clientMetadataUrl: record.clientMetadataUrl,
|
|
194
|
+
...record.registration !== void 0 ? { registration: record.registration } : {}
|
|
195
|
+
});
|
|
196
|
+
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.`;
|
|
197
|
+
var newMcpOAuthProvider = (mod, options) => {
|
|
198
|
+
if (!mod.BrowserOAuthProvider) throw new Error(OAUTH_UNSUPPORTED);
|
|
199
|
+
const provider = new mod.BrowserOAuthProvider(options);
|
|
200
|
+
const asked = options.registration;
|
|
201
|
+
if (asked !== void 0 && asked !== "auto" && provider.registration !== asked) {
|
|
202
|
+
throw new Error(registrationUnsupported(asked));
|
|
203
|
+
}
|
|
204
|
+
return provider;
|
|
205
|
+
};
|
|
206
|
+
var mcpOAuthRegistrationOf = async (provider) => {
|
|
207
|
+
if (typeof provider?.registrationKind !== "function") return void 0;
|
|
208
|
+
try {
|
|
209
|
+
const kind = await provider.registrationKind();
|
|
210
|
+
return kind === "cimd" || kind === "dcr" ? kind : void 0;
|
|
211
|
+
} catch {
|
|
212
|
+
return void 0;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
104
215
|
var isUnauthorizedError = (err, mod) => {
|
|
105
216
|
if (!(err instanceof Error)) return false;
|
|
106
217
|
if (mod?.UnauthorizedError && err instanceof mod.UnauthorizedError) return true;
|
|
@@ -136,8 +247,12 @@ var useMcp = (options = {}) => {
|
|
|
136
247
|
const [tools, setTools] = useState(void 0);
|
|
137
248
|
const [catalog, setCatalog] = useState([]);
|
|
138
249
|
const [instructions, setInstructions] = useState(void 0);
|
|
250
|
+
const [protocol, setProtocol] = useState(void 0);
|
|
139
251
|
const [error, setError] = useState(void 0);
|
|
140
252
|
const [authorizationUrl, setAuthorizationUrl] = useState(void 0);
|
|
253
|
+
const [oauthRegistration, setOauthRegistration] = useState(
|
|
254
|
+
void 0
|
|
255
|
+
);
|
|
141
256
|
const [oauthSupported, setOauthSupported] = useState(void 0);
|
|
142
257
|
const [completingAuthorization, setCompletingAuthorization] = useState(
|
|
143
258
|
() => readCallbackParams() !== void 0
|
|
@@ -147,12 +262,15 @@ var useMcp = (options = {}) => {
|
|
|
147
262
|
const epochRef = useRef(0);
|
|
148
263
|
const optionsRef = useRef(options);
|
|
149
264
|
optionsRef.current = options;
|
|
265
|
+
const elicitation = useElicitationQueue(optionsRef);
|
|
266
|
+
const cancelElicitations = elicitation.cancel;
|
|
150
267
|
const closeConnection = useCallback(async () => {
|
|
151
268
|
const open = connectionRef.current;
|
|
152
269
|
connectionRef.current = void 0;
|
|
270
|
+
cancelElicitations();
|
|
153
271
|
if (open) await open.close().catch(() => {
|
|
154
272
|
});
|
|
155
|
-
}, []);
|
|
273
|
+
}, [cancelElicitations]);
|
|
156
274
|
const checkOAuthSupport = useCallback(async () => {
|
|
157
275
|
try {
|
|
158
276
|
const mod = await loadMcp();
|
|
@@ -173,9 +291,11 @@ var useMcp = (options = {}) => {
|
|
|
173
291
|
setStatus("connecting");
|
|
174
292
|
setError(void 0);
|
|
175
293
|
setAuthorizationUrl(void 0);
|
|
294
|
+
setOauthRegistration(void 0);
|
|
176
295
|
setTools(void 0);
|
|
177
296
|
setCatalog([]);
|
|
178
297
|
setInstructions(void 0);
|
|
298
|
+
setProtocol(void 0);
|
|
179
299
|
try {
|
|
180
300
|
const mod = await loadMcp();
|
|
181
301
|
setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
|
|
@@ -191,13 +311,12 @@ var useMcp = (options = {}) => {
|
|
|
191
311
|
const record = {
|
|
192
312
|
url: opts.url,
|
|
193
313
|
name,
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
clientMetadataUrl: providerOptions.clientMetadataUrl,
|
|
314
|
+
...mcpOAuthRecordOf(providerOptions),
|
|
315
|
+
...opts.protocol ? { protocol: opts.protocol } : {},
|
|
316
|
+
...mcpSkillsSettingOf(opts.skills) ? { skills: mcpSkillsSettingOf(opts.skills) } : {},
|
|
198
317
|
startedAt: Date.now()
|
|
199
318
|
};
|
|
200
|
-
authProvider =
|
|
319
|
+
authProvider = newMcpOAuthProvider(mod, providerOptions);
|
|
201
320
|
providerRef.current = authProvider;
|
|
202
321
|
writeRecord(PENDING_KEY, record);
|
|
203
322
|
writeRecord(OAUTH_KEY, record);
|
|
@@ -209,10 +328,19 @@ var useMcp = (options = {}) => {
|
|
|
209
328
|
[name]: {
|
|
210
329
|
url: opts.url,
|
|
211
330
|
headers: opts.oauth ? void 0 : opts.headers,
|
|
212
|
-
authProvider
|
|
331
|
+
authProvider,
|
|
332
|
+
// Only when asked for: without it the connection is built as it always was.
|
|
333
|
+
...opts.protocol ? { protocol: opts.protocol } : {},
|
|
334
|
+
...mcpSkillsSettingOf(opts.skills) ? { skills: mcpSkillsSettingOf(opts.skills) } : {}
|
|
213
335
|
}
|
|
214
336
|
},
|
|
215
|
-
{
|
|
337
|
+
{
|
|
338
|
+
clientName: optionsRef.current.clientName,
|
|
339
|
+
onLog: optionsRef.current.onLog,
|
|
340
|
+
...optionsRef.current.apps ? { apps: true } : {},
|
|
341
|
+
// Off: neither key is passed, so the core declares no capability.
|
|
342
|
+
...elicitationConnectOptions(optionsRef.current.elicitation, elicitation.handler)
|
|
343
|
+
}
|
|
216
344
|
);
|
|
217
345
|
if (!current()) {
|
|
218
346
|
await connection.close().catch(() => {
|
|
@@ -243,6 +371,10 @@ var useMcp = (options = {}) => {
|
|
|
243
371
|
);
|
|
244
372
|
setCatalog(connection.catalog);
|
|
245
373
|
setInstructions(mcpInstructionsOf(connection, name));
|
|
374
|
+
setProtocol(mcpProtocolOf(connection, name));
|
|
375
|
+
const registered = await mcpOAuthRegistrationOf(authProvider);
|
|
376
|
+
if (!current()) return;
|
|
377
|
+
setOauthRegistration(registered);
|
|
246
378
|
setStatus("connected");
|
|
247
379
|
} catch (err) {
|
|
248
380
|
if (!current()) return;
|
|
@@ -250,7 +382,7 @@ var useMcp = (options = {}) => {
|
|
|
250
382
|
setStatus("error");
|
|
251
383
|
}
|
|
252
384
|
},
|
|
253
|
-
[closeConnection]
|
|
385
|
+
[closeConnection, elicitation.handler]
|
|
254
386
|
);
|
|
255
387
|
const disconnect = useCallback(async () => {
|
|
256
388
|
epochRef.current++;
|
|
@@ -258,7 +390,9 @@ var useMcp = (options = {}) => {
|
|
|
258
390
|
setTools(void 0);
|
|
259
391
|
setCatalog([]);
|
|
260
392
|
setInstructions(void 0);
|
|
393
|
+
setProtocol(void 0);
|
|
261
394
|
setAuthorizationUrl(void 0);
|
|
395
|
+
setOauthRegistration(void 0);
|
|
262
396
|
setError(void 0);
|
|
263
397
|
setStatus("idle");
|
|
264
398
|
}, [closeConnection]);
|
|
@@ -311,7 +445,8 @@ var useMcp = (options = {}) => {
|
|
|
311
445
|
const mod = await loadMcp();
|
|
312
446
|
setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
|
|
313
447
|
if (!mod.BrowserOAuthProvider || !mod.finishMcpOAuth) throw new Error(OAUTH_UNSUPPORTED);
|
|
314
|
-
const
|
|
448
|
+
const oauth = mcpOAuthOptionsOfRecord(pending);
|
|
449
|
+
const provider = newMcpOAuthProvider(mod, mcpOAuthProviderOptions(pending.url, oauth));
|
|
315
450
|
providerRef.current = provider;
|
|
316
451
|
await mod.finishMcpOAuth(provider, callback);
|
|
317
452
|
writeRecord(PENDING_KEY, void 0);
|
|
@@ -319,12 +454,9 @@ var useMcp = (options = {}) => {
|
|
|
319
454
|
await connect({
|
|
320
455
|
url: pending.url,
|
|
321
456
|
name: pending.name,
|
|
322
|
-
oauth
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
clientName: pending.clientName,
|
|
326
|
-
clientMetadataUrl: pending.clientMetadataUrl
|
|
327
|
-
}
|
|
457
|
+
oauth,
|
|
458
|
+
...pending.protocol ? { protocol: pending.protocol } : {},
|
|
459
|
+
...mcpSkillsSettingOf(pending.skills) ? { skills: mcpSkillsSettingOf(pending.skills) } : {}
|
|
328
460
|
});
|
|
329
461
|
} catch (err) {
|
|
330
462
|
writeRecord(PENDING_KEY, void 0);
|
|
@@ -342,15 +474,25 @@ var useMcp = (options = {}) => {
|
|
|
342
474
|
},
|
|
343
475
|
[closeConnection]
|
|
344
476
|
);
|
|
477
|
+
const appsOn = options.apps === true;
|
|
478
|
+
const apps = useMemo(
|
|
479
|
+
() => appsOn ? mcpAppsRouter(() => connectionRef.current) : void 0,
|
|
480
|
+
[appsOn]
|
|
481
|
+
);
|
|
345
482
|
return {
|
|
483
|
+
apps,
|
|
346
484
|
status,
|
|
347
485
|
tools,
|
|
348
486
|
catalog,
|
|
349
487
|
instructions,
|
|
488
|
+
protocol,
|
|
350
489
|
error,
|
|
351
490
|
authorizationUrl,
|
|
491
|
+
oauthRegistration,
|
|
352
492
|
oauthSupported,
|
|
353
493
|
completingAuthorization,
|
|
494
|
+
pendingElicitations: elicitation.pendingElicitations,
|
|
495
|
+
answerElicitation: elicitation.answerElicitation,
|
|
354
496
|
connect,
|
|
355
497
|
disconnect,
|
|
356
498
|
authorize,
|
|
@@ -360,13 +502,17 @@ var useMcp = (options = {}) => {
|
|
|
360
502
|
};
|
|
361
503
|
|
|
362
504
|
// src/hooks/use-mcp-servers.ts
|
|
363
|
-
import { useCallback as useCallback2, useEffect as useEffect2, useMemo, useRef as useRef2, useState as useState2 } from "react";
|
|
505
|
+
import { useCallback as useCallback2, useEffect as useEffect2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
|
|
364
506
|
var DEFAULT_KEY = "agent-web-react:mcp-servers";
|
|
365
507
|
var sanitize = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 32) || "mcp";
|
|
508
|
+
var isProtocolMode = (value) => value === "legacy" || value === "auto" || value === "modern";
|
|
366
509
|
var view = (s, patch = {}) => ({
|
|
367
510
|
name: s.name,
|
|
368
511
|
url: s.url,
|
|
369
512
|
auth: s.auth,
|
|
513
|
+
...isProtocolMode(s.protocol) ? { protocolMode: s.protocol } : {},
|
|
514
|
+
...mcpSkillsSettingOf(s.skills) ? { skills: mcpSkillsSettingOf(s.skills) } : {},
|
|
515
|
+
...typeof s.apps === "boolean" ? { apps: s.apps } : {},
|
|
370
516
|
status: "idle",
|
|
371
517
|
catalog: [],
|
|
372
518
|
...patch
|
|
@@ -393,13 +539,18 @@ var useMcpServers = (options = {}) => {
|
|
|
393
539
|
name: s.name,
|
|
394
540
|
url: s.url,
|
|
395
541
|
auth: s.auth,
|
|
396
|
-
...oauth && typeof oauth === "object" ? { oauth } : {}
|
|
542
|
+
...oauth && typeof oauth === "object" ? { oauth } : {},
|
|
543
|
+
...s.protocolMode ? { protocol: s.protocolMode } : {},
|
|
544
|
+
...mcpSkillsSettingOf(s.skills) ? { skills: mcpSkillsSettingOf(s.skills) } : {},
|
|
545
|
+
...typeof s.apps === "boolean" ? { apps: s.apps } : {}
|
|
397
546
|
});
|
|
398
547
|
}
|
|
399
548
|
}
|
|
400
549
|
const optionsRef = useRef2(options);
|
|
401
550
|
optionsRef.current = options;
|
|
402
551
|
const unmountedRef = useRef2(false);
|
|
552
|
+
const elicitation = useElicitationQueue(optionsRef);
|
|
553
|
+
const cancelElicitations = elicitation.cancel;
|
|
403
554
|
const saveList = useCallback2(() => {
|
|
404
555
|
if (!persist) return;
|
|
405
556
|
writeRecord(storageKey, [...specsRef.current.values()]);
|
|
@@ -426,15 +577,11 @@ var useMcpServers = (options = {}) => {
|
|
|
426
577
|
l.tools = void 0;
|
|
427
578
|
setToolsVersion((v) => v + 1);
|
|
428
579
|
}
|
|
580
|
+
cancelElicitations(name);
|
|
429
581
|
if (open) await open.close().catch(() => {
|
|
430
582
|
});
|
|
431
583
|
}, []);
|
|
432
|
-
const providerFor = (mod, spec) =>
|
|
433
|
-
if (!mod.BrowserOAuthProvider) throw new Error(OAUTH_UNSUPPORTED);
|
|
434
|
-
return new mod.BrowserOAuthProvider(
|
|
435
|
-
mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current)
|
|
436
|
-
);
|
|
437
|
-
};
|
|
584
|
+
const providerFor = (mod, spec) => newMcpOAuthProvider(mod, mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current));
|
|
438
585
|
const connectServer = useCallback2(
|
|
439
586
|
async (name) => {
|
|
440
587
|
const spec = specsRef.current.get(name);
|
|
@@ -451,8 +598,10 @@ var useMcpServers = (options = {}) => {
|
|
|
451
598
|
status: "connecting",
|
|
452
599
|
error: void 0,
|
|
453
600
|
authorizationUrl: void 0,
|
|
601
|
+
oauthRegistration: void 0,
|
|
454
602
|
catalog: [],
|
|
455
|
-
instructions: void 0
|
|
603
|
+
instructions: void 0,
|
|
604
|
+
protocol: void 0
|
|
456
605
|
});
|
|
457
606
|
try {
|
|
458
607
|
const mod = await loadMcp();
|
|
@@ -468,13 +617,21 @@ var useMcpServers = (options = {}) => {
|
|
|
468
617
|
url: spec.url,
|
|
469
618
|
headers: spec.auth === "bearer" && l.token ? { Authorization: `Bearer ${l.token}` } : void 0,
|
|
470
619
|
authProvider: provider,
|
|
471
|
-
connectTimeoutMs: optionsRef.current.connectTimeoutMs
|
|
620
|
+
connectTimeoutMs: optionsRef.current.connectTimeoutMs,
|
|
621
|
+
// Only when asked for: without it the connection is built as it always was.
|
|
622
|
+
...spec.protocol ? { protocol: spec.protocol } : {},
|
|
623
|
+
...mcpSkillsSettingOf(spec.skills) ? { skills: mcpSkillsSettingOf(spec.skills) } : {},
|
|
624
|
+
// Only when given: without it the hook's `apps` decides, as before.
|
|
625
|
+
...typeof spec.apps === "boolean" ? { apps: spec.apps } : {}
|
|
472
626
|
}
|
|
473
627
|
},
|
|
474
628
|
{
|
|
475
629
|
clientName: optionsRef.current.clientName,
|
|
476
630
|
onLog: optionsRef.current.onLog,
|
|
477
|
-
connectTimeoutMs: optionsRef.current.connectTimeoutMs
|
|
631
|
+
connectTimeoutMs: optionsRef.current.connectTimeoutMs,
|
|
632
|
+
...optionsRef.current.apps ? { apps: true } : {},
|
|
633
|
+
// Off: neither key is passed, so the core declares no capability.
|
|
634
|
+
...elicitationConnectOptions(optionsRef.current.elicitation, elicitation.handler)
|
|
478
635
|
}
|
|
479
636
|
);
|
|
480
637
|
if (!current()) {
|
|
@@ -506,10 +663,15 @@ var useMcpServers = (options = {}) => {
|
|
|
506
663
|
});
|
|
507
664
|
});
|
|
508
665
|
setToolsVersion((v) => v + 1);
|
|
666
|
+
const negotiated = mcpProtocolOf(connection, name);
|
|
667
|
+
const oauthRegistration = await mcpOAuthRegistrationOf(provider);
|
|
668
|
+
if (!current()) return;
|
|
509
669
|
patch(name, {
|
|
510
670
|
status: "connected",
|
|
671
|
+
oauthRegistration,
|
|
511
672
|
catalog: connection.catalog,
|
|
512
|
-
instructions: mcpInstructionsOf(connection, name)
|
|
673
|
+
instructions: mcpInstructionsOf(connection, name),
|
|
674
|
+
protocol: negotiated ? { version: negotiated.version, era: negotiated.era } : void 0
|
|
513
675
|
});
|
|
514
676
|
} catch (err) {
|
|
515
677
|
if (!current()) return;
|
|
@@ -532,7 +694,10 @@ var useMcpServers = (options = {}) => {
|
|
|
532
694
|
name,
|
|
533
695
|
url: input.url,
|
|
534
696
|
auth: input.auth ?? "none",
|
|
535
|
-
...input.oauth ? { oauth: input.oauth } : {}
|
|
697
|
+
...input.oauth ? { oauth: input.oauth } : {},
|
|
698
|
+
...isProtocolMode(input.protocol) ? { protocol: input.protocol } : {},
|
|
699
|
+
...mcpSkillsSettingOf(input.skills) ? { skills: mcpSkillsSettingOf(input.skills) } : {},
|
|
700
|
+
...typeof input.apps === "boolean" ? { apps: input.apps } : {}
|
|
536
701
|
};
|
|
537
702
|
specsRef.current.set(name, spec);
|
|
538
703
|
live(name).token = input.auth === "bearer" ? input.token : void 0;
|
|
@@ -570,10 +735,7 @@ var useMcpServers = (options = {}) => {
|
|
|
570
735
|
const pending = {
|
|
571
736
|
name,
|
|
572
737
|
url: spec.url,
|
|
573
|
-
|
|
574
|
-
scope: spec.oauth?.scope,
|
|
575
|
-
clientName: spec.oauth?.clientName ?? optionsRef.current.clientName,
|
|
576
|
-
clientMetadataUrl: spec.oauth?.clientMetadataUrl ?? optionsRef.current.clientMetadataUrl,
|
|
738
|
+
...mcpOAuthRecordOf(mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current)),
|
|
577
739
|
startedAt: Date.now()
|
|
578
740
|
};
|
|
579
741
|
writeRecord(pendingKey, pending);
|
|
@@ -604,8 +766,10 @@ var useMcpServers = (options = {}) => {
|
|
|
604
766
|
patch(name, {
|
|
605
767
|
status: "idle",
|
|
606
768
|
authorizationUrl: void 0,
|
|
769
|
+
oauthRegistration: void 0,
|
|
607
770
|
catalog: [],
|
|
608
771
|
instructions: void 0,
|
|
772
|
+
protocol: void 0,
|
|
609
773
|
error: void 0
|
|
610
774
|
});
|
|
611
775
|
},
|
|
@@ -650,15 +814,7 @@ var useMcpServers = (options = {}) => {
|
|
|
650
814
|
setServers((list) => [...list, view(spec)]);
|
|
651
815
|
saveList();
|
|
652
816
|
}
|
|
653
|
-
const provider = providerFor(mod, {
|
|
654
|
-
...spec,
|
|
655
|
-
oauth: {
|
|
656
|
-
redirectUrl: pending.redirectUrl,
|
|
657
|
-
scope: pending.scope,
|
|
658
|
-
clientName: pending.clientName,
|
|
659
|
-
clientMetadataUrl: pending.clientMetadataUrl
|
|
660
|
-
}
|
|
661
|
-
});
|
|
817
|
+
const provider = providerFor(mod, { ...spec, oauth: mcpOAuthOptionsOfRecord(pending) });
|
|
662
818
|
live(spec.name).provider = provider;
|
|
663
819
|
await mod.finishMcpOAuth(provider, callback);
|
|
664
820
|
writeRecord(pendingKey, void 0);
|
|
@@ -682,19 +838,39 @@ var useMcpServers = (options = {}) => {
|
|
|
682
838
|
for (const name of liveRef.current.keys()) void closeServer(name);
|
|
683
839
|
};
|
|
684
840
|
}, []);
|
|
685
|
-
const tools =
|
|
841
|
+
const tools = useMemo2(() => {
|
|
686
842
|
const merged = {};
|
|
687
843
|
for (const l of liveRef.current.values()) if (l.tools) Object.assign(merged, l.tools);
|
|
688
844
|
return merged;
|
|
689
845
|
}, [toolsVersion]);
|
|
690
|
-
const catalog =
|
|
846
|
+
const catalog = useMemo2(
|
|
691
847
|
() => servers.filter((s) => s.status === "connected").flatMap((s) => s.catalog),
|
|
692
848
|
[servers]
|
|
693
849
|
);
|
|
850
|
+
const appsOn = options.apps === true || servers.some((s) => s.apps === true);
|
|
851
|
+
const hookApps = options.apps === true;
|
|
852
|
+
const apps = useMemo2(
|
|
853
|
+
() => appsOn ? mcpAppsRouter((server) => {
|
|
854
|
+
const spec = specsRef.current.get(server);
|
|
855
|
+
if (!spec || (spec.apps ?? hookApps) !== true) return void 0;
|
|
856
|
+
return liveRef.current.get(server)?.connection;
|
|
857
|
+
}) : void 0,
|
|
858
|
+
[appsOn, hookApps]
|
|
859
|
+
);
|
|
860
|
+
const protocols = useMemo2(
|
|
861
|
+
() => servers.flatMap(
|
|
862
|
+
(s) => s.status === "connected" && s.protocol ? [{ server: s.name, ...s.protocol }] : []
|
|
863
|
+
),
|
|
864
|
+
[servers]
|
|
865
|
+
);
|
|
694
866
|
return {
|
|
867
|
+
apps,
|
|
695
868
|
servers,
|
|
696
869
|
tools,
|
|
697
870
|
catalog,
|
|
871
|
+
protocols,
|
|
872
|
+
pendingElicitations: elicitation.pendingElicitations,
|
|
873
|
+
answerElicitation: elicitation.answerElicitation,
|
|
698
874
|
connectedCount: servers.filter((s) => s.status === "connected").length,
|
|
699
875
|
completingAuthorization,
|
|
700
876
|
oauthSupported,
|
|
@@ -708,10 +884,21 @@ var useMcpServers = (options = {}) => {
|
|
|
708
884
|
};
|
|
709
885
|
export {
|
|
710
886
|
claimOAuthCallback,
|
|
887
|
+
createElicitationQueue,
|
|
711
888
|
describeMcpResult,
|
|
889
|
+
elicitationConnectOptions,
|
|
890
|
+
elicitationSettings,
|
|
891
|
+
elicitationTimeoutOf,
|
|
712
892
|
isUnauthorizedError,
|
|
893
|
+
mcpAppsRouter,
|
|
713
894
|
mcpInstructionsOf,
|
|
895
|
+
mcpOAuthOptionsOfRecord,
|
|
714
896
|
mcpOAuthProviderOptions,
|
|
897
|
+
mcpOAuthRecordOf,
|
|
898
|
+
mcpOAuthRegistrationOf,
|
|
899
|
+
mcpProtocolOf,
|
|
900
|
+
mcpSkillsSettingOf,
|
|
901
|
+
newMcpOAuthProvider,
|
|
715
902
|
readCallbackParams,
|
|
716
903
|
stripOAuthParams,
|
|
717
904
|
useMcp,
|