@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/README.md +360 -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-DbW6QKxS.d.cts +1537 -0
- package/dist/elicitation-DbW6QKxS.d.ts +1537 -0
- package/dist/index.cjs +4364 -618
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +712 -433
- package/dist/index.d.ts +712 -433
- package/dist/index.js +4033 -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 +322 -42
- package/dist/mcp.cjs.map +1 -1
- package/dist/mcp.d.cts +185 -96
- package/dist/mcp.d.ts +185 -96
- package/dist/mcp.js +240 -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 +1140 -0
- package/package.json +13 -3
- package/dist/chunk-UUB7CE6N.js.map +0 -1
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,169 @@ 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, dynamic } = value;
|
|
144
|
+
const known = consent === "ask" || consent === "once-per-skill" || consent === "never";
|
|
145
|
+
if (!known && consent !== void 0) return void 0;
|
|
146
|
+
if (dynamic !== void 0 && typeof dynamic !== "boolean") return void 0;
|
|
147
|
+
if (!known && dynamic !== true) return true;
|
|
148
|
+
return {
|
|
149
|
+
...known ? { consent } : {},
|
|
150
|
+
...dynamic === true ? { dynamic: true } : {}
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
var mcpAppsRouter = (connectionOf) => {
|
|
154
|
+
const appsOf = (server) => connectionOf(server)?.apps;
|
|
155
|
+
const notConnected = (server) => new Error(`the server \u201C${server}\u201D is not connected`);
|
|
156
|
+
return {
|
|
157
|
+
readUiResource: (server, uri, options) => {
|
|
158
|
+
const apps = appsOf(server);
|
|
159
|
+
return apps ? apps.readUiResource(server, uri, options) : Promise.reject(notConnected(server));
|
|
160
|
+
},
|
|
161
|
+
appTool: (server, name) => appsOf(server)?.appTool(server, name),
|
|
162
|
+
readResource: (server, uri, options) => {
|
|
163
|
+
const apps = appsOf(server);
|
|
164
|
+
if (!apps) return Promise.reject(notConnected(server));
|
|
165
|
+
if (!apps.readResource) {
|
|
166
|
+
return Promise.reject(new Error("this version of the core cannot read a linked file"));
|
|
167
|
+
}
|
|
168
|
+
return apps.readResource(server, uri, options);
|
|
169
|
+
},
|
|
170
|
+
callAppTool: (server, name, args, options) => {
|
|
171
|
+
const apps = appsOf(server);
|
|
172
|
+
return apps ? apps.callAppTool(server, name, args, options) : Promise.reject(notConnected(server));
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
};
|
|
47
176
|
var mcpInstructionsOf = (connection, name) => {
|
|
48
177
|
const list = Array.isArray(connection.instructions) ? connection.instructions : [];
|
|
49
178
|
const text = list.find((i) => i?.server === name)?.instructions;
|
|
50
179
|
return typeof text === "string" && text.trim() ? text : void 0;
|
|
51
180
|
};
|
|
181
|
+
var mcpProtocolOf = (connection, name) => {
|
|
182
|
+
const list = Array.isArray(connection.protocols) ? connection.protocols : [];
|
|
183
|
+
const found = list.find((p) => p?.server === name);
|
|
184
|
+
return found && typeof found.version === "string" ? { server: name, version: found.version, era: found.era } : void 0;
|
|
185
|
+
};
|
|
186
|
+
var useElicitationQueue = (optionsRef) => {
|
|
187
|
+
const [pendingElicitations, setPending] = (0, import_react.useState)([]);
|
|
188
|
+
const mountedRef = (0, import_react.useRef)(true);
|
|
189
|
+
const queueRef = (0, import_react.useRef)(void 0);
|
|
190
|
+
queueRef.current ??= createElicitationQueue({
|
|
191
|
+
timeoutMs: () => {
|
|
192
|
+
const settings = elicitationSettings(optionsRef.current.elicitation);
|
|
193
|
+
return settings ? elicitationTimeoutOf(settings) : void 0;
|
|
194
|
+
},
|
|
195
|
+
onChange: (pending) => {
|
|
196
|
+
if (mountedRef.current) setPending(pending);
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
const queue = queueRef.current;
|
|
200
|
+
const handler = (0, import_react.useCallback)(
|
|
201
|
+
(request, ctx) => mountedRef.current ? queue.handler(request, ctx) : { action: "cancel" },
|
|
202
|
+
[queue]
|
|
203
|
+
);
|
|
204
|
+
const answerElicitation = (0, import_react.useCallback)(
|
|
205
|
+
(id, result) => queue.answer(id, result),
|
|
206
|
+
[queue]
|
|
207
|
+
);
|
|
208
|
+
const cancel = (0, import_react.useCallback)(
|
|
209
|
+
(server) => queue.cancel(server === void 0 ? void 0 : (request) => request.server === server),
|
|
210
|
+
[queue]
|
|
211
|
+
);
|
|
212
|
+
(0, import_react.useEffect)(() => {
|
|
213
|
+
mountedRef.current = true;
|
|
214
|
+
return () => {
|
|
215
|
+
mountedRef.current = false;
|
|
216
|
+
queue.cancel();
|
|
217
|
+
};
|
|
218
|
+
}, [queue]);
|
|
219
|
+
return { pendingElicitations, answerElicitation, handler, cancel };
|
|
220
|
+
};
|
|
52
221
|
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
222
|
var PENDING_KEY = "agent-web-react:mcp:pending";
|
|
54
223
|
var OAUTH_KEY = "agent-web-react:mcp:oauth";
|
|
@@ -142,9 +311,44 @@ var mcpOAuthProviderOptions = (serverUrl, oauth = {}, defaults = {}) => {
|
|
|
142
311
|
clientName: oauth.clientName ?? defaults.clientName,
|
|
143
312
|
scope: oauth.scope,
|
|
144
313
|
// Left out when unset: a provider built without it keeps registering dynamically.
|
|
145
|
-
...clientMetadataUrl !== void 0 ? { clientMetadataUrl } : {}
|
|
314
|
+
...clientMetadataUrl !== void 0 ? { clientMetadataUrl } : {},
|
|
315
|
+
// Left out when unset, too: the core's default is 'auto'.
|
|
316
|
+
...oauth.registration !== void 0 ? { registration: oauth.registration } : {}
|
|
146
317
|
};
|
|
147
318
|
};
|
|
319
|
+
var mcpOAuthRecordOf = (resolved) => ({
|
|
320
|
+
redirectUrl: resolved.redirectUrl,
|
|
321
|
+
scope: resolved.scope,
|
|
322
|
+
clientName: resolved.clientName,
|
|
323
|
+
clientMetadataUrl: resolved.clientMetadataUrl,
|
|
324
|
+
...resolved.registration !== void 0 ? { registration: resolved.registration } : {}
|
|
325
|
+
});
|
|
326
|
+
var mcpOAuthOptionsOfRecord = (record) => ({
|
|
327
|
+
redirectUrl: record.redirectUrl,
|
|
328
|
+
scope: record.scope,
|
|
329
|
+
clientName: record.clientName,
|
|
330
|
+
clientMetadataUrl: record.clientMetadataUrl,
|
|
331
|
+
...record.registration !== void 0 ? { registration: record.registration } : {}
|
|
332
|
+
});
|
|
333
|
+
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.`;
|
|
334
|
+
var newMcpOAuthProvider = (mod, options) => {
|
|
335
|
+
if (!mod.BrowserOAuthProvider) throw new Error(OAUTH_UNSUPPORTED);
|
|
336
|
+
const provider = new mod.BrowserOAuthProvider(options);
|
|
337
|
+
const asked = options.registration;
|
|
338
|
+
if (asked !== void 0 && asked !== "auto" && provider.registration !== asked) {
|
|
339
|
+
throw new Error(registrationUnsupported(asked));
|
|
340
|
+
}
|
|
341
|
+
return provider;
|
|
342
|
+
};
|
|
343
|
+
var mcpOAuthRegistrationOf = async (provider) => {
|
|
344
|
+
if (typeof provider?.registrationKind !== "function") return void 0;
|
|
345
|
+
try {
|
|
346
|
+
const kind = await provider.registrationKind();
|
|
347
|
+
return kind === "cimd" || kind === "dcr" ? kind : void 0;
|
|
348
|
+
} catch {
|
|
349
|
+
return void 0;
|
|
350
|
+
}
|
|
351
|
+
};
|
|
148
352
|
var isUnauthorizedError = (err, mod) => {
|
|
149
353
|
if (!(err instanceof Error)) return false;
|
|
150
354
|
if (mod?.UnauthorizedError && err instanceof mod.UnauthorizedError) return true;
|
|
@@ -180,8 +384,12 @@ var useMcp = (options = {}) => {
|
|
|
180
384
|
const [tools, setTools] = (0, import_react.useState)(void 0);
|
|
181
385
|
const [catalog, setCatalog] = (0, import_react.useState)([]);
|
|
182
386
|
const [instructions, setInstructions] = (0, import_react.useState)(void 0);
|
|
387
|
+
const [protocol, setProtocol] = (0, import_react.useState)(void 0);
|
|
183
388
|
const [error, setError] = (0, import_react.useState)(void 0);
|
|
184
389
|
const [authorizationUrl, setAuthorizationUrl] = (0, import_react.useState)(void 0);
|
|
390
|
+
const [oauthRegistration, setOauthRegistration] = (0, import_react.useState)(
|
|
391
|
+
void 0
|
|
392
|
+
);
|
|
185
393
|
const [oauthSupported, setOauthSupported] = (0, import_react.useState)(void 0);
|
|
186
394
|
const [completingAuthorization, setCompletingAuthorization] = (0, import_react.useState)(
|
|
187
395
|
() => readCallbackParams() !== void 0
|
|
@@ -191,12 +399,15 @@ var useMcp = (options = {}) => {
|
|
|
191
399
|
const epochRef = (0, import_react.useRef)(0);
|
|
192
400
|
const optionsRef = (0, import_react.useRef)(options);
|
|
193
401
|
optionsRef.current = options;
|
|
402
|
+
const elicitation = useElicitationQueue(optionsRef);
|
|
403
|
+
const cancelElicitations = elicitation.cancel;
|
|
194
404
|
const closeConnection = (0, import_react.useCallback)(async () => {
|
|
195
405
|
const open = connectionRef.current;
|
|
196
406
|
connectionRef.current = void 0;
|
|
407
|
+
cancelElicitations();
|
|
197
408
|
if (open) await open.close().catch(() => {
|
|
198
409
|
});
|
|
199
|
-
}, []);
|
|
410
|
+
}, [cancelElicitations]);
|
|
200
411
|
const checkOAuthSupport = (0, import_react.useCallback)(async () => {
|
|
201
412
|
try {
|
|
202
413
|
const mod = await loadMcp();
|
|
@@ -217,9 +428,11 @@ var useMcp = (options = {}) => {
|
|
|
217
428
|
setStatus("connecting");
|
|
218
429
|
setError(void 0);
|
|
219
430
|
setAuthorizationUrl(void 0);
|
|
431
|
+
setOauthRegistration(void 0);
|
|
220
432
|
setTools(void 0);
|
|
221
433
|
setCatalog([]);
|
|
222
434
|
setInstructions(void 0);
|
|
435
|
+
setProtocol(void 0);
|
|
223
436
|
try {
|
|
224
437
|
const mod = await loadMcp();
|
|
225
438
|
setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
|
|
@@ -235,13 +448,12 @@ var useMcp = (options = {}) => {
|
|
|
235
448
|
const record = {
|
|
236
449
|
url: opts.url,
|
|
237
450
|
name,
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
clientMetadataUrl: providerOptions.clientMetadataUrl,
|
|
451
|
+
...mcpOAuthRecordOf(providerOptions),
|
|
452
|
+
...opts.protocol ? { protocol: opts.protocol } : {},
|
|
453
|
+
...mcpSkillsSettingOf(opts.skills) ? { skills: mcpSkillsSettingOf(opts.skills) } : {},
|
|
242
454
|
startedAt: Date.now()
|
|
243
455
|
};
|
|
244
|
-
authProvider =
|
|
456
|
+
authProvider = newMcpOAuthProvider(mod, providerOptions);
|
|
245
457
|
providerRef.current = authProvider;
|
|
246
458
|
writeRecord(PENDING_KEY, record);
|
|
247
459
|
writeRecord(OAUTH_KEY, record);
|
|
@@ -253,10 +465,19 @@ var useMcp = (options = {}) => {
|
|
|
253
465
|
[name]: {
|
|
254
466
|
url: opts.url,
|
|
255
467
|
headers: opts.oauth ? void 0 : opts.headers,
|
|
256
|
-
authProvider
|
|
468
|
+
authProvider,
|
|
469
|
+
// Only when asked for: without it the connection is built as it always was.
|
|
470
|
+
...opts.protocol ? { protocol: opts.protocol } : {},
|
|
471
|
+
...mcpSkillsSettingOf(opts.skills) ? { skills: mcpSkillsSettingOf(opts.skills) } : {}
|
|
257
472
|
}
|
|
258
473
|
},
|
|
259
|
-
{
|
|
474
|
+
{
|
|
475
|
+
clientName: optionsRef.current.clientName,
|
|
476
|
+
onLog: optionsRef.current.onLog,
|
|
477
|
+
...optionsRef.current.apps ? { apps: true } : {},
|
|
478
|
+
// Off: neither key is passed, so the core declares no capability.
|
|
479
|
+
...elicitationConnectOptions(optionsRef.current.elicitation, elicitation.handler)
|
|
480
|
+
}
|
|
260
481
|
);
|
|
261
482
|
if (!current()) {
|
|
262
483
|
await connection.close().catch(() => {
|
|
@@ -287,6 +508,10 @@ var useMcp = (options = {}) => {
|
|
|
287
508
|
);
|
|
288
509
|
setCatalog(connection.catalog);
|
|
289
510
|
setInstructions(mcpInstructionsOf(connection, name));
|
|
511
|
+
setProtocol(mcpProtocolOf(connection, name));
|
|
512
|
+
const registered = await mcpOAuthRegistrationOf(authProvider);
|
|
513
|
+
if (!current()) return;
|
|
514
|
+
setOauthRegistration(registered);
|
|
290
515
|
setStatus("connected");
|
|
291
516
|
} catch (err) {
|
|
292
517
|
if (!current()) return;
|
|
@@ -294,7 +519,7 @@ var useMcp = (options = {}) => {
|
|
|
294
519
|
setStatus("error");
|
|
295
520
|
}
|
|
296
521
|
},
|
|
297
|
-
[closeConnection]
|
|
522
|
+
[closeConnection, elicitation.handler]
|
|
298
523
|
);
|
|
299
524
|
const disconnect = (0, import_react.useCallback)(async () => {
|
|
300
525
|
epochRef.current++;
|
|
@@ -302,7 +527,9 @@ var useMcp = (options = {}) => {
|
|
|
302
527
|
setTools(void 0);
|
|
303
528
|
setCatalog([]);
|
|
304
529
|
setInstructions(void 0);
|
|
530
|
+
setProtocol(void 0);
|
|
305
531
|
setAuthorizationUrl(void 0);
|
|
532
|
+
setOauthRegistration(void 0);
|
|
306
533
|
setError(void 0);
|
|
307
534
|
setStatus("idle");
|
|
308
535
|
}, [closeConnection]);
|
|
@@ -355,7 +582,8 @@ var useMcp = (options = {}) => {
|
|
|
355
582
|
const mod = await loadMcp();
|
|
356
583
|
setOauthSupported(typeof mod.BrowserOAuthProvider === "function");
|
|
357
584
|
if (!mod.BrowserOAuthProvider || !mod.finishMcpOAuth) throw new Error(OAUTH_UNSUPPORTED);
|
|
358
|
-
const
|
|
585
|
+
const oauth = mcpOAuthOptionsOfRecord(pending);
|
|
586
|
+
const provider = newMcpOAuthProvider(mod, mcpOAuthProviderOptions(pending.url, oauth));
|
|
359
587
|
providerRef.current = provider;
|
|
360
588
|
await mod.finishMcpOAuth(provider, callback);
|
|
361
589
|
writeRecord(PENDING_KEY, void 0);
|
|
@@ -363,12 +591,9 @@ var useMcp = (options = {}) => {
|
|
|
363
591
|
await connect({
|
|
364
592
|
url: pending.url,
|
|
365
593
|
name: pending.name,
|
|
366
|
-
oauth
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
clientName: pending.clientName,
|
|
370
|
-
clientMetadataUrl: pending.clientMetadataUrl
|
|
371
|
-
}
|
|
594
|
+
oauth,
|
|
595
|
+
...pending.protocol ? { protocol: pending.protocol } : {},
|
|
596
|
+
...mcpSkillsSettingOf(pending.skills) ? { skills: mcpSkillsSettingOf(pending.skills) } : {}
|
|
372
597
|
});
|
|
373
598
|
} catch (err) {
|
|
374
599
|
writeRecord(PENDING_KEY, void 0);
|
|
@@ -386,15 +611,25 @@ var useMcp = (options = {}) => {
|
|
|
386
611
|
},
|
|
387
612
|
[closeConnection]
|
|
388
613
|
);
|
|
614
|
+
const appsOn = options.apps === true;
|
|
615
|
+
const apps = (0, import_react.useMemo)(
|
|
616
|
+
() => appsOn ? mcpAppsRouter(() => connectionRef.current) : void 0,
|
|
617
|
+
[appsOn]
|
|
618
|
+
);
|
|
389
619
|
return {
|
|
620
|
+
apps,
|
|
390
621
|
status,
|
|
391
622
|
tools,
|
|
392
623
|
catalog,
|
|
393
624
|
instructions,
|
|
625
|
+
protocol,
|
|
394
626
|
error,
|
|
395
627
|
authorizationUrl,
|
|
628
|
+
oauthRegistration,
|
|
396
629
|
oauthSupported,
|
|
397
630
|
completingAuthorization,
|
|
631
|
+
pendingElicitations: elicitation.pendingElicitations,
|
|
632
|
+
answerElicitation: elicitation.answerElicitation,
|
|
398
633
|
connect,
|
|
399
634
|
disconnect,
|
|
400
635
|
authorize,
|
|
@@ -407,10 +642,14 @@ var useMcp = (options = {}) => {
|
|
|
407
642
|
var import_react2 = require("react");
|
|
408
643
|
var DEFAULT_KEY = "agent-web-react:mcp-servers";
|
|
409
644
|
var sanitize = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 32) || "mcp";
|
|
645
|
+
var isProtocolMode = (value) => value === "legacy" || value === "auto" || value === "modern";
|
|
410
646
|
var view = (s, patch = {}) => ({
|
|
411
647
|
name: s.name,
|
|
412
648
|
url: s.url,
|
|
413
649
|
auth: s.auth,
|
|
650
|
+
...isProtocolMode(s.protocol) ? { protocolMode: s.protocol } : {},
|
|
651
|
+
...mcpSkillsSettingOf(s.skills) ? { skills: mcpSkillsSettingOf(s.skills) } : {},
|
|
652
|
+
...typeof s.apps === "boolean" ? { apps: s.apps } : {},
|
|
414
653
|
status: "idle",
|
|
415
654
|
catalog: [],
|
|
416
655
|
...patch
|
|
@@ -437,13 +676,18 @@ var useMcpServers = (options = {}) => {
|
|
|
437
676
|
name: s.name,
|
|
438
677
|
url: s.url,
|
|
439
678
|
auth: s.auth,
|
|
440
|
-
...oauth && typeof oauth === "object" ? { oauth } : {}
|
|
679
|
+
...oauth && typeof oauth === "object" ? { oauth } : {},
|
|
680
|
+
...s.protocolMode ? { protocol: s.protocolMode } : {},
|
|
681
|
+
...mcpSkillsSettingOf(s.skills) ? { skills: mcpSkillsSettingOf(s.skills) } : {},
|
|
682
|
+
...typeof s.apps === "boolean" ? { apps: s.apps } : {}
|
|
441
683
|
});
|
|
442
684
|
}
|
|
443
685
|
}
|
|
444
686
|
const optionsRef = (0, import_react2.useRef)(options);
|
|
445
687
|
optionsRef.current = options;
|
|
446
688
|
const unmountedRef = (0, import_react2.useRef)(false);
|
|
689
|
+
const elicitation = useElicitationQueue(optionsRef);
|
|
690
|
+
const cancelElicitations = elicitation.cancel;
|
|
447
691
|
const saveList = (0, import_react2.useCallback)(() => {
|
|
448
692
|
if (!persist) return;
|
|
449
693
|
writeRecord(storageKey, [...specsRef.current.values()]);
|
|
@@ -470,15 +714,11 @@ var useMcpServers = (options = {}) => {
|
|
|
470
714
|
l.tools = void 0;
|
|
471
715
|
setToolsVersion((v) => v + 1);
|
|
472
716
|
}
|
|
717
|
+
cancelElicitations(name);
|
|
473
718
|
if (open) await open.close().catch(() => {
|
|
474
719
|
});
|
|
475
720
|
}, []);
|
|
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
|
-
};
|
|
721
|
+
const providerFor = (mod, spec) => newMcpOAuthProvider(mod, mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current));
|
|
482
722
|
const connectServer = (0, import_react2.useCallback)(
|
|
483
723
|
async (name) => {
|
|
484
724
|
const spec = specsRef.current.get(name);
|
|
@@ -495,8 +735,10 @@ var useMcpServers = (options = {}) => {
|
|
|
495
735
|
status: "connecting",
|
|
496
736
|
error: void 0,
|
|
497
737
|
authorizationUrl: void 0,
|
|
738
|
+
oauthRegistration: void 0,
|
|
498
739
|
catalog: [],
|
|
499
|
-
instructions: void 0
|
|
740
|
+
instructions: void 0,
|
|
741
|
+
protocol: void 0
|
|
500
742
|
});
|
|
501
743
|
try {
|
|
502
744
|
const mod = await loadMcp();
|
|
@@ -512,13 +754,21 @@ var useMcpServers = (options = {}) => {
|
|
|
512
754
|
url: spec.url,
|
|
513
755
|
headers: spec.auth === "bearer" && l.token ? { Authorization: `Bearer ${l.token}` } : void 0,
|
|
514
756
|
authProvider: provider,
|
|
515
|
-
connectTimeoutMs: optionsRef.current.connectTimeoutMs
|
|
757
|
+
connectTimeoutMs: optionsRef.current.connectTimeoutMs,
|
|
758
|
+
// Only when asked for: without it the connection is built as it always was.
|
|
759
|
+
...spec.protocol ? { protocol: spec.protocol } : {},
|
|
760
|
+
...mcpSkillsSettingOf(spec.skills) ? { skills: mcpSkillsSettingOf(spec.skills) } : {},
|
|
761
|
+
// Only when given: without it the hook's `apps` decides, as before.
|
|
762
|
+
...typeof spec.apps === "boolean" ? { apps: spec.apps } : {}
|
|
516
763
|
}
|
|
517
764
|
},
|
|
518
765
|
{
|
|
519
766
|
clientName: optionsRef.current.clientName,
|
|
520
767
|
onLog: optionsRef.current.onLog,
|
|
521
|
-
connectTimeoutMs: optionsRef.current.connectTimeoutMs
|
|
768
|
+
connectTimeoutMs: optionsRef.current.connectTimeoutMs,
|
|
769
|
+
...optionsRef.current.apps ? { apps: true } : {},
|
|
770
|
+
// Off: neither key is passed, so the core declares no capability.
|
|
771
|
+
...elicitationConnectOptions(optionsRef.current.elicitation, elicitation.handler)
|
|
522
772
|
}
|
|
523
773
|
);
|
|
524
774
|
if (!current()) {
|
|
@@ -550,10 +800,15 @@ var useMcpServers = (options = {}) => {
|
|
|
550
800
|
});
|
|
551
801
|
});
|
|
552
802
|
setToolsVersion((v) => v + 1);
|
|
803
|
+
const negotiated = mcpProtocolOf(connection, name);
|
|
804
|
+
const oauthRegistration = await mcpOAuthRegistrationOf(provider);
|
|
805
|
+
if (!current()) return;
|
|
553
806
|
patch(name, {
|
|
554
807
|
status: "connected",
|
|
808
|
+
oauthRegistration,
|
|
555
809
|
catalog: connection.catalog,
|
|
556
|
-
instructions: mcpInstructionsOf(connection, name)
|
|
810
|
+
instructions: mcpInstructionsOf(connection, name),
|
|
811
|
+
protocol: negotiated ? { version: negotiated.version, era: negotiated.era } : void 0
|
|
557
812
|
});
|
|
558
813
|
} catch (err) {
|
|
559
814
|
if (!current()) return;
|
|
@@ -576,7 +831,10 @@ var useMcpServers = (options = {}) => {
|
|
|
576
831
|
name,
|
|
577
832
|
url: input.url,
|
|
578
833
|
auth: input.auth ?? "none",
|
|
579
|
-
...input.oauth ? { oauth: input.oauth } : {}
|
|
834
|
+
...input.oauth ? { oauth: input.oauth } : {},
|
|
835
|
+
...isProtocolMode(input.protocol) ? { protocol: input.protocol } : {},
|
|
836
|
+
...mcpSkillsSettingOf(input.skills) ? { skills: mcpSkillsSettingOf(input.skills) } : {},
|
|
837
|
+
...typeof input.apps === "boolean" ? { apps: input.apps } : {}
|
|
580
838
|
};
|
|
581
839
|
specsRef.current.set(name, spec);
|
|
582
840
|
live(name).token = input.auth === "bearer" ? input.token : void 0;
|
|
@@ -614,10 +872,7 @@ var useMcpServers = (options = {}) => {
|
|
|
614
872
|
const pending = {
|
|
615
873
|
name,
|
|
616
874
|
url: spec.url,
|
|
617
|
-
|
|
618
|
-
scope: spec.oauth?.scope,
|
|
619
|
-
clientName: spec.oauth?.clientName ?? optionsRef.current.clientName,
|
|
620
|
-
clientMetadataUrl: spec.oauth?.clientMetadataUrl ?? optionsRef.current.clientMetadataUrl,
|
|
875
|
+
...mcpOAuthRecordOf(mcpOAuthProviderOptions(spec.url, spec.oauth, optionsRef.current)),
|
|
621
876
|
startedAt: Date.now()
|
|
622
877
|
};
|
|
623
878
|
writeRecord(pendingKey, pending);
|
|
@@ -648,8 +903,10 @@ var useMcpServers = (options = {}) => {
|
|
|
648
903
|
patch(name, {
|
|
649
904
|
status: "idle",
|
|
650
905
|
authorizationUrl: void 0,
|
|
906
|
+
oauthRegistration: void 0,
|
|
651
907
|
catalog: [],
|
|
652
908
|
instructions: void 0,
|
|
909
|
+
protocol: void 0,
|
|
653
910
|
error: void 0
|
|
654
911
|
});
|
|
655
912
|
},
|
|
@@ -694,15 +951,7 @@ var useMcpServers = (options = {}) => {
|
|
|
694
951
|
setServers((list) => [...list, view(spec)]);
|
|
695
952
|
saveList();
|
|
696
953
|
}
|
|
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
|
-
});
|
|
954
|
+
const provider = providerFor(mod, { ...spec, oauth: mcpOAuthOptionsOfRecord(pending) });
|
|
706
955
|
live(spec.name).provider = provider;
|
|
707
956
|
await mod.finishMcpOAuth(provider, callback);
|
|
708
957
|
writeRecord(pendingKey, void 0);
|
|
@@ -735,10 +984,30 @@ var useMcpServers = (options = {}) => {
|
|
|
735
984
|
() => servers.filter((s) => s.status === "connected").flatMap((s) => s.catalog),
|
|
736
985
|
[servers]
|
|
737
986
|
);
|
|
987
|
+
const appsOn = options.apps === true || servers.some((s) => s.apps === true);
|
|
988
|
+
const hookApps = options.apps === true;
|
|
989
|
+
const apps = (0, import_react2.useMemo)(
|
|
990
|
+
() => appsOn ? mcpAppsRouter((server) => {
|
|
991
|
+
const spec = specsRef.current.get(server);
|
|
992
|
+
if (!spec || (spec.apps ?? hookApps) !== true) return void 0;
|
|
993
|
+
return liveRef.current.get(server)?.connection;
|
|
994
|
+
}) : void 0,
|
|
995
|
+
[appsOn, hookApps]
|
|
996
|
+
);
|
|
997
|
+
const protocols = (0, import_react2.useMemo)(
|
|
998
|
+
() => servers.flatMap(
|
|
999
|
+
(s) => s.status === "connected" && s.protocol ? [{ server: s.name, ...s.protocol }] : []
|
|
1000
|
+
),
|
|
1001
|
+
[servers]
|
|
1002
|
+
);
|
|
738
1003
|
return {
|
|
1004
|
+
apps,
|
|
739
1005
|
servers,
|
|
740
1006
|
tools,
|
|
741
1007
|
catalog,
|
|
1008
|
+
protocols,
|
|
1009
|
+
pendingElicitations: elicitation.pendingElicitations,
|
|
1010
|
+
answerElicitation: elicitation.answerElicitation,
|
|
742
1011
|
connectedCount: servers.filter((s) => s.status === "connected").length,
|
|
743
1012
|
completingAuthorization,
|
|
744
1013
|
oauthSupported,
|
|
@@ -753,10 +1022,21 @@ var useMcpServers = (options = {}) => {
|
|
|
753
1022
|
// Annotate the CommonJS export names for ESM import in node:
|
|
754
1023
|
0 && (module.exports = {
|
|
755
1024
|
claimOAuthCallback,
|
|
1025
|
+
createElicitationQueue,
|
|
756
1026
|
describeMcpResult,
|
|
1027
|
+
elicitationConnectOptions,
|
|
1028
|
+
elicitationSettings,
|
|
1029
|
+
elicitationTimeoutOf,
|
|
757
1030
|
isUnauthorizedError,
|
|
1031
|
+
mcpAppsRouter,
|
|
758
1032
|
mcpInstructionsOf,
|
|
1033
|
+
mcpOAuthOptionsOfRecord,
|
|
759
1034
|
mcpOAuthProviderOptions,
|
|
1035
|
+
mcpOAuthRecordOf,
|
|
1036
|
+
mcpOAuthRegistrationOf,
|
|
1037
|
+
mcpProtocolOf,
|
|
1038
|
+
mcpSkillsSettingOf,
|
|
1039
|
+
newMcpOAuthProvider,
|
|
760
1040
|
readCallbackParams,
|
|
761
1041
|
stripOAuthParams,
|
|
762
1042
|
useMcp,
|