@dexto/core 1.6.26 → 1.7.0
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/agent/DextoAgent.cjs +75 -90
- package/dist/agent/DextoAgent.d.ts +7 -7
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +76 -91
- package/dist/agent/error-codes.cjs +1 -0
- package/dist/agent/error-codes.d.ts +1 -0
- package/dist/agent/error-codes.d.ts.map +1 -1
- package/dist/agent/error-codes.js +1 -0
- package/dist/agent/errors.cjs +13 -0
- package/dist/agent/errors.d.ts +6 -0
- package/dist/agent/errors.d.ts.map +1 -1
- package/dist/agent/errors.js +13 -0
- package/dist/agent/index.d.ts +1 -0
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/schemas.cjs +5 -5
- package/dist/agent/schemas.d.ts +69 -980
- package/dist/agent/schemas.d.ts.map +1 -1
- package/dist/agent/schemas.js +5 -5
- package/dist/agent/types.d.ts +11 -0
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/approval/factory.cjs +1 -0
- package/dist/approval/factory.d.ts.map +1 -1
- package/dist/approval/factory.js +1 -0
- package/dist/approval/manager.cjs +19 -6
- package/dist/approval/manager.d.ts +6 -0
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +19 -6
- package/dist/approval/schemas.cjs +16 -6
- package/dist/approval/schemas.d.ts +373 -1044
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +16 -6
- package/dist/approval/session-approval-store.cjs +1 -1
- package/dist/approval/session-approval-store.d.ts +12 -30
- package/dist/approval/session-approval-store.d.ts.map +1 -1
- package/dist/approval/session-approval-store.js +1 -1
- package/dist/events/index.cjs +210 -75
- package/dist/events/index.d.ts +44 -181
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +206 -74
- package/dist/hooks/manager.cjs +5 -2
- package/dist/hooks/manager.d.ts +2 -0
- package/dist/hooks/manager.d.ts.map +1 -1
- package/dist/hooks/manager.js +5 -2
- package/dist/hooks/types.d.ts +3 -0
- package/dist/hooks/types.d.ts.map +1 -1
- package/dist/index.browser.d.ts +1 -0
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.cjs +3 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/llm/executor/turn-executor.cjs +8 -4
- package/dist/llm/executor/turn-executor.d.ts +3 -1
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +8 -4
- package/dist/llm/providers/local/schemas.d.ts +102 -262
- package/dist/llm/providers/local/schemas.d.ts.map +1 -1
- package/dist/llm/registry/index.d.ts +5 -3
- package/dist/llm/registry/index.d.ts.map +1 -1
- package/dist/llm/resolver.cjs +0 -1
- package/dist/llm/resolver.d.ts.map +1 -1
- package/dist/llm/resolver.js +0 -1
- package/dist/llm/schemas.d.ts +95 -199
- package/dist/llm/schemas.d.ts.map +1 -1
- package/dist/llm/services/vercel.cjs +29 -6
- package/dist/llm/services/vercel.d.ts +3 -0
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +27 -5
- package/dist/logger/default-logger-factory.d.ts +28 -256
- package/dist/logger/default-logger-factory.d.ts.map +1 -1
- package/dist/logger/v2/schemas.d.ts +18 -120
- package/dist/logger/v2/schemas.d.ts.map +1 -1
- package/dist/mcp/manager.cjs +7 -2
- package/dist/mcp/manager.d.ts +3 -1
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +7 -2
- package/dist/mcp/mcp-client.cjs +71 -62
- package/dist/mcp/mcp-client.d.ts +3 -2
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +71 -62
- package/dist/mcp/schemas.cjs +4 -4
- package/dist/mcp/schemas.d.ts +77 -270
- package/dist/mcp/schemas.d.ts.map +1 -1
- package/dist/mcp/schemas.js +4 -4
- package/dist/memory/schemas.d.ts +37 -117
- package/dist/memory/schemas.d.ts.map +1 -1
- package/dist/prompts/schemas.d.ts +46 -190
- package/dist/prompts/schemas.d.ts.map +1 -1
- package/dist/resources/handlers/filesystem-handler.cjs +22 -3
- package/dist/resources/handlers/filesystem-handler.d.ts.map +1 -1
- package/dist/resources/handlers/filesystem-handler.js +22 -3
- package/dist/resources/schemas.d.ts +14 -68
- package/dist/resources/schemas.d.ts.map +1 -1
- package/dist/runtime/host-runtime.cjs +163 -0
- package/dist/runtime/host-runtime.d.ts +19 -0
- package/dist/runtime/host-runtime.d.ts.map +1 -0
- package/dist/runtime/host-runtime.js +133 -0
- package/dist/runtime/index.cjs +42 -0
- package/dist/runtime/index.d.ts +2 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +21 -0
- package/dist/runtime/run-context.cjs +53 -0
- package/dist/runtime/run-context.d.ts +13 -0
- package/dist/runtime/run-context.d.ts.map +1 -0
- package/dist/runtime/run-context.js +34 -0
- package/dist/session/chat-session.cjs +30 -32
- package/dist/session/chat-session.d.ts +5 -15
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +31 -33
- package/dist/session/error-codes.cjs +1 -0
- package/dist/session/error-codes.d.ts +2 -1
- package/dist/session/error-codes.d.ts.map +1 -1
- package/dist/session/error-codes.js +1 -0
- package/dist/session/errors.cjs +13 -0
- package/dist/session/errors.d.ts +6 -0
- package/dist/session/errors.d.ts.map +1 -1
- package/dist/session/errors.js +13 -0
- package/dist/session/schemas.d.ts +1 -7
- package/dist/session/schemas.d.ts.map +1 -1
- package/dist/systemPrompt/schemas.cjs +2 -10
- package/dist/systemPrompt/schemas.d.ts +53 -343
- package/dist/systemPrompt/schemas.d.ts.map +1 -1
- package/dist/systemPrompt/schemas.js +2 -10
- package/dist/telemetry/decorators.cjs +75 -57
- package/dist/telemetry/decorators.d.ts +2 -0
- package/dist/telemetry/decorators.d.ts.map +1 -1
- package/dist/telemetry/decorators.js +75 -57
- package/dist/telemetry/schemas.cjs +1 -1
- package/dist/telemetry/schemas.d.ts +9 -44
- package/dist/telemetry/schemas.d.ts.map +1 -1
- package/dist/telemetry/schemas.js +1 -1
- package/dist/telemetry/utils.cjs +9 -6
- package/dist/telemetry/utils.d.ts +3 -0
- package/dist/telemetry/utils.d.ts.map +1 -1
- package/dist/telemetry/utils.js +9 -6
- package/dist/tools/schemas.cjs +1 -1
- package/dist/tools/schemas.d.ts +19 -62
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +1 -1
- package/dist/tools/session-tool-preferences-store.d.ts +3 -9
- package/dist/tools/session-tool-preferences-store.d.ts.map +1 -1
- package/dist/tools/tool-manager.cjs +92 -36
- package/dist/tools/tool-manager.d.ts +12 -3
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +92 -36
- package/dist/tools/types.d.ts +7 -1
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/result.cjs +11 -8
- package/dist/utils/result.d.ts +6 -6
- package/dist/utils/result.d.ts.map +1 -1
- package/dist/utils/result.js +12 -9
- package/dist/utils/schema.cjs +6 -2
- package/dist/utils/schema.d.ts +2 -7
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +6 -2
- package/dist/utils/zod-schema-converter.cjs +66 -66
- package/dist/utils/zod-schema-converter.d.ts +3 -2
- package/dist/utils/zod-schema-converter.d.ts.map +1 -1
- package/dist/utils/zod-schema-converter.js +66 -66
- package/package.json +4 -5
package/dist/mcp/mcp-client.cjs
CHANGED
|
@@ -22,6 +22,7 @@ __export(mcp_client_exports, {
|
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(mcp_client_exports);
|
|
24
24
|
var import_client = require("@modelcontextprotocol/sdk/client/index.js");
|
|
25
|
+
var import_async_hooks = require("async_hooks");
|
|
25
26
|
var import_stdio = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
26
27
|
var import_sse = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
27
28
|
var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
@@ -49,6 +50,7 @@ function buildClientCapabilities() {
|
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
class DextoMcpClient extends import_events.EventEmitter {
|
|
53
|
+
toolInvocationContext = new import_async_hooks.AsyncLocalStorage();
|
|
52
54
|
client = null;
|
|
53
55
|
transport = null;
|
|
54
56
|
isConnected = false;
|
|
@@ -322,71 +324,75 @@ class DextoMcpClient extends import_events.EventEmitter {
|
|
|
322
324
|
* @param args Tool arguments
|
|
323
325
|
* @returns Result of the tool execution
|
|
324
326
|
*/
|
|
325
|
-
async callTool(name, args) {
|
|
327
|
+
async callTool(name, args, invocation) {
|
|
326
328
|
this.ensureConnected();
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
this.logger.debug(`Calling tool '${name}' with args: ${JSON.stringify(args, null, 2)}`);
|
|
342
|
-
let toolArgs = args;
|
|
343
|
-
if (typeof args === "string") {
|
|
344
|
-
try {
|
|
345
|
-
toolArgs = JSON.parse(args);
|
|
346
|
-
} catch {
|
|
347
|
-
toolArgs = { input: args };
|
|
329
|
+
return await this.toolInvocationContext.run(invocation, async () => {
|
|
330
|
+
const shouldTrace = (0, import_utils.hasActiveTelemetry)();
|
|
331
|
+
const tracer = shouldTrace ? import_api.trace.getTracer("dexto") : null;
|
|
332
|
+
const span = tracer?.startSpan(`mcp.tool.${name}`, {
|
|
333
|
+
kind: import_api.SpanKind.CLIENT
|
|
334
|
+
});
|
|
335
|
+
try {
|
|
336
|
+
if (span) {
|
|
337
|
+
const ctx = import_api.trace.setSpan(import_api.context.active(), span);
|
|
338
|
+
(0, import_utils.addBaggageAttributesToSpan)(span, ctx, this.logger);
|
|
339
|
+
span.setAttribute("tool.name", name);
|
|
340
|
+
span.setAttribute("tool.server", this.serverAlias || "unknown");
|
|
341
|
+
span.setAttribute("tool.timeout", this.timeout);
|
|
342
|
+
span.setAttribute("tool.arguments", (0, import_safe_stringify.safeStringify)(args, 4096));
|
|
348
343
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const logResult = JSON.stringify(
|
|
359
|
-
result,
|
|
360
|
-
(key, value) => {
|
|
361
|
-
if (key === "data" && typeof value === "string" && value.length > 100) {
|
|
362
|
-
return `[Base64 data: ${value.length} chars]`;
|
|
344
|
+
this.logger.debug(
|
|
345
|
+
`Calling tool '${name}' with args: ${JSON.stringify(args, null, 2)}`
|
|
346
|
+
);
|
|
347
|
+
let toolArgs = args;
|
|
348
|
+
if (typeof args === "string") {
|
|
349
|
+
try {
|
|
350
|
+
toolArgs = JSON.parse(args);
|
|
351
|
+
} catch {
|
|
352
|
+
toolArgs = { input: args };
|
|
363
353
|
}
|
|
364
|
-
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
354
|
+
}
|
|
355
|
+
this.logger.debug(`Using timeout: ${this.timeout}`);
|
|
356
|
+
const result = await this.client.callTool(
|
|
357
|
+
{ name, arguments: toolArgs },
|
|
358
|
+
void 0,
|
|
359
|
+
// resultSchema (optional)
|
|
360
|
+
{ timeout: this.timeout }
|
|
361
|
+
// Use server-specific timeout, default 1 minute
|
|
362
|
+
);
|
|
363
|
+
const logResult = JSON.stringify(
|
|
364
|
+
result,
|
|
365
|
+
(key, value) => {
|
|
366
|
+
if (key === "data" && typeof value === "string" && value.length > 100) {
|
|
367
|
+
return `[Base64 data: ${value.length} chars]`;
|
|
368
|
+
}
|
|
369
|
+
return value;
|
|
370
|
+
},
|
|
371
|
+
2
|
|
372
|
+
);
|
|
373
|
+
this.logger.debug(`Tool '${name}' result: ${logResult}`);
|
|
374
|
+
if (span) {
|
|
375
|
+
span.setAttribute("tool.result", (0, import_safe_stringify.safeStringify)(result, 4096));
|
|
376
|
+
span.setStatus({ code: import_api.SpanStatusCode.OK });
|
|
377
|
+
}
|
|
378
|
+
if (result === null || result === void 0) {
|
|
379
|
+
return "Tool executed successfully with no result data.";
|
|
380
|
+
}
|
|
381
|
+
return result;
|
|
382
|
+
} catch (error) {
|
|
383
|
+
this.logger.error(`Tool call '${name}' failed: ${JSON.stringify(error, null, 2)}`);
|
|
384
|
+
if (span) {
|
|
385
|
+
span.recordException(error);
|
|
386
|
+
span.setStatus({
|
|
387
|
+
code: import_api.SpanStatusCode.ERROR,
|
|
388
|
+
message: error instanceof Error ? error.message : String(error)
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
return `Error executing tool '${name}': ${error instanceof Error ? error.message : String(error)}`;
|
|
392
|
+
} finally {
|
|
393
|
+
span?.end();
|
|
385
394
|
}
|
|
386
|
-
|
|
387
|
-
} finally {
|
|
388
|
-
span?.end();
|
|
389
|
-
}
|
|
395
|
+
});
|
|
390
396
|
}
|
|
391
397
|
/**
|
|
392
398
|
* Get the list of tools provided by this client
|
|
@@ -657,10 +663,13 @@ class DextoMcpClient extends import_events.EventEmitter {
|
|
|
657
663
|
);
|
|
658
664
|
return { action: "decline" };
|
|
659
665
|
}
|
|
666
|
+
const invocation = this.toolInvocationContext.getStore();
|
|
660
667
|
const response = await this.approvalManager.requestElicitation({
|
|
661
668
|
schema: params.requestedSchema,
|
|
662
669
|
prompt: params.message,
|
|
663
|
-
serverName: this.serverAlias || "unknown"
|
|
670
|
+
serverName: this.serverAlias || "unknown",
|
|
671
|
+
...invocation?.sessionId !== void 0 ? { sessionId: invocation.sessionId } : {},
|
|
672
|
+
...invocation?.runContext?.hostRuntime !== void 0 ? { hostRuntime: invocation.runContext.hostRuntime } : {}
|
|
664
673
|
});
|
|
665
674
|
if (response.status === import_types2.ApprovalStatus.APPROVED && response.data) {
|
|
666
675
|
const formData = response.data && typeof response.data === "object" && "formData" in response.data ? response.data.formData : {};
|
package/dist/mcp/mcp-client.d.ts
CHANGED
|
@@ -3,13 +3,14 @@ import { EventEmitter } from 'events';
|
|
|
3
3
|
import type { Logger } from '../logger/v2/types.js';
|
|
4
4
|
import type { ApprovalManager } from '../approval/manager.js';
|
|
5
5
|
import type { ValidatedMcpServerConfig } from './schemas.js';
|
|
6
|
-
import type { ToolSet } from '../tools/types.js';
|
|
6
|
+
import type { ToolExecutionContextBase, ToolSet } from '../tools/types.js';
|
|
7
7
|
import type { McpClient, MCPResourceSummary, McpAuthProviderFactory } from './types.js';
|
|
8
8
|
import type { GetPromptResult, ReadResourceResult, Prompt } from '@modelcontextprotocol/sdk/types.js';
|
|
9
9
|
/**
|
|
10
10
|
* Wrapper on top of Client class provided in model context protocol SDK, to add additional metadata about the server
|
|
11
11
|
*/
|
|
12
12
|
export declare class DextoMcpClient extends EventEmitter implements McpClient {
|
|
13
|
+
private readonly toolInvocationContext;
|
|
13
14
|
private client;
|
|
14
15
|
private transport;
|
|
15
16
|
private isConnected;
|
|
@@ -52,7 +53,7 @@ export declare class DextoMcpClient extends EventEmitter implements McpClient {
|
|
|
52
53
|
* @param args Tool arguments
|
|
53
54
|
* @returns Result of the tool execution
|
|
54
55
|
*/
|
|
55
|
-
callTool(name: string, args: any): Promise<any>;
|
|
56
|
+
callTool(name: string, args: any, invocation?: Pick<ToolExecutionContextBase, 'sessionId' | 'runContext'>): Promise<any>;
|
|
56
57
|
/**
|
|
57
58
|
* Get the list of tools provided by this client
|
|
58
59
|
* @returns Array of available tools
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp-client.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-client.ts"],"names":[],"mappings":"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"}
|
package/dist/mcp/mcp-client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import "../chunk-PTJYTZNU.js";
|
|
2
2
|
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
3
|
+
import { AsyncLocalStorage } from "async_hooks";
|
|
3
4
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
4
5
|
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
5
6
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
@@ -31,6 +32,7 @@ function buildClientCapabilities() {
|
|
|
31
32
|
};
|
|
32
33
|
}
|
|
33
34
|
class DextoMcpClient extends EventEmitter {
|
|
35
|
+
toolInvocationContext = new AsyncLocalStorage();
|
|
34
36
|
client = null;
|
|
35
37
|
transport = null;
|
|
36
38
|
isConnected = false;
|
|
@@ -304,71 +306,75 @@ class DextoMcpClient extends EventEmitter {
|
|
|
304
306
|
* @param args Tool arguments
|
|
305
307
|
* @returns Result of the tool execution
|
|
306
308
|
*/
|
|
307
|
-
async callTool(name, args) {
|
|
309
|
+
async callTool(name, args, invocation) {
|
|
308
310
|
this.ensureConnected();
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
this.logger.debug(`Calling tool '${name}' with args: ${JSON.stringify(args, null, 2)}`);
|
|
324
|
-
let toolArgs = args;
|
|
325
|
-
if (typeof args === "string") {
|
|
326
|
-
try {
|
|
327
|
-
toolArgs = JSON.parse(args);
|
|
328
|
-
} catch {
|
|
329
|
-
toolArgs = { input: args };
|
|
311
|
+
return await this.toolInvocationContext.run(invocation, async () => {
|
|
312
|
+
const shouldTrace = hasActiveTelemetry();
|
|
313
|
+
const tracer = shouldTrace ? trace.getTracer("dexto") : null;
|
|
314
|
+
const span = tracer?.startSpan(`mcp.tool.${name}`, {
|
|
315
|
+
kind: SpanKind.CLIENT
|
|
316
|
+
});
|
|
317
|
+
try {
|
|
318
|
+
if (span) {
|
|
319
|
+
const ctx = trace.setSpan(context.active(), span);
|
|
320
|
+
addBaggageAttributesToSpan(span, ctx, this.logger);
|
|
321
|
+
span.setAttribute("tool.name", name);
|
|
322
|
+
span.setAttribute("tool.server", this.serverAlias || "unknown");
|
|
323
|
+
span.setAttribute("tool.timeout", this.timeout);
|
|
324
|
+
span.setAttribute("tool.arguments", safeStringify(args, 4096));
|
|
330
325
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
const logResult = JSON.stringify(
|
|
341
|
-
result,
|
|
342
|
-
(key, value) => {
|
|
343
|
-
if (key === "data" && typeof value === "string" && value.length > 100) {
|
|
344
|
-
return `[Base64 data: ${value.length} chars]`;
|
|
326
|
+
this.logger.debug(
|
|
327
|
+
`Calling tool '${name}' with args: ${JSON.stringify(args, null, 2)}`
|
|
328
|
+
);
|
|
329
|
+
let toolArgs = args;
|
|
330
|
+
if (typeof args === "string") {
|
|
331
|
+
try {
|
|
332
|
+
toolArgs = JSON.parse(args);
|
|
333
|
+
} catch {
|
|
334
|
+
toolArgs = { input: args };
|
|
345
335
|
}
|
|
346
|
-
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
336
|
+
}
|
|
337
|
+
this.logger.debug(`Using timeout: ${this.timeout}`);
|
|
338
|
+
const result = await this.client.callTool(
|
|
339
|
+
{ name, arguments: toolArgs },
|
|
340
|
+
void 0,
|
|
341
|
+
// resultSchema (optional)
|
|
342
|
+
{ timeout: this.timeout }
|
|
343
|
+
// Use server-specific timeout, default 1 minute
|
|
344
|
+
);
|
|
345
|
+
const logResult = JSON.stringify(
|
|
346
|
+
result,
|
|
347
|
+
(key, value) => {
|
|
348
|
+
if (key === "data" && typeof value === "string" && value.length > 100) {
|
|
349
|
+
return `[Base64 data: ${value.length} chars]`;
|
|
350
|
+
}
|
|
351
|
+
return value;
|
|
352
|
+
},
|
|
353
|
+
2
|
|
354
|
+
);
|
|
355
|
+
this.logger.debug(`Tool '${name}' result: ${logResult}`);
|
|
356
|
+
if (span) {
|
|
357
|
+
span.setAttribute("tool.result", safeStringify(result, 4096));
|
|
358
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
359
|
+
}
|
|
360
|
+
if (result === null || result === void 0) {
|
|
361
|
+
return "Tool executed successfully with no result data.";
|
|
362
|
+
}
|
|
363
|
+
return result;
|
|
364
|
+
} catch (error) {
|
|
365
|
+
this.logger.error(`Tool call '${name}' failed: ${JSON.stringify(error, null, 2)}`);
|
|
366
|
+
if (span) {
|
|
367
|
+
span.recordException(error);
|
|
368
|
+
span.setStatus({
|
|
369
|
+
code: SpanStatusCode.ERROR,
|
|
370
|
+
message: error instanceof Error ? error.message : String(error)
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
return `Error executing tool '${name}': ${error instanceof Error ? error.message : String(error)}`;
|
|
374
|
+
} finally {
|
|
375
|
+
span?.end();
|
|
367
376
|
}
|
|
368
|
-
|
|
369
|
-
} finally {
|
|
370
|
-
span?.end();
|
|
371
|
-
}
|
|
377
|
+
});
|
|
372
378
|
}
|
|
373
379
|
/**
|
|
374
380
|
* Get the list of tools provided by this client
|
|
@@ -639,10 +645,13 @@ class DextoMcpClient extends EventEmitter {
|
|
|
639
645
|
);
|
|
640
646
|
return { action: "decline" };
|
|
641
647
|
}
|
|
648
|
+
const invocation = this.toolInvocationContext.getStore();
|
|
642
649
|
const response = await this.approvalManager.requestElicitation({
|
|
643
650
|
schema: params.requestedSchema,
|
|
644
651
|
prompt: params.message,
|
|
645
|
-
serverName: this.serverAlias || "unknown"
|
|
652
|
+
serverName: this.serverAlias || "unknown",
|
|
653
|
+
...invocation?.sessionId !== void 0 ? { sessionId: invocation.sessionId } : {},
|
|
654
|
+
...invocation?.runContext?.hostRuntime !== void 0 ? { hostRuntime: invocation.runContext.hostRuntime } : {}
|
|
646
655
|
});
|
|
647
656
|
if (response.status === ApprovalStatus.APPROVED && response.data) {
|
|
648
657
|
const formData = response.data && typeof response.data === "object" && "formData" in response.data ? response.data.formData : {};
|
package/dist/mcp/schemas.cjs
CHANGED
|
@@ -60,7 +60,7 @@ const StdioServerConfigSchema = import_zod.z.object({
|
|
|
60
60
|
}
|
|
61
61
|
}),
|
|
62
62
|
args: import_zod.z.array((0, import_result.EnvExpandedString)()).default([]).describe("Array of arguments for the command (e.g., ['script.js'])"),
|
|
63
|
-
env: import_zod.z.record((0, import_result.EnvExpandedString)()).default({}).describe("Optional environment variables for the server process"),
|
|
63
|
+
env: import_zod.z.record(import_zod.z.string(), (0, import_result.EnvExpandedString)()).default({}).describe("Optional environment variables for the server process"),
|
|
64
64
|
timeout: import_zod.z.coerce.number().int().positive().default(3e4),
|
|
65
65
|
connectionMode: import_zod.z.enum(MCP_CONNECTION_MODES).default(DEFAULT_MCP_CONNECTION_MODE)
|
|
66
66
|
}).strict();
|
|
@@ -68,7 +68,7 @@ const SseServerConfigSchema = import_zod.z.object({
|
|
|
68
68
|
type: import_zod.z.literal("sse"),
|
|
69
69
|
enabled: import_zod.z.boolean().default(true).describe("Whether this server is enabled (disabled servers are not connected)"),
|
|
70
70
|
url: (0, import_result.RequiredEnvURL)(process.env).describe("URL for the SSE server endpoint"),
|
|
71
|
-
headers: import_zod.z.record((0, import_result.EnvExpandedString)()).default({}),
|
|
71
|
+
headers: import_zod.z.record(import_zod.z.string(), (0, import_result.EnvExpandedString)()).default({}),
|
|
72
72
|
timeout: import_zod.z.coerce.number().int().positive().default(3e4),
|
|
73
73
|
connectionMode: import_zod.z.enum(MCP_CONNECTION_MODES).default(DEFAULT_MCP_CONNECTION_MODE)
|
|
74
74
|
}).strict();
|
|
@@ -76,7 +76,7 @@ const HttpServerConfigSchema = import_zod.z.object({
|
|
|
76
76
|
type: import_zod.z.literal("http"),
|
|
77
77
|
enabled: import_zod.z.boolean().default(true).describe("Whether this server is enabled (disabled servers are not connected)"),
|
|
78
78
|
url: (0, import_result.RequiredEnvURL)(process.env).describe("URL for the HTTP server"),
|
|
79
|
-
headers: import_zod.z.record((0, import_result.EnvExpandedString)()).default({}),
|
|
79
|
+
headers: import_zod.z.record(import_zod.z.string(), (0, import_result.EnvExpandedString)()).default({}),
|
|
80
80
|
timeout: import_zod.z.coerce.number().int().positive().default(3e4),
|
|
81
81
|
connectionMode: import_zod.z.enum(MCP_CONNECTION_MODES).default(DEFAULT_MCP_CONNECTION_MODE)
|
|
82
82
|
}).strict();
|
|
@@ -86,7 +86,7 @@ const McpServerConfigSchema = import_zod.z.discriminatedUnion("type", [
|
|
|
86
86
|
HttpServerConfigSchema
|
|
87
87
|
]).superRefine((_data, _ctx) => {
|
|
88
88
|
}).brand();
|
|
89
|
-
const ServersConfigSchema = import_zod.z.record(McpServerConfigSchema).describe("A dictionary of server configurations, keyed by server name").brand();
|
|
89
|
+
const ServersConfigSchema = import_zod.z.record(import_zod.z.string(), McpServerConfigSchema).describe("A dictionary of server configurations, keyed by server name").brand();
|
|
90
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
91
91
|
0 && (module.exports = {
|
|
92
92
|
DEFAULT_MCP_CONNECTION_MODE,
|