@dudko.dev/agent-web-react 0.0.28 → 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 +368 -24
- 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 +316 -42
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +195 -100
- package/dist/mcp.d.ts +195 -100
- package/dist/mcp.js +234 -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 +1143 -1
- 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,12 +174,48 @@ 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;
|
|
218
|
+
if (err.name === "UnauthorizedError") return true;
|
|
107
219
|
return err.constructor?.name === "UnauthorizedError";
|
|
108
220
|
};
|
|
109
221
|
var watchAuthorization = (tools, mod, onUnauthorized) => {
|
|
@@ -135,8 +247,12 @@ var useMcp = (options = {}) => {
|
|
|
135
247
|
const [tools, setTools] = useState(void 0);
|
|
136
248
|
const [catalog, setCatalog] = useState([]);
|
|
137
249
|
const [instructions, setInstructions] = useState(void 0);
|
|
250
|
+
const [protocol, setProtocol] = useState(void 0);
|
|
138
251
|
const [error, setError] = useState(void 0);
|
|
139
252
|
const [authorizationUrl, setAuthorizationUrl] = useState(void 0);
|
|
253
|
+
const [oauthRegistration, setOauthRegistration] = useState(
|
|
254
|
+
void 0
|
|
255
|
+
);
|
|
140
256
|
const [oauthSupported, setOauthSupported] = useState(void 0);
|
|
141
257
|
const [completingAuthorization, setCompletingAuthorization] = useState(
|
|
142
258
|
() => readCallbackParams() !== void 0
|
|
@@ -146,12 +262,15 @@ var useMcp = (options = {}) => {
|
|
|
146
262
|
const epochRef = useRef(0);
|
|
147
263
|
const optionsRef = useRef(options);
|
|
148
264
|
optionsRef.current = options;
|
|
265
|
+
const elicitation = useElicitationQueue(optionsRef);
|
|
266
|
+
const cancelElicitations = elicitation.cancel;
|
|
149
267
|
const closeConnection = useCallback(async () => {
|
|
150
268
|
const open = connectionRef.current;
|
|
151
269
|
connectionRef.current = void 0;
|
|
270
|
+
cancelElicitations();
|
|
152
271
|
if (open) await open.close().catch(() => {
|
|
153
272
|
});
|
|
154
|
-
}, []);
|
|
273
|
+
}, [cancelElicitations]);
|
|
155
274
|
const checkOAuthSupport = useCallback(async () => {
|
|
156
275
|
try {
|
|
157
276
|
const mod = await loadMcp();
|
|
@@ -172,9 +291,11 @@ var useMcp = (options = {}) => {
|
|
|
172
291
|
setStatus("connecting");
|
|
173
292
|
setError(void 0);
|
|
174
293
|
setAuthorizationUrl(void 0);
|
|
294
|
+
setOauthRegistration(void 0);
|
|
175
295
|
setTools(void 0);
|
|
176
296
|
setCatalog([]);
|
|
177
297
|
setInstructions(void 0);
|
|
298
|
+
setProtocol(void 0);
|
|
178
299
|
try {
|
|
179
300
|
const mod = await loadMcp();
|
|
180
301
|
setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
|
|
@@ -190,13 +311,12 @@ var useMcp = (options = {}) => {
|
|
|
190
311
|
const record = {
|
|
191
312
|
url: opts.url,
|
|
192
313
|
name,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
clientMetadataUrl: providerOptions.clientMetadataUrl,
|
|
314
|
+
...mcpOAuthRecordOf(providerOptions),
|
|
315
|
+
...opts.protocol ? { protocol: opts.protocol } : {},
|
|
316
|
+
...mcpSkillsSettingOf(opts.skills) ? { skills: mcpSkillsSettingOf(opts.skills) } : {},
|
|
197
317
|
startedAt: Date.now()
|
|
198
318
|
};
|
|
199
|
-
authProvider =
|
|
319
|
+
authProvider = newMcpOAuthProvider(mod, providerOptions);
|
|
200
320
|
providerRef.current = authProvider;
|
|
201
321
|
writeRecord(PENDING_KEY, record);
|
|
202
322
|
writeRecord(OAUTH_KEY, record);
|
|
@@ -208,10 +328,19 @@ var useMcp = (options = {}) => {
|
|
|
208
328
|
[name]: {
|
|
209
329
|
url: opts.url,
|
|
210
330
|
headers: opts.oauth ? void 0 : opts.headers,
|
|
211
|
-
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) } : {}
|
|
212
335
|
}
|
|
213
336
|
},
|
|
214
|
-
{
|
|
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
|
+
}
|
|
215
344
|
);
|
|
216
345
|
if (!current()) {
|
|
217
346
|
await connection.close().catch(() => {
|
|
@@ -242,6 +371,10 @@ var useMcp = (options = {}) => {
|
|
|
242
371
|
);
|
|
243
372
|
setCatalog(connection.catalog);
|
|
244
373
|
setInstructions(mcpInstructionsOf(connection, name));
|
|
374
|
+
setProtocol(mcpProtocolOf(connection, name));
|
|
375
|
+
const registered = await mcpOAuthRegistrationOf(authProvider);
|
|
376
|
+
if (!current()) return;
|
|
377
|
+
setOauthRegistration(registered);
|
|
245
378
|
setStatus("connected");
|
|
246
379
|
} catch (err) {
|
|
247
380
|
if (!current()) return;
|
|
@@ -249,7 +382,7 @@ var useMcp = (options = {}) => {
|
|
|
249
382
|
setStatus("error");
|
|
250
383
|
}
|
|
251
384
|
},
|
|
252
|
-
[closeConnection]
|
|
385
|
+
[closeConnection, elicitation.handler]
|
|
253
386
|
);
|
|
254
387
|
const disconnect = useCallback(async () => {
|
|
255
388
|
epochRef.current++;
|
|
@@ -257,7 +390,9 @@ var useMcp = (options = {}) => {
|
|
|
257
390
|
setTools(void 0);
|
|
258
391
|
setCatalog([]);
|
|
259
392
|
setInstructions(void 0);
|
|
393
|
+
setProtocol(void 0);
|
|
260
394
|
setAuthorizationUrl(void 0);
|
|
395
|
+
setOauthRegistration(void 0);
|
|
261
396
|
setError(void 0);
|
|
262
397
|
setStatus("idle");
|
|
263
398
|
}, [closeConnection]);
|
|
@@ -310,7 +445,8 @@ var useMcp = (options = {}) => {
|
|
|
310
445
|
const mod = await loadMcp();
|
|
311
446
|
setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
|
|
312
447
|
if (!mod.BrowserOAuthProvider || !mod.finishMcpOAuth) throw new Error(OAUTH_UNSUPPORTED);
|
|
313
|
-
const
|
|
448
|
+
const oauth = mcpOAuthOptionsOfRecord(pending);
|
|
449
|
+
const provider = newMcpOAuthProvider(mod, mcpOAuthProviderOptions(pending.url, oauth));
|
|
314
450
|
providerRef.current = provider;
|
|
315
451
|
await mod.finishMcpOAuth(provider, callback);
|
|
316
452
|
writeRecord(PENDING_KEY, void 0);
|
|
@@ -318,12 +454,9 @@ var useMcp = (options = {}) => {
|
|
|
318
454
|
await connect({
|
|
319
455
|
url: pending.url,
|
|
320
456
|
name: pending.name,
|
|
321
|
-
oauth
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
clientName: pending.clientName,
|
|
325
|
-
clientMetadataUrl: pending.clientMetadataUrl
|
|
326
|
-
}
|
|
457
|
+
oauth,
|
|
458
|
+
...pending.protocol ? { protocol: pending.protocol } : {},
|
|
459
|
+
...mcpSkillsSettingOf(pending.skills) ? { skills: mcpSkillsSettingOf(pending.skills) } : {}
|
|
327
460
|
});
|
|
328
461
|
} catch (err) {
|
|
329
462
|
writeRecord(PENDING_KEY, void 0);
|
|
@@ -341,15 +474,25 @@ var useMcp = (options = {}) => {
|
|
|
341
474
|
},
|
|
342
475
|
[closeConnection]
|
|
343
476
|
);
|
|
477
|
+
const appsOn = options.apps === true;
|
|
478
|
+
const apps = useMemo(
|
|
479
|
+
() => appsOn ? mcpAppsRouter(() => connectionRef.current) : void 0,
|
|
480
|
+
[appsOn]
|
|
481
|
+
);
|
|
344
482
|
return {
|
|
483
|
+
apps,
|
|
345
484
|
status,
|
|
346
485
|
tools,
|
|
347
486
|
catalog,
|
|
348
487
|
instructions,
|
|
488
|
+
protocol,
|
|
349
489
|
error,
|
|
350
490
|
authorizationUrl,
|
|
491
|
+
oauthRegistration,
|
|
351
492
|
oauthSupported,
|
|
352
493
|
completingAuthorization,
|
|
494
|
+
pendingElicitations: elicitation.pendingElicitations,
|
|
495
|
+
answerElicitation: elicitation.answerElicitation,
|
|
353
496
|
connect,
|
|
354
497
|
disconnect,
|
|
355
498
|
authorize,
|
|
@@ -359,13 +502,17 @@ var useMcp = (options = {}) => {
|
|
|
359
502
|
};
|
|
360
503
|
|
|
361
504
|
// src/hooks/use-mcp-servers.ts
|
|
362
|
-
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";
|
|
363
506
|
var DEFAULT_KEY = "agent-web-react:mcp-servers";
|
|
364
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";
|
|
365
509
|
var view = (s, patch = {}) => ({
|
|
366
510
|
name: s.name,
|
|
367
511
|
url: s.url,
|
|
368
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 } : {},
|
|
369
516
|
status: "idle",
|
|
370
517
|
catalog: [],
|
|
371
518
|
...patch
|
|
@@ -392,13 +539,18 @@ var useMcpServers = (options = {}) => {
|
|
|
392
539
|
name: s.name,
|
|
393
540
|
url: s.url,
|
|
394
541
|
auth: s.auth,
|
|
395
|
-
...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 } : {}
|
|
396
546
|
});
|
|
397
547
|
}
|
|
398
548
|
}
|
|
399
549
|
const optionsRef = useRef2(options);
|
|
400
550
|
optionsRef.current = options;
|
|
401
551
|
const unmountedRef = useRef2(false);
|
|
552
|
+
const elicitation = useElicitationQueue(optionsRef);
|
|
553
|
+
const cancelElicitations = elicitation.cancel;
|
|
402
554
|
const saveList = useCallback2(() => {
|
|
403
555
|
if (!persist) return;
|
|
404
556
|
writeRecord(storageKey, [...specsRef.current.values()]);
|
|
@@ -425,15 +577,11 @@ var useMcpServers = (options = {}) => {
|
|
|
425
577
|
l.tools = void 0;
|
|
426
578
|
setToolsVersion((v) => v + 1);
|
|
427
579
|
}
|
|
580
|
+
cancelElicitations(name);
|
|
428
581
|
if (open) await open.close().catch(() => {
|
|
429
582
|
});
|
|
430
583
|
}, []);
|
|
431
|
-
const providerFor = (mod, spec) =>
|
|
432
|
-
if (!mod.BrowserOAuthProvider) throw new Error(OAUTH_UNSUPPORTED);
|
|
433
|
-
return new mod.BrowserOAuthProvider(
|
|
434
|
-
mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current)
|
|
435
|
-
);
|
|
436
|
-
};
|
|
584
|
+
const providerFor = (mod, spec) => newMcpOAuthProvider(mod, mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current));
|
|
437
585
|
const connectServer = useCallback2(
|
|
438
586
|
async (name) => {
|
|
439
587
|
const spec = specsRef.current.get(name);
|
|
@@ -450,8 +598,10 @@ var useMcpServers = (options = {}) => {
|
|
|
450
598
|
status: "connecting",
|
|
451
599
|
error: void 0,
|
|
452
600
|
authorizationUrl: void 0,
|
|
601
|
+
oauthRegistration: void 0,
|
|
453
602
|
catalog: [],
|
|
454
|
-
instructions: void 0
|
|
603
|
+
instructions: void 0,
|
|
604
|
+
protocol: void 0
|
|
455
605
|
});
|
|
456
606
|
try {
|
|
457
607
|
const mod = await loadMcp();
|
|
@@ -467,13 +617,21 @@ var useMcpServers = (options = {}) => {
|
|
|
467
617
|
url: spec.url,
|
|
468
618
|
headers: spec.auth === "bearer" && l.token ? { Authorization: `Bearer ${l.token}` } : void 0,
|
|
469
619
|
authProvider: provider,
|
|
470
|
-
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 } : {}
|
|
471
626
|
}
|
|
472
627
|
},
|
|
473
628
|
{
|
|
474
629
|
clientName: optionsRef.current.clientName,
|
|
475
630
|
onLog: optionsRef.current.onLog,
|
|
476
|
-
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)
|
|
477
635
|
}
|
|
478
636
|
);
|
|
479
637
|
if (!current()) {
|
|
@@ -505,10 +663,15 @@ var useMcpServers = (options = {}) => {
|
|
|
505
663
|
});
|
|
506
664
|
});
|
|
507
665
|
setToolsVersion((v) => v + 1);
|
|
666
|
+
const negotiated = mcpProtocolOf(connection, name);
|
|
667
|
+
const oauthRegistration = await mcpOAuthRegistrationOf(provider);
|
|
668
|
+
if (!current()) return;
|
|
508
669
|
patch(name, {
|
|
509
670
|
status: "connected",
|
|
671
|
+
oauthRegistration,
|
|
510
672
|
catalog: connection.catalog,
|
|
511
|
-
instructions: mcpInstructionsOf(connection, name)
|
|
673
|
+
instructions: mcpInstructionsOf(connection, name),
|
|
674
|
+
protocol: negotiated ? { version: negotiated.version, era: negotiated.era } : void 0
|
|
512
675
|
});
|
|
513
676
|
} catch (err) {
|
|
514
677
|
if (!current()) return;
|
|
@@ -531,7 +694,10 @@ var useMcpServers = (options = {}) => {
|
|
|
531
694
|
name,
|
|
532
695
|
url: input.url,
|
|
533
696
|
auth: input.auth ?? "none",
|
|
534
|
-
...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 } : {}
|
|
535
701
|
};
|
|
536
702
|
specsRef.current.set(name, spec);
|
|
537
703
|
live(name).token = input.auth === "bearer" ? input.token : void 0;
|
|
@@ -569,10 +735,7 @@ var useMcpServers = (options = {}) => {
|
|
|
569
735
|
const pending = {
|
|
570
736
|
name,
|
|
571
737
|
url: spec.url,
|
|
572
|
-
|
|
573
|
-
scope: spec.oauth?.scope,
|
|
574
|
-
clientName: spec.oauth?.clientName ?? optionsRef.current.clientName,
|
|
575
|
-
clientMetadataUrl: spec.oauth?.clientMetadataUrl ?? optionsRef.current.clientMetadataUrl,
|
|
738
|
+
...mcpOAuthRecordOf(mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current)),
|
|
576
739
|
startedAt: Date.now()
|
|
577
740
|
};
|
|
578
741
|
writeRecord(pendingKey, pending);
|
|
@@ -603,8 +766,10 @@ var useMcpServers = (options = {}) => {
|
|
|
603
766
|
patch(name, {
|
|
604
767
|
status: "idle",
|
|
605
768
|
authorizationUrl: void 0,
|
|
769
|
+
oauthRegistration: void 0,
|
|
606
770
|
catalog: [],
|
|
607
771
|
instructions: void 0,
|
|
772
|
+
protocol: void 0,
|
|
608
773
|
error: void 0
|
|
609
774
|
});
|
|
610
775
|
},
|
|
@@ -649,15 +814,7 @@ var useMcpServers = (options = {}) => {
|
|
|
649
814
|
setServers((list) => [...list, view(spec)]);
|
|
650
815
|
saveList();
|
|
651
816
|
}
|
|
652
|
-
const provider = providerFor(mod, {
|
|
653
|
-
...spec,
|
|
654
|
-
oauth: {
|
|
655
|
-
redirectUrl: pending.redirectUrl,
|
|
656
|
-
scope: pending.scope,
|
|
657
|
-
clientName: pending.clientName,
|
|
658
|
-
clientMetadataUrl: pending.clientMetadataUrl
|
|
659
|
-
}
|
|
660
|
-
});
|
|
817
|
+
const provider = providerFor(mod, { ...spec, oauth: mcpOAuthOptionsOfRecord(pending) });
|
|
661
818
|
live(spec.name).provider = provider;
|
|
662
819
|
await mod.finishMcpOAuth(provider, callback);
|
|
663
820
|
writeRecord(pendingKey, void 0);
|
|
@@ -681,19 +838,39 @@ var useMcpServers = (options = {}) => {
|
|
|
681
838
|
for (const name of liveRef.current.keys()) void closeServer(name);
|
|
682
839
|
};
|
|
683
840
|
}, []);
|
|
684
|
-
const tools =
|
|
841
|
+
const tools = useMemo2(() => {
|
|
685
842
|
const merged = {};
|
|
686
843
|
for (const l of liveRef.current.values()) if (l.tools) Object.assign(merged, l.tools);
|
|
687
844
|
return merged;
|
|
688
845
|
}, [toolsVersion]);
|
|
689
|
-
const catalog =
|
|
846
|
+
const catalog = useMemo2(
|
|
690
847
|
() => servers.filter((s) => s.status === "connected").flatMap((s) => s.catalog),
|
|
691
848
|
[servers]
|
|
692
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
|
+
);
|
|
693
866
|
return {
|
|
867
|
+
apps,
|
|
694
868
|
servers,
|
|
695
869
|
tools,
|
|
696
870
|
catalog,
|
|
871
|
+
protocols,
|
|
872
|
+
pendingElicitations: elicitation.pendingElicitations,
|
|
873
|
+
answerElicitation: elicitation.answerElicitation,
|
|
697
874
|
connectedCount: servers.filter((s) => s.status === "connected").length,
|
|
698
875
|
completingAuthorization,
|
|
699
876
|
oauthSupported,
|
|
@@ -707,10 +884,21 @@ var useMcpServers = (options = {}) => {
|
|
|
707
884
|
};
|
|
708
885
|
export {
|
|
709
886
|
claimOAuthCallback,
|
|
887
|
+
createElicitationQueue,
|
|
710
888
|
describeMcpResult,
|
|
889
|
+
elicitationConnectOptions,
|
|
890
|
+
elicitationSettings,
|
|
891
|
+
elicitationTimeoutOf,
|
|
711
892
|
isUnauthorizedError,
|
|
893
|
+
mcpAppsRouter,
|
|
712
894
|
mcpInstructionsOf,
|
|
895
|
+
mcpOAuthOptionsOfRecord,
|
|
713
896
|
mcpOAuthProviderOptions,
|
|
897
|
+
mcpOAuthRecordOf,
|
|
898
|
+
mcpOAuthRegistrationOf,
|
|
899
|
+
mcpProtocolOf,
|
|
900
|
+
mcpSkillsSettingOf,
|
|
901
|
+
newMcpOAuthProvider,
|
|
714
902
|
readCallbackParams,
|
|
715
903
|
stripOAuthParams,
|
|
716
904
|
useMcp,
|