mcp-use 1.2.2-canary.0 → 1.2.2
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/.tsbuildinfo +1 -1
- package/dist/{chunk-VPPILX7B.js → chunk-3RJENWH4.js} +15 -6
- package/dist/{chunk-UVUM35MV.js → chunk-7UX634PO.js} +307 -112
- package/dist/{chunk-CPV4QNHD.js → chunk-KLIBVJ3Z.js} +145 -79
- package/dist/{chunk-EYAIJPBH.js → chunk-MZLETWQQ.js} +55 -17
- package/dist/{chunk-C3SRZK7H.js → chunk-RSGKBEHH.js} +144 -72
- package/dist/index.cjs +719 -300
- package/dist/index.d.ts +24 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +86 -28
- package/dist/{langfuse-MO3AMDBE.js → langfuse-LCJ6VJEP.js} +2 -2
- package/dist/src/adapters/base.d.ts +2 -2
- package/dist/src/adapters/base.d.ts.map +1 -1
- package/dist/src/adapters/index.d.ts +2 -2
- package/dist/src/adapters/index.d.ts.map +1 -1
- package/dist/src/adapters/langchain_adapter.d.ts +4 -4
- package/dist/src/adapters/langchain_adapter.d.ts.map +1 -1
- package/dist/src/agents/base.d.ts +1 -1
- package/dist/src/agents/base.d.ts.map +1 -1
- package/dist/src/agents/index.d.ts +3 -3
- package/dist/src/agents/index.d.ts.map +1 -1
- package/dist/src/agents/mcp_agent.d.ts +12 -12
- package/dist/src/agents/mcp_agent.d.ts.map +1 -1
- package/dist/src/agents/prompts/system_prompt_builder.d.ts +2 -2
- package/dist/src/agents/prompts/system_prompt_builder.d.ts.map +1 -1
- package/dist/src/agents/prompts/templates.d.ts.map +1 -1
- package/dist/src/agents/remote.d.ts +2 -2
- package/dist/src/agents/remote.d.ts.map +1 -1
- package/dist/src/agents/types.d.ts +1 -1
- package/dist/src/agents/types.d.ts.map +1 -1
- package/dist/src/agents/utils/ai_sdk.d.ts +1 -1
- package/dist/src/agents/utils/ai_sdk.d.ts.map +1 -1
- package/dist/src/agents/utils/index.d.ts +1 -1
- package/dist/src/agents/utils/index.d.ts.map +1 -1
- package/dist/src/auth/browser-provider.d.ts +2 -2
- package/dist/src/auth/browser-provider.d.ts.map +1 -1
- package/dist/src/auth/callback.d.ts.map +1 -1
- package/dist/src/auth/index.d.ts +3 -3
- package/dist/src/auth/index.d.ts.map +1 -1
- package/dist/src/auth/types.d.ts +1 -1
- package/dist/src/auth/types.d.ts.map +1 -1
- package/dist/src/browser.cjs +508 -201
- package/dist/src/browser.d.ts +17 -17
- package/dist/src/browser.d.ts.map +1 -1
- package/dist/src/browser.js +11 -5
- package/dist/src/client/base.d.ts +2 -2
- package/dist/src/client/base.d.ts.map +1 -1
- package/dist/src/client/browser.d.ts +2 -2
- package/dist/src/client/browser.d.ts.map +1 -1
- package/dist/src/client.d.ts +2 -2
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/config.d.ts +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/connectors/base.d.ts +5 -5
- package/dist/src/connectors/base.d.ts.map +1 -1
- package/dist/src/connectors/http.d.ts +3 -3
- package/dist/src/connectors/http.d.ts.map +1 -1
- package/dist/src/connectors/index.d.ts +4 -4
- package/dist/src/connectors/index.d.ts.map +1 -1
- package/dist/src/connectors/stdio.d.ts +3 -3
- package/dist/src/connectors/stdio.d.ts.map +1 -1
- package/dist/src/connectors/websocket.d.ts +3 -3
- package/dist/src/connectors/websocket.d.ts.map +1 -1
- package/dist/src/logging.d.ts +4 -4
- package/dist/src/logging.d.ts.map +1 -1
- package/dist/src/managers/index.d.ts +2 -2
- package/dist/src/managers/index.d.ts.map +1 -1
- package/dist/src/managers/server_manager.d.ts +4 -4
- package/dist/src/managers/server_manager.d.ts.map +1 -1
- package/dist/src/managers/tools/acquire_active_mcp_server.d.ts +3 -3
- package/dist/src/managers/tools/acquire_active_mcp_server.d.ts.map +1 -1
- package/dist/src/managers/tools/add_server_from_config.d.ts +3 -3
- package/dist/src/managers/tools/add_server_from_config.d.ts.map +1 -1
- package/dist/src/managers/tools/base.d.ts +6 -6
- package/dist/src/managers/tools/base.d.ts.map +1 -1
- package/dist/src/managers/tools/connect_mcp_server.d.ts +4 -4
- package/dist/src/managers/tools/connect_mcp_server.d.ts.map +1 -1
- package/dist/src/managers/tools/index.d.ts +5 -5
- package/dist/src/managers/tools/index.d.ts.map +1 -1
- package/dist/src/managers/tools/list_mcp_servers.d.ts +3 -3
- package/dist/src/managers/tools/list_mcp_servers.d.ts.map +1 -1
- package/dist/src/managers/tools/release_mcp_server_connection.d.ts +3 -3
- package/dist/src/managers/tools/release_mcp_server_connection.d.ts.map +1 -1
- package/dist/src/managers/types.d.ts +3 -3
- package/dist/src/managers/types.d.ts.map +1 -1
- package/dist/src/oauth-helper.d.ts.map +1 -1
- package/dist/src/observability/index.d.ts +3 -3
- package/dist/src/observability/index.d.ts.map +1 -1
- package/dist/src/observability/langfuse.d.ts +1 -1
- package/dist/src/observability/langfuse.d.ts.map +1 -1
- package/dist/src/observability/manager.d.ts +1 -1
- package/dist/src/observability/manager.d.ts.map +1 -1
- package/dist/src/observability/types.d.ts +1 -1
- package/dist/src/observability/types.d.ts.map +1 -1
- package/dist/src/react/index.cjs +295 -154
- package/dist/src/react/index.d.ts +6 -6
- package/dist/src/react/index.d.ts.map +1 -1
- package/dist/src/react/index.js +3 -3
- package/dist/src/react/types.d.ts +6 -6
- package/dist/src/react/types.d.ts.map +1 -1
- package/dist/src/react/useMcp.d.ts +1 -1
- package/dist/src/react/useMcp.d.ts.map +1 -1
- package/dist/src/react/useWidget.d.ts +5 -2
- package/dist/src/react/useWidget.d.ts.map +1 -1
- package/dist/src/react/widget-types.d.ts +3 -3
- package/dist/src/react/widget-types.d.ts.map +1 -1
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts +3 -3
- package/dist/src/server/adapters/mcp-ui-adapter.d.ts.map +1 -1
- package/dist/src/server/index.cjs +170 -50
- package/dist/src/server/index.d.ts +4 -4
- package/dist/src/server/index.d.ts.map +1 -1
- package/dist/src/server/index.js +174 -51
- package/dist/src/server/logging.d.ts +1 -1
- package/dist/src/server/logging.d.ts.map +1 -1
- package/dist/src/server/mcp-server.d.ts +29 -29
- package/dist/src/server/mcp-server.d.ts.map +1 -1
- package/dist/src/server/types/common.d.ts +2 -2
- package/dist/src/server/types/common.d.ts.map +1 -1
- package/dist/src/server/types/index.d.ts +4 -4
- package/dist/src/server/types/index.d.ts.map +1 -1
- package/dist/src/server/types/prompt.d.ts +2 -2
- package/dist/src/server/types/prompt.d.ts.map +1 -1
- package/dist/src/server/types/resource.d.ts +24 -24
- package/dist/src/server/types/resource.d.ts.map +1 -1
- package/dist/src/server/types/tool.d.ts +3 -3
- package/dist/src/server/types/tool.d.ts.map +1 -1
- package/dist/src/server/types/widget.d.ts +1 -1
- package/dist/src/server/types.d.ts +1 -1
- package/dist/src/server/types.d.ts.map +1 -1
- package/dist/src/session.d.ts +1 -1
- package/dist/src/session.d.ts.map +1 -1
- package/dist/src/task_managers/base.d.ts.map +1 -1
- package/dist/src/task_managers/index.d.ts +5 -5
- package/dist/src/task_managers/index.d.ts.map +1 -1
- package/dist/src/task_managers/sse.d.ts +3 -3
- package/dist/src/task_managers/sse.d.ts.map +1 -1
- package/dist/src/task_managers/stdio.d.ts +4 -4
- package/dist/src/task_managers/stdio.d.ts.map +1 -1
- package/dist/src/task_managers/streamable_http.d.ts +3 -3
- package/dist/src/task_managers/streamable_http.d.ts.map +1 -1
- package/dist/src/task_managers/websocket.d.ts +2 -2
- package/dist/src/task_managers/websocket.d.ts.map +1 -1
- package/dist/src/telemetry/events.d.ts.map +1 -1
- package/dist/src/telemetry/index.d.ts +4 -4
- package/dist/src/telemetry/index.d.ts.map +1 -1
- package/dist/src/telemetry/telemetry.d.ts +1 -1
- package/dist/src/telemetry/telemetry.d.ts.map +1 -1
- package/dist/src/telemetry/utils.d.ts +1 -1
- package/dist/src/telemetry/utils.d.ts.map +1 -1
- package/dist/tsup.config.d.ts.map +1 -1
- package/dist/vitest.config.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -90,7 +90,15 @@ var init_logging = __esm({
|
|
|
90
90
|
this._level = level;
|
|
91
91
|
}
|
|
92
92
|
shouldLog(level) {
|
|
93
|
-
const levels = [
|
|
93
|
+
const levels = [
|
|
94
|
+
"error",
|
|
95
|
+
"warn",
|
|
96
|
+
"info",
|
|
97
|
+
"http",
|
|
98
|
+
"verbose",
|
|
99
|
+
"debug",
|
|
100
|
+
"silly"
|
|
101
|
+
];
|
|
94
102
|
const currentIndex = levels.indexOf(this._level);
|
|
95
103
|
const messageIndex = levels.indexOf(level);
|
|
96
104
|
return messageIndex <= currentIndex;
|
|
@@ -163,7 +171,10 @@ var init_logging = __esm({
|
|
|
163
171
|
if (!isNodeJSEnvironment()) {
|
|
164
172
|
if (!this.simpleInstances[name]) {
|
|
165
173
|
const debugEnv = typeof process !== "undefined" && process.env?.DEBUG || void 0;
|
|
166
|
-
this.simpleInstances[name] = new SimpleConsoleLogger(
|
|
174
|
+
this.simpleInstances[name] = new SimpleConsoleLogger(
|
|
175
|
+
name,
|
|
176
|
+
resolveLevel(debugEnv)
|
|
177
|
+
);
|
|
167
178
|
}
|
|
168
179
|
return this.simpleInstances[name];
|
|
169
180
|
}
|
|
@@ -237,10 +248,8 @@ var init_logging = __esm({
|
|
|
237
248
|
}
|
|
238
249
|
static setDebug(enabled) {
|
|
239
250
|
let level;
|
|
240
|
-
if (enabled === 2 || enabled === true)
|
|
241
|
-
|
|
242
|
-
else if (enabled === 1)
|
|
243
|
-
level = "info";
|
|
251
|
+
if (enabled === 2 || enabled === true) level = "debug";
|
|
252
|
+
else if (enabled === 1) level = "info";
|
|
244
253
|
else level = "info";
|
|
245
254
|
Object.values(this.simpleInstances).forEach((logger2) => {
|
|
246
255
|
logger2.level = level;
|
|
@@ -280,7 +289,9 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
|
|
|
280
289
|
try {
|
|
281
290
|
const langfuseModule = await import("langfuse-langchain").catch(() => null);
|
|
282
291
|
if (!langfuseModule) {
|
|
283
|
-
logger.debug(
|
|
292
|
+
logger.debug(
|
|
293
|
+
"Langfuse package not installed - tracing disabled. Install with: npm install @langfuse/langchain"
|
|
294
|
+
);
|
|
284
295
|
return;
|
|
285
296
|
}
|
|
286
297
|
const { CallbackHandler } = langfuseModule;
|
|
@@ -309,10 +320,23 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
|
|
|
309
320
|
const enhancedTags = [...tags || [], ...customTags];
|
|
310
321
|
const enhancedMetadata = { ...metadata2 || {}, ...metadataToAdd };
|
|
311
322
|
if (this.verbose) {
|
|
312
|
-
logger.debug(
|
|
313
|
-
|
|
323
|
+
logger.debug(
|
|
324
|
+
`Langfuse: Chain start with custom tags: ${JSON.stringify(enhancedTags)}`
|
|
325
|
+
);
|
|
326
|
+
logger.debug(
|
|
327
|
+
`Langfuse: Chain start with metadata: ${JSON.stringify(enhancedMetadata)}`
|
|
328
|
+
);
|
|
314
329
|
}
|
|
315
|
-
return super.handleChainStart(
|
|
330
|
+
return super.handleChainStart(
|
|
331
|
+
chain,
|
|
332
|
+
inputs,
|
|
333
|
+
runId,
|
|
334
|
+
parentRunId,
|
|
335
|
+
enhancedTags,
|
|
336
|
+
enhancedMetadata,
|
|
337
|
+
name,
|
|
338
|
+
kwargs
|
|
339
|
+
);
|
|
316
340
|
}
|
|
317
341
|
// Get custom tags based on environment and agent configuration
|
|
318
342
|
getCustomTags() {
|
|
@@ -388,7 +412,9 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
|
|
|
388
412
|
async handleRetrieverStart(...args) {
|
|
389
413
|
logger.debug("Langfuse: Retriever start intercepted");
|
|
390
414
|
if (this.verbose) {
|
|
391
|
-
logger.debug(
|
|
415
|
+
logger.debug(
|
|
416
|
+
`Langfuse: Retriever start args: ${JSON.stringify(args)}`
|
|
417
|
+
);
|
|
392
418
|
}
|
|
393
419
|
return super.handleRetrieverStart(...args);
|
|
394
420
|
}
|
|
@@ -414,9 +440,13 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
|
|
|
414
440
|
secretKey: process.env.LANGFUSE_SECRET_KEY,
|
|
415
441
|
baseUrl: process.env.LANGFUSE_HOST || process.env.LANGFUSE_BASEURL || "https://cloud.langfuse.com",
|
|
416
442
|
flushAt: Number.parseInt(process.env.LANGFUSE_FLUSH_AT || "15"),
|
|
417
|
-
flushInterval: Number.parseInt(
|
|
443
|
+
flushInterval: Number.parseInt(
|
|
444
|
+
process.env.LANGFUSE_FLUSH_INTERVAL || "10000"
|
|
445
|
+
),
|
|
418
446
|
release: process.env.LANGFUSE_RELEASE,
|
|
419
|
-
requestTimeout: Number.parseInt(
|
|
447
|
+
requestTimeout: Number.parseInt(
|
|
448
|
+
process.env.LANGFUSE_REQUEST_TIMEOUT || "10000"
|
|
449
|
+
),
|
|
420
450
|
enabled: process.env.LANGFUSE_ENABLED !== "false",
|
|
421
451
|
// Set trace name - can be customized via metadata.trace_name or defaults to 'mcp-use-agent'
|
|
422
452
|
traceName: initialMetadata.trace_name || process.env.LANGFUSE_TRACE_NAME || "mcp-use-agent",
|
|
@@ -426,14 +456,29 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
|
|
|
426
456
|
tags: initialTags.length > 0 ? initialTags : void 0,
|
|
427
457
|
metadata: initialMetadata || void 0
|
|
428
458
|
};
|
|
429
|
-
logger.debug(
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
459
|
+
logger.debug(
|
|
460
|
+
"Langfuse handler config:",
|
|
461
|
+
JSON.stringify(
|
|
462
|
+
{
|
|
463
|
+
traceName: config2.traceName,
|
|
464
|
+
sessionId: config2.sessionId,
|
|
465
|
+
userId: config2.userId,
|
|
466
|
+
tags: config2.tags
|
|
467
|
+
},
|
|
468
|
+
null,
|
|
469
|
+
2
|
|
470
|
+
)
|
|
471
|
+
);
|
|
472
|
+
langfuseState.handler = new LoggingCallbackHandler(
|
|
473
|
+
config2,
|
|
474
|
+
agentId,
|
|
475
|
+
metadata,
|
|
476
|
+
metadataProvider,
|
|
477
|
+
tagsProvider
|
|
478
|
+
);
|
|
479
|
+
logger.debug(
|
|
480
|
+
"Langfuse observability initialized successfully with logging enabled"
|
|
481
|
+
);
|
|
437
482
|
try {
|
|
438
483
|
const langfuseCore = await import("langfuse").catch(() => null);
|
|
439
484
|
if (langfuseCore) {
|
|
@@ -467,7 +512,9 @@ var init_langfuse = __esm({
|
|
|
467
512
|
};
|
|
468
513
|
__name(initializeLangfuse, "initializeLangfuse");
|
|
469
514
|
if (langfuseDisabled) {
|
|
470
|
-
logger.debug(
|
|
515
|
+
logger.debug(
|
|
516
|
+
"Langfuse tracing disabled via MCP_USE_LANGFUSE environment variable"
|
|
517
|
+
);
|
|
471
518
|
} else if (!process.env.LANGFUSE_PUBLIC_KEY || !process.env.LANGFUSE_SECRET_KEY) {
|
|
472
519
|
logger.debug(
|
|
473
520
|
"Langfuse API keys not found - tracing disabled. Set LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY to enable"
|
|
@@ -682,9 +729,14 @@ var LangChainAdapter = class extends BaseAdapter {
|
|
|
682
729
|
// Blank is acceptable but discouraged.
|
|
683
730
|
schema: argsSchema,
|
|
684
731
|
func: /* @__PURE__ */ __name(async (input) => {
|
|
685
|
-
logger.debug(
|
|
732
|
+
logger.debug(
|
|
733
|
+
`MCP tool "${mcpTool.name}" received input: ${JSON.stringify(input)}`
|
|
734
|
+
);
|
|
686
735
|
try {
|
|
687
|
-
const result = await connector.callTool(
|
|
736
|
+
const result = await connector.callTool(
|
|
737
|
+
mcpTool.name,
|
|
738
|
+
input
|
|
739
|
+
);
|
|
688
740
|
return JSON.stringify(result);
|
|
689
741
|
} catch (err) {
|
|
690
742
|
logger.error(`Error executing MCP tool: ${err.message}`);
|
|
@@ -844,7 +896,9 @@ var ConnectMCPServerTool = class extends MCPServerTool {
|
|
|
844
896
|
const numTools = serverTools.length;
|
|
845
897
|
return `Connected to MCP server '${serverName}'. ${numTools} tools are now available.`;
|
|
846
898
|
} catch (error) {
|
|
847
|
-
logger.error(
|
|
899
|
+
logger.error(
|
|
900
|
+
`Error connecting to server '${serverName}': ${String(error)}`
|
|
901
|
+
);
|
|
848
902
|
return `Failed to connect to server '${serverName}': ${String(error)}`;
|
|
849
903
|
}
|
|
850
904
|
}
|
|
@@ -880,7 +934,9 @@ var ListMCPServersTool = class extends MCPServerTool {
|
|
|
880
934
|
outputLines.push(`${numberOfTools} tools available for this server
|
|
881
935
|
`);
|
|
882
936
|
} catch (error) {
|
|
883
|
-
logger.error(
|
|
937
|
+
logger.error(
|
|
938
|
+
`Unexpected error listing tools for server '${serverName}': ${String(error)}`
|
|
939
|
+
);
|
|
884
940
|
}
|
|
885
941
|
}
|
|
886
942
|
return outputLines.join("\n");
|
|
@@ -941,10 +997,10 @@ var ServerManager = class {
|
|
|
941
997
|
}
|
|
942
998
|
const tableData = allServerNames.map((name) => ({
|
|
943
999
|
"Server Name": name,
|
|
944
|
-
|
|
945
|
-
|
|
1000
|
+
Connected: activeSessionNames.includes(name) ? "\u2705" : "\u274C",
|
|
1001
|
+
Initialized: this.initializedServers[name] ? "\u2705" : "\u274C",
|
|
946
1002
|
"Tool Count": this.serverTools[name]?.length ?? 0,
|
|
947
|
-
|
|
1003
|
+
Active: this.activeServer === name ? "\u2705" : "\u274C"
|
|
948
1004
|
}));
|
|
949
1005
|
logger.info(`Server Manager State: [${context}]`);
|
|
950
1006
|
console.table(tableData);
|
|
@@ -961,13 +1017,19 @@ var ServerManager = class {
|
|
|
961
1017
|
try {
|
|
962
1018
|
let session = null;
|
|
963
1019
|
session = this.client.getSession(serverName);
|
|
964
|
-
logger.debug(
|
|
1020
|
+
logger.debug(
|
|
1021
|
+
`Using existing session for server '${serverName}' to prefetch tools.`
|
|
1022
|
+
);
|
|
965
1023
|
if (!session) {
|
|
966
1024
|
session = await this.client.createSession(serverName).catch((createSessionError) => {
|
|
967
|
-
logger.warn(
|
|
1025
|
+
logger.warn(
|
|
1026
|
+
`Could not create session for '${serverName}' during prefetch: ${createSessionError}`
|
|
1027
|
+
);
|
|
968
1028
|
return null;
|
|
969
1029
|
});
|
|
970
|
-
logger.debug(
|
|
1030
|
+
logger.debug(
|
|
1031
|
+
`Temporarily created session for '${serverName}' to prefetch tools.`
|
|
1032
|
+
);
|
|
971
1033
|
}
|
|
972
1034
|
if (session) {
|
|
973
1035
|
const connector = session.connector;
|
|
@@ -975,7 +1037,9 @@ var ServerManager = class {
|
|
|
975
1037
|
try {
|
|
976
1038
|
tools = await this.adapter.createToolsFromConnectors([connector]);
|
|
977
1039
|
} catch (toolFetchError) {
|
|
978
|
-
logger.error(
|
|
1040
|
+
logger.error(
|
|
1041
|
+
`Failed to create tools from connector for server '${serverName}': ${toolFetchError}`
|
|
1042
|
+
);
|
|
979
1043
|
continue;
|
|
980
1044
|
}
|
|
981
1045
|
const cachedTools = this.serverTools[serverName];
|
|
@@ -983,7 +1047,9 @@ var ServerManager = class {
|
|
|
983
1047
|
if (toolsChanged) {
|
|
984
1048
|
this.serverTools[serverName] = tools;
|
|
985
1049
|
this.initializedServers[serverName] = true;
|
|
986
|
-
logger.debug(
|
|
1050
|
+
logger.debug(
|
|
1051
|
+
`Prefetched ${tools.length} tools for server '${serverName}'.`
|
|
1052
|
+
);
|
|
987
1053
|
} else {
|
|
988
1054
|
logger.debug(
|
|
989
1055
|
`Tools for server '${serverName}' unchanged, using cached version.`
|
|
@@ -991,7 +1057,9 @@ var ServerManager = class {
|
|
|
991
1057
|
}
|
|
992
1058
|
}
|
|
993
1059
|
} catch (outerError) {
|
|
994
|
-
logger.error(
|
|
1060
|
+
logger.error(
|
|
1061
|
+
`Error prefetching tools for server '${serverName}': ${outerError}`
|
|
1062
|
+
);
|
|
995
1063
|
}
|
|
996
1064
|
}
|
|
997
1065
|
}
|
|
@@ -1057,8 +1125,15 @@ var ObservabilityManager = class {
|
|
|
1057
1125
|
const { langfuseHandler: langfuseHandler2, langfuseInitPromise: langfuseInitPromise2 } = await Promise.resolve().then(() => (init_langfuse(), langfuse_exports));
|
|
1058
1126
|
if (this.agentId || this.metadata || this.metadataProvider || this.tagsProvider) {
|
|
1059
1127
|
const { initializeLangfuse: initializeLangfuse2 } = await Promise.resolve().then(() => (init_langfuse(), langfuse_exports));
|
|
1060
|
-
await initializeLangfuse2(
|
|
1061
|
-
|
|
1128
|
+
await initializeLangfuse2(
|
|
1129
|
+
this.agentId,
|
|
1130
|
+
this.metadata,
|
|
1131
|
+
this.metadataProvider,
|
|
1132
|
+
this.tagsProvider
|
|
1133
|
+
);
|
|
1134
|
+
logger.debug(
|
|
1135
|
+
`ObservabilityManager: Reinitialized Langfuse with agent ID: ${this.agentId}, metadata: ${JSON.stringify(this.metadata)}`
|
|
1136
|
+
);
|
|
1062
1137
|
} else {
|
|
1063
1138
|
const initPromise = langfuseInitPromise2();
|
|
1064
1139
|
if (initPromise) {
|
|
@@ -1082,16 +1157,22 @@ var ObservabilityManager = class {
|
|
|
1082
1157
|
*/
|
|
1083
1158
|
async getCallbacks() {
|
|
1084
1159
|
if (!this.observe) {
|
|
1085
|
-
logger.debug(
|
|
1160
|
+
logger.debug(
|
|
1161
|
+
"ObservabilityManager: Observability disabled via observe=false"
|
|
1162
|
+
);
|
|
1086
1163
|
return [];
|
|
1087
1164
|
}
|
|
1088
1165
|
if (this.customCallbacks) {
|
|
1089
|
-
logger.debug(
|
|
1166
|
+
logger.debug(
|
|
1167
|
+
`ObservabilityManager: Using ${this.customCallbacks.length} custom callbacks`
|
|
1168
|
+
);
|
|
1090
1169
|
return this.customCallbacks;
|
|
1091
1170
|
}
|
|
1092
1171
|
await this.collectAvailableHandlers();
|
|
1093
1172
|
if (this.availableHandlers.length > 0) {
|
|
1094
|
-
logger.debug(
|
|
1173
|
+
logger.debug(
|
|
1174
|
+
`ObservabilityManager: Using ${this.availableHandlers.length} handlers`
|
|
1175
|
+
);
|
|
1095
1176
|
} else {
|
|
1096
1177
|
logger.debug("ObservabilityManager: No callbacks configured");
|
|
1097
1178
|
}
|
|
@@ -1148,7 +1229,9 @@ var ObservabilityManager = class {
|
|
|
1148
1229
|
this.customCallbacks = [];
|
|
1149
1230
|
}
|
|
1150
1231
|
this.customCallbacks.push(callback);
|
|
1151
|
-
logger.debug(
|
|
1232
|
+
logger.debug(
|
|
1233
|
+
`ObservabilityManager: Added custom callback: ${callback.constructor.name}`
|
|
1234
|
+
);
|
|
1152
1235
|
}
|
|
1153
1236
|
/**
|
|
1154
1237
|
* Clear all custom callbacks.
|
|
@@ -1280,7 +1363,15 @@ function getModelName(llm) {
|
|
|
1280
1363
|
if ("_identifyingParams" in llm) {
|
|
1281
1364
|
const identifyingParams = llm._identifyingParams;
|
|
1282
1365
|
if (typeof identifyingParams === "object" && identifyingParams !== null) {
|
|
1283
|
-
for (const key of [
|
|
1366
|
+
for (const key of [
|
|
1367
|
+
"model",
|
|
1368
|
+
"modelName",
|
|
1369
|
+
"model_name",
|
|
1370
|
+
"modelId",
|
|
1371
|
+
"model_id",
|
|
1372
|
+
"deploymentName",
|
|
1373
|
+
"deployment_name"
|
|
1374
|
+
]) {
|
|
1284
1375
|
if (key in identifyingParams) {
|
|
1285
1376
|
return String(identifyingParams[key]);
|
|
1286
1377
|
}
|
|
@@ -1371,8 +1462,16 @@ var Telemetry = class _Telemetry {
|
|
|
1371
1462
|
__name(this, "Telemetry");
|
|
1372
1463
|
}
|
|
1373
1464
|
static instance = null;
|
|
1374
|
-
USER_ID_PATH = path2.join(
|
|
1375
|
-
|
|
1465
|
+
USER_ID_PATH = path2.join(
|
|
1466
|
+
getCacheHome(),
|
|
1467
|
+
"mcp_use_3",
|
|
1468
|
+
"telemetry_user_id"
|
|
1469
|
+
);
|
|
1470
|
+
VERSION_DOWNLOAD_PATH = path2.join(
|
|
1471
|
+
getCacheHome(),
|
|
1472
|
+
"mcp_use",
|
|
1473
|
+
"download_version"
|
|
1474
|
+
);
|
|
1376
1475
|
PROJECT_API_KEY = "phc_lyTtbYwvkdSbrcMQNPiKiiRWrrM1seyKIMjycSvItEI";
|
|
1377
1476
|
HOST = "https://eu.i.posthog.com";
|
|
1378
1477
|
SCARF_GATEWAY_URL = "https://mcpuse.gateway.scarf.sh/events-ts";
|
|
@@ -1392,17 +1491,18 @@ var Telemetry = class _Telemetry {
|
|
|
1392
1491
|
} else if (!isNodeJS) {
|
|
1393
1492
|
this._posthogClient = null;
|
|
1394
1493
|
this._scarfClient = null;
|
|
1395
|
-
logger.debug(
|
|
1494
|
+
logger.debug(
|
|
1495
|
+
"Telemetry disabled - non-Node.js environment detected (e.g., Cloudflare Workers)"
|
|
1496
|
+
);
|
|
1396
1497
|
} else {
|
|
1397
|
-
logger.info(
|
|
1498
|
+
logger.info(
|
|
1499
|
+
"Anonymized telemetry enabled. Set MCP_USE_ANONYMIZED_TELEMETRY=false to disable."
|
|
1500
|
+
);
|
|
1398
1501
|
try {
|
|
1399
|
-
this._posthogClient = new import_posthog_node.PostHog(
|
|
1400
|
-
this.
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
disableGeoip: false
|
|
1404
|
-
}
|
|
1405
|
-
);
|
|
1502
|
+
this._posthogClient = new import_posthog_node.PostHog(this.PROJECT_API_KEY, {
|
|
1503
|
+
host: this.HOST,
|
|
1504
|
+
disableGeoip: false
|
|
1505
|
+
});
|
|
1406
1506
|
} catch (e) {
|
|
1407
1507
|
logger.warn(`Failed to initialize PostHog telemetry: ${e}`);
|
|
1408
1508
|
this._posthogClient = null;
|
|
@@ -1512,7 +1612,9 @@ var Telemetry = class _Telemetry {
|
|
|
1512
1612
|
if (!fs2.existsSync(this.VERSION_DOWNLOAD_PATH)) {
|
|
1513
1613
|
shouldTrack = true;
|
|
1514
1614
|
firstDownload = true;
|
|
1515
|
-
fs2.mkdirSync(path2.dirname(this.VERSION_DOWNLOAD_PATH), {
|
|
1615
|
+
fs2.mkdirSync(path2.dirname(this.VERSION_DOWNLOAD_PATH), {
|
|
1616
|
+
recursive: true
|
|
1617
|
+
});
|
|
1516
1618
|
fs2.writeFileSync(this.VERSION_DOWNLOAD_PATH, currentVersion);
|
|
1517
1619
|
} else {
|
|
1518
1620
|
const savedVersion = fs2.readFileSync(this.VERSION_DOWNLOAD_PATH, "utf-8").trim();
|
|
@@ -1523,7 +1625,9 @@ var Telemetry = class _Telemetry {
|
|
|
1523
1625
|
}
|
|
1524
1626
|
}
|
|
1525
1627
|
if (shouldTrack) {
|
|
1526
|
-
logger.debug(
|
|
1628
|
+
logger.debug(
|
|
1629
|
+
`Tracking package download event with properties: ${JSON.stringify(properties)}`
|
|
1630
|
+
);
|
|
1527
1631
|
const eventProperties = { ...properties || {} };
|
|
1528
1632
|
eventProperties.mcp_use_version = currentVersion;
|
|
1529
1633
|
eventProperties.user_id = this.userId;
|
|
@@ -1581,8 +1685,7 @@ function generateToolDescriptions(tools, disallowedTools) {
|
|
|
1581
1685
|
const disallowedSet = new Set(disallowedTools ?? []);
|
|
1582
1686
|
const descriptions = [];
|
|
1583
1687
|
for (const tool of tools) {
|
|
1584
|
-
if (disallowedSet.has(tool.name))
|
|
1585
|
-
continue;
|
|
1688
|
+
if (disallowedSet.has(tool.name)) continue;
|
|
1586
1689
|
const escaped = tool.description.replace(/\{/g, "{{").replace(/\}/g, "}}");
|
|
1587
1690
|
descriptions.push(`- ${tool.name}: ${escaped}`);
|
|
1588
1691
|
}
|
|
@@ -1595,7 +1698,9 @@ function buildSystemPromptContent(template, toolDescriptionLines, additionalInst
|
|
|
1595
1698
|
if (template.includes("{tool_descriptions}")) {
|
|
1596
1699
|
content = template.replace("{tool_descriptions}", block);
|
|
1597
1700
|
} else {
|
|
1598
|
-
console.warn(
|
|
1701
|
+
console.warn(
|
|
1702
|
+
"`{tool_descriptions}` placeholder not found; appending at end."
|
|
1703
|
+
);
|
|
1599
1704
|
content = `${template}
|
|
1600
1705
|
|
|
1601
1706
|
Available tools:
|
|
@@ -1751,7 +1856,9 @@ var RemoteAgent = class {
|
|
|
1751
1856
|
`Agent not found: Agent '${this.agentId}' does not exist or you don't have access to it. Please verify the agent ID and ensure it exists in your account.`
|
|
1752
1857
|
);
|
|
1753
1858
|
}
|
|
1754
|
-
throw new Error(
|
|
1859
|
+
throw new Error(
|
|
1860
|
+
`Failed to create chat session: ${statusCode} - ${responseText}`
|
|
1861
|
+
);
|
|
1755
1862
|
}
|
|
1756
1863
|
const chatData = await response.json();
|
|
1757
1864
|
const chatId = chatData.id;
|
|
@@ -1824,8 +1931,12 @@ var RemoteAgent = class {
|
|
|
1824
1931
|
"Internal server error occurred during agent execution. Please try again later or contact support if the issue persists."
|
|
1825
1932
|
);
|
|
1826
1933
|
} else {
|
|
1827
|
-
logger.error(
|
|
1828
|
-
|
|
1934
|
+
logger.error(
|
|
1935
|
+
`\u274C Remote execution failed with status ${statusCode}: ${responseText}`
|
|
1936
|
+
);
|
|
1937
|
+
throw new Error(
|
|
1938
|
+
`Remote agent execution failed: ${statusCode} - ${responseText}`
|
|
1939
|
+
);
|
|
1829
1940
|
}
|
|
1830
1941
|
}
|
|
1831
1942
|
const result = await response.json();
|
|
@@ -1876,7 +1987,13 @@ Raw error: ${result}`
|
|
|
1876
1987
|
}
|
|
1877
1988
|
// eslint-disable-next-line require-yield
|
|
1878
1989
|
async *stream(query, maxSteps, manageConnector, externalHistory, outputSchema) {
|
|
1879
|
-
const result = await this.run(
|
|
1990
|
+
const result = await this.run(
|
|
1991
|
+
query,
|
|
1992
|
+
maxSteps,
|
|
1993
|
+
manageConnector,
|
|
1994
|
+
externalHistory,
|
|
1995
|
+
outputSchema
|
|
1996
|
+
);
|
|
1880
1997
|
return result;
|
|
1881
1998
|
}
|
|
1882
1999
|
async close() {
|
|
@@ -1952,7 +2069,9 @@ var MCPAgent = class {
|
|
|
1952
2069
|
return;
|
|
1953
2070
|
}
|
|
1954
2071
|
if (!options.llm) {
|
|
1955
|
-
throw new Error(
|
|
2072
|
+
throw new Error(
|
|
2073
|
+
"llm is required for local execution. For remote execution, provide agentId instead."
|
|
2074
|
+
);
|
|
1956
2075
|
}
|
|
1957
2076
|
this.llm = options.llm;
|
|
1958
2077
|
this.client = options.client;
|
|
@@ -1970,11 +2089,15 @@ var MCPAgent = class {
|
|
|
1970
2089
|
this.verbose = options.verbose ?? false;
|
|
1971
2090
|
this.observe = options.observe ?? true;
|
|
1972
2091
|
if (!this.client && this.connectors.length === 0) {
|
|
1973
|
-
throw new Error(
|
|
2092
|
+
throw new Error(
|
|
2093
|
+
"Either 'client' or at least one 'connector' must be provided."
|
|
2094
|
+
);
|
|
1974
2095
|
}
|
|
1975
2096
|
if (this.useServerManager) {
|
|
1976
2097
|
if (!this.client) {
|
|
1977
|
-
throw new Error(
|
|
2098
|
+
throw new Error(
|
|
2099
|
+
"'client' must be provided when 'useServerManager' is true."
|
|
2100
|
+
);
|
|
1978
2101
|
}
|
|
1979
2102
|
this.adapter = options.adapter ?? new LangChainAdapter(this.disallowedTools);
|
|
1980
2103
|
this.serverManager = options.serverManagerFactory?.(this.client) ?? new ServerManager(this.client, this.adapter);
|
|
@@ -2034,25 +2157,37 @@ var MCPAgent = class {
|
|
|
2034
2157
|
} else {
|
|
2035
2158
|
if (this.client) {
|
|
2036
2159
|
this.sessions = this.client.getAllActiveSessions();
|
|
2037
|
-
logger.info(
|
|
2160
|
+
logger.info(
|
|
2161
|
+
`\u{1F50C} Found ${Object.keys(this.sessions).length} existing sessions`
|
|
2162
|
+
);
|
|
2038
2163
|
if (Object.keys(this.sessions).length === 0) {
|
|
2039
2164
|
logger.info("\u{1F504} No active sessions found, creating new ones...");
|
|
2040
2165
|
this.sessions = await this.client.createAllSessions();
|
|
2041
|
-
logger.info(
|
|
2166
|
+
logger.info(
|
|
2167
|
+
`\u2705 Created ${Object.keys(this.sessions).length} new sessions`
|
|
2168
|
+
);
|
|
2042
2169
|
}
|
|
2043
2170
|
this._tools = await LangChainAdapter.createTools(this.client);
|
|
2044
2171
|
this._tools.push(...this.additionalTools);
|
|
2045
|
-
logger.info(
|
|
2172
|
+
logger.info(
|
|
2173
|
+
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain tools from client`
|
|
2174
|
+
);
|
|
2046
2175
|
} else {
|
|
2047
|
-
logger.info(
|
|
2176
|
+
logger.info(
|
|
2177
|
+
`\u{1F517} Connecting to ${this.connectors.length} direct connectors...`
|
|
2178
|
+
);
|
|
2048
2179
|
for (const connector of this.connectors) {
|
|
2049
2180
|
if (!connector.isClientConnected) {
|
|
2050
2181
|
await connector.connect();
|
|
2051
2182
|
}
|
|
2052
2183
|
}
|
|
2053
|
-
this._tools = await this.adapter.createToolsFromConnectors(
|
|
2184
|
+
this._tools = await this.adapter.createToolsFromConnectors(
|
|
2185
|
+
this.connectors
|
|
2186
|
+
);
|
|
2054
2187
|
this._tools.push(...this.additionalTools);
|
|
2055
|
-
logger.info(
|
|
2188
|
+
logger.info(
|
|
2189
|
+
`\u{1F6E0}\uFE0F Created ${this._tools.length} LangChain tools from connectors`
|
|
2190
|
+
);
|
|
2056
2191
|
}
|
|
2057
2192
|
logger.info(`\u{1F9F0} Found ${this._tools.length} tools across all connectors`);
|
|
2058
2193
|
await this.createSystemMessageFromTools(this._tools);
|
|
@@ -2062,7 +2197,9 @@ var MCPAgent = class {
|
|
|
2062
2197
|
const mcpServerInfo = this.getMCPServerInfo();
|
|
2063
2198
|
if (Object.keys(mcpServerInfo).length > 0) {
|
|
2064
2199
|
this.setMetadata(mcpServerInfo);
|
|
2065
|
-
logger.debug(
|
|
2200
|
+
logger.debug(
|
|
2201
|
+
`MCP server info added to metadata: ${JSON.stringify(mcpServerInfo)}`
|
|
2202
|
+
);
|
|
2066
2203
|
}
|
|
2067
2204
|
logger.info("\u2728 Agent initialization complete");
|
|
2068
2205
|
}
|
|
@@ -2080,7 +2217,9 @@ var MCPAgent = class {
|
|
|
2080
2217
|
if (this.memoryEnabled) {
|
|
2081
2218
|
this.conversationHistory = [
|
|
2082
2219
|
this.systemMessage,
|
|
2083
|
-
...this.conversationHistory.filter(
|
|
2220
|
+
...this.conversationHistory.filter(
|
|
2221
|
+
(m) => !(m instanceof import_langchain2.SystemMessage)
|
|
2222
|
+
)
|
|
2084
2223
|
];
|
|
2085
2224
|
}
|
|
2086
2225
|
}
|
|
@@ -2098,7 +2237,9 @@ var MCPAgent = class {
|
|
|
2098
2237
|
systemPrompt: systemContent,
|
|
2099
2238
|
middleware
|
|
2100
2239
|
});
|
|
2101
|
-
logger.debug(
|
|
2240
|
+
logger.debug(
|
|
2241
|
+
`Created agent with max_steps=${this.maxSteps} (via ModelCallLimitMiddleware) and ${this.callbacks.length} callbacks`
|
|
2242
|
+
);
|
|
2102
2243
|
return agent;
|
|
2103
2244
|
}
|
|
2104
2245
|
getConversationHistory() {
|
|
@@ -2108,8 +2249,7 @@ var MCPAgent = class {
|
|
|
2108
2249
|
this.conversationHistory = this.memoryEnabled && this.systemMessage ? [this.systemMessage] : [];
|
|
2109
2250
|
}
|
|
2110
2251
|
addToHistory(message) {
|
|
2111
|
-
if (this.memoryEnabled)
|
|
2112
|
-
this.conversationHistory.push(message);
|
|
2252
|
+
if (this.memoryEnabled) this.conversationHistory.push(message);
|
|
2113
2253
|
}
|
|
2114
2254
|
getSystemMessage() {
|
|
2115
2255
|
return this.systemMessage;
|
|
@@ -2117,7 +2257,9 @@ var MCPAgent = class {
|
|
|
2117
2257
|
setSystemMessage(message) {
|
|
2118
2258
|
this.systemMessage = new import_langchain2.SystemMessage(message);
|
|
2119
2259
|
if (this.memoryEnabled) {
|
|
2120
|
-
this.conversationHistory = this.conversationHistory.filter(
|
|
2260
|
+
this.conversationHistory = this.conversationHistory.filter(
|
|
2261
|
+
(m) => !(m instanceof import_langchain2.SystemMessage)
|
|
2262
|
+
);
|
|
2121
2263
|
this.conversationHistory.unshift(this.systemMessage);
|
|
2122
2264
|
}
|
|
2123
2265
|
if (this._initialized && this._tools.length) {
|
|
@@ -2129,7 +2271,9 @@ var MCPAgent = class {
|
|
|
2129
2271
|
this.disallowedTools = disallowedTools;
|
|
2130
2272
|
this.adapter = new LangChainAdapter(this.disallowedTools);
|
|
2131
2273
|
if (this._initialized) {
|
|
2132
|
-
logger.debug(
|
|
2274
|
+
logger.debug(
|
|
2275
|
+
"Agent already initialized. Changes will take effect on next initialization."
|
|
2276
|
+
);
|
|
2133
2277
|
}
|
|
2134
2278
|
}
|
|
2135
2279
|
getDisallowedTools() {
|
|
@@ -2195,16 +2339,22 @@ var MCPAgent = class {
|
|
|
2195
2339
|
try {
|
|
2196
2340
|
const serialized = JSON.stringify(value);
|
|
2197
2341
|
if (serialized.length > 1e3) {
|
|
2198
|
-
logger.warn(
|
|
2342
|
+
logger.warn(
|
|
2343
|
+
`Metadata value for key '${sanitizedKey}' is too large. Truncating.`
|
|
2344
|
+
);
|
|
2199
2345
|
sanitized[sanitizedKey] = `${serialized.substring(0, 1e3)}...`;
|
|
2200
2346
|
} else {
|
|
2201
2347
|
sanitized[sanitizedKey] = value;
|
|
2202
2348
|
}
|
|
2203
2349
|
} catch (error) {
|
|
2204
|
-
logger.warn(
|
|
2350
|
+
logger.warn(
|
|
2351
|
+
`Failed to serialize metadata value for key '${sanitizedKey}': ${error}. Skipping.`
|
|
2352
|
+
);
|
|
2205
2353
|
}
|
|
2206
2354
|
} else {
|
|
2207
|
-
logger.warn(
|
|
2355
|
+
logger.warn(
|
|
2356
|
+
`Unsupported metadata value type for key '${sanitizedKey}': ${typeof value}. Skipping.`
|
|
2357
|
+
);
|
|
2208
2358
|
}
|
|
2209
2359
|
}
|
|
2210
2360
|
return sanitized;
|
|
@@ -2251,15 +2401,24 @@ var MCPAgent = class {
|
|
|
2251
2401
|
};
|
|
2252
2402
|
}
|
|
2253
2403
|
} catch (error) {
|
|
2254
|
-
logger.warn(
|
|
2255
|
-
|
|
2404
|
+
logger.warn(
|
|
2405
|
+
`Failed to get config for server '${serverName}': ${error}`
|
|
2406
|
+
);
|
|
2407
|
+
serverConfigs[serverName] = {
|
|
2408
|
+
type: "error",
|
|
2409
|
+
error: "config_unavailable"
|
|
2410
|
+
};
|
|
2256
2411
|
}
|
|
2257
2412
|
}
|
|
2258
2413
|
serverInfo.mcp_server_configs = serverConfigs;
|
|
2259
2414
|
} else if (this.connectors && this.connectors.length > 0) {
|
|
2260
2415
|
serverInfo.mcp_servers_count = this.connectors.length;
|
|
2261
|
-
serverInfo.mcp_server_names = this.connectors.map(
|
|
2262
|
-
|
|
2416
|
+
serverInfo.mcp_server_names = this.connectors.map(
|
|
2417
|
+
(c) => c.publicIdentifier
|
|
2418
|
+
);
|
|
2419
|
+
serverInfo.mcp_server_types = this.connectors.map(
|
|
2420
|
+
(c) => c.constructor.name
|
|
2421
|
+
);
|
|
2263
2422
|
}
|
|
2264
2423
|
} catch (error) {
|
|
2265
2424
|
logger.warn(`Failed to collect MCP server info: ${error}`);
|
|
@@ -2313,7 +2472,13 @@ var MCPAgent = class {
|
|
|
2313
2472
|
}
|
|
2314
2473
|
async run(query, maxSteps, manageConnector, externalHistory, outputSchema) {
|
|
2315
2474
|
if (this.isRemote && this.remoteAgent) {
|
|
2316
|
-
return this.remoteAgent.run(
|
|
2475
|
+
return this.remoteAgent.run(
|
|
2476
|
+
query,
|
|
2477
|
+
maxSteps,
|
|
2478
|
+
manageConnector,
|
|
2479
|
+
externalHistory,
|
|
2480
|
+
outputSchema
|
|
2481
|
+
);
|
|
2317
2482
|
}
|
|
2318
2483
|
const generator = this.stream(
|
|
2319
2484
|
query,
|
|
@@ -2326,7 +2491,13 @@ var MCPAgent = class {
|
|
|
2326
2491
|
}
|
|
2327
2492
|
async *stream(query, maxSteps, manageConnector = true, externalHistory, outputSchema) {
|
|
2328
2493
|
if (this.isRemote && this.remoteAgent) {
|
|
2329
|
-
const result = await this.remoteAgent.run(
|
|
2494
|
+
const result = await this.remoteAgent.run(
|
|
2495
|
+
query,
|
|
2496
|
+
maxSteps,
|
|
2497
|
+
manageConnector,
|
|
2498
|
+
externalHistory,
|
|
2499
|
+
outputSchema
|
|
2500
|
+
);
|
|
2330
2501
|
return result;
|
|
2331
2502
|
}
|
|
2332
2503
|
let initializedHere = false;
|
|
@@ -2371,27 +2542,31 @@ var MCPAgent = class {
|
|
|
2371
2542
|
logger.info("\u{1F3C1} Starting agent execution");
|
|
2372
2543
|
const maxRestarts = 3;
|
|
2373
2544
|
let restartCount = 0;
|
|
2374
|
-
const accumulatedMessages = [
|
|
2545
|
+
const accumulatedMessages = [
|
|
2546
|
+
...langchainHistory,
|
|
2547
|
+
new import_langchain2.HumanMessage(query)
|
|
2548
|
+
];
|
|
2375
2549
|
while (restartCount <= maxRestarts) {
|
|
2376
2550
|
const inputs = { messages: accumulatedMessages };
|
|
2377
2551
|
let shouldRestart = false;
|
|
2378
|
-
const stream = await this._agentExecutor.stream(
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
...this.metadata.session_id && { sessionId: this.metadata.session_id }
|
|
2552
|
+
const stream = await this._agentExecutor.stream(inputs, {
|
|
2553
|
+
streamMode: "updates",
|
|
2554
|
+
// Get updates as they happen
|
|
2555
|
+
callbacks: this.callbacks,
|
|
2556
|
+
metadata: this.getMetadata(),
|
|
2557
|
+
tags: this.getTags(),
|
|
2558
|
+
// Set trace name for LangChain/Langfuse
|
|
2559
|
+
runName: this.metadata.trace_name || "mcp-use-agent",
|
|
2560
|
+
// Pass sessionId for Langfuse if present in metadata
|
|
2561
|
+
...this.metadata.session_id && {
|
|
2562
|
+
sessionId: this.metadata.session_id
|
|
2390
2563
|
}
|
|
2391
|
-
);
|
|
2564
|
+
});
|
|
2392
2565
|
for await (const chunk of stream) {
|
|
2393
2566
|
for (const [nodeName, nodeOutput] of Object.entries(chunk)) {
|
|
2394
|
-
logger.debug(
|
|
2567
|
+
logger.debug(
|
|
2568
|
+
`\u{1F4E6} Node '${nodeName}' output: ${JSON.stringify(nodeOutput)}`
|
|
2569
|
+
);
|
|
2395
2570
|
if (nodeOutput && typeof nodeOutput === "object" && "messages" in nodeOutput) {
|
|
2396
2571
|
let messages = nodeOutput.messages;
|
|
2397
2572
|
if (!Array.isArray(messages)) {
|
|
@@ -2413,7 +2588,9 @@ var MCPAgent = class {
|
|
|
2413
2588
|
if (toolInputStr.length > 100) {
|
|
2414
2589
|
toolInputStr = `${toolInputStr.slice(0, 97)}...`;
|
|
2415
2590
|
}
|
|
2416
|
-
logger.info(
|
|
2591
|
+
logger.info(
|
|
2592
|
+
`\u{1F527} Tool call: ${toolName} with input: ${toolInputStr}`
|
|
2593
|
+
);
|
|
2417
2594
|
yield {
|
|
2418
2595
|
action: {
|
|
2419
2596
|
tool: toolName,
|
|
@@ -2435,9 +2612,15 @@ var MCPAgent = class {
|
|
|
2435
2612
|
logger.info(`\u{1F4C4} Tool result: ${observationStr}`);
|
|
2436
2613
|
if (this.useServerManager && this.serverManager) {
|
|
2437
2614
|
const currentTools = this.serverManager.tools;
|
|
2438
|
-
const currentToolNames = new Set(
|
|
2439
|
-
|
|
2440
|
-
|
|
2615
|
+
const currentToolNames = new Set(
|
|
2616
|
+
currentTools.map((t) => t.name)
|
|
2617
|
+
);
|
|
2618
|
+
const existingToolNames = new Set(
|
|
2619
|
+
this._tools.map((t) => t.name)
|
|
2620
|
+
);
|
|
2621
|
+
if (currentToolNames.size !== existingToolNames.size || [...currentToolNames].some(
|
|
2622
|
+
(n) => !existingToolNames.has(n)
|
|
2623
|
+
)) {
|
|
2441
2624
|
logger.info(
|
|
2442
2625
|
`\u{1F504} Tools changed during execution. New tools: ${[...currentToolNames].join(", ")}`
|
|
2443
2626
|
);
|
|
@@ -2472,7 +2655,9 @@ var MCPAgent = class {
|
|
|
2472
2655
|
break;
|
|
2473
2656
|
}
|
|
2474
2657
|
if (restartCount > maxRestarts) {
|
|
2475
|
-
logger.warn(
|
|
2658
|
+
logger.warn(
|
|
2659
|
+
`\u26A0\uFE0F Max restarts (${maxRestarts}) reached. Continuing with current tools.`
|
|
2660
|
+
);
|
|
2476
2661
|
break;
|
|
2477
2662
|
}
|
|
2478
2663
|
}
|
|
@@ -2491,17 +2676,25 @@ var MCPAgent = class {
|
|
|
2491
2676
|
outputSchema
|
|
2492
2677
|
);
|
|
2493
2678
|
if (this.memoryEnabled) {
|
|
2494
|
-
this.addToHistory(
|
|
2679
|
+
this.addToHistory(
|
|
2680
|
+
new import_langchain2.AIMessage(
|
|
2681
|
+
`Structured result: ${JSON.stringify(structuredResult)}`
|
|
2682
|
+
)
|
|
2683
|
+
);
|
|
2495
2684
|
}
|
|
2496
2685
|
logger.info("\u2705 Structured output successful");
|
|
2497
2686
|
success = true;
|
|
2498
2687
|
return structuredResult;
|
|
2499
2688
|
} catch (e) {
|
|
2500
2689
|
logger.error(`\u274C Structured output failed: ${e}`);
|
|
2501
|
-
throw new Error(
|
|
2690
|
+
throw new Error(
|
|
2691
|
+
`Failed to generate structured output: ${e instanceof Error ? e.message : String(e)}`
|
|
2692
|
+
);
|
|
2502
2693
|
}
|
|
2503
2694
|
}
|
|
2504
|
-
logger.info(
|
|
2695
|
+
logger.info(
|
|
2696
|
+
`\u{1F389} Agent execution complete in ${((Date.now() - startTime) / 1e3).toFixed(2)} seconds`
|
|
2697
|
+
);
|
|
2505
2698
|
success = true;
|
|
2506
2699
|
return finalOutput || "No output generated";
|
|
2507
2700
|
} catch (e) {
|
|
@@ -2528,7 +2721,9 @@ var MCPAgent = class {
|
|
|
2528
2721
|
modelProvider: this.modelProvider,
|
|
2529
2722
|
modelName: this.modelName,
|
|
2530
2723
|
serverCount,
|
|
2531
|
-
serverIdentifiers: this.connectors.map(
|
|
2724
|
+
serverIdentifiers: this.connectors.map(
|
|
2725
|
+
(connector) => connector.publicIdentifier
|
|
2726
|
+
),
|
|
2532
2727
|
totalToolsAvailable: toolsAvailable.length,
|
|
2533
2728
|
toolsAvailableNames: toolsAvailable.map((t) => t.name),
|
|
2534
2729
|
maxStepsConfigured: this.maxSteps,
|
|
@@ -2632,7 +2827,10 @@ var MCPAgent = class {
|
|
|
2632
2827
|
logger.info(`\u26A0\uFE0F Skipped message of type: ${msg.constructor.name}`);
|
|
2633
2828
|
}
|
|
2634
2829
|
}
|
|
2635
|
-
const inputs = [
|
|
2830
|
+
const inputs = [
|
|
2831
|
+
...langchainHistory,
|
|
2832
|
+
new import_langchain2.HumanMessage(query)
|
|
2833
|
+
];
|
|
2636
2834
|
logger.info("callbacks", this.callbacks);
|
|
2637
2835
|
const eventStream = agentExecutor.streamEvents(
|
|
2638
2836
|
{ messages: inputs },
|
|
@@ -2645,7 +2843,9 @@ var MCPAgent = class {
|
|
|
2645
2843
|
// Set trace name for LangChain/Langfuse
|
|
2646
2844
|
runName: this.metadata.trace_name || "mcp-use-agent",
|
|
2647
2845
|
// Pass sessionId for Langfuse if present in metadata
|
|
2648
|
-
...this.metadata.session_id && {
|
|
2846
|
+
...this.metadata.session_id && {
|
|
2847
|
+
sessionId: this.metadata.session_id
|
|
2848
|
+
}
|
|
2649
2849
|
}
|
|
2650
2850
|
);
|
|
2651
2851
|
for await (const event of eventStream) {
|
|
@@ -2664,7 +2864,9 @@ var MCPAgent = class {
|
|
|
2664
2864
|
}
|
|
2665
2865
|
const normalizedContent = this._normalizeOutput(chunk.content);
|
|
2666
2866
|
finalResponse += normalizedContent;
|
|
2667
|
-
logger.debug(
|
|
2867
|
+
logger.debug(
|
|
2868
|
+
`\u{1F4DD} Accumulated response length: ${finalResponse.length}`
|
|
2869
|
+
);
|
|
2668
2870
|
}
|
|
2669
2871
|
}
|
|
2670
2872
|
yield event;
|
|
@@ -2721,7 +2923,11 @@ var MCPAgent = class {
|
|
|
2721
2923
|
data: { output: conversionResult }
|
|
2722
2924
|
};
|
|
2723
2925
|
if (this.memoryEnabled) {
|
|
2724
|
-
this.addToHistory(
|
|
2926
|
+
this.addToHistory(
|
|
2927
|
+
new import_langchain2.AIMessage(
|
|
2928
|
+
`Structured result: ${JSON.stringify(conversionResult)}`
|
|
2929
|
+
)
|
|
2930
|
+
);
|
|
2725
2931
|
}
|
|
2726
2932
|
logger.info("\u2705 Structured output successful");
|
|
2727
2933
|
}
|
|
@@ -2740,7 +2946,9 @@ var MCPAgent = class {
|
|
|
2740
2946
|
} catch (e) {
|
|
2741
2947
|
logger.error(`\u274C Error during streamEvents: ${e}`);
|
|
2742
2948
|
if (initializedHere && manageConnector) {
|
|
2743
|
-
logger.info(
|
|
2949
|
+
logger.info(
|
|
2950
|
+
"\u{1F9F9} Cleaning up resources after initialization error in streamEvents"
|
|
2951
|
+
);
|
|
2744
2952
|
await this.close();
|
|
2745
2953
|
}
|
|
2746
2954
|
throw e;
|
|
@@ -2760,7 +2968,9 @@ var MCPAgent = class {
|
|
|
2760
2968
|
modelProvider: this.modelProvider,
|
|
2761
2969
|
modelName: this.modelName,
|
|
2762
2970
|
serverCount,
|
|
2763
|
-
serverIdentifiers: this.connectors.map(
|
|
2971
|
+
serverIdentifiers: this.connectors.map(
|
|
2972
|
+
(connector) => connector.publicIdentifier
|
|
2973
|
+
),
|
|
2764
2974
|
totalToolsAvailable: this._tools.length,
|
|
2765
2975
|
toolsAvailableNames: this._tools.map((t) => t.name),
|
|
2766
2976
|
maxStepsConfigured: this.maxSteps,
|
|
@@ -2788,11 +2998,15 @@ var MCPAgent = class {
|
|
|
2788
2998
|
* @param outputSchema - The Zod schema to validate against
|
|
2789
2999
|
*/
|
|
2790
3000
|
async _attemptStructuredOutput(rawResult, llm, outputSchema) {
|
|
2791
|
-
logger.info(
|
|
3001
|
+
logger.info(
|
|
3002
|
+
`\u{1F504} Attempting structured output with schema: ${JSON.stringify(outputSchema, null, 2)}`
|
|
3003
|
+
);
|
|
2792
3004
|
logger.info(`\u{1F504} Raw result: ${JSON.stringify(rawResult, null, 2)}`);
|
|
2793
3005
|
let structuredLlm = null;
|
|
2794
3006
|
let schemaDescription = "";
|
|
2795
|
-
logger.debug(
|
|
3007
|
+
logger.debug(
|
|
3008
|
+
`\u{1F504} Structured output requested, schema: ${JSON.stringify((0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema), null, 2)}`
|
|
3009
|
+
);
|
|
2796
3010
|
if (llm && "withStructuredOutput" in llm && typeof llm.withStructuredOutput === "function") {
|
|
2797
3011
|
structuredLlm = llm.withStructuredOutput(outputSchema);
|
|
2798
3012
|
} else if (llm) {
|
|
@@ -2844,11 +3058,17 @@ var MCPAgent = class {
|
|
|
2844
3058
|
`;
|
|
2845
3059
|
}
|
|
2846
3060
|
try {
|
|
2847
|
-
logger.info(
|
|
3061
|
+
logger.info(
|
|
3062
|
+
`\u{1F504} Structured output attempt ${attempt} - using streaming approach`
|
|
3063
|
+
);
|
|
2848
3064
|
const contentPreview = textContent.length > 300 ? `${textContent.slice(0, 300)}...` : textContent;
|
|
2849
|
-
logger.info(
|
|
2850
|
-
|
|
2851
|
-
|
|
3065
|
+
logger.info(
|
|
3066
|
+
`\u{1F504} Content being formatted (${textContent.length} chars): ${contentPreview}`
|
|
3067
|
+
);
|
|
3068
|
+
logger.info(
|
|
3069
|
+
`\u{1F504} Full format prompt (${formatPrompt.length} chars):
|
|
3070
|
+
${formatPrompt}`
|
|
3071
|
+
);
|
|
2852
3072
|
const stream = await structuredLlm.stream(formatPrompt);
|
|
2853
3073
|
let structuredResult = null;
|
|
2854
3074
|
let chunkCount = 0;
|
|
@@ -2874,19 +3094,30 @@ ${formatPrompt}`);
|
|
|
2874
3094
|
logger.info(`\u{1F504} Structured output streaming: ${chunkCount} chunks`);
|
|
2875
3095
|
}
|
|
2876
3096
|
}
|
|
2877
|
-
logger.info(
|
|
3097
|
+
logger.info(
|
|
3098
|
+
`\u{1F504} Structured result attempt ${attempt}: ${JSON.stringify(structuredResult, null, 2)}`
|
|
3099
|
+
);
|
|
2878
3100
|
if (!structuredResult) {
|
|
2879
3101
|
throw new Error("No structured result received from stream");
|
|
2880
3102
|
}
|
|
2881
|
-
const validatedResult = this._validateStructuredResult(
|
|
3103
|
+
const validatedResult = this._validateStructuredResult(
|
|
3104
|
+
structuredResult,
|
|
3105
|
+
outputSchema
|
|
3106
|
+
);
|
|
2882
3107
|
logger.info(`\u2705 Structured output successful on attempt ${attempt}`);
|
|
2883
3108
|
return validatedResult;
|
|
2884
3109
|
} catch (e) {
|
|
2885
3110
|
lastError = e instanceof Error ? e.message : String(e);
|
|
2886
|
-
logger.warn(
|
|
3111
|
+
logger.warn(
|
|
3112
|
+
`\u26A0\uFE0F Structured output attempt ${attempt} failed: ${lastError}`
|
|
3113
|
+
);
|
|
2887
3114
|
if (attempt === maxRetries) {
|
|
2888
|
-
logger.error(
|
|
2889
|
-
|
|
3115
|
+
logger.error(
|
|
3116
|
+
`\u274C All ${maxRetries} structured output attempts failed`
|
|
3117
|
+
);
|
|
3118
|
+
throw new Error(
|
|
3119
|
+
`Failed to generate valid structured output after ${maxRetries} attempts. Last error: ${lastError}`
|
|
3120
|
+
);
|
|
2890
3121
|
}
|
|
2891
3122
|
continue;
|
|
2892
3123
|
}
|
|
@@ -2901,14 +3132,18 @@ ${formatPrompt}`);
|
|
|
2901
3132
|
const validatedResult = outputSchema.parse(structuredResult);
|
|
2902
3133
|
const schemaType = outputSchema;
|
|
2903
3134
|
if (schemaType._def && schemaType._def.shape) {
|
|
2904
|
-
for (const [fieldName, fieldSchema] of Object.entries(
|
|
3135
|
+
for (const [fieldName, fieldSchema] of Object.entries(
|
|
3136
|
+
schemaType._def.shape
|
|
3137
|
+
)) {
|
|
2905
3138
|
const field = fieldSchema;
|
|
2906
3139
|
const isOptional = field.isOptional?.() ?? field._def?.typeName === "ZodOptional";
|
|
2907
3140
|
const isNullable = field.isNullable?.() ?? field._def?.typeName === "ZodNullable";
|
|
2908
3141
|
if (!isOptional && !isNullable) {
|
|
2909
3142
|
const value = validatedResult[fieldName];
|
|
2910
3143
|
if (value === null || value === void 0 || typeof value === "string" && !value.trim() || Array.isArray(value) && value.length === 0) {
|
|
2911
|
-
throw new Error(
|
|
3144
|
+
throw new Error(
|
|
3145
|
+
`Required field '${fieldName}' is missing or empty`
|
|
3146
|
+
);
|
|
2912
3147
|
}
|
|
2913
3148
|
}
|
|
2914
3149
|
}
|
|
@@ -3059,7 +3294,9 @@ var BaseMCPClient = class {
|
|
|
3059
3294
|
async closeSession(serverName) {
|
|
3060
3295
|
const session = this.sessions[serverName];
|
|
3061
3296
|
if (!session) {
|
|
3062
|
-
logger.warn(
|
|
3297
|
+
logger.warn(
|
|
3298
|
+
`No session exists for server ${serverName}, nothing to close`
|
|
3299
|
+
);
|
|
3063
3300
|
return;
|
|
3064
3301
|
}
|
|
3065
3302
|
try {
|
|
@@ -3086,7 +3323,9 @@ var BaseMCPClient = class {
|
|
|
3086
3323
|
}
|
|
3087
3324
|
}
|
|
3088
3325
|
if (errors.length) {
|
|
3089
|
-
logger.error(
|
|
3326
|
+
logger.error(
|
|
3327
|
+
`Encountered ${errors.length} errors while closing sessions`
|
|
3328
|
+
);
|
|
3090
3329
|
} else {
|
|
3091
3330
|
logger.debug("All sessions closed successfully");
|
|
3092
3331
|
}
|
|
@@ -3192,7 +3431,9 @@ var ConnectionManager = class {
|
|
|
3192
3431
|
try {
|
|
3193
3432
|
await this.closeConnection(this._connection);
|
|
3194
3433
|
} catch (closeErr) {
|
|
3195
|
-
logger.warn(
|
|
3434
|
+
logger.warn(
|
|
3435
|
+
`Error closing connection in ${this.constructor.name}: ${closeErr}`
|
|
3436
|
+
);
|
|
3196
3437
|
}
|
|
3197
3438
|
this._connection = null;
|
|
3198
3439
|
}
|
|
@@ -3360,7 +3601,10 @@ var BaseConnector = class {
|
|
|
3360
3601
|
logger.debug("Caching server capabilities & tools");
|
|
3361
3602
|
const capabilities = this.client.getServerCapabilities();
|
|
3362
3603
|
this.capabilitiesCache = capabilities;
|
|
3363
|
-
const listToolsRes = await this.client.listTools(
|
|
3604
|
+
const listToolsRes = await this.client.listTools(
|
|
3605
|
+
void 0,
|
|
3606
|
+
defaultRequestOptions
|
|
3607
|
+
);
|
|
3364
3608
|
this.toolsCache = listToolsRes.tools ?? [];
|
|
3365
3609
|
logger.debug(`Fetched ${this.toolsCache.length} tools from server`);
|
|
3366
3610
|
logger.debug("Server capabilities:", capabilities);
|
|
@@ -3379,7 +3623,11 @@ var BaseConnector = class {
|
|
|
3379
3623
|
throw new Error("MCP client is not connected");
|
|
3380
3624
|
}
|
|
3381
3625
|
logger.debug(`Calling tool '${name}' with args`, args);
|
|
3382
|
-
const res = await this.client.callTool(
|
|
3626
|
+
const res = await this.client.callTool(
|
|
3627
|
+
{ name, arguments: args },
|
|
3628
|
+
void 0,
|
|
3629
|
+
options
|
|
3630
|
+
);
|
|
3383
3631
|
logger.debug(`Tool '${name}' returned`, res);
|
|
3384
3632
|
return res;
|
|
3385
3633
|
}
|
|
@@ -3509,7 +3757,11 @@ var BaseConnector = class {
|
|
|
3509
3757
|
throw new Error("MCP client is not connected");
|
|
3510
3758
|
}
|
|
3511
3759
|
logger.debug(`Sending raw request '${method}' with params`, params);
|
|
3512
|
-
return await this.client.request(
|
|
3760
|
+
return await this.client.request(
|
|
3761
|
+
{ method, params: params ?? {} },
|
|
3762
|
+
void 0,
|
|
3763
|
+
options
|
|
3764
|
+
);
|
|
3513
3765
|
}
|
|
3514
3766
|
/**
|
|
3515
3767
|
* Helper to tear down the client & connection manager safely.
|
|
@@ -3568,7 +3820,10 @@ var HttpConnector = class extends BaseConnector {
|
|
|
3568
3820
|
}
|
|
3569
3821
|
this.timeout = opts.timeout ?? 3e4;
|
|
3570
3822
|
this.sseReadTimeout = opts.sseReadTimeout ?? 3e5;
|
|
3571
|
-
this.clientInfo = opts.clientInfo ?? {
|
|
3823
|
+
this.clientInfo = opts.clientInfo ?? {
|
|
3824
|
+
name: "http-connector",
|
|
3825
|
+
version: "1.0.0"
|
|
3826
|
+
};
|
|
3572
3827
|
this.preferSse = opts.preferSse ?? false;
|
|
3573
3828
|
}
|
|
3574
3829
|
/** Establish connection to the MCP implementation via HTTP (streamable or SSE). */
|
|
@@ -3639,29 +3894,28 @@ var HttpConnector = class extends BaseConnector {
|
|
|
3639
3894
|
authError.code = 401;
|
|
3640
3895
|
throw authError;
|
|
3641
3896
|
}
|
|
3642
|
-
throw new Error(
|
|
3897
|
+
throw new Error(
|
|
3898
|
+
"Could not connect to server with any available transport"
|
|
3899
|
+
);
|
|
3643
3900
|
}
|
|
3644
3901
|
}
|
|
3645
3902
|
}
|
|
3646
3903
|
async connectWithStreamableHttp(baseUrl) {
|
|
3647
3904
|
try {
|
|
3648
|
-
this.connectionManager = new StreamableHttpConnectionManager(
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
reconnectionDelayGrowFactor: 1.5,
|
|
3661
|
-
maxRetries: 2
|
|
3662
|
-
}
|
|
3905
|
+
this.connectionManager = new StreamableHttpConnectionManager(baseUrl, {
|
|
3906
|
+
authProvider: this.opts.authProvider,
|
|
3907
|
+
// ← Pass OAuth provider to SDK
|
|
3908
|
+
requestInit: {
|
|
3909
|
+
headers: this.headers
|
|
3910
|
+
},
|
|
3911
|
+
// Pass through timeout and other options
|
|
3912
|
+
reconnectionOptions: {
|
|
3913
|
+
maxReconnectionDelay: 3e4,
|
|
3914
|
+
initialReconnectionDelay: 1e3,
|
|
3915
|
+
reconnectionDelayGrowFactor: 1.5,
|
|
3916
|
+
maxRetries: 2
|
|
3663
3917
|
}
|
|
3664
|
-
);
|
|
3918
|
+
});
|
|
3665
3919
|
const transport = await this.connectionManager.start();
|
|
3666
3920
|
this.client = new import_client.Client(this.clientInfo, this.opts.clientOptions);
|
|
3667
3921
|
try {
|
|
@@ -3670,7 +3924,9 @@ var HttpConnector = class extends BaseConnector {
|
|
|
3670
3924
|
if (connectErr instanceof Error) {
|
|
3671
3925
|
const errMsg = connectErr.message || connectErr.toString();
|
|
3672
3926
|
if (errMsg.includes("Missing session ID") || errMsg.includes("Bad Request: Missing session ID")) {
|
|
3673
|
-
const wrappedError = new Error(
|
|
3927
|
+
const wrappedError = new Error(
|
|
3928
|
+
`FastMCP session ID error: ${errMsg}`
|
|
3929
|
+
);
|
|
3674
3930
|
wrappedError.cause = connectErr;
|
|
3675
3931
|
throw wrappedError;
|
|
3676
3932
|
}
|
|
@@ -3679,7 +3935,9 @@ var HttpConnector = class extends BaseConnector {
|
|
|
3679
3935
|
}
|
|
3680
3936
|
this.connected = true;
|
|
3681
3937
|
this.transportType = "streamable-http";
|
|
3682
|
-
logger.debug(
|
|
3938
|
+
logger.debug(
|
|
3939
|
+
`Successfully connected to MCP implementation via streamable HTTP: ${baseUrl}`
|
|
3940
|
+
);
|
|
3683
3941
|
} catch (err) {
|
|
3684
3942
|
await this.cleanupResources();
|
|
3685
3943
|
throw err;
|
|
@@ -3687,20 +3945,19 @@ var HttpConnector = class extends BaseConnector {
|
|
|
3687
3945
|
}
|
|
3688
3946
|
async connectWithSse(baseUrl) {
|
|
3689
3947
|
try {
|
|
3690
|
-
this.connectionManager = new SseConnectionManager(
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
requestInit: {
|
|
3694
|
-
headers: this.headers
|
|
3695
|
-
}
|
|
3948
|
+
this.connectionManager = new SseConnectionManager(baseUrl, {
|
|
3949
|
+
requestInit: {
|
|
3950
|
+
headers: this.headers
|
|
3696
3951
|
}
|
|
3697
|
-
);
|
|
3952
|
+
});
|
|
3698
3953
|
const transport = await this.connectionManager.start();
|
|
3699
3954
|
this.client = new import_client.Client(this.clientInfo, this.opts.clientOptions);
|
|
3700
3955
|
await this.client.connect(transport);
|
|
3701
3956
|
this.connected = true;
|
|
3702
3957
|
this.transportType = "sse";
|
|
3703
|
-
logger.debug(
|
|
3958
|
+
logger.debug(
|
|
3959
|
+
`Successfully connected to MCP implementation via HTTP/SSE: ${baseUrl}`
|
|
3960
|
+
);
|
|
3704
3961
|
} catch (err) {
|
|
3705
3962
|
await this.cleanupResources();
|
|
3706
3963
|
throw err;
|
|
@@ -3755,7 +4012,9 @@ var StdioConnectionManager = class extends ConnectionManager {
|
|
|
3755
4012
|
async establishConnection() {
|
|
3756
4013
|
this._transport = new import_stdio.StdioClientTransport(this.serverParams);
|
|
3757
4014
|
if (this._transport.stderr && typeof this._transport.stderr.pipe === "function") {
|
|
3758
|
-
this._transport.stderr.pipe(
|
|
4015
|
+
this._transport.stderr.pipe(
|
|
4016
|
+
this.errlog
|
|
4017
|
+
);
|
|
3759
4018
|
}
|
|
3760
4019
|
logger.debug(`${this.constructor.name} connected successfully`);
|
|
3761
4020
|
return this._transport;
|
|
@@ -3799,7 +4058,10 @@ var StdioConnector = class extends BaseConnector {
|
|
|
3799
4058
|
this.args = args;
|
|
3800
4059
|
this.env = env;
|
|
3801
4060
|
this.errlog = errlog;
|
|
3802
|
-
this.clientInfo = rest.clientInfo ?? {
|
|
4061
|
+
this.clientInfo = rest.clientInfo ?? {
|
|
4062
|
+
name: "stdio-connector",
|
|
4063
|
+
version: "1.0.0"
|
|
4064
|
+
};
|
|
3803
4065
|
}
|
|
3804
4066
|
/** Establish connection to the MCP implementation. */
|
|
3805
4067
|
async connect() {
|
|
@@ -3824,12 +4086,17 @@ var StdioConnector = class extends BaseConnector {
|
|
|
3824
4086
|
args: this.args,
|
|
3825
4087
|
env: mergedEnv
|
|
3826
4088
|
};
|
|
3827
|
-
this.connectionManager = new StdioConnectionManager(
|
|
4089
|
+
this.connectionManager = new StdioConnectionManager(
|
|
4090
|
+
serverParams,
|
|
4091
|
+
this.errlog
|
|
4092
|
+
);
|
|
3828
4093
|
const transport = await this.connectionManager.start();
|
|
3829
4094
|
this.client = new import_client2.Client(this.clientInfo, this.opts.clientOptions);
|
|
3830
4095
|
await this.client.connect(transport);
|
|
3831
4096
|
this.connected = true;
|
|
3832
|
-
logger.debug(
|
|
4097
|
+
logger.debug(
|
|
4098
|
+
`Successfully connected to MCP implementation: ${this.command}`
|
|
4099
|
+
);
|
|
3833
4100
|
} catch (err) {
|
|
3834
4101
|
logger.error(`Failed to connect to MCP implementation: ${err}`);
|
|
3835
4102
|
await this.cleanupResources();
|
|
@@ -3838,7 +4105,7 @@ var StdioConnector = class extends BaseConnector {
|
|
|
3838
4105
|
}
|
|
3839
4106
|
get publicIdentifier() {
|
|
3840
4107
|
return {
|
|
3841
|
-
|
|
4108
|
+
type: "stdio",
|
|
3842
4109
|
"command&args": `${this.command} ${this.args.join(" ")}`
|
|
3843
4110
|
};
|
|
3844
4111
|
}
|
|
@@ -3871,7 +4138,9 @@ var WebSocketConnectionManager = class extends ConnectionManager {
|
|
|
3871
4138
|
async establishConnection() {
|
|
3872
4139
|
logger.debug(`Connecting to WebSocket: ${this.url}`);
|
|
3873
4140
|
return new Promise((resolve, reject) => {
|
|
3874
|
-
const ws = new import_ws.default(this.url, {
|
|
4141
|
+
const ws = new import_ws.default(this.url, {
|
|
4142
|
+
headers: this.headers
|
|
4143
|
+
});
|
|
3875
4144
|
this._ws = ws;
|
|
3876
4145
|
const onOpen = /* @__PURE__ */ __name(() => {
|
|
3877
4146
|
cleanup();
|
|
@@ -3931,8 +4200,7 @@ var WebSocketConnector = class extends BaseConnector {
|
|
|
3931
4200
|
super();
|
|
3932
4201
|
this.url = url;
|
|
3933
4202
|
this.headers = { ...opts.headers ?? {} };
|
|
3934
|
-
if (opts.authToken)
|
|
3935
|
-
this.headers.Authorization = `Bearer ${opts.authToken}`;
|
|
4203
|
+
if (opts.authToken) this.headers.Authorization = `Bearer ${opts.authToken}`;
|
|
3936
4204
|
}
|
|
3937
4205
|
async connect() {
|
|
3938
4206
|
if (this.connected) {
|
|
@@ -3941,7 +4209,10 @@ var WebSocketConnector = class extends BaseConnector {
|
|
|
3941
4209
|
}
|
|
3942
4210
|
logger.debug(`Connecting via WebSocket: ${this.url}`);
|
|
3943
4211
|
try {
|
|
3944
|
-
this.connectionManager = new WebSocketConnectionManager(
|
|
4212
|
+
this.connectionManager = new WebSocketConnectionManager(
|
|
4213
|
+
this.url,
|
|
4214
|
+
this.headers
|
|
4215
|
+
);
|
|
3945
4216
|
this.ws = await this.connectionManager.start();
|
|
3946
4217
|
this.receiverTask = this.receiveLoop();
|
|
3947
4218
|
this.connected = true;
|
|
@@ -3962,8 +4233,7 @@ var WebSocketConnector = class extends BaseConnector {
|
|
|
3962
4233
|
this.connected = false;
|
|
3963
4234
|
}
|
|
3964
4235
|
sendRequest(method, params = null) {
|
|
3965
|
-
if (!this.ws)
|
|
3966
|
-
throw new Error("WebSocket is not connected");
|
|
4236
|
+
if (!this.ws) throw new Error("WebSocket is not connected");
|
|
3967
4237
|
const id = (0, import_uuid2.v4)();
|
|
3968
4238
|
const payload = JSON.stringify({ id, method, params: params ?? {} });
|
|
3969
4239
|
return new Promise((resolve, reject) => {
|
|
@@ -3977,8 +4247,7 @@ var WebSocketConnector = class extends BaseConnector {
|
|
|
3977
4247
|
});
|
|
3978
4248
|
}
|
|
3979
4249
|
async receiveLoop() {
|
|
3980
|
-
if (!this.ws)
|
|
3981
|
-
return;
|
|
4250
|
+
if (!this.ws) return;
|
|
3982
4251
|
const socket = this.ws;
|
|
3983
4252
|
const onMessage = /* @__PURE__ */ __name((msg) => {
|
|
3984
4253
|
let data;
|
|
@@ -3992,10 +4261,8 @@ var WebSocketConnector = class extends BaseConnector {
|
|
|
3992
4261
|
if (id && this.pending.has(id)) {
|
|
3993
4262
|
const { resolve, reject } = this.pending.get(id);
|
|
3994
4263
|
this.pending.delete(id);
|
|
3995
|
-
if ("result" in data)
|
|
3996
|
-
|
|
3997
|
-
else if ("error" in data)
|
|
3998
|
-
reject(data.error);
|
|
4264
|
+
if ("result" in data) resolve(data.result);
|
|
4265
|
+
else if ("error" in data) reject(data.error);
|
|
3999
4266
|
} else {
|
|
4000
4267
|
logger.debug("Received unsolicited message", data);
|
|
4001
4268
|
}
|
|
@@ -4053,14 +4320,12 @@ var WebSocketConnector = class extends BaseConnector {
|
|
|
4053
4320
|
return await this.sendRequest(method, params);
|
|
4054
4321
|
}
|
|
4055
4322
|
get tools() {
|
|
4056
|
-
if (!this.toolsCache)
|
|
4057
|
-
throw new Error("MCP client is not initialized");
|
|
4323
|
+
if (!this.toolsCache) throw new Error("MCP client is not initialized");
|
|
4058
4324
|
return this.toolsCache;
|
|
4059
4325
|
}
|
|
4060
4326
|
async cleanupResources() {
|
|
4061
|
-
if (this.receiverTask)
|
|
4062
|
-
|
|
4063
|
-
});
|
|
4327
|
+
if (this.receiverTask) await this.receiverTask.catch(() => {
|
|
4328
|
+
});
|
|
4064
4329
|
this.receiverTask = null;
|
|
4065
4330
|
this.rejectAll(new Error("WebSocket disconnected"));
|
|
4066
4331
|
if (this.connectionManager) {
|
|
@@ -4245,7 +4510,7 @@ var OAuthHelper = class {
|
|
|
4245
4510
|
const response = await fetch(serverUrl, {
|
|
4246
4511
|
method: "GET",
|
|
4247
4512
|
headers: {
|
|
4248
|
-
|
|
4513
|
+
Accept: "text/event-stream",
|
|
4249
4514
|
"Cache-Control": "no-cache"
|
|
4250
4515
|
},
|
|
4251
4516
|
redirect: "manual",
|
|
@@ -4261,16 +4526,29 @@ var OAuthHelper = class {
|
|
|
4261
4526
|
console.log("\u{1F510} [OAuthHelper] Authentication required for:", serverUrl);
|
|
4262
4527
|
return true;
|
|
4263
4528
|
}
|
|
4264
|
-
console.log(
|
|
4529
|
+
console.log(
|
|
4530
|
+
"\u2705 [OAuthHelper] No authentication required for:",
|
|
4531
|
+
serverUrl
|
|
4532
|
+
);
|
|
4265
4533
|
return false;
|
|
4266
4534
|
} catch (error) {
|
|
4267
|
-
console.warn(
|
|
4535
|
+
console.warn(
|
|
4536
|
+
"\u26A0\uFE0F [OAuthHelper] Could not check auth requirement for:",
|
|
4537
|
+
serverUrl,
|
|
4538
|
+
error
|
|
4539
|
+
);
|
|
4268
4540
|
if (error.name === "TypeError" && (error.message?.includes("CORS") || error.message?.includes("Failed to fetch"))) {
|
|
4269
|
-
console.log(
|
|
4541
|
+
console.log(
|
|
4542
|
+
"\u{1F50D} [OAuthHelper] CORS blocked direct check, using heuristics for:",
|
|
4543
|
+
serverUrl
|
|
4544
|
+
);
|
|
4270
4545
|
return this.checkAuthByHeuristics(serverUrl);
|
|
4271
4546
|
}
|
|
4272
4547
|
if (error.name === "AbortError") {
|
|
4273
|
-
console.log(
|
|
4548
|
+
console.log(
|
|
4549
|
+
"\u23F0 [OAuthHelper] Request timeout, assuming no auth required for:",
|
|
4550
|
+
serverUrl
|
|
4551
|
+
);
|
|
4274
4552
|
return false;
|
|
4275
4553
|
}
|
|
4276
4554
|
return this.checkAuthByHeuristics(serverUrl);
|
|
@@ -4280,7 +4558,10 @@ var OAuthHelper = class {
|
|
|
4280
4558
|
* Fallback heuristics for determining auth requirements when direct checking fails
|
|
4281
4559
|
*/
|
|
4282
4560
|
checkAuthByHeuristics(serverUrl) {
|
|
4283
|
-
console.log(
|
|
4561
|
+
console.log(
|
|
4562
|
+
"\u{1F50D} [OAuthHelper] Using heuristics to determine auth for:",
|
|
4563
|
+
serverUrl
|
|
4564
|
+
);
|
|
4284
4565
|
const authRequiredPatterns = [
|
|
4285
4566
|
/api\.githubcopilot\.com/i,
|
|
4286
4567
|
// GitHub Copilot
|
|
@@ -4313,17 +4594,26 @@ var OAuthHelper = class {
|
|
|
4313
4594
|
];
|
|
4314
4595
|
for (const pattern of noAuthPatterns) {
|
|
4315
4596
|
if (pattern.test(serverUrl)) {
|
|
4316
|
-
console.log(
|
|
4597
|
+
console.log(
|
|
4598
|
+
"\u2705 [OAuthHelper] Heuristic: No auth required (matches no-auth pattern):",
|
|
4599
|
+
serverUrl
|
|
4600
|
+
);
|
|
4317
4601
|
return false;
|
|
4318
4602
|
}
|
|
4319
4603
|
}
|
|
4320
4604
|
for (const pattern of authRequiredPatterns) {
|
|
4321
4605
|
if (pattern.test(serverUrl)) {
|
|
4322
|
-
console.log(
|
|
4606
|
+
console.log(
|
|
4607
|
+
"\u{1F510} [OAuthHelper] Heuristic: Auth required (matches auth pattern):",
|
|
4608
|
+
serverUrl
|
|
4609
|
+
);
|
|
4323
4610
|
return true;
|
|
4324
4611
|
}
|
|
4325
4612
|
}
|
|
4326
|
-
console.log(
|
|
4613
|
+
console.log(
|
|
4614
|
+
"\u2753 [OAuthHelper] Heuristic: Unknown pattern, assuming no auth required:",
|
|
4615
|
+
serverUrl
|
|
4616
|
+
);
|
|
4327
4617
|
return false;
|
|
4328
4618
|
}
|
|
4329
4619
|
/**
|
|
@@ -4332,7 +4622,10 @@ var OAuthHelper = class {
|
|
|
4332
4622
|
async discoverOAuthConfig(serverUrl) {
|
|
4333
4623
|
try {
|
|
4334
4624
|
const discoveryUrl = `${serverUrl}/.well-known/oauth-authorization-server`;
|
|
4335
|
-
console.log(
|
|
4625
|
+
console.log(
|
|
4626
|
+
"\u{1F50D} [OAuthHelper] Attempting OAuth discovery at:",
|
|
4627
|
+
discoveryUrl
|
|
4628
|
+
);
|
|
4336
4629
|
const response = await fetch(discoveryUrl);
|
|
4337
4630
|
if (!response.ok) {
|
|
4338
4631
|
console.error("\u274C [OAuthHelper] OAuth discovery failed:", {
|
|
@@ -4340,7 +4633,9 @@ var OAuthHelper = class {
|
|
|
4340
4633
|
statusText: response.statusText,
|
|
4341
4634
|
url: discoveryUrl
|
|
4342
4635
|
});
|
|
4343
|
-
throw new Error(
|
|
4636
|
+
throw new Error(
|
|
4637
|
+
`OAuth discovery failed: ${response.status} ${response.statusText}`
|
|
4638
|
+
);
|
|
4344
4639
|
}
|
|
4345
4640
|
this.discovery = await response.json();
|
|
4346
4641
|
console.log("\u2705 [OAuthHelper] OAuth discovery successful:", {
|
|
@@ -4359,7 +4654,9 @@ var OAuthHelper = class {
|
|
|
4359
4654
|
*/
|
|
4360
4655
|
async registerClient(_serverUrl) {
|
|
4361
4656
|
if (!this.discovery) {
|
|
4362
|
-
throw new Error(
|
|
4657
|
+
throw new Error(
|
|
4658
|
+
"OAuth discovery not performed. Call discoverOAuthConfig first."
|
|
4659
|
+
);
|
|
4363
4660
|
}
|
|
4364
4661
|
if (!this.discovery.registration_endpoint) {
|
|
4365
4662
|
throw new Error("Server does not support dynamic client registration");
|
|
@@ -4388,7 +4685,9 @@ var OAuthHelper = class {
|
|
|
4388
4685
|
});
|
|
4389
4686
|
if (!response.ok) {
|
|
4390
4687
|
const errorText = await response.text();
|
|
4391
|
-
throw new Error(
|
|
4688
|
+
throw new Error(
|
|
4689
|
+
`Client registration failed: ${response.status} ${response.statusText} - ${errorText}`
|
|
4690
|
+
);
|
|
4392
4691
|
}
|
|
4393
4692
|
this.clientRegistration = await response.json();
|
|
4394
4693
|
console.log("\u2705 [OAuthHelper] Client registered successfully:", {
|
|
@@ -4406,7 +4705,9 @@ var OAuthHelper = class {
|
|
|
4406
4705
|
*/
|
|
4407
4706
|
generateAuthUrl(serverUrl, additionalParams) {
|
|
4408
4707
|
if (!this.discovery) {
|
|
4409
|
-
throw new Error(
|
|
4708
|
+
throw new Error(
|
|
4709
|
+
"OAuth discovery not performed. Call discoverOAuthConfig first."
|
|
4710
|
+
);
|
|
4410
4711
|
}
|
|
4411
4712
|
if (!this.clientRegistration) {
|
|
4412
4713
|
throw new Error("Client not registered. Call registerClient first.");
|
|
@@ -4426,7 +4727,9 @@ var OAuthHelper = class {
|
|
|
4426
4727
|
*/
|
|
4427
4728
|
async exchangeCodeForToken(serverUrl, code, codeVerifier) {
|
|
4428
4729
|
if (!this.discovery) {
|
|
4429
|
-
throw new Error(
|
|
4730
|
+
throw new Error(
|
|
4731
|
+
"OAuth discovery not performed. Call discoverOAuthConfig first."
|
|
4732
|
+
);
|
|
4430
4733
|
}
|
|
4431
4734
|
if (!this.clientRegistration) {
|
|
4432
4735
|
throw new Error("Client not registered. Call registerClient first.");
|
|
@@ -4449,7 +4752,9 @@ var OAuthHelper = class {
|
|
|
4449
4752
|
});
|
|
4450
4753
|
if (!response.ok) {
|
|
4451
4754
|
const error = await response.text();
|
|
4452
|
-
throw new Error(
|
|
4755
|
+
throw new Error(
|
|
4756
|
+
`Token exchange failed: ${response.status} ${response.statusText} - ${error}`
|
|
4757
|
+
);
|
|
4453
4758
|
}
|
|
4454
4759
|
return await response.json();
|
|
4455
4760
|
}
|
|
@@ -4487,7 +4792,9 @@ var OAuthHelper = class {
|
|
|
4487
4792
|
"width=500,height=600,scrollbars=yes,resizable=yes,status=yes,location=yes"
|
|
4488
4793
|
);
|
|
4489
4794
|
if (!authWindow) {
|
|
4490
|
-
throw new Error(
|
|
4795
|
+
throw new Error(
|
|
4796
|
+
"Failed to open authentication window. Please allow popups for this site and try again."
|
|
4797
|
+
);
|
|
4491
4798
|
}
|
|
4492
4799
|
console.log("\u2705 [OAuthHelper] OAuth popup opened successfully");
|
|
4493
4800
|
} catch (error) {
|
|
@@ -4622,7 +4929,10 @@ var BrowserOAuthClientProvider = class {
|
|
|
4622
4929
|
try {
|
|
4623
4930
|
return JSON.parse(data);
|
|
4624
4931
|
} catch (e) {
|
|
4625
|
-
console.warn(
|
|
4932
|
+
console.warn(
|
|
4933
|
+
`[${this.storageKeyPrefix}] Failed to parse client information:`,
|
|
4934
|
+
e
|
|
4935
|
+
);
|
|
4626
4936
|
localStorage.removeItem(key);
|
|
4627
4937
|
return void 0;
|
|
4628
4938
|
}
|
|
@@ -4704,7 +5014,11 @@ var BrowserOAuthClientProvider = class {
|
|
|
4704
5014
|
const sanitizedAuthUrl = await this.prepareAuthorizationUrl(authorizationUrl);
|
|
4705
5015
|
const popupFeatures = "width=600,height=700,resizable=yes,scrollbars=yes,status=yes";
|
|
4706
5016
|
try {
|
|
4707
|
-
const popup = window.open(
|
|
5017
|
+
const popup = window.open(
|
|
5018
|
+
sanitizedAuthUrl,
|
|
5019
|
+
`mcp_auth_${this.serverUrlHash}`,
|
|
5020
|
+
popupFeatures
|
|
5021
|
+
);
|
|
4708
5022
|
if (this.onPopupWindow) {
|
|
4709
5023
|
this.onPopupWindow(sanitizedAuthUrl, popupFeatures, popup);
|
|
4710
5024
|
}
|
|
@@ -4714,10 +5028,15 @@ var BrowserOAuthClientProvider = class {
|
|
|
4714
5028
|
);
|
|
4715
5029
|
} else {
|
|
4716
5030
|
popup.focus();
|
|
4717
|
-
console.info(
|
|
5031
|
+
console.info(
|
|
5032
|
+
`[${this.storageKeyPrefix}] Redirecting to authorization URL in popup.`
|
|
5033
|
+
);
|
|
4718
5034
|
}
|
|
4719
5035
|
} catch (e) {
|
|
4720
|
-
console.error(
|
|
5036
|
+
console.error(
|
|
5037
|
+
`[${this.storageKeyPrefix}] Error opening popup window:`,
|
|
5038
|
+
e
|
|
5039
|
+
);
|
|
4721
5040
|
}
|
|
4722
5041
|
}
|
|
4723
5042
|
// --- Helper Methods ---
|
|
@@ -4748,7 +5067,10 @@ var BrowserOAuthClientProvider = class {
|
|
|
4748
5067
|
}
|
|
4749
5068
|
}
|
|
4750
5069
|
} catch (e) {
|
|
4751
|
-
console.warn(
|
|
5070
|
+
console.warn(
|
|
5071
|
+
`[${this.storageKeyPrefix}] Error parsing state key ${key} during clearStorage:`,
|
|
5072
|
+
e
|
|
5073
|
+
);
|
|
4752
5074
|
}
|
|
4753
5075
|
}
|
|
4754
5076
|
}
|
|
@@ -4782,23 +5104,36 @@ async function onMcpAuthorization() {
|
|
|
4782
5104
|
const error = queryParams.get("error");
|
|
4783
5105
|
const errorDescription = queryParams.get("error_description");
|
|
4784
5106
|
const logPrefix = "[mcp-callback]";
|
|
4785
|
-
console.log(`${logPrefix} Handling callback...`, {
|
|
5107
|
+
console.log(`${logPrefix} Handling callback...`, {
|
|
5108
|
+
code,
|
|
5109
|
+
state,
|
|
5110
|
+
error,
|
|
5111
|
+
errorDescription
|
|
5112
|
+
});
|
|
4786
5113
|
let provider = null;
|
|
4787
5114
|
let storedStateData = null;
|
|
4788
5115
|
const stateKey = state ? `mcp:auth:state_${state}` : null;
|
|
4789
5116
|
try {
|
|
4790
5117
|
if (error) {
|
|
4791
|
-
throw new Error(
|
|
5118
|
+
throw new Error(
|
|
5119
|
+
`OAuth error: ${error} - ${errorDescription || "No description provided."}`
|
|
5120
|
+
);
|
|
4792
5121
|
}
|
|
4793
5122
|
if (!code) {
|
|
4794
|
-
throw new Error(
|
|
5123
|
+
throw new Error(
|
|
5124
|
+
"Authorization code not found in callback query parameters."
|
|
5125
|
+
);
|
|
4795
5126
|
}
|
|
4796
5127
|
if (!state || !stateKey) {
|
|
4797
|
-
throw new Error(
|
|
5128
|
+
throw new Error(
|
|
5129
|
+
"State parameter not found or invalid in callback query parameters."
|
|
5130
|
+
);
|
|
4798
5131
|
}
|
|
4799
5132
|
const storedStateJSON = localStorage.getItem(stateKey);
|
|
4800
5133
|
if (!storedStateJSON) {
|
|
4801
|
-
throw new Error(
|
|
5134
|
+
throw new Error(
|
|
5135
|
+
`Invalid or expired state parameter "${state}". No matching state found in storage.`
|
|
5136
|
+
);
|
|
4802
5137
|
}
|
|
4803
5138
|
try {
|
|
4804
5139
|
storedStateData = JSON.parse(storedStateJSON);
|
|
@@ -4807,38 +5142,59 @@ async function onMcpAuthorization() {
|
|
|
4807
5142
|
}
|
|
4808
5143
|
if (!storedStateData.expiry || storedStateData.expiry < Date.now()) {
|
|
4809
5144
|
localStorage.removeItem(stateKey);
|
|
4810
|
-
throw new Error(
|
|
5145
|
+
throw new Error(
|
|
5146
|
+
"OAuth state has expired. Please try initiating authentication again."
|
|
5147
|
+
);
|
|
4811
5148
|
}
|
|
4812
5149
|
if (!storedStateData.providerOptions) {
|
|
4813
5150
|
throw new Error("Stored state is missing required provider options.");
|
|
4814
5151
|
}
|
|
4815
5152
|
const { serverUrl, ...providerOptions } = storedStateData.providerOptions;
|
|
4816
|
-
console.log(
|
|
5153
|
+
console.log(
|
|
5154
|
+
`${logPrefix} Re-instantiating provider for server: ${serverUrl}`
|
|
5155
|
+
);
|
|
4817
5156
|
provider = new BrowserOAuthClientProvider(serverUrl, providerOptions);
|
|
4818
5157
|
console.log(`${logPrefix} Calling SDK auth() to exchange code...`);
|
|
4819
5158
|
const baseUrl = new URL(serverUrl).origin;
|
|
4820
|
-
const authResult = await (0, import_auth.auth)(provider, {
|
|
5159
|
+
const authResult = await (0, import_auth.auth)(provider, {
|
|
5160
|
+
serverUrl: baseUrl,
|
|
5161
|
+
authorizationCode: code
|
|
5162
|
+
});
|
|
4821
5163
|
if (authResult === "AUTHORIZED") {
|
|
4822
|
-
console.log(
|
|
5164
|
+
console.log(
|
|
5165
|
+
`${logPrefix} Authorization successful via SDK auth(). Notifying opener...`
|
|
5166
|
+
);
|
|
4823
5167
|
if (window.opener && !window.opener.closed) {
|
|
4824
|
-
window.opener.postMessage(
|
|
5168
|
+
window.opener.postMessage(
|
|
5169
|
+
{ type: "mcp_auth_callback", success: true },
|
|
5170
|
+
window.location.origin
|
|
5171
|
+
);
|
|
4825
5172
|
window.close();
|
|
4826
5173
|
} else {
|
|
4827
|
-
console.warn(
|
|
5174
|
+
console.warn(
|
|
5175
|
+
`${logPrefix} No opener window detected. Redirecting to root.`
|
|
5176
|
+
);
|
|
4828
5177
|
const pathParts = window.location.pathname.split("/").filter(Boolean);
|
|
4829
5178
|
const basePath = pathParts.length > 0 && pathParts[pathParts.length - 1] === "callback" ? "/" + pathParts.slice(0, -2).join("/") : "/";
|
|
4830
5179
|
window.location.href = basePath || "/";
|
|
4831
5180
|
}
|
|
4832
5181
|
localStorage.removeItem(stateKey);
|
|
4833
5182
|
} else {
|
|
4834
|
-
console.warn(
|
|
4835
|
-
|
|
5183
|
+
console.warn(
|
|
5184
|
+
`${logPrefix} SDK auth() returned unexpected status: ${authResult}`
|
|
5185
|
+
);
|
|
5186
|
+
throw new Error(
|
|
5187
|
+
`Unexpected result from authentication library: ${authResult}`
|
|
5188
|
+
);
|
|
4836
5189
|
}
|
|
4837
5190
|
} catch (err) {
|
|
4838
5191
|
console.error(`${logPrefix} Error during OAuth callback handling:`, err);
|
|
4839
5192
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
4840
5193
|
if (window.opener && !window.opener.closed) {
|
|
4841
|
-
window.opener.postMessage(
|
|
5194
|
+
window.opener.postMessage(
|
|
5195
|
+
{ type: "mcp_auth_callback", success: false, error: errorMessage },
|
|
5196
|
+
window.location.origin
|
|
5197
|
+
);
|
|
4842
5198
|
}
|
|
4843
5199
|
try {
|
|
4844
5200
|
document.body.innerHTML = `
|
|
@@ -4852,7 +5208,10 @@ async function onMcpAuthorization() {
|
|
|
4852
5208
|
</div>
|
|
4853
5209
|
`;
|
|
4854
5210
|
} catch (displayError) {
|
|
4855
|
-
console.error(
|
|
5211
|
+
console.error(
|
|
5212
|
+
`${logPrefix} Could not display error in callback window:`,
|
|
5213
|
+
displayError
|
|
5214
|
+
);
|
|
4856
5215
|
}
|
|
4857
5216
|
if (stateKey) {
|
|
4858
5217
|
localStorage.removeItem(stateKey);
|
|
@@ -4923,7 +5282,9 @@ function useMcp(options) {
|
|
|
4923
5282
|
enabled = true,
|
|
4924
5283
|
clientName,
|
|
4925
5284
|
clientUri,
|
|
4926
|
-
callbackUrl = typeof window !== "undefined" ? (0, import_strict_url_sanitise2.sanitizeUrl)(
|
|
5285
|
+
callbackUrl = typeof window !== "undefined" ? (0, import_strict_url_sanitise2.sanitizeUrl)(
|
|
5286
|
+
new URL("/oauth/callback", window.location.origin).toString()
|
|
5287
|
+
) : "/oauth/callback",
|
|
4927
5288
|
storageKeyPrefix = "mcp:auth",
|
|
4928
5289
|
clientConfig = {},
|
|
4929
5290
|
customHeaders = {},
|
|
@@ -4964,7 +5325,10 @@ function useMcp(options) {
|
|
|
4964
5325
|
const fullMessage = args.length > 0 ? `${message} ${args.map((arg) => JSON.stringify(arg)).join(" ")}` : message;
|
|
4965
5326
|
console[level](`[useMcp] ${fullMessage}`);
|
|
4966
5327
|
if (isMountedRef.current) {
|
|
4967
|
-
setLog((prevLog) => [
|
|
5328
|
+
setLog((prevLog) => [
|
|
5329
|
+
...prevLog.slice(-100),
|
|
5330
|
+
{ level, message: fullMessage, timestamp: Date.now() }
|
|
5331
|
+
]);
|
|
4968
5332
|
}
|
|
4969
5333
|
},
|
|
4970
5334
|
[]
|
|
@@ -5005,7 +5369,11 @@ function useMcp(options) {
|
|
|
5005
5369
|
const manualUrl = authProviderRef.current?.getLastAttemptedAuthUrl();
|
|
5006
5370
|
if (manualUrl) {
|
|
5007
5371
|
setAuthUrl(manualUrl);
|
|
5008
|
-
addLog(
|
|
5372
|
+
addLog(
|
|
5373
|
+
"info",
|
|
5374
|
+
"Manual authentication URL may be available.",
|
|
5375
|
+
manualUrl
|
|
5376
|
+
);
|
|
5009
5377
|
}
|
|
5010
5378
|
}
|
|
5011
5379
|
connectingRef.current = false;
|
|
@@ -5014,7 +5382,10 @@ function useMcp(options) {
|
|
|
5014
5382
|
);
|
|
5015
5383
|
const connect = (0, import_react.useCallback)(async () => {
|
|
5016
5384
|
if (!enabled || !url) {
|
|
5017
|
-
addLog(
|
|
5385
|
+
addLog(
|
|
5386
|
+
"debug",
|
|
5387
|
+
enabled ? "No server URL provided, skipping connection." : "Connection disabled via enabled flag."
|
|
5388
|
+
);
|
|
5018
5389
|
return;
|
|
5019
5390
|
}
|
|
5020
5391
|
if (connectingRef.current) {
|
|
@@ -5031,7 +5402,10 @@ function useMcp(options) {
|
|
|
5031
5402
|
setAuthUrl(void 0);
|
|
5032
5403
|
successfulTransportRef.current = null;
|
|
5033
5404
|
setState("discovering");
|
|
5034
|
-
addLog(
|
|
5405
|
+
addLog(
|
|
5406
|
+
"info",
|
|
5407
|
+
`Connecting attempt #${connectAttemptRef.current} to ${url}...`
|
|
5408
|
+
);
|
|
5035
5409
|
if (!authProviderRef.current) {
|
|
5036
5410
|
authProviderRef.current = new BrowserOAuthClientProvider(url, {
|
|
5037
5411
|
storageKeyPrefix,
|
|
@@ -5048,7 +5422,10 @@ function useMcp(options) {
|
|
|
5048
5422
|
addLog("debug", "BrowserMCPClient initialized in connect.");
|
|
5049
5423
|
}
|
|
5050
5424
|
const tryConnectWithTransport = /* @__PURE__ */ __name(async (transportTypeParam, isAuthRetry = false) => {
|
|
5051
|
-
addLog(
|
|
5425
|
+
addLog(
|
|
5426
|
+
"info",
|
|
5427
|
+
`Attempting connection with transport: ${transportTypeParam}`
|
|
5428
|
+
);
|
|
5052
5429
|
try {
|
|
5053
5430
|
const serverName = "inspector-server";
|
|
5054
5431
|
const serverConfig = {
|
|
@@ -5145,7 +5522,9 @@ function useMcp(options) {
|
|
|
5145
5522
|
const callTool = (0, import_react.useCallback)(
|
|
5146
5523
|
async (name, args) => {
|
|
5147
5524
|
if (stateRef.current !== "ready" || !clientRef.current) {
|
|
5148
|
-
throw new Error(
|
|
5525
|
+
throw new Error(
|
|
5526
|
+
`MCP client is not ready (current state: ${state}). Cannot call tool "${name}".`
|
|
5527
|
+
);
|
|
5149
5528
|
}
|
|
5150
5529
|
addLog("info", `Calling tool: ${name}`, args);
|
|
5151
5530
|
try {
|
|
@@ -5169,7 +5548,10 @@ function useMcp(options) {
|
|
|
5169
5548
|
addLog("info", "Retry requested...");
|
|
5170
5549
|
connect();
|
|
5171
5550
|
} else {
|
|
5172
|
-
addLog(
|
|
5551
|
+
addLog(
|
|
5552
|
+
"warn",
|
|
5553
|
+
`Retry called but state is not 'failed' (state: ${stateRef.current}). Ignoring.`
|
|
5554
|
+
);
|
|
5173
5555
|
}
|
|
5174
5556
|
}, [addLog, connect]);
|
|
5175
5557
|
const authenticate = (0, import_react.useCallback)(async () => {
|
|
@@ -5191,9 +5573,15 @@ function useMcp(options) {
|
|
|
5191
5573
|
}
|
|
5192
5574
|
}, AUTH_TIMEOUT);
|
|
5193
5575
|
try {
|
|
5194
|
-
assert(
|
|
5576
|
+
assert(
|
|
5577
|
+
authProviderRef.current,
|
|
5578
|
+
"Auth Provider not available for manual auth"
|
|
5579
|
+
);
|
|
5195
5580
|
assert(url, "Server URL is required for authentication");
|
|
5196
|
-
addLog(
|
|
5581
|
+
addLog(
|
|
5582
|
+
"info",
|
|
5583
|
+
"Redirecting for manual authentication. Waiting for callback..."
|
|
5584
|
+
);
|
|
5197
5585
|
} catch (authError) {
|
|
5198
5586
|
if (!isMountedRef.current) return;
|
|
5199
5587
|
if (authTimeoutRef.current) clearTimeout(authTimeoutRef.current);
|
|
@@ -5203,7 +5591,10 @@ function useMcp(options) {
|
|
|
5203
5591
|
);
|
|
5204
5592
|
}
|
|
5205
5593
|
} else if (currentState === "authenticating") {
|
|
5206
|
-
addLog(
|
|
5594
|
+
addLog(
|
|
5595
|
+
"warn",
|
|
5596
|
+
"Already attempting authentication. Check for blocked popups or wait for timeout."
|
|
5597
|
+
);
|
|
5207
5598
|
const manualUrl = authProviderRef.current?.getLastAttemptedAuthUrl();
|
|
5208
5599
|
if (manualUrl && !authUrl) {
|
|
5209
5600
|
setAuthUrl(manualUrl);
|
|
@@ -5226,32 +5617,33 @@ function useMcp(options) {
|
|
|
5226
5617
|
addLog("warn", "Auth provider not initialized, cannot clear storage.");
|
|
5227
5618
|
}
|
|
5228
5619
|
}, [url, addLog, disconnect]);
|
|
5229
|
-
const listResources = (0, import_react.useCallback)(
|
|
5230
|
-
|
|
5231
|
-
|
|
5232
|
-
|
|
5233
|
-
|
|
5234
|
-
|
|
5235
|
-
|
|
5236
|
-
|
|
5237
|
-
|
|
5238
|
-
|
|
5239
|
-
|
|
5240
|
-
|
|
5241
|
-
const resourcesResult = await session.connector.listAllResources();
|
|
5242
|
-
setResources(resourcesResult.resources || []);
|
|
5243
|
-
addLog("info", "Resources listed successfully");
|
|
5244
|
-
} catch (err) {
|
|
5245
|
-
addLog("error", "List resources failed:", err);
|
|
5246
|
-
throw err;
|
|
5620
|
+
const listResources = (0, import_react.useCallback)(async () => {
|
|
5621
|
+
if (stateRef.current !== "ready" || !clientRef.current) {
|
|
5622
|
+
throw new Error(
|
|
5623
|
+
`MCP client is not ready (current state: ${state}). Cannot list resources.`
|
|
5624
|
+
);
|
|
5625
|
+
}
|
|
5626
|
+
addLog("info", "Listing resources");
|
|
5627
|
+
try {
|
|
5628
|
+
const serverName = "inspector-server";
|
|
5629
|
+
const session = clientRef.current.getSession(serverName);
|
|
5630
|
+
if (!session) {
|
|
5631
|
+
throw new Error("No active session found");
|
|
5247
5632
|
}
|
|
5248
|
-
|
|
5249
|
-
|
|
5250
|
-
|
|
5633
|
+
const resourcesResult = await session.connector.listAllResources();
|
|
5634
|
+
setResources(resourcesResult.resources || []);
|
|
5635
|
+
addLog("info", "Resources listed successfully");
|
|
5636
|
+
} catch (err) {
|
|
5637
|
+
addLog("error", "List resources failed:", err);
|
|
5638
|
+
throw err;
|
|
5639
|
+
}
|
|
5640
|
+
}, [state]);
|
|
5251
5641
|
const readResource = (0, import_react.useCallback)(
|
|
5252
5642
|
async (uri) => {
|
|
5253
5643
|
if (stateRef.current !== "ready" || !clientRef.current) {
|
|
5254
|
-
throw new Error(
|
|
5644
|
+
throw new Error(
|
|
5645
|
+
`MCP client is not ready (current state: ${state}). Cannot read resource.`
|
|
5646
|
+
);
|
|
5255
5647
|
}
|
|
5256
5648
|
addLog("info", `Reading resource: ${uri}`);
|
|
5257
5649
|
try {
|
|
@@ -5270,32 +5662,33 @@ function useMcp(options) {
|
|
|
5270
5662
|
},
|
|
5271
5663
|
[state]
|
|
5272
5664
|
);
|
|
5273
|
-
const listPrompts = (0, import_react.useCallback)(
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
|
|
5277
|
-
|
|
5278
|
-
|
|
5279
|
-
|
|
5280
|
-
|
|
5281
|
-
|
|
5282
|
-
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
const promptsResult = await session.connector.listPrompts();
|
|
5286
|
-
setPrompts(promptsResult.prompts || []);
|
|
5287
|
-
addLog("info", "Prompts listed successfully");
|
|
5288
|
-
} catch (err) {
|
|
5289
|
-
addLog("error", "List prompts failed:", err);
|
|
5290
|
-
throw err;
|
|
5665
|
+
const listPrompts = (0, import_react.useCallback)(async () => {
|
|
5666
|
+
if (stateRef.current !== "ready" || !clientRef.current) {
|
|
5667
|
+
throw new Error(
|
|
5668
|
+
`MCP client is not ready (current state: ${state}). Cannot list prompts.`
|
|
5669
|
+
);
|
|
5670
|
+
}
|
|
5671
|
+
addLog("info", "Listing prompts");
|
|
5672
|
+
try {
|
|
5673
|
+
const serverName = "inspector-server";
|
|
5674
|
+
const session = clientRef.current.getSession(serverName);
|
|
5675
|
+
if (!session) {
|
|
5676
|
+
throw new Error("No active session found");
|
|
5291
5677
|
}
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5678
|
+
const promptsResult = await session.connector.listPrompts();
|
|
5679
|
+
setPrompts(promptsResult.prompts || []);
|
|
5680
|
+
addLog("info", "Prompts listed successfully");
|
|
5681
|
+
} catch (err) {
|
|
5682
|
+
addLog("error", "List prompts failed:", err);
|
|
5683
|
+
throw err;
|
|
5684
|
+
}
|
|
5685
|
+
}, [state]);
|
|
5295
5686
|
const getPrompt = (0, import_react.useCallback)(
|
|
5296
5687
|
async (name, args) => {
|
|
5297
5688
|
if (stateRef.current !== "ready" || !clientRef.current) {
|
|
5298
|
-
throw new Error(
|
|
5689
|
+
throw new Error(
|
|
5690
|
+
`MCP client is not ready (current state: ${state}). Cannot get prompt.`
|
|
5691
|
+
);
|
|
5299
5692
|
}
|
|
5300
5693
|
addLog("info", `Getting prompt: ${name}`, args);
|
|
5301
5694
|
try {
|
|
@@ -5328,19 +5721,30 @@ function useMcp(options) {
|
|
|
5328
5721
|
if (authTimeoutRef.current) clearTimeout(authTimeoutRef.current);
|
|
5329
5722
|
authTimeoutRef.current = null;
|
|
5330
5723
|
if (event.data.success) {
|
|
5331
|
-
addLog(
|
|
5724
|
+
addLog(
|
|
5725
|
+
"info",
|
|
5726
|
+
"Authentication successful via popup. Reconnecting client..."
|
|
5727
|
+
);
|
|
5332
5728
|
if (connectingRef.current) {
|
|
5333
|
-
addLog(
|
|
5729
|
+
addLog(
|
|
5730
|
+
"debug",
|
|
5731
|
+
"Connection attempt already in progress, resetting flag to allow reconnection."
|
|
5732
|
+
);
|
|
5334
5733
|
}
|
|
5335
5734
|
connectingRef.current = false;
|
|
5336
5735
|
setTimeout(() => {
|
|
5337
5736
|
if (isMountedRef.current) {
|
|
5338
|
-
addLog(
|
|
5737
|
+
addLog(
|
|
5738
|
+
"debug",
|
|
5739
|
+
"Initiating reconnection after successful auth callback."
|
|
5740
|
+
);
|
|
5339
5741
|
connectRef.current();
|
|
5340
5742
|
}
|
|
5341
5743
|
}, 100);
|
|
5342
5744
|
} else {
|
|
5343
|
-
failConnectionRef.current(
|
|
5745
|
+
failConnectionRef.current(
|
|
5746
|
+
`Authentication failed in callback: ${event.data.error || "Unknown reason."}`
|
|
5747
|
+
);
|
|
5344
5748
|
}
|
|
5345
5749
|
}
|
|
5346
5750
|
}, "messageHandler");
|
|
@@ -5355,7 +5759,10 @@ function useMcp(options) {
|
|
|
5355
5759
|
(0, import_react.useEffect)(() => {
|
|
5356
5760
|
isMountedRef.current = true;
|
|
5357
5761
|
if (!enabled || !url) {
|
|
5358
|
-
addLog(
|
|
5762
|
+
addLog(
|
|
5763
|
+
"debug",
|
|
5764
|
+
enabled ? "No server URL provided, skipping connection." : "Connection disabled via enabled flag."
|
|
5765
|
+
);
|
|
5359
5766
|
setState("discovering");
|
|
5360
5767
|
return () => {
|
|
5361
5768
|
isMountedRef.current = false;
|
|
@@ -5372,7 +5779,10 @@ function useMcp(options) {
|
|
|
5372
5779
|
preventAutoAuth,
|
|
5373
5780
|
onPopupWindow
|
|
5374
5781
|
});
|
|
5375
|
-
addLog(
|
|
5782
|
+
addLog(
|
|
5783
|
+
"debug",
|
|
5784
|
+
"BrowserOAuthClientProvider initialized/updated on mount/option change."
|
|
5785
|
+
);
|
|
5376
5786
|
}
|
|
5377
5787
|
connect();
|
|
5378
5788
|
return () => {
|
|
@@ -5380,7 +5790,16 @@ function useMcp(options) {
|
|
|
5380
5790
|
addLog("debug", "useMcp unmounting, disconnecting.");
|
|
5381
5791
|
disconnect(true);
|
|
5382
5792
|
};
|
|
5383
|
-
}, [
|
|
5793
|
+
}, [
|
|
5794
|
+
url,
|
|
5795
|
+
enabled,
|
|
5796
|
+
storageKeyPrefix,
|
|
5797
|
+
callbackUrl,
|
|
5798
|
+
clientName,
|
|
5799
|
+
clientUri,
|
|
5800
|
+
clientConfig.name,
|
|
5801
|
+
clientConfig.version
|
|
5802
|
+
]);
|
|
5384
5803
|
(0, import_react.useEffect)(() => {
|
|
5385
5804
|
let retryTimeoutId = null;
|
|
5386
5805
|
if (state === "failed" && autoRetry && connectAttemptRef.current > 0) {
|
|
@@ -5438,17 +5857,11 @@ function useOpenAiGlobal(key) {
|
|
|
5438
5857
|
onChange();
|
|
5439
5858
|
}, "handleSetGlobal");
|
|
5440
5859
|
if (typeof window !== "undefined") {
|
|
5441
|
-
window.addEventListener(
|
|
5442
|
-
SET_GLOBALS_EVENT_TYPE,
|
|
5443
|
-
handleSetGlobal
|
|
5444
|
-
);
|
|
5860
|
+
window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
|
|
5445
5861
|
}
|
|
5446
5862
|
return () => {
|
|
5447
5863
|
if (typeof window !== "undefined") {
|
|
5448
|
-
window.removeEventListener(
|
|
5449
|
-
SET_GLOBALS_EVENT_TYPE,
|
|
5450
|
-
handleSetGlobal
|
|
5451
|
-
);
|
|
5864
|
+
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
|
|
5452
5865
|
}
|
|
5453
5866
|
};
|
|
5454
5867
|
},
|
|
@@ -5458,7 +5871,10 @@ function useOpenAiGlobal(key) {
|
|
|
5458
5871
|
__name(useOpenAiGlobal, "useOpenAiGlobal");
|
|
5459
5872
|
function useWidget(defaultProps) {
|
|
5460
5873
|
console.log(window?.location?.search, window.openai);
|
|
5461
|
-
const isOpenAiAvailable = (0, import_react2.useMemo)(
|
|
5874
|
+
const isOpenAiAvailable = (0, import_react2.useMemo)(
|
|
5875
|
+
() => typeof window !== "undefined" && !!window.openai,
|
|
5876
|
+
[]
|
|
5877
|
+
);
|
|
5462
5878
|
const provider = (0, import_react2.useMemo)(() => {
|
|
5463
5879
|
return isOpenAiAvailable ? "openai" : "mcp-ui";
|
|
5464
5880
|
}, [isOpenAiAvailable]);
|
|
@@ -5499,12 +5915,15 @@ function useWidget(defaultProps) {
|
|
|
5499
5915
|
},
|
|
5500
5916
|
[]
|
|
5501
5917
|
);
|
|
5502
|
-
const sendFollowUpMessage = (0, import_react2.useCallback)(
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
|
|
5507
|
-
|
|
5918
|
+
const sendFollowUpMessage = (0, import_react2.useCallback)(
|
|
5919
|
+
async (prompt) => {
|
|
5920
|
+
if (!window.openai?.sendFollowUpMessage) {
|
|
5921
|
+
throw new Error("window.openai.sendFollowUpMessage is not available");
|
|
5922
|
+
}
|
|
5923
|
+
return window.openai.sendFollowUpMessage({ prompt });
|
|
5924
|
+
},
|
|
5925
|
+
[]
|
|
5926
|
+
);
|
|
5508
5927
|
const openExternal = (0, import_react2.useCallback)((href) => {
|
|
5509
5928
|
if (!window.openai?.openExternal) {
|
|
5510
5929
|
throw new Error("window.openai.openExternal is not available");
|