@dexto/core 1.12.0 → 1.13.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.d.ts +2 -5
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/approval/index.cjs +4 -2
- package/dist/approval/index.d.ts +1 -1
- package/dist/approval/index.d.ts.map +1 -1
- package/dist/approval/index.js +3 -2
- package/dist/approval/manager.cjs +23 -4
- package/dist/approval/manager.d.ts +3 -2
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +21 -3
- package/dist/approval/schemas.cjs +5 -0
- package/dist/approval/schemas.d.ts +8 -0
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +5 -0
- package/dist/approval/types.d.ts +2 -2
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/events/index.d.ts +2 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/llm/executor/provider-options.cjs +6 -6
- package/dist/llm/executor/provider-options.d.ts.map +1 -1
- package/dist/llm/executor/provider-options.js +7 -8
- package/dist/llm/executor/turn-executor.cjs +13 -20
- package/dist/llm/executor/turn-executor.d.ts +0 -1
- package/dist/llm/executor/turn-executor.d.ts.map +1 -1
- package/dist/llm/executor/turn-executor.js +13 -20
- package/dist/mcp/errors.cjs +9 -0
- package/dist/mcp/errors.d.ts +4 -0
- package/dist/mcp/errors.d.ts.map +1 -1
- package/dist/mcp/errors.js +9 -0
- package/dist/mcp/manager.cjs +79 -3
- package/dist/mcp/manager.d.ts +14 -7
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +79 -3
- package/dist/mcp/mcp-client.cjs +52 -62
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +54 -63
- package/dist/storage/tool-executions/types.cjs +12 -8
- package/dist/storage/tool-executions/types.d.ts +9 -0
- package/dist/storage/tool-executions/types.d.ts.map +1 -1
- package/dist/storage/tool-executions/types.js +12 -8
- package/dist/telemetry/decorators.cjs +47 -23
- package/dist/telemetry/decorators.d.ts +6 -0
- package/dist/telemetry/decorators.d.ts.map +1 -1
- package/dist/telemetry/decorators.js +47 -23
- package/dist/telemetry/operation-span.cjs +5 -2
- package/dist/telemetry/operation-span.d.ts +3 -0
- package/dist/telemetry/operation-span.d.ts.map +1 -1
- package/dist/telemetry/operation-span.js +5 -2
- package/dist/tools/approval/tool-approval-policy.cjs +11 -1
- package/dist/tools/approval/tool-approval-policy.d.ts +2 -2
- package/dist/tools/approval/tool-approval-policy.d.ts.map +1 -1
- package/dist/tools/approval/tool-approval-policy.js +11 -1
- package/dist/tools/identity.cjs +36 -0
- package/dist/tools/identity.d.ts +6 -0
- package/dist/tools/identity.d.ts.map +1 -0
- package/dist/tools/identity.js +13 -0
- package/dist/tools/index.cjs +2 -0
- package/dist/tools/index.d.ts +2 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +4 -1
- package/dist/tools/presentation/tool-presentation.d.ts +5 -0
- package/dist/tools/presentation/tool-presentation.d.ts.map +1 -1
- package/dist/tools/schema-fingerprint.cjs +48 -0
- package/dist/tools/schema-fingerprint.d.ts +4 -0
- package/dist/tools/schema-fingerprint.d.ts.map +1 -0
- package/dist/tools/schema-fingerprint.js +25 -0
- package/dist/tools/schemas.cjs +3 -0
- package/dist/tools/schemas.d.ts +1 -0
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +2 -0
- package/dist/tools/tool-manager.cjs +160 -43
- package/dist/tools/tool-manager.d.ts +20 -11
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +160 -43
- package/dist/tools/types.d.ts +48 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/schema.cjs +2 -2
- package/dist/utils/schema.d.ts +1 -1
- package/dist/utils/schema.d.ts.map +1 -1
- package/dist/utils/schema.js +2 -2
- package/dist/utils/stable-fingerprint.cjs +32 -0
- package/dist/utils/stable-fingerprint.d.ts +3 -0
- package/dist/utils/stable-fingerprint.d.ts.map +1 -0
- package/dist/utils/stable-fingerprint.js +9 -0
- package/package.json +9 -2
|
@@ -48,7 +48,7 @@ var import_error_conversion = require("../../utils/error-conversion.js");
|
|
|
48
48
|
var import_codex_base_url = require("../providers/codex-base-url.js");
|
|
49
49
|
var import_tool_definitions = require("./tool-definitions.js");
|
|
50
50
|
var import_model_request_diagnostics = require("./model-request-diagnostics.js");
|
|
51
|
-
var
|
|
51
|
+
var import_manager2 = require("../../approval/manager.js");
|
|
52
52
|
var import_content_audit = require("../../context/content-audit.js");
|
|
53
53
|
var import_content_clone = require("../../context/content-clone.js");
|
|
54
54
|
const MCP_TOOL_PREFIX = "mcp--";
|
|
@@ -101,15 +101,26 @@ const ProviderOptionsStateSchema = import_zod.z.record(
|
|
|
101
101
|
const JsonSchemaStateSchema = import_zod.z.custom(
|
|
102
102
|
(value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
103
103
|
);
|
|
104
|
+
const ToolAnnotationsStateSchema = import_zod.z.object({
|
|
105
|
+
title: import_zod.z.string().optional(),
|
|
106
|
+
readOnlyHint: import_zod.z.boolean().optional(),
|
|
107
|
+
destructiveHint: import_zod.z.boolean().optional(),
|
|
108
|
+
idempotentHint: import_zod.z.boolean().optional(),
|
|
109
|
+
openWorldHint: import_zod.z.boolean().optional()
|
|
110
|
+
}).catchall(JsonValueSchema);
|
|
104
111
|
const ToolSetEntryStateSchema = import_zod.z.object({
|
|
105
112
|
name: import_zod.z.string().optional(),
|
|
106
113
|
description: import_zod.z.string().optional(),
|
|
107
114
|
parameters: JsonSchemaStateSchema,
|
|
115
|
+
outputSchema: JsonSchemaStateSchema.optional(),
|
|
116
|
+
annotations: ToolAnnotationsStateSchema.optional(),
|
|
108
117
|
_meta: import_zod.z.record(import_zod.z.string(), JsonValueSchema).optional()
|
|
109
118
|
}).strict().transform((parsed) => {
|
|
110
119
|
const tool = { parameters: parsed.parameters };
|
|
111
120
|
if (parsed.name !== void 0) tool.name = parsed.name;
|
|
112
121
|
if (parsed.description !== void 0) tool.description = parsed.description;
|
|
122
|
+
if (parsed.outputSchema !== void 0) tool.outputSchema = parsed.outputSchema;
|
|
123
|
+
if (parsed.annotations !== void 0) tool.annotations = parsed.annotations;
|
|
113
124
|
if (parsed._meta !== void 0) tool._meta = parsed._meta;
|
|
114
125
|
return tool;
|
|
115
126
|
});
|
|
@@ -1449,7 +1460,7 @@ class TurnExecutor {
|
|
|
1449
1460
|
if (approval.kind === "terminal") {
|
|
1450
1461
|
return approval.modelVisibleResult;
|
|
1451
1462
|
}
|
|
1452
|
-
const decision =
|
|
1463
|
+
const decision = (0, import_manager2.approvalResponseToDecisionInput)(approval.response);
|
|
1453
1464
|
const applied = await this.toolManager.applyApprovalDecision(recorded, decision);
|
|
1454
1465
|
if (applied.kind === "terminal") {
|
|
1455
1466
|
return applied.modelVisibleResult;
|
|
@@ -1639,24 +1650,6 @@ class TurnExecutor {
|
|
|
1639
1650
|
toolCallId
|
|
1640
1651
|
};
|
|
1641
1652
|
}
|
|
1642
|
-
toApprovalDecisionInput(response) {
|
|
1643
|
-
if (response.status === import_types3.ApprovalStatus.APPROVED) {
|
|
1644
|
-
return {
|
|
1645
|
-
approvalId: response.approvalId,
|
|
1646
|
-
status: import_types3.ApprovalStatus.APPROVED,
|
|
1647
|
-
...response.data !== void 0 ? { data: response.data } : {}
|
|
1648
|
-
};
|
|
1649
|
-
}
|
|
1650
|
-
const status = response.status === import_types3.ApprovalStatus.DENIED ? import_types3.ApprovalStatus.DENIED : import_types3.ApprovalStatus.CANCELLED;
|
|
1651
|
-
return {
|
|
1652
|
-
approvalId: response.approvalId,
|
|
1653
|
-
status,
|
|
1654
|
-
...response.reason !== void 0 ? { reason: response.reason } : {},
|
|
1655
|
-
...response.message !== void 0 ? { message: response.message } : {},
|
|
1656
|
-
...response.timeoutMs !== void 0 ? { timeoutMs: response.timeoutMs } : {},
|
|
1657
|
-
...response.data !== void 0 ? { data: response.data } : {}
|
|
1658
|
-
};
|
|
1659
|
-
}
|
|
1660
1653
|
getToolExecutionMetadata(executionResult) {
|
|
1661
1654
|
const metadata = {};
|
|
1662
1655
|
if (executionResult.presentationSnapshot !== void 0) {
|
|
@@ -341,7 +341,6 @@ export declare class TurnExecutor {
|
|
|
341
341
|
private emitToolCall;
|
|
342
342
|
private resolveToolApprovalIdentity;
|
|
343
343
|
private resolveModelToolExecutionIdentity;
|
|
344
|
-
private toApprovalDecisionInput;
|
|
345
344
|
private getToolExecutionMetadata;
|
|
346
345
|
private isToolExecutionSuccessful;
|
|
347
346
|
private getToolExecutionErrorMessage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-executor.d.ts","sourceRoot":"","sources":["../../../src/llm/executor/turn-executor.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,aAAa,EAMb,KAAK,YAAY,EAEpB,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAa,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAE3E,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAS1D,OAAO,EACH,WAAW,EAId,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAMpD,OAAO,KAAK,EAAE,cAAc,EAAiB,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEvF,OAAO,KAAK,EACR,UAAU,EACV,kBAAkB,EAClB,UAAU,EAEV,aAAa,EAEhB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAEvD,OAAO,KAAK,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,yBAAyB,EAAE,MAAM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2BAA2B;YA2B3B,YAAY;YAuDZ,qBAAqB;IAoCnC,OAAO,CAAC,oBAAoB;YAOd,oBAAoB;YAqDpB,qBAAqB;YA+DrB,oBAAoB;YA+CpB,4BAA4B;IA6C1C,OAAO,CAAC,oBAAoB;YAad,gCAAgC;YA+BhC,gCAAgC;IA6C9C,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,gBAAgB;IAexB,OAAO,CAAC,2BAA2B;YAkBrB,sBAAsB;IAsDpC,OAAO,CAAC,YAAY;IAkBpB,OAAO,CAAC,2BAA2B;IAanC,OAAO,CAAC,iCAAiC;IAUzC,OAAO,CAAC,wBAAwB;IA6BhC,OAAO,CAAC,yBAAyB;IAIjC,OAAO,CAAC,4BAA4B;IAQpC,OAAO,CAAC,wBAAwB;IAMhC,OAAO,CAAC,6BAA6B;IAYrC;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAU;IAC/C,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAU;IAE/C;;;;;;;;;;;OAWG;YACW,mBAAmB;IAkDjC;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAgB1B;;;OAGG;IACH,OAAO,CAAC,OAAO;IASf;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;IAOrB;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAO/B;;;;;;;;;;;OAWG;YACW,cAAc;IAwF5B;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAoB9B,OAAO,CAAC,qBAAqB;IAK7B;;OAEG;IACH,OAAO,CAAC,gBAAgB;CAQ3B"}
|
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
createModelRequestDiagnostics,
|
|
26
26
|
modelRequestDiagnosticAttributes
|
|
27
27
|
} from "./model-request-diagnostics.js";
|
|
28
|
-
import {
|
|
28
|
+
import { approvalResponseToDecisionInput } from "../../approval/manager.js";
|
|
29
29
|
import {
|
|
30
30
|
describeContentPartsForAudit,
|
|
31
31
|
describeInternalMessageTailForAudit
|
|
@@ -81,15 +81,26 @@ const ProviderOptionsStateSchema = z.record(
|
|
|
81
81
|
const JsonSchemaStateSchema = z.custom(
|
|
82
82
|
(value) => typeof value === "object" && value !== null && !Array.isArray(value)
|
|
83
83
|
);
|
|
84
|
+
const ToolAnnotationsStateSchema = z.object({
|
|
85
|
+
title: z.string().optional(),
|
|
86
|
+
readOnlyHint: z.boolean().optional(),
|
|
87
|
+
destructiveHint: z.boolean().optional(),
|
|
88
|
+
idempotentHint: z.boolean().optional(),
|
|
89
|
+
openWorldHint: z.boolean().optional()
|
|
90
|
+
}).catchall(JsonValueSchema);
|
|
84
91
|
const ToolSetEntryStateSchema = z.object({
|
|
85
92
|
name: z.string().optional(),
|
|
86
93
|
description: z.string().optional(),
|
|
87
94
|
parameters: JsonSchemaStateSchema,
|
|
95
|
+
outputSchema: JsonSchemaStateSchema.optional(),
|
|
96
|
+
annotations: ToolAnnotationsStateSchema.optional(),
|
|
88
97
|
_meta: z.record(z.string(), JsonValueSchema).optional()
|
|
89
98
|
}).strict().transform((parsed) => {
|
|
90
99
|
const tool = { parameters: parsed.parameters };
|
|
91
100
|
if (parsed.name !== void 0) tool.name = parsed.name;
|
|
92
101
|
if (parsed.description !== void 0) tool.description = parsed.description;
|
|
102
|
+
if (parsed.outputSchema !== void 0) tool.outputSchema = parsed.outputSchema;
|
|
103
|
+
if (parsed.annotations !== void 0) tool.annotations = parsed.annotations;
|
|
93
104
|
if (parsed._meta !== void 0) tool._meta = parsed._meta;
|
|
94
105
|
return tool;
|
|
95
106
|
});
|
|
@@ -1429,7 +1440,7 @@ class TurnExecutor {
|
|
|
1429
1440
|
if (approval.kind === "terminal") {
|
|
1430
1441
|
return approval.modelVisibleResult;
|
|
1431
1442
|
}
|
|
1432
|
-
const decision =
|
|
1443
|
+
const decision = approvalResponseToDecisionInput(approval.response);
|
|
1433
1444
|
const applied = await this.toolManager.applyApprovalDecision(recorded, decision);
|
|
1434
1445
|
if (applied.kind === "terminal") {
|
|
1435
1446
|
return applied.modelVisibleResult;
|
|
@@ -1619,24 +1630,6 @@ class TurnExecutor {
|
|
|
1619
1630
|
toolCallId
|
|
1620
1631
|
};
|
|
1621
1632
|
}
|
|
1622
|
-
toApprovalDecisionInput(response) {
|
|
1623
|
-
if (response.status === ApprovalStatus.APPROVED) {
|
|
1624
|
-
return {
|
|
1625
|
-
approvalId: response.approvalId,
|
|
1626
|
-
status: ApprovalStatus.APPROVED,
|
|
1627
|
-
...response.data !== void 0 ? { data: response.data } : {}
|
|
1628
|
-
};
|
|
1629
|
-
}
|
|
1630
|
-
const status = response.status === ApprovalStatus.DENIED ? ApprovalStatus.DENIED : ApprovalStatus.CANCELLED;
|
|
1631
|
-
return {
|
|
1632
|
-
approvalId: response.approvalId,
|
|
1633
|
-
status,
|
|
1634
|
-
...response.reason !== void 0 ? { reason: response.reason } : {},
|
|
1635
|
-
...response.message !== void 0 ? { message: response.message } : {},
|
|
1636
|
-
...response.timeoutMs !== void 0 ? { timeoutMs: response.timeoutMs } : {},
|
|
1637
|
-
...response.data !== void 0 ? { data: response.data } : {}
|
|
1638
|
-
};
|
|
1639
|
-
}
|
|
1640
1633
|
getToolExecutionMetadata(executionResult) {
|
|
1641
1634
|
const metadata = {};
|
|
1642
1635
|
if (executionResult.presentationSnapshot !== void 0) {
|
package/dist/mcp/errors.cjs
CHANGED
|
@@ -162,6 +162,15 @@ class MCPError {
|
|
|
162
162
|
{ toolName, reason }
|
|
163
163
|
);
|
|
164
164
|
}
|
|
165
|
+
static invalidToolArguments(toolName, reason) {
|
|
166
|
+
return new import_DextoRuntimeError.DextoRuntimeError(
|
|
167
|
+
import_error_codes.MCPErrorCode.PROTOCOL_ERROR,
|
|
168
|
+
import_types.ErrorScope.MCP,
|
|
169
|
+
import_types.ErrorType.USER,
|
|
170
|
+
`MCP tool '${toolName}' received invalid arguments: ${reason}`,
|
|
171
|
+
{ toolName, reason }
|
|
172
|
+
);
|
|
173
|
+
}
|
|
165
174
|
}
|
|
166
175
|
// Annotate the CommonJS export names for ESM import in node:
|
|
167
176
|
0 && (module.exports = {
|
package/dist/mcp/errors.d.ts
CHANGED
package/dist/mcp/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/mcp/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAInE;;;GAGG;AACH,qBAAa,QAAQ;IACjB;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAW1D;;OAEG;IACH,MAAM,CAAC,mBAAmB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;;;;IAW7D;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAWvD;;OAEG;IACH,MAAM,CAAC,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;;;;IAWjE;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM;;;;IAWvD;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;;;;IAUzD;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM;;;IAUpC;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,MAAM;;;IAUxC;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,WAAW,EAAE,MAAM;;;IAU3C;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,MAAM;;;IAU1C;;OAEG;IACH,MAAM,CAAC,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAA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Error {
|
|
|
140
140
|
{ toolName, reason }
|
|
141
141
|
);
|
|
142
142
|
}
|
|
143
|
+
static invalidToolArguments(toolName, reason) {
|
|
144
|
+
return new DextoRuntimeError(
|
|
145
|
+
MCPErrorCode.PROTOCOL_ERROR,
|
|
146
|
+
ErrorScope.MCP,
|
|
147
|
+
ErrorType.USER,
|
|
148
|
+
`MCP tool '${toolName}' received invalid arguments: ${reason}`,
|
|
149
|
+
{ toolName, reason }
|
|
150
|
+
);
|
|
151
|
+
}
|
|
143
152
|
}
|
|
144
153
|
export {
|
|
145
154
|
MCPError
|
package/dist/mcp/manager.cjs
CHANGED
|
@@ -25,12 +25,19 @@ var import_mcp_client = require("./mcp-client.js");
|
|
|
25
25
|
var import_types = require("../logger/v2/types.js");
|
|
26
26
|
var import_errors = require("./errors.js");
|
|
27
27
|
var import_events = require("../events/index.js");
|
|
28
|
+
var import_schema_fingerprint = require("../tools/schema-fingerprint.js");
|
|
29
|
+
var import_cfworker = require("@modelcontextprotocol/sdk/validation/cfworker");
|
|
30
|
+
function isJsonSchemaObject(value) {
|
|
31
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
32
|
+
}
|
|
28
33
|
class MCPManager {
|
|
29
34
|
clients = /* @__PURE__ */ new Map();
|
|
30
35
|
connectionErrors = {};
|
|
31
36
|
configCache = /* @__PURE__ */ new Map();
|
|
32
37
|
// Store original configs for restart
|
|
33
38
|
toolCache = /* @__PURE__ */ new Map();
|
|
39
|
+
toolInputValidators = /* @__PURE__ */ new Map();
|
|
40
|
+
jsonSchemaValidator = new import_cfworker.CfWorkerJsonSchemaValidator();
|
|
34
41
|
toolConflicts = /* @__PURE__ */ new Set();
|
|
35
42
|
// Track which tool names have conflicts
|
|
36
43
|
promptCache = /* @__PURE__ */ new Map();
|
|
@@ -245,6 +252,7 @@ class MCPManager {
|
|
|
245
252
|
this.toolCache.set(newQualified, {
|
|
246
253
|
serverName: clientName,
|
|
247
254
|
client,
|
|
255
|
+
upstreamToolName: toolName,
|
|
248
256
|
definition: toolDef
|
|
249
257
|
});
|
|
250
258
|
this.logger.warn(
|
|
@@ -256,6 +264,7 @@ class MCPManager {
|
|
|
256
264
|
this.toolCache.set(qualifiedName, {
|
|
257
265
|
serverName: clientName,
|
|
258
266
|
client,
|
|
267
|
+
upstreamToolName: toolName,
|
|
259
268
|
definition: toolDef
|
|
260
269
|
});
|
|
261
270
|
this.logger.debug(`\u2705 Tool '${qualifiedName}' cached (known conflict)`);
|
|
@@ -263,6 +272,7 @@ class MCPManager {
|
|
|
263
272
|
this.toolCache.set(toolName, {
|
|
264
273
|
serverName: clientName,
|
|
265
274
|
client,
|
|
275
|
+
upstreamToolName: toolName,
|
|
266
276
|
definition: toolDef
|
|
267
277
|
});
|
|
268
278
|
this.logger.debug(`\u2705 Tool '${toolName}' mapped to ${clientName}`);
|
|
@@ -346,6 +356,70 @@ class MCPManager {
|
|
|
346
356
|
this.logger.silly(`MCP tools: ${JSON.stringify(allTools, null, 2)}`);
|
|
347
357
|
return allTools;
|
|
348
358
|
}
|
|
359
|
+
/**
|
|
360
|
+
* Describe cached MCP tools without provider-specific schema wrapping.
|
|
361
|
+
* The callable name may change when conflicts appear, while identity remains connection-based.
|
|
362
|
+
*/
|
|
363
|
+
getToolDescriptors() {
|
|
364
|
+
return Array.from(
|
|
365
|
+
this.toolCache.entries(),
|
|
366
|
+
([name, entry]) => this.buildToolDescriptor(name, entry)
|
|
367
|
+
);
|
|
368
|
+
}
|
|
369
|
+
getToolDescriptor(name) {
|
|
370
|
+
const entry = this.toolCache.get(name);
|
|
371
|
+
return entry === void 0 ? void 0 : this.buildToolDescriptor(name, entry);
|
|
372
|
+
}
|
|
373
|
+
/** Validate arguments against the tool's advertised input schema before calling the server. */
|
|
374
|
+
validateToolInput(toolName, input) {
|
|
375
|
+
const entry = this.toolCache.get(toolName);
|
|
376
|
+
if (entry === void 0) {
|
|
377
|
+
throw import_errors.MCPError.toolNotFound(toolName);
|
|
378
|
+
}
|
|
379
|
+
const schemaFingerprint = (0, import_schema_fingerprint.toolSchemaFingerprint)(entry.definition.parameters);
|
|
380
|
+
let cached = this.toolInputValidators.get(toolName);
|
|
381
|
+
if (cached?.schemaFingerprint !== schemaFingerprint) {
|
|
382
|
+
const inputSchema = entry.definition.parameters;
|
|
383
|
+
if (!isJsonSchemaObject(inputSchema)) {
|
|
384
|
+
throw import_errors.MCPError.invalidToolSchema(entry.upstreamToolName, "expected an object");
|
|
385
|
+
}
|
|
386
|
+
try {
|
|
387
|
+
cached = {
|
|
388
|
+
schemaFingerprint,
|
|
389
|
+
validate: this.jsonSchemaValidator.getValidator(inputSchema)
|
|
390
|
+
};
|
|
391
|
+
} catch (error) {
|
|
392
|
+
throw import_errors.MCPError.invalidToolSchema(
|
|
393
|
+
entry.upstreamToolName,
|
|
394
|
+
error instanceof Error ? error.message : String(error)
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
this.toolInputValidators.set(toolName, cached);
|
|
398
|
+
}
|
|
399
|
+
const result = cached.validate(input);
|
|
400
|
+
if (!result.valid) {
|
|
401
|
+
throw import_errors.MCPError.invalidToolArguments(entry.upstreamToolName, result.errorMessage);
|
|
402
|
+
}
|
|
403
|
+
return result.data;
|
|
404
|
+
}
|
|
405
|
+
buildToolDescriptor(name, entry) {
|
|
406
|
+
return {
|
|
407
|
+
name,
|
|
408
|
+
description: entry.definition.description ?? "",
|
|
409
|
+
identity: {
|
|
410
|
+
type: "mcp",
|
|
411
|
+
connectionId: entry.serverName,
|
|
412
|
+
toolName: entry.upstreamToolName
|
|
413
|
+
},
|
|
414
|
+
inputSchema: entry.definition.parameters,
|
|
415
|
+
...entry.definition.outputSchema !== void 0 ? { outputSchema: entry.definition.outputSchema } : {},
|
|
416
|
+
...entry.definition.annotations !== void 0 ? { annotations: entry.definition.annotations } : {},
|
|
417
|
+
schemaFingerprint: (0, import_schema_fingerprint.toolSchemaFingerprint)(
|
|
418
|
+
entry.definition.parameters,
|
|
419
|
+
entry.definition.outputSchema
|
|
420
|
+
)
|
|
421
|
+
};
|
|
422
|
+
}
|
|
349
423
|
/**
|
|
350
424
|
* Get all MCP tools with their server metadata.
|
|
351
425
|
* This returns the internal tool cache entries which include server names.
|
|
@@ -414,9 +488,7 @@ class MCPManager {
|
|
|
414
488
|
const result = await client.callTool(actualToolName, args, invocation);
|
|
415
489
|
return result;
|
|
416
490
|
} catch (error) {
|
|
417
|
-
this.logger.error(
|
|
418
|
-
`\u274C MCP tool execution failed: '${actualToolName}' - ${error instanceof Error ? error.message : String(error)}`
|
|
419
|
-
);
|
|
491
|
+
this.logger.error(`MCP tool execution failed: '${actualToolName}'`);
|
|
420
492
|
throw error;
|
|
421
493
|
}
|
|
422
494
|
}
|
|
@@ -739,6 +811,7 @@ class MCPManager {
|
|
|
739
811
|
this.connectionErrors = {};
|
|
740
812
|
this.configCache.clear();
|
|
741
813
|
this.toolCache.clear();
|
|
814
|
+
this.toolInputValidators.clear();
|
|
742
815
|
this.toolConflicts.clear();
|
|
743
816
|
this.promptCache.clear();
|
|
744
817
|
this.resourceCache.clear();
|
|
@@ -876,6 +949,7 @@ class MCPManager {
|
|
|
876
949
|
this.toolCache.set(newQualified, {
|
|
877
950
|
serverName,
|
|
878
951
|
client,
|
|
952
|
+
upstreamToolName: toolName,
|
|
879
953
|
definition: toolDef
|
|
880
954
|
});
|
|
881
955
|
this.logger.warn(
|
|
@@ -887,6 +961,7 @@ class MCPManager {
|
|
|
887
961
|
this.toolCache.set(qualifiedName, {
|
|
888
962
|
serverName,
|
|
889
963
|
client,
|
|
964
|
+
upstreamToolName: toolName,
|
|
890
965
|
definition: toolDef
|
|
891
966
|
});
|
|
892
967
|
this.logger.debug(`\u2705 Tool '${qualifiedName}' cached (known conflict)`);
|
|
@@ -894,6 +969,7 @@ class MCPManager {
|
|
|
894
969
|
this.toolCache.set(toolName, {
|
|
895
970
|
serverName,
|
|
896
971
|
client,
|
|
972
|
+
upstreamToolName: toolName,
|
|
897
973
|
definition: toolDef
|
|
898
974
|
});
|
|
899
975
|
this.logger.debug(`\u2705 Tool '${toolName}' mapped to ${serverName}`);
|
package/dist/mcp/manager.d.ts
CHANGED
|
@@ -2,26 +2,24 @@ import type { ValidatedServersConfig, ValidatedMcpServerConfig } from './schemas
|
|
|
2
2
|
import type { Logger } from '../logger/v2/types.js';
|
|
3
3
|
import type { GetPromptResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
|
|
4
4
|
import type { McpClient, MCPResolvedResource, McpAuthProviderFactory } from './types.js';
|
|
5
|
-
import type { ToolSet } from '../tools/types.js';
|
|
5
|
+
import type { MCPToolDescriptor, ToolSet } from '../tools/types.js';
|
|
6
6
|
import { type AgentEventBus } from '../events/index.js';
|
|
7
7
|
import type { PromptDefinition } from '../prompts/types.js';
|
|
8
|
-
import type { JSONSchema7 } from 'json-schema';
|
|
9
8
|
import type { ApprovalManager } from '../approval/manager.js';
|
|
10
9
|
import type { AgentRunContext } from '../runtime/run-context.js';
|
|
11
10
|
type ToolCacheEntry = {
|
|
12
11
|
serverName: string;
|
|
13
12
|
client: McpClient;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
description?: string;
|
|
17
|
-
parameters: JSONSchema7;
|
|
18
|
-
};
|
|
13
|
+
upstreamToolName: string;
|
|
14
|
+
definition: ToolSet[string];
|
|
19
15
|
};
|
|
20
16
|
export declare class MCPManager {
|
|
21
17
|
private clients;
|
|
22
18
|
private connectionErrors;
|
|
23
19
|
private configCache;
|
|
24
20
|
private toolCache;
|
|
21
|
+
private toolInputValidators;
|
|
22
|
+
private readonly jsonSchemaValidator;
|
|
25
23
|
private toolConflicts;
|
|
26
24
|
private promptCache;
|
|
27
25
|
private resourceCache;
|
|
@@ -108,6 +106,15 @@ export declare class MCPManager {
|
|
|
108
106
|
* @returns Promise resolving to a ToolSet mapping tool names to Tool definitions
|
|
109
107
|
*/
|
|
110
108
|
getAllTools(): Promise<ToolSet>;
|
|
109
|
+
/**
|
|
110
|
+
* Describe cached MCP tools without provider-specific schema wrapping.
|
|
111
|
+
* The callable name may change when conflicts appear, while identity remains connection-based.
|
|
112
|
+
*/
|
|
113
|
+
getToolDescriptors(): MCPToolDescriptor[];
|
|
114
|
+
getToolDescriptor(name: string): MCPToolDescriptor | undefined;
|
|
115
|
+
/** Validate arguments against the tool's advertised input schema before calling the server. */
|
|
116
|
+
validateToolInput(toolName: string, input: Record<string, unknown>): Record<string, unknown>;
|
|
117
|
+
private buildToolDescriptor;
|
|
111
118
|
/**
|
|
112
119
|
* Get all MCP tools with their server metadata.
|
|
113
120
|
* This returns the internal tool cache entries which include server names.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/mcp/manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,EACR,eAAe,EACf,kBAAkB,EAErB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EACR,SAAS,EACT,mBAAmB,EAEnB,sBAAsB,EACzB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/mcp/manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAEpD,OAAO,KAAK,EACR,eAAe,EACf,kBAAkB,EAErB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EACR,SAAS,EACT,mBAAmB,EAEnB,sBAAsB,EACzB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;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G;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAc9B;;;OAGG;IACG,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA0B/C;;;;OAIG;IACG,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAuEhD;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IA0BpC;;OAEG;IACH,OAAO,CAAC,wBAAwB;IA4BhC;;OAEG;YACW,qBAAqB;IAuCnC;;OAEG;YACW,wBAAwB;IAkDtC;;OAEG;YACW,sBAAsB;CA+HvC"}
|
package/dist/mcp/manager.js
CHANGED
|
@@ -3,12 +3,19 @@ import { DextoMcpClient } from "./mcp-client.js";
|
|
|
3
3
|
import { DextoLogComponent } from "../logger/v2/types.js";
|
|
4
4
|
import { MCPError } from "./errors.js";
|
|
5
5
|
import { eventBus } from "../events/index.js";
|
|
6
|
+
import { toolSchemaFingerprint } from "../tools/schema-fingerprint.js";
|
|
7
|
+
import { CfWorkerJsonSchemaValidator } from "@modelcontextprotocol/sdk/validation/cfworker";
|
|
8
|
+
function isJsonSchemaObject(value) {
|
|
9
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
}
|
|
6
11
|
class MCPManager {
|
|
7
12
|
clients = /* @__PURE__ */ new Map();
|
|
8
13
|
connectionErrors = {};
|
|
9
14
|
configCache = /* @__PURE__ */ new Map();
|
|
10
15
|
// Store original configs for restart
|
|
11
16
|
toolCache = /* @__PURE__ */ new Map();
|
|
17
|
+
toolInputValidators = /* @__PURE__ */ new Map();
|
|
18
|
+
jsonSchemaValidator = new CfWorkerJsonSchemaValidator();
|
|
12
19
|
toolConflicts = /* @__PURE__ */ new Set();
|
|
13
20
|
// Track which tool names have conflicts
|
|
14
21
|
promptCache = /* @__PURE__ */ new Map();
|
|
@@ -223,6 +230,7 @@ class MCPManager {
|
|
|
223
230
|
this.toolCache.set(newQualified, {
|
|
224
231
|
serverName: clientName,
|
|
225
232
|
client,
|
|
233
|
+
upstreamToolName: toolName,
|
|
226
234
|
definition: toolDef
|
|
227
235
|
});
|
|
228
236
|
this.logger.warn(
|
|
@@ -234,6 +242,7 @@ class MCPManager {
|
|
|
234
242
|
this.toolCache.set(qualifiedName, {
|
|
235
243
|
serverName: clientName,
|
|
236
244
|
client,
|
|
245
|
+
upstreamToolName: toolName,
|
|
237
246
|
definition: toolDef
|
|
238
247
|
});
|
|
239
248
|
this.logger.debug(`\u2705 Tool '${qualifiedName}' cached (known conflict)`);
|
|
@@ -241,6 +250,7 @@ class MCPManager {
|
|
|
241
250
|
this.toolCache.set(toolName, {
|
|
242
251
|
serverName: clientName,
|
|
243
252
|
client,
|
|
253
|
+
upstreamToolName: toolName,
|
|
244
254
|
definition: toolDef
|
|
245
255
|
});
|
|
246
256
|
this.logger.debug(`\u2705 Tool '${toolName}' mapped to ${clientName}`);
|
|
@@ -324,6 +334,70 @@ class MCPManager {
|
|
|
324
334
|
this.logger.silly(`MCP tools: ${JSON.stringify(allTools, null, 2)}`);
|
|
325
335
|
return allTools;
|
|
326
336
|
}
|
|
337
|
+
/**
|
|
338
|
+
* Describe cached MCP tools without provider-specific schema wrapping.
|
|
339
|
+
* The callable name may change when conflicts appear, while identity remains connection-based.
|
|
340
|
+
*/
|
|
341
|
+
getToolDescriptors() {
|
|
342
|
+
return Array.from(
|
|
343
|
+
this.toolCache.entries(),
|
|
344
|
+
([name, entry]) => this.buildToolDescriptor(name, entry)
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
getToolDescriptor(name) {
|
|
348
|
+
const entry = this.toolCache.get(name);
|
|
349
|
+
return entry === void 0 ? void 0 : this.buildToolDescriptor(name, entry);
|
|
350
|
+
}
|
|
351
|
+
/** Validate arguments against the tool's advertised input schema before calling the server. */
|
|
352
|
+
validateToolInput(toolName, input) {
|
|
353
|
+
const entry = this.toolCache.get(toolName);
|
|
354
|
+
if (entry === void 0) {
|
|
355
|
+
throw MCPError.toolNotFound(toolName);
|
|
356
|
+
}
|
|
357
|
+
const schemaFingerprint = toolSchemaFingerprint(entry.definition.parameters);
|
|
358
|
+
let cached = this.toolInputValidators.get(toolName);
|
|
359
|
+
if (cached?.schemaFingerprint !== schemaFingerprint) {
|
|
360
|
+
const inputSchema = entry.definition.parameters;
|
|
361
|
+
if (!isJsonSchemaObject(inputSchema)) {
|
|
362
|
+
throw MCPError.invalidToolSchema(entry.upstreamToolName, "expected an object");
|
|
363
|
+
}
|
|
364
|
+
try {
|
|
365
|
+
cached = {
|
|
366
|
+
schemaFingerprint,
|
|
367
|
+
validate: this.jsonSchemaValidator.getValidator(inputSchema)
|
|
368
|
+
};
|
|
369
|
+
} catch (error) {
|
|
370
|
+
throw MCPError.invalidToolSchema(
|
|
371
|
+
entry.upstreamToolName,
|
|
372
|
+
error instanceof Error ? error.message : String(error)
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
this.toolInputValidators.set(toolName, cached);
|
|
376
|
+
}
|
|
377
|
+
const result = cached.validate(input);
|
|
378
|
+
if (!result.valid) {
|
|
379
|
+
throw MCPError.invalidToolArguments(entry.upstreamToolName, result.errorMessage);
|
|
380
|
+
}
|
|
381
|
+
return result.data;
|
|
382
|
+
}
|
|
383
|
+
buildToolDescriptor(name, entry) {
|
|
384
|
+
return {
|
|
385
|
+
name,
|
|
386
|
+
description: entry.definition.description ?? "",
|
|
387
|
+
identity: {
|
|
388
|
+
type: "mcp",
|
|
389
|
+
connectionId: entry.serverName,
|
|
390
|
+
toolName: entry.upstreamToolName
|
|
391
|
+
},
|
|
392
|
+
inputSchema: entry.definition.parameters,
|
|
393
|
+
...entry.definition.outputSchema !== void 0 ? { outputSchema: entry.definition.outputSchema } : {},
|
|
394
|
+
...entry.definition.annotations !== void 0 ? { annotations: entry.definition.annotations } : {},
|
|
395
|
+
schemaFingerprint: toolSchemaFingerprint(
|
|
396
|
+
entry.definition.parameters,
|
|
397
|
+
entry.definition.outputSchema
|
|
398
|
+
)
|
|
399
|
+
};
|
|
400
|
+
}
|
|
327
401
|
/**
|
|
328
402
|
* Get all MCP tools with their server metadata.
|
|
329
403
|
* This returns the internal tool cache entries which include server names.
|
|
@@ -392,9 +466,7 @@ class MCPManager {
|
|
|
392
466
|
const result = await client.callTool(actualToolName, args, invocation);
|
|
393
467
|
return result;
|
|
394
468
|
} catch (error) {
|
|
395
|
-
this.logger.error(
|
|
396
|
-
`\u274C MCP tool execution failed: '${actualToolName}' - ${error instanceof Error ? error.message : String(error)}`
|
|
397
|
-
);
|
|
469
|
+
this.logger.error(`MCP tool execution failed: '${actualToolName}'`);
|
|
398
470
|
throw error;
|
|
399
471
|
}
|
|
400
472
|
}
|
|
@@ -717,6 +789,7 @@ class MCPManager {
|
|
|
717
789
|
this.connectionErrors = {};
|
|
718
790
|
this.configCache.clear();
|
|
719
791
|
this.toolCache.clear();
|
|
792
|
+
this.toolInputValidators.clear();
|
|
720
793
|
this.toolConflicts.clear();
|
|
721
794
|
this.promptCache.clear();
|
|
722
795
|
this.resourceCache.clear();
|
|
@@ -854,6 +927,7 @@ class MCPManager {
|
|
|
854
927
|
this.toolCache.set(newQualified, {
|
|
855
928
|
serverName,
|
|
856
929
|
client,
|
|
930
|
+
upstreamToolName: toolName,
|
|
857
931
|
definition: toolDef
|
|
858
932
|
});
|
|
859
933
|
this.logger.warn(
|
|
@@ -865,6 +939,7 @@ class MCPManager {
|
|
|
865
939
|
this.toolCache.set(qualifiedName, {
|
|
866
940
|
serverName,
|
|
867
941
|
client,
|
|
942
|
+
upstreamToolName: toolName,
|
|
868
943
|
definition: toolDef
|
|
869
944
|
});
|
|
870
945
|
this.logger.debug(`\u2705 Tool '${qualifiedName}' cached (known conflict)`);
|
|
@@ -872,6 +947,7 @@ class MCPManager {
|
|
|
872
947
|
this.toolCache.set(toolName, {
|
|
873
948
|
serverName,
|
|
874
949
|
client,
|
|
950
|
+
upstreamToolName: toolName,
|
|
875
951
|
definition: toolDef
|
|
876
952
|
});
|
|
877
953
|
this.logger.debug(`\u2705 Tool '${toolName}' mapped to ${serverName}`);
|