@mcpc-tech/core 0.3.1 → 0.3.3
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/index.mjs +1471 -1496
- package/package.json +1 -1
- package/types/mod.d.ts +1 -0
- package/types/mod.d.ts.map +1 -1
- package/types/src/compose.d.ts +3 -0
- package/types/src/compose.d.ts.map +1 -1
- package/types/src/plugin-types.d.ts +36 -5
- package/types/src/plugin-types.d.ts.map +1 -1
- package/types/src/prompts/types.d.ts +4 -0
- package/types/src/prompts/types.d.ts.map +1 -0
- package/types/src/set-up-mcp-compose.d.ts +8 -6
- package/types/src/set-up-mcp-compose.d.ts.map +1 -1
- package/types/src/types.d.ts.map +1 -1
package/index.mjs
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire } from 'node:module';
|
|
3
3
|
const require = createRequire(import.meta.url);
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
8
|
-
};
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
4
|
+
|
|
5
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/compose.js
|
|
6
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, SetLevelRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
13
7
|
|
|
14
8
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/schema.js
|
|
9
|
+
var schemaSymbol = Symbol.for("mcpc.schema");
|
|
10
|
+
var vercelSchemaSymbol = Symbol.for("vercel.ai.schema");
|
|
11
|
+
var validatorSymbol = Symbol.for("mcpc.validator");
|
|
15
12
|
function jsonSchema(schema, options = {}) {
|
|
16
13
|
if (isWrappedSchema(schema)) {
|
|
17
14
|
return schema;
|
|
@@ -33,447 +30,8 @@ function extractJsonSchema(schema) {
|
|
|
33
30
|
}
|
|
34
31
|
return schema;
|
|
35
32
|
}
|
|
36
|
-
var schemaSymbol, vercelSchemaSymbol, validatorSymbol;
|
|
37
|
-
var init_schema = __esm({
|
|
38
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/utils/schema.js"() {
|
|
39
|
-
schemaSymbol = Symbol.for("mcpc.schema");
|
|
40
|
-
vercelSchemaSymbol = Symbol.for("vercel.ai.schema");
|
|
41
|
-
validatorSymbol = Symbol.for("mcpc.validator");
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/config.js
|
|
46
|
-
import process2 from "node:process";
|
|
47
|
-
var GEMINI_PREFERRED_FORMAT;
|
|
48
|
-
var init_config = __esm({
|
|
49
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/config.js"() {
|
|
50
|
-
GEMINI_PREFERRED_FORMAT = process2.env.GEMINI_PREFERRED_FORMAT === "0" ? false : true;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/json.js
|
|
55
|
-
import { jsonrepair as jsonrepair2 } from "jsonrepair";
|
|
56
|
-
import { inspect } from "node:util";
|
|
57
|
-
function parseJSON2(text, throwError) {
|
|
58
|
-
try {
|
|
59
|
-
return JSON.parse(text);
|
|
60
|
-
} catch (_error) {
|
|
61
|
-
try {
|
|
62
|
-
const repairedText = jsonrepair2(text);
|
|
63
|
-
console.warn(`Failed to parse JSON, attempting to repair, result: ${text}`);
|
|
64
|
-
if (throwError) {
|
|
65
|
-
throw _error;
|
|
66
|
-
}
|
|
67
|
-
return JSON.parse(repairedText);
|
|
68
|
-
} catch {
|
|
69
|
-
if (throwError) {
|
|
70
|
-
throw new Error("Failed to parse repaired JSON");
|
|
71
|
-
}
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
function truncateJSON(obj) {
|
|
77
|
-
return inspect(obj, {
|
|
78
|
-
depth: 3,
|
|
79
|
-
colors: false,
|
|
80
|
-
maxStringLength: 120
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
function optionalObject(obj, condition) {
|
|
84
|
-
if (condition) {
|
|
85
|
-
return obj;
|
|
86
|
-
}
|
|
87
|
-
return {};
|
|
88
|
-
}
|
|
89
|
-
var init_json = __esm({
|
|
90
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/json.js"() {
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/provider.js
|
|
95
|
-
function sanitizePropertyKey(name) {
|
|
96
|
-
return name.replace(/[@.,/\\:;!?#$%^&*()[\]{}]/g, "_").substring(0, 64);
|
|
97
|
-
}
|
|
98
|
-
var createGoogleCompatibleJSONSchema;
|
|
99
|
-
var init_provider = __esm({
|
|
100
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/provider.js"() {
|
|
101
|
-
init_config();
|
|
102
|
-
init_json();
|
|
103
|
-
createGoogleCompatibleJSONSchema = (schema) => {
|
|
104
|
-
if (!GEMINI_PREFERRED_FORMAT) {
|
|
105
|
-
return schema;
|
|
106
|
-
}
|
|
107
|
-
const { oneOf: _oneOf, allOf: _allOf, anyOf: _anyOf, ...cleanSchema } = schema;
|
|
108
|
-
const removeAdditionalProperties = (obj) => {
|
|
109
|
-
if (Array.isArray(obj)) {
|
|
110
|
-
return obj.map(removeAdditionalProperties);
|
|
111
|
-
}
|
|
112
|
-
if (obj && typeof obj === "object") {
|
|
113
|
-
const result = {};
|
|
114
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
115
|
-
if (key !== "additionalProperties") {
|
|
116
|
-
result[key] = removeAdditionalProperties(value);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return result;
|
|
120
|
-
}
|
|
121
|
-
return obj;
|
|
122
|
-
};
|
|
123
|
-
return removeAdditionalProperties(cleanSchema);
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/logger.js
|
|
129
|
-
function createLogger(name, server) {
|
|
130
|
-
return new MCPLogger(name, server);
|
|
131
|
-
}
|
|
132
|
-
var LOG_LEVELS, MCPLogger, logger;
|
|
133
|
-
var init_logger = __esm({
|
|
134
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/utils/logger.js"() {
|
|
135
|
-
LOG_LEVELS = {
|
|
136
|
-
debug: 0,
|
|
137
|
-
info: 1,
|
|
138
|
-
notice: 2,
|
|
139
|
-
warning: 3,
|
|
140
|
-
error: 4,
|
|
141
|
-
critical: 5,
|
|
142
|
-
alert: 6,
|
|
143
|
-
emergency: 7
|
|
144
|
-
};
|
|
145
|
-
MCPLogger = class _MCPLogger {
|
|
146
|
-
server;
|
|
147
|
-
loggerName;
|
|
148
|
-
minLevel = "debug";
|
|
149
|
-
constructor(loggerName = "mcpc", server) {
|
|
150
|
-
this.loggerName = loggerName;
|
|
151
|
-
this.server = server;
|
|
152
|
-
}
|
|
153
|
-
setServer(server) {
|
|
154
|
-
this.server = server;
|
|
155
|
-
}
|
|
156
|
-
setLevel(level) {
|
|
157
|
-
this.minLevel = level;
|
|
158
|
-
}
|
|
159
|
-
async log(level, data) {
|
|
160
|
-
if (LOG_LEVELS[level] < LOG_LEVELS[this.minLevel]) {
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
|
-
this.logToConsole(level, data);
|
|
164
|
-
if (this.server) {
|
|
165
|
-
try {
|
|
166
|
-
await this.server.sendLoggingMessage({
|
|
167
|
-
level,
|
|
168
|
-
logger: this.loggerName,
|
|
169
|
-
data
|
|
170
|
-
});
|
|
171
|
-
} catch {
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
logToConsole(level, data) {
|
|
176
|
-
const message = typeof data === "string" ? data : JSON.stringify(data);
|
|
177
|
-
const prefix = `[${this.loggerName}:${level}]`;
|
|
178
|
-
console.error(prefix, message);
|
|
179
|
-
}
|
|
180
|
-
debug(data) {
|
|
181
|
-
return this.log("debug", data);
|
|
182
|
-
}
|
|
183
|
-
info(data) {
|
|
184
|
-
return this.log("info", data);
|
|
185
|
-
}
|
|
186
|
-
notice(data) {
|
|
187
|
-
return this.log("notice", data);
|
|
188
|
-
}
|
|
189
|
-
warning(data) {
|
|
190
|
-
return this.log("warning", data);
|
|
191
|
-
}
|
|
192
|
-
error(data) {
|
|
193
|
-
return this.log("error", data);
|
|
194
|
-
}
|
|
195
|
-
critical(data) {
|
|
196
|
-
return this.log("critical", data);
|
|
197
|
-
}
|
|
198
|
-
alert(data) {
|
|
199
|
-
return this.log("alert", data);
|
|
200
|
-
}
|
|
201
|
-
emergency(data) {
|
|
202
|
-
return this.log("emergency", data);
|
|
203
|
-
}
|
|
204
|
-
child(name) {
|
|
205
|
-
const child = new _MCPLogger(`${this.loggerName}.${name}`, this.server);
|
|
206
|
-
child.setLevel(this.minLevel);
|
|
207
|
-
return child;
|
|
208
|
-
}
|
|
209
|
-
};
|
|
210
|
-
logger = new MCPLogger("mcpc");
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/config-plugin.js
|
|
215
|
-
var createConfigPlugin, config_plugin_default;
|
|
216
|
-
var init_config_plugin = __esm({
|
|
217
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/config-plugin.js"() {
|
|
218
|
-
createConfigPlugin = () => ({
|
|
219
|
-
name: "built-in-config",
|
|
220
|
-
version: "1.0.0",
|
|
221
|
-
enforce: "pre",
|
|
222
|
-
transformTool: (tool, context2) => {
|
|
223
|
-
const server = context2.server;
|
|
224
|
-
const config = server.findToolConfig?.(context2.toolName);
|
|
225
|
-
if (config?.description) {
|
|
226
|
-
tool.description = config.description;
|
|
227
|
-
}
|
|
228
|
-
return tool;
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
config_plugin_default = createConfigPlugin();
|
|
232
|
-
}
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/tool-name-mapping-plugin.js
|
|
236
|
-
var createToolNameMappingPlugin, tool_name_mapping_plugin_default;
|
|
237
|
-
var init_tool_name_mapping_plugin = __esm({
|
|
238
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/tool-name-mapping-plugin.js"() {
|
|
239
|
-
createToolNameMappingPlugin = () => ({
|
|
240
|
-
name: "built-in-tool-name-mapping",
|
|
241
|
-
version: "1.0.0",
|
|
242
|
-
enforce: "pre",
|
|
243
|
-
transformTool: (tool, context2) => {
|
|
244
|
-
const server = context2.server;
|
|
245
|
-
const toolName = context2.toolName;
|
|
246
|
-
const originalName = tool._originalName || toolName;
|
|
247
|
-
const dotNotation = originalName.replace(/_/g, ".");
|
|
248
|
-
const underscoreNotation = originalName.replace(/\./g, "_");
|
|
249
|
-
if (dotNotation !== originalName && server.toolNameMapping) {
|
|
250
|
-
server.toolNameMapping.set(dotNotation, toolName);
|
|
251
|
-
}
|
|
252
|
-
if (underscoreNotation !== originalName && server.toolNameMapping) {
|
|
253
|
-
server.toolNameMapping.set(underscoreNotation, toolName);
|
|
254
|
-
}
|
|
255
|
-
if (originalName !== toolName && server.toolNameMapping) {
|
|
256
|
-
server.toolNameMapping.set(originalName, toolName);
|
|
257
|
-
}
|
|
258
|
-
return tool;
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
tool_name_mapping_plugin_default = createToolNameMappingPlugin();
|
|
262
|
-
}
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/logging-plugin.js
|
|
266
|
-
var createLoggingPlugin, logging_plugin_default;
|
|
267
|
-
var init_logging_plugin = __esm({
|
|
268
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/logging-plugin.js"() {
|
|
269
|
-
init_logger();
|
|
270
|
-
createLoggingPlugin = (options = {}) => {
|
|
271
|
-
const { enabled = true, verbose = false, compact: compact2 = true } = options;
|
|
272
|
-
return {
|
|
273
|
-
name: "built-in-logging",
|
|
274
|
-
version: "1.0.0",
|
|
275
|
-
composeEnd: async (context2) => {
|
|
276
|
-
if (!enabled) return;
|
|
277
|
-
const logger2 = createLogger("mcpc.plugin.logging", context2.server);
|
|
278
|
-
if (compact2) {
|
|
279
|
-
const pluginCount = context2.pluginNames.length;
|
|
280
|
-
const { stats } = context2;
|
|
281
|
-
await logger2.info(`[${context2.toolName}] ${pluginCount} plugins \u2022 ${stats.publicTools} public \u2022 ${stats.hiddenTools} hidden`);
|
|
282
|
-
} else if (verbose) {
|
|
283
|
-
await logger2.info(`[${context2.toolName}] Composition complete`);
|
|
284
|
-
await logger2.info(` \u251C\u2500 Plugins: ${context2.pluginNames.join(", ")}`);
|
|
285
|
-
const { stats } = context2;
|
|
286
|
-
const server = context2.server;
|
|
287
|
-
const publicTools = Array.from(new Set(server.getPublicToolNames().map(String)));
|
|
288
|
-
const internalTools = Array.from(new Set(server.getInternalToolNames().map(String)));
|
|
289
|
-
const hiddenTools = Array.from(new Set(server.getHiddenToolNames().map(String)));
|
|
290
|
-
const normalInternal = internalTools.filter((name) => !hiddenTools.includes(name));
|
|
291
|
-
if (publicTools.length > 0) {
|
|
292
|
-
await logger2.info(` \u251C\u2500 Public: ${publicTools.join(", ")}`);
|
|
293
|
-
}
|
|
294
|
-
if (internalTools.length > 0) {
|
|
295
|
-
const parts = [];
|
|
296
|
-
if (normalInternal.length > 0) {
|
|
297
|
-
parts.push(normalInternal.join(", "));
|
|
298
|
-
}
|
|
299
|
-
if (hiddenTools.length > 0) {
|
|
300
|
-
parts.push(`(${hiddenTools.join(", ")})`);
|
|
301
|
-
}
|
|
302
|
-
await logger2.info(` \u251C\u2500 Internal: ${parts.join(", ")}`);
|
|
303
|
-
}
|
|
304
|
-
await logger2.info(` \u2514\u2500 Total: ${stats.totalTools} tools`);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
};
|
|
308
|
-
};
|
|
309
|
-
logging_plugin_default = createLoggingPlugin({
|
|
310
|
-
verbose: true,
|
|
311
|
-
compact: false
|
|
312
|
-
});
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/index.js
|
|
317
|
-
var built_in_exports = {};
|
|
318
|
-
__export(built_in_exports, {
|
|
319
|
-
createConfigPlugin: () => createConfigPlugin,
|
|
320
|
-
createLoggingPlugin: () => createLoggingPlugin,
|
|
321
|
-
createToolNameMappingPlugin: () => createToolNameMappingPlugin,
|
|
322
|
-
getBuiltInPlugins: () => getBuiltInPlugins
|
|
323
|
-
});
|
|
324
|
-
function getBuiltInPlugins() {
|
|
325
|
-
return [
|
|
326
|
-
tool_name_mapping_plugin_default,
|
|
327
|
-
config_plugin_default,
|
|
328
|
-
logging_plugin_default
|
|
329
|
-
];
|
|
330
|
-
}
|
|
331
|
-
var init_built_in = __esm({
|
|
332
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/index.js"() {
|
|
333
|
-
init_config_plugin();
|
|
334
|
-
init_tool_name_mapping_plugin();
|
|
335
|
-
init_logging_plugin();
|
|
336
|
-
init_config_plugin();
|
|
337
|
-
init_tool_name_mapping_plugin();
|
|
338
|
-
init_logging_plugin();
|
|
339
|
-
}
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/schema.js
|
|
343
|
-
import traverse from "json-schema-traverse";
|
|
344
|
-
function updateRefPaths(schema, wrapperPath) {
|
|
345
|
-
if (!schema || typeof schema !== "object") {
|
|
346
|
-
return schema;
|
|
347
|
-
}
|
|
348
|
-
if (!wrapperPath || typeof wrapperPath !== "string") {
|
|
349
|
-
throw new Error("wrapperPath must be a non-empty string");
|
|
350
|
-
}
|
|
351
|
-
const clonedSchema = JSON.parse(JSON.stringify(schema));
|
|
352
|
-
try {
|
|
353
|
-
traverse(clonedSchema, {
|
|
354
|
-
allKeys: true,
|
|
355
|
-
cb: function(schemaNode, _jsonPtr, _rootSchema, _parentJsonPtr, _parentKeyword, _parentSchema, _keyIndex) {
|
|
356
|
-
if (schemaNode && typeof schemaNode === "object" && schemaNode.$ref) {
|
|
357
|
-
const ref = schemaNode.$ref;
|
|
358
|
-
if (ref.startsWith("#/properties/")) {
|
|
359
|
-
const relativePath = ref.substring(13);
|
|
360
|
-
schemaNode.$ref = `#/properties/${wrapperPath}/properties/${relativePath}`;
|
|
361
|
-
} else if (ref === "#") {
|
|
362
|
-
schemaNode.$ref = `#/properties/${wrapperPath}`;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
} catch (error) {
|
|
368
|
-
console.warn(`Failed to traverse schema for path "${wrapperPath}":`, error);
|
|
369
|
-
return clonedSchema;
|
|
370
|
-
}
|
|
371
|
-
return clonedSchema;
|
|
372
|
-
}
|
|
373
|
-
var init_schema2 = __esm({
|
|
374
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/schema.js"() {
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/compose-helpers.js
|
|
379
|
-
var compose_helpers_exports = {};
|
|
380
|
-
__export(compose_helpers_exports, {
|
|
381
|
-
buildDependencyGroups: () => buildDependencyGroups,
|
|
382
|
-
processToolsWithPlugins: () => processToolsWithPlugins,
|
|
383
|
-
registerGlobalTools: () => registerGlobalTools
|
|
384
|
-
});
|
|
385
|
-
async function processToolsWithPlugins(server, externalTools, mode) {
|
|
386
|
-
const toolManager = server.toolManager;
|
|
387
|
-
const pluginManager = server.pluginManager;
|
|
388
|
-
for (const [toolId, toolData] of toolManager.getToolEntries()) {
|
|
389
|
-
const defaultSchema = {
|
|
390
|
-
type: "object",
|
|
391
|
-
properties: {},
|
|
392
|
-
additionalProperties: true
|
|
393
|
-
};
|
|
394
|
-
const tempTool = {
|
|
395
|
-
name: toolId,
|
|
396
|
-
description: toolData.description,
|
|
397
|
-
inputSchema: toolData.schema || defaultSchema,
|
|
398
|
-
execute: toolData.callback
|
|
399
|
-
};
|
|
400
|
-
const processedTool = await pluginManager.applyTransformToolHooks(tempTool, {
|
|
401
|
-
toolName: toolId,
|
|
402
|
-
server,
|
|
403
|
-
mode,
|
|
404
|
-
originalTool: {
|
|
405
|
-
...tempTool
|
|
406
|
-
},
|
|
407
|
-
transformationIndex: 0
|
|
408
|
-
});
|
|
409
|
-
toolManager.registerTool(toolId, processedTool.description || toolData.description, processedTool.inputSchema, processedTool.execute);
|
|
410
|
-
if (externalTools[toolId]) {
|
|
411
|
-
try {
|
|
412
|
-
const builtIn = await Promise.resolve().then(() => (init_built_in(), built_in_exports));
|
|
413
|
-
if (builtIn && typeof builtIn.processToolVisibility === "function") {
|
|
414
|
-
builtIn.processToolVisibility(toolId, processedTool, server, externalTools);
|
|
415
|
-
}
|
|
416
|
-
} catch {
|
|
417
|
-
}
|
|
418
|
-
externalTools[toolId] = processedTool;
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicToolNames, server) {
|
|
423
|
-
const depGroups = {};
|
|
424
|
-
const toolManager = server.toolManager;
|
|
425
|
-
toolNameToDetailList.forEach(([toolName, tool]) => {
|
|
426
|
-
const resolvedName = toolManager.resolveToolName(toolName);
|
|
427
|
-
if (hiddenToolNames.includes(resolvedName ?? "") || publicToolNames.includes(resolvedName ?? "")) {
|
|
428
|
-
return;
|
|
429
|
-
}
|
|
430
|
-
if (!tool) {
|
|
431
|
-
const allToolNames = [
|
|
432
|
-
...toolNameToDetailList.map(([n]) => n)
|
|
433
|
-
];
|
|
434
|
-
throw new Error(`Action ${toolName} not found, available action list: ${allToolNames.join(", ")}`);
|
|
435
|
-
}
|
|
436
|
-
const baseSchema = tool.inputSchema.jsonSchema ?? tool.inputSchema ?? {
|
|
437
|
-
type: "object",
|
|
438
|
-
properties: {},
|
|
439
|
-
required: []
|
|
440
|
-
};
|
|
441
|
-
const baseProperties = baseSchema.type === "object" && baseSchema.properties ? baseSchema.properties : {};
|
|
442
|
-
const baseRequired = baseSchema.type === "object" && Array.isArray(baseSchema.required) ? baseSchema.required : [];
|
|
443
|
-
const updatedProperties = updateRefPaths(baseProperties, toolName);
|
|
444
|
-
const sanitizedKey = sanitizePropertyKey(toolName);
|
|
445
|
-
depGroups[sanitizedKey] = {
|
|
446
|
-
type: "object",
|
|
447
|
-
description: tool.description,
|
|
448
|
-
properties: updatedProperties,
|
|
449
|
-
required: [
|
|
450
|
-
...baseRequired
|
|
451
|
-
],
|
|
452
|
-
additionalProperties: false
|
|
453
|
-
};
|
|
454
|
-
});
|
|
455
|
-
return depGroups;
|
|
456
|
-
}
|
|
457
|
-
function registerGlobalTools(globalToolNames, tools, server) {
|
|
458
|
-
globalToolNames.forEach((toolId) => {
|
|
459
|
-
const tool = tools[toolId];
|
|
460
|
-
if (!tool) {
|
|
461
|
-
throw new Error(`Global tool ${toolId} not found in registry, available: ${Object.keys(tools).join(", ")}`);
|
|
462
|
-
}
|
|
463
|
-
server.tool(toolId, tool.description || "No description available", jsonSchema(tool.inputSchema), tool.execute);
|
|
464
|
-
});
|
|
465
|
-
}
|
|
466
|
-
var init_compose_helpers = __esm({
|
|
467
|
-
"__mcpc__core_latest/node_modules/@mcpc/core/src/utils/compose-helpers.js"() {
|
|
468
|
-
init_schema2();
|
|
469
|
-
init_schema();
|
|
470
|
-
init_provider();
|
|
471
|
-
}
|
|
472
|
-
});
|
|
473
33
|
|
|
474
34
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/compose.js
|
|
475
|
-
init_schema();
|
|
476
|
-
import { CallToolRequestSchema, ListToolsRequestSchema, SetLevelRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
477
35
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
478
36
|
|
|
479
37
|
// __mcpc__core_latest/node_modules/@jsr/mcpc__utils/src/json.js
|
|
@@ -672,20 +230,86 @@ function smitheryToolNameCompatibale(name, scope) {
|
|
|
672
230
|
};
|
|
673
231
|
}
|
|
674
232
|
|
|
675
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
233
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/config.js
|
|
234
|
+
import process2 from "node:process";
|
|
235
|
+
var GEMINI_PREFERRED_FORMAT = process2.env.GEMINI_PREFERRED_FORMAT === "0" ? false : true;
|
|
236
|
+
|
|
237
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/json.js
|
|
238
|
+
import { jsonrepair as jsonrepair2 } from "jsonrepair";
|
|
239
|
+
import { inspect } from "node:util";
|
|
240
|
+
function parseJSON2(text, throwError) {
|
|
241
|
+
try {
|
|
242
|
+
return JSON.parse(text);
|
|
243
|
+
} catch (_error) {
|
|
244
|
+
try {
|
|
245
|
+
const repairedText = jsonrepair2(text);
|
|
246
|
+
console.warn(`Failed to parse JSON, attempting to repair, result: ${text}`);
|
|
247
|
+
if (throwError) {
|
|
248
|
+
throw _error;
|
|
249
|
+
}
|
|
250
|
+
return JSON.parse(repairedText);
|
|
251
|
+
} catch {
|
|
252
|
+
if (throwError) {
|
|
253
|
+
throw new Error("Failed to parse repaired JSON");
|
|
254
|
+
}
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
function truncateJSON(obj) {
|
|
260
|
+
return inspect(obj, {
|
|
261
|
+
depth: 3,
|
|
262
|
+
colors: false,
|
|
263
|
+
maxStringLength: 120
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
function optionalObject(obj, condition) {
|
|
267
|
+
if (condition) {
|
|
268
|
+
return obj;
|
|
269
|
+
}
|
|
270
|
+
return {};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/provider.js
|
|
274
|
+
function sanitizePropertyKey(name) {
|
|
275
|
+
return name.replace(/[@.,/\\:;!?#$%^&*()[\]{}]/g, "_").substring(0, 64);
|
|
276
|
+
}
|
|
277
|
+
var createGoogleCompatibleJSONSchema = (schema) => {
|
|
278
|
+
if (!GEMINI_PREFERRED_FORMAT) {
|
|
279
|
+
return schema;
|
|
280
|
+
}
|
|
281
|
+
const { oneOf: _oneOf, allOf: _allOf, anyOf: _anyOf, ...cleanSchema } = schema;
|
|
282
|
+
const removeAdditionalProperties = (obj) => {
|
|
283
|
+
if (Array.isArray(obj)) {
|
|
284
|
+
return obj.map(removeAdditionalProperties);
|
|
285
|
+
}
|
|
286
|
+
if (obj && typeof obj === "object") {
|
|
287
|
+
const result = {};
|
|
288
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
289
|
+
if (key !== "additionalProperties") {
|
|
290
|
+
result[key] = removeAdditionalProperties(value);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
return result;
|
|
294
|
+
}
|
|
295
|
+
return obj;
|
|
296
|
+
};
|
|
297
|
+
return removeAdditionalProperties(cleanSchema);
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/mcp.js
|
|
301
|
+
import { cwd } from "node:process";
|
|
302
|
+
import process3 from "node:process";
|
|
303
|
+
import { createHash } from "node:crypto";
|
|
304
|
+
var mcpClientPool = /* @__PURE__ */ new Map();
|
|
305
|
+
var mcpClientConnecting = /* @__PURE__ */ new Map();
|
|
306
|
+
var shortHash = (s) => createHash("sha256").update(s).digest("hex").slice(0, 8);
|
|
307
|
+
function defSignature(def) {
|
|
308
|
+
const defCopy = {
|
|
309
|
+
...def
|
|
310
|
+
};
|
|
311
|
+
if (defCopy.transportType === "memory" || defCopy.transport) {
|
|
312
|
+
return `memory:${Date.now()}:${Math.random()}`;
|
|
689
313
|
}
|
|
690
314
|
return JSON.stringify(defCopy);
|
|
691
315
|
}
|
|
@@ -859,9 +483,208 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
859
483
|
};
|
|
860
484
|
}
|
|
861
485
|
|
|
862
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/
|
|
863
|
-
|
|
864
|
-
|
|
486
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/tool-tag-processor.js
|
|
487
|
+
var ALL_TOOLS_PLACEHOLDER = "__ALL__";
|
|
488
|
+
function findToolId(toolName, tools, toolNameMapping) {
|
|
489
|
+
const mappedId = toolNameMapping?.get(toolName);
|
|
490
|
+
if (mappedId) {
|
|
491
|
+
return mappedId;
|
|
492
|
+
}
|
|
493
|
+
return Object.keys(tools).find((id) => {
|
|
494
|
+
const dotNotation = id.replace(/_/g, ".");
|
|
495
|
+
return toolName === id || toolName === dotNotation;
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
function processToolTags({ description, tagToResults, $, tools, toolOverrides, toolNameMapping }) {
|
|
499
|
+
tagToResults.tool.forEach((toolEl) => {
|
|
500
|
+
const toolName = toolEl.attribs.name;
|
|
501
|
+
if (!toolName || toolName.includes(ALL_TOOLS_PLACEHOLDER)) {
|
|
502
|
+
$(toolEl).remove();
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
const override = toolOverrides.get(toolName);
|
|
506
|
+
if (override?.visibility?.hidden) {
|
|
507
|
+
$(toolEl).remove();
|
|
508
|
+
} else if (override?.visibility?.public) {
|
|
509
|
+
$(toolEl).replaceWith(`<tool name="${toolName}"/>`);
|
|
510
|
+
} else {
|
|
511
|
+
const toolId = findToolId(toolName, tools, toolNameMapping);
|
|
512
|
+
if (toolId) {
|
|
513
|
+
$(toolEl).replaceWith(`<action action="${toolId}"/>`);
|
|
514
|
+
} else {
|
|
515
|
+
$(toolEl).remove();
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
return $.root().html() ?? description;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/config-plugin.js
|
|
523
|
+
var createConfigPlugin = () => ({
|
|
524
|
+
name: "built-in-config",
|
|
525
|
+
version: "1.0.0",
|
|
526
|
+
enforce: "pre",
|
|
527
|
+
transformTool: (tool, context2) => {
|
|
528
|
+
const server = context2.server;
|
|
529
|
+
const config = server.findToolConfig?.(context2.toolName);
|
|
530
|
+
if (config?.description) {
|
|
531
|
+
tool.description = config.description;
|
|
532
|
+
}
|
|
533
|
+
return tool;
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
var config_plugin_default = createConfigPlugin();
|
|
537
|
+
|
|
538
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/tool-name-mapping-plugin.js
|
|
539
|
+
var createToolNameMappingPlugin = () => ({
|
|
540
|
+
name: "built-in-tool-name-mapping",
|
|
541
|
+
version: "1.0.0",
|
|
542
|
+
enforce: "pre",
|
|
543
|
+
transformTool: (tool, context2) => {
|
|
544
|
+
const server = context2.server;
|
|
545
|
+
const toolName = context2.toolName;
|
|
546
|
+
const originalName = tool._originalName || toolName;
|
|
547
|
+
const dotNotation = originalName.replace(/_/g, ".");
|
|
548
|
+
const underscoreNotation = originalName.replace(/\./g, "_");
|
|
549
|
+
if (dotNotation !== originalName && server.toolNameMapping) {
|
|
550
|
+
server.toolNameMapping.set(dotNotation, toolName);
|
|
551
|
+
}
|
|
552
|
+
if (underscoreNotation !== originalName && server.toolNameMapping) {
|
|
553
|
+
server.toolNameMapping.set(underscoreNotation, toolName);
|
|
554
|
+
}
|
|
555
|
+
if (originalName !== toolName && server.toolNameMapping) {
|
|
556
|
+
server.toolNameMapping.set(originalName, toolName);
|
|
557
|
+
}
|
|
558
|
+
return tool;
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
var tool_name_mapping_plugin_default = createToolNameMappingPlugin();
|
|
562
|
+
|
|
563
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/logger.js
|
|
564
|
+
var LOG_LEVELS = {
|
|
565
|
+
debug: 0,
|
|
566
|
+
info: 1,
|
|
567
|
+
notice: 2,
|
|
568
|
+
warning: 3,
|
|
569
|
+
error: 4,
|
|
570
|
+
critical: 5,
|
|
571
|
+
alert: 6,
|
|
572
|
+
emergency: 7
|
|
573
|
+
};
|
|
574
|
+
var MCPLogger = class _MCPLogger {
|
|
575
|
+
server;
|
|
576
|
+
loggerName;
|
|
577
|
+
minLevel = "debug";
|
|
578
|
+
constructor(loggerName = "mcpc", server) {
|
|
579
|
+
this.loggerName = loggerName;
|
|
580
|
+
this.server = server;
|
|
581
|
+
}
|
|
582
|
+
setServer(server) {
|
|
583
|
+
this.server = server;
|
|
584
|
+
}
|
|
585
|
+
setLevel(level) {
|
|
586
|
+
this.minLevel = level;
|
|
587
|
+
}
|
|
588
|
+
async log(level, data) {
|
|
589
|
+
if (LOG_LEVELS[level] < LOG_LEVELS[this.minLevel]) {
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
this.logToConsole(level, data);
|
|
593
|
+
if (this.server) {
|
|
594
|
+
try {
|
|
595
|
+
await this.server.sendLoggingMessage({
|
|
596
|
+
level,
|
|
597
|
+
logger: this.loggerName,
|
|
598
|
+
data
|
|
599
|
+
});
|
|
600
|
+
} catch {
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
logToConsole(level, data) {
|
|
605
|
+
const message = typeof data === "string" ? data : JSON.stringify(data);
|
|
606
|
+
const prefix = `[${this.loggerName}:${level}]`;
|
|
607
|
+
console.error(prefix, message);
|
|
608
|
+
}
|
|
609
|
+
debug(data) {
|
|
610
|
+
return this.log("debug", data);
|
|
611
|
+
}
|
|
612
|
+
info(data) {
|
|
613
|
+
return this.log("info", data);
|
|
614
|
+
}
|
|
615
|
+
notice(data) {
|
|
616
|
+
return this.log("notice", data);
|
|
617
|
+
}
|
|
618
|
+
warning(data) {
|
|
619
|
+
return this.log("warning", data);
|
|
620
|
+
}
|
|
621
|
+
error(data) {
|
|
622
|
+
return this.log("error", data);
|
|
623
|
+
}
|
|
624
|
+
critical(data) {
|
|
625
|
+
return this.log("critical", data);
|
|
626
|
+
}
|
|
627
|
+
alert(data) {
|
|
628
|
+
return this.log("alert", data);
|
|
629
|
+
}
|
|
630
|
+
emergency(data) {
|
|
631
|
+
return this.log("emergency", data);
|
|
632
|
+
}
|
|
633
|
+
child(name) {
|
|
634
|
+
const child = new _MCPLogger(`${this.loggerName}.${name}`, this.server);
|
|
635
|
+
child.setLevel(this.minLevel);
|
|
636
|
+
return child;
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
var logger = new MCPLogger("mcpc");
|
|
640
|
+
function createLogger(name, server) {
|
|
641
|
+
return new MCPLogger(name, server);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/logging-plugin.js
|
|
645
|
+
var createLoggingPlugin = (options = {}) => {
|
|
646
|
+
const { enabled = true, verbose = false, compact: compact2 = true } = options;
|
|
647
|
+
return {
|
|
648
|
+
name: "built-in-logging",
|
|
649
|
+
version: "1.0.0",
|
|
650
|
+
composeEnd: async (context2) => {
|
|
651
|
+
if (!enabled) return;
|
|
652
|
+
const logger2 = createLogger("mcpc.plugin.logging", context2.server);
|
|
653
|
+
if (compact2) {
|
|
654
|
+
const pluginCount = context2.pluginNames.length;
|
|
655
|
+
const { stats } = context2;
|
|
656
|
+
await logger2.info(`[${context2.toolName}] ${pluginCount} plugins \u2022 ${stats.publicTools} public \u2022 ${stats.hiddenTools} hidden`);
|
|
657
|
+
} else if (verbose) {
|
|
658
|
+
await logger2.info(`[${context2.toolName}] Composition complete`);
|
|
659
|
+
await logger2.info(` \u251C\u2500 Plugins: ${context2.pluginNames.join(", ")}`);
|
|
660
|
+
const { stats } = context2;
|
|
661
|
+
const server = context2.server;
|
|
662
|
+
const publicTools = Array.from(new Set(server.getPublicToolNames().map(String)));
|
|
663
|
+
const internalTools = Array.from(new Set(server.getInternalToolNames().map(String)));
|
|
664
|
+
const hiddenTools = Array.from(new Set(server.getHiddenToolNames().map(String)));
|
|
665
|
+
const normalInternal = internalTools.filter((name) => !hiddenTools.includes(name));
|
|
666
|
+
if (publicTools.length > 0) {
|
|
667
|
+
await logger2.info(` \u251C\u2500 Public: ${publicTools.join(", ")}`);
|
|
668
|
+
}
|
|
669
|
+
if (internalTools.length > 0) {
|
|
670
|
+
const parts = [];
|
|
671
|
+
if (normalInternal.length > 0) {
|
|
672
|
+
parts.push(normalInternal.join(", "));
|
|
673
|
+
}
|
|
674
|
+
if (hiddenTools.length > 0) {
|
|
675
|
+
parts.push(`(${hiddenTools.join(", ")})`);
|
|
676
|
+
}
|
|
677
|
+
await logger2.info(` \u251C\u2500 Internal: ${parts.join(", ")}`);
|
|
678
|
+
}
|
|
679
|
+
await logger2.info(` \u2514\u2500 Total: ${stats.totalTools} tools`);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
};
|
|
684
|
+
var logging_plugin_default = createLoggingPlugin({
|
|
685
|
+
verbose: true,
|
|
686
|
+
compact: false
|
|
687
|
+
});
|
|
865
688
|
|
|
866
689
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/prompts/index.js
|
|
867
690
|
var SystemPrompts = {
|
|
@@ -1199,11 +1022,28 @@ ${JSON.stringify(steps, null, 2)}`;
|
|
|
1199
1022
|
}
|
|
1200
1023
|
};
|
|
1201
1024
|
|
|
1202
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/
|
|
1025
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/schema-validator.js
|
|
1203
1026
|
import { Ajv } from "ajv";
|
|
1204
|
-
import { AggregateAjvError } from "@segment/ajv-human-errors";
|
|
1205
1027
|
import addFormats from "ajv-formats";
|
|
1206
|
-
|
|
1028
|
+
import { AggregateAjvError } from "@segment/ajv-human-errors";
|
|
1029
|
+
var ajv = new Ajv({
|
|
1030
|
+
allErrors: true,
|
|
1031
|
+
verbose: true
|
|
1032
|
+
});
|
|
1033
|
+
addFormats.default(ajv);
|
|
1034
|
+
function validateSchema(args, schema) {
|
|
1035
|
+
const validate = ajv.compile(schema);
|
|
1036
|
+
if (!validate(args)) {
|
|
1037
|
+
const errors = new AggregateAjvError(validate.errors);
|
|
1038
|
+
return {
|
|
1039
|
+
valid: false,
|
|
1040
|
+
error: errors.message
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
return {
|
|
1044
|
+
valid: true
|
|
1045
|
+
};
|
|
1046
|
+
}
|
|
1207
1047
|
|
|
1208
1048
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/tracing.js
|
|
1209
1049
|
import { context, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
@@ -1274,11 +1114,6 @@ function endSpan(span, error) {
|
|
|
1274
1114
|
|
|
1275
1115
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/agentic/agentic-executor.js
|
|
1276
1116
|
import process4 from "node:process";
|
|
1277
|
-
var ajv = new Ajv({
|
|
1278
|
-
allErrors: true,
|
|
1279
|
-
verbose: true
|
|
1280
|
-
});
|
|
1281
|
-
addFormats(ajv);
|
|
1282
1117
|
var AgenticExecutor = class {
|
|
1283
1118
|
name;
|
|
1284
1119
|
allToolNames;
|
|
@@ -1386,7 +1221,8 @@ var AgenticExecutor = class {
|
|
|
1386
1221
|
currentResult?.content?.push({
|
|
1387
1222
|
type: "text",
|
|
1388
1223
|
text: CompiledPrompts.planningPrompt({
|
|
1389
|
-
currentAction: actionName
|
|
1224
|
+
currentAction: actionName,
|
|
1225
|
+
toolName: this.name
|
|
1390
1226
|
})
|
|
1391
1227
|
});
|
|
1392
1228
|
}
|
|
@@ -1432,7 +1268,8 @@ var AgenticExecutor = class {
|
|
|
1432
1268
|
callToolResult.content.push({
|
|
1433
1269
|
type: "text",
|
|
1434
1270
|
text: CompiledPrompts.planningPrompt({
|
|
1435
|
-
currentAction: actionName
|
|
1271
|
+
currentAction: actionName,
|
|
1272
|
+
toolName: this.name
|
|
1436
1273
|
})
|
|
1437
1274
|
});
|
|
1438
1275
|
}
|
|
@@ -1513,17 +1350,7 @@ var AgenticExecutor = class {
|
|
|
1513
1350
|
valid: true
|
|
1514
1351
|
};
|
|
1515
1352
|
}
|
|
1516
|
-
|
|
1517
|
-
if (!validate(args)) {
|
|
1518
|
-
const errors = new AggregateAjvError(validate.errors);
|
|
1519
|
-
return {
|
|
1520
|
-
valid: false,
|
|
1521
|
-
error: errors.message
|
|
1522
|
-
};
|
|
1523
|
-
}
|
|
1524
|
-
return {
|
|
1525
|
-
valid: true
|
|
1526
|
-
};
|
|
1353
|
+
return validateSchema(args, schema);
|
|
1527
1354
|
}
|
|
1528
1355
|
};
|
|
1529
1356
|
|
|
@@ -1849,1025 +1676,1082 @@ NOTE: The \`steps\` has been predefined` : `**You MUST execute this tool with fo
|
|
|
1849
1676
|
};
|
|
1850
1677
|
}
|
|
1851
1678
|
|
|
1852
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1679
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/agentic/agentic-tool-registrar.js
|
|
1680
|
+
function registerAgenticTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList }) {
|
|
1681
|
+
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
1682
|
+
const agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server);
|
|
1683
|
+
description = CompiledPrompts.autonomousExecution({
|
|
1684
|
+
toolName: name,
|
|
1685
|
+
description
|
|
1686
|
+
});
|
|
1687
|
+
const agenticArgsDef = createArgsDef.forAgentic(toolNameToDetailList, false);
|
|
1688
|
+
const argsDef = agenticArgsDef;
|
|
1689
|
+
const schema = allToolNames.length > 0 ? argsDef : {
|
|
1690
|
+
type: "object",
|
|
1691
|
+
properties: {}
|
|
1692
|
+
};
|
|
1693
|
+
server.tool(name, description, jsonSchema(createGoogleCompatibleJSONSchema(schema)), async (args) => {
|
|
1694
|
+
return await agenticExecutor.execute(args, schema);
|
|
1695
|
+
});
|
|
1696
|
+
}
|
|
1697
|
+
|
|
1698
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-agentic-plugin.js
|
|
1699
|
+
var createAgenticModePlugin = () => ({
|
|
1700
|
+
name: "mode-agentic",
|
|
1701
|
+
version: "1.0.0",
|
|
1702
|
+
// Only apply to agentic mode
|
|
1703
|
+
apply: "agentic",
|
|
1704
|
+
// Register the agent tool
|
|
1705
|
+
registerAgentTool: (context2) => {
|
|
1706
|
+
registerAgenticTool(context2.server, {
|
|
1707
|
+
description: context2.description,
|
|
1708
|
+
name: context2.name,
|
|
1709
|
+
allToolNames: context2.allToolNames,
|
|
1710
|
+
depGroups: context2.depGroups,
|
|
1711
|
+
toolNameToDetailList: context2.toolNameToDetailList
|
|
1712
|
+
});
|
|
1713
|
+
}
|
|
1861
1714
|
});
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
this.name = name;
|
|
1877
|
-
this.description = description;
|
|
1878
|
-
this.allToolNames = allToolNames;
|
|
1879
|
-
this.toolNameToDetailList = toolNameToDetailList;
|
|
1880
|
-
this.server = server;
|
|
1881
|
-
this.conversationHistory = [];
|
|
1882
|
-
this.maxIterations = 55;
|
|
1883
|
-
this.currentIteration = 0;
|
|
1884
|
-
this.tracingEnabled = false;
|
|
1885
|
-
this.summarize = true;
|
|
1886
|
-
if (config?.maxIterations) {
|
|
1887
|
-
this.maxIterations = config.maxIterations;
|
|
1888
|
-
}
|
|
1889
|
-
if (config?.summarize !== void 0) {
|
|
1890
|
-
this.summarize = config.summarize;
|
|
1891
|
-
}
|
|
1892
|
-
this.logger = createLogger(`mcpc.sampling.${name}`, server);
|
|
1893
|
-
try {
|
|
1894
|
-
const tracingConfig = {
|
|
1895
|
-
enabled: process5.env.MCPC_TRACING_ENABLED === "true",
|
|
1896
|
-
serviceName: `mcpc-sampling-${name}`,
|
|
1897
|
-
exportTo: process5.env.MCPC_TRACING_EXPORT ?? "otlp",
|
|
1898
|
-
otlpEndpoint: process5.env.MCPC_TRACING_OTLP_ENDPOINT ?? "http://localhost:4318/v1/traces"
|
|
1899
|
-
};
|
|
1900
|
-
this.tracingEnabled = tracingConfig.enabled;
|
|
1901
|
-
if (this.tracingEnabled) {
|
|
1902
|
-
initializeTracing(tracingConfig);
|
|
1903
|
-
}
|
|
1904
|
-
} catch {
|
|
1905
|
-
this.tracingEnabled = false;
|
|
1715
|
+
var mode_agentic_plugin_default = createAgenticModePlugin();
|
|
1716
|
+
|
|
1717
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/state.js
|
|
1718
|
+
var WorkflowState = class {
|
|
1719
|
+
currentStepIndex = -1;
|
|
1720
|
+
steps = [];
|
|
1721
|
+
stepStatuses = [];
|
|
1722
|
+
stepResults = [];
|
|
1723
|
+
stepErrors = [];
|
|
1724
|
+
isInitialized = false;
|
|
1725
|
+
isStarted = false;
|
|
1726
|
+
constructor(steps) {
|
|
1727
|
+
if (steps) {
|
|
1728
|
+
this.initialize(steps);
|
|
1906
1729
|
}
|
|
1907
1730
|
}
|
|
1908
|
-
|
|
1909
|
-
this.
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
maxIterations: this.maxIterations,
|
|
1921
|
-
systemPrompt: systemPrompt()
|
|
1922
|
-
}) : null;
|
|
1923
|
-
try {
|
|
1924
|
-
for (this.currentIteration = 0; this.currentIteration < this.maxIterations; this.currentIteration++) {
|
|
1925
|
-
let iterationSpan = null;
|
|
1926
|
-
try {
|
|
1927
|
-
const response = await this.server.createMessage({
|
|
1928
|
-
systemPrompt: systemPrompt(),
|
|
1929
|
-
messages: this.conversationHistory,
|
|
1930
|
-
maxTokens: 55e3
|
|
1931
|
-
});
|
|
1932
|
-
const responseContent = response.content.text || "{}";
|
|
1933
|
-
const model = response.model;
|
|
1934
|
-
const stopReason = response.stopReason;
|
|
1935
|
-
const role = response.role;
|
|
1936
|
-
let parsedData;
|
|
1937
|
-
try {
|
|
1938
|
-
parsedData = parseJSON(responseContent.trim(), true);
|
|
1939
|
-
} catch (parseError) {
|
|
1940
|
-
iterationSpan = this.tracingEnabled ? startSpan("mcpc.sampling_iteration.parse_error", {
|
|
1941
|
-
iteration: this.currentIteration + 1,
|
|
1942
|
-
agent: this.name,
|
|
1943
|
-
error: String(parseError),
|
|
1944
|
-
maxIterations: this.maxIterations
|
|
1945
|
-
}, loopSpan ?? void 0) : null;
|
|
1946
|
-
this.addParsingErrorToHistory(responseContent, parseError);
|
|
1947
|
-
if (iterationSpan) endSpan(iterationSpan);
|
|
1948
|
-
continue;
|
|
1949
|
-
}
|
|
1950
|
-
this.conversationHistory.push({
|
|
1951
|
-
role: "assistant",
|
|
1952
|
-
content: {
|
|
1953
|
-
type: "text",
|
|
1954
|
-
text: JSON.stringify(parsedData, null, 2)
|
|
1955
|
-
}
|
|
1956
|
-
});
|
|
1957
|
-
const action = parsedData["action"];
|
|
1958
|
-
const decision = parsedData["decision"];
|
|
1959
|
-
if (typeof decision !== "string") {
|
|
1960
|
-
this.conversationHistory.push({
|
|
1961
|
-
role: "user",
|
|
1962
|
-
content: {
|
|
1963
|
-
type: "text",
|
|
1964
|
-
text: 'Missing required field "decision". Provide: {"action":"<tool>","decision":"proceed|retry","<tool>":{}} or {"decision":"complete"}'
|
|
1965
|
-
}
|
|
1966
|
-
});
|
|
1967
|
-
if (iterationSpan) endSpan(iterationSpan);
|
|
1968
|
-
continue;
|
|
1969
|
-
}
|
|
1970
|
-
if (decision === "complete" && action) {
|
|
1971
|
-
this.conversationHistory.push({
|
|
1972
|
-
role: "user",
|
|
1973
|
-
content: {
|
|
1974
|
-
type: "text",
|
|
1975
|
-
text: 'Invalid: Cannot have both "decision":"complete" and "action" field. When complete, only provide {"decision":"complete"}.'
|
|
1976
|
-
}
|
|
1977
|
-
});
|
|
1978
|
-
if (iterationSpan) endSpan(iterationSpan);
|
|
1979
|
-
continue;
|
|
1980
|
-
}
|
|
1981
|
-
if (decision !== "complete" && !action) {
|
|
1982
|
-
this.conversationHistory.push({
|
|
1983
|
-
role: "user",
|
|
1984
|
-
content: {
|
|
1985
|
-
type: "text",
|
|
1986
|
-
text: 'Missing required field "action". When executing, provide: {"action":"<tool>","decision":"proceed|retry","<tool>":{}}'
|
|
1987
|
-
}
|
|
1988
|
-
});
|
|
1989
|
-
if (iterationSpan) endSpan(iterationSpan);
|
|
1990
|
-
continue;
|
|
1991
|
-
}
|
|
1992
|
-
const actionStr = decision === "complete" ? "completion" : action && typeof action === "string" ? String(action) : "unknown_action";
|
|
1993
|
-
const spanName = `mcpc.sampling_iteration.${actionStr}`;
|
|
1994
|
-
iterationSpan = this.tracingEnabled ? startSpan(spanName, {
|
|
1995
|
-
iteration: this.currentIteration + 1,
|
|
1996
|
-
agent: this.name,
|
|
1997
|
-
action: actionStr,
|
|
1998
|
-
systemPrompt: systemPrompt(),
|
|
1999
|
-
maxTokens: String(Number.MAX_SAFE_INTEGER),
|
|
2000
|
-
maxIterations: this.maxIterations,
|
|
2001
|
-
messages: JSON.stringify(this.conversationHistory)
|
|
2002
|
-
}, loopSpan ?? void 0) : null;
|
|
2003
|
-
const result = await this.processAction(parsedData, schema, state, iterationSpan);
|
|
2004
|
-
this.logIterationProgress(parsedData, result, model, stopReason, role);
|
|
2005
|
-
if (iterationSpan) {
|
|
2006
|
-
let rawJson = "{}";
|
|
2007
|
-
try {
|
|
2008
|
-
rawJson = parsedData ? JSON.stringify(parsedData) : "{}";
|
|
2009
|
-
} catch {
|
|
2010
|
-
}
|
|
2011
|
-
const attr = {
|
|
2012
|
-
isError: !!result.isError,
|
|
2013
|
-
isComplete: !!result.isComplete,
|
|
2014
|
-
iteration: this.currentIteration + 1,
|
|
2015
|
-
maxIterations: this.maxIterations,
|
|
2016
|
-
parsed: rawJson,
|
|
2017
|
-
action: typeof action === "string" ? action : String(action),
|
|
2018
|
-
decision: typeof decision === "string" ? decision : String(decision),
|
|
2019
|
-
samplingResponse: responseContent,
|
|
2020
|
-
toolResult: JSON.stringify(result),
|
|
2021
|
-
model,
|
|
2022
|
-
role
|
|
2023
|
-
};
|
|
2024
|
-
if (stopReason) {
|
|
2025
|
-
attr.stopReason = stopReason;
|
|
2026
|
-
}
|
|
2027
|
-
iterationSpan.setAttributes(attr);
|
|
2028
|
-
}
|
|
2029
|
-
if (result.isError) {
|
|
2030
|
-
this.conversationHistory.push({
|
|
2031
|
-
role: "user",
|
|
2032
|
-
content: {
|
|
2033
|
-
type: "text",
|
|
2034
|
-
text: result.content[0].text
|
|
2035
|
-
}
|
|
2036
|
-
});
|
|
2037
|
-
if (iterationSpan) endSpan(iterationSpan);
|
|
2038
|
-
continue;
|
|
2039
|
-
}
|
|
2040
|
-
if (result.isComplete) {
|
|
2041
|
-
if (iterationSpan) endSpan(iterationSpan);
|
|
2042
|
-
if (loopSpan) endSpan(loopSpan);
|
|
2043
|
-
return result;
|
|
2044
|
-
}
|
|
2045
|
-
if (iterationSpan) endSpan(iterationSpan);
|
|
2046
|
-
} catch (iterError) {
|
|
2047
|
-
if (iterationSpan) endSpan(iterationSpan, iterError);
|
|
2048
|
-
throw iterError;
|
|
2049
|
-
}
|
|
2050
|
-
}
|
|
2051
|
-
if (loopSpan) endSpan(loopSpan);
|
|
2052
|
-
return await this.createMaxIterationsError(loopSpan);
|
|
2053
|
-
} catch (error) {
|
|
2054
|
-
if (loopSpan) endSpan(loopSpan, error);
|
|
2055
|
-
return await this.createExecutionError(error, loopSpan);
|
|
1731
|
+
getCurrentStepIndex() {
|
|
1732
|
+
return this.currentStepIndex;
|
|
1733
|
+
}
|
|
1734
|
+
getSteps() {
|
|
1735
|
+
return this.steps;
|
|
1736
|
+
}
|
|
1737
|
+
isWorkflowInitialized() {
|
|
1738
|
+
return this.isInitialized;
|
|
1739
|
+
}
|
|
1740
|
+
getCurrentStep() {
|
|
1741
|
+
if (!this.isInitialized || this.currentStepIndex < 0) {
|
|
1742
|
+
return null;
|
|
2056
1743
|
}
|
|
1744
|
+
return this.steps[this.currentStepIndex] || null;
|
|
2057
1745
|
}
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
this.
|
|
2061
|
-
|
|
2062
|
-
content: {
|
|
2063
|
-
type: "text",
|
|
2064
|
-
text: `Invalid JSON: ${errorMsg}
|
|
2065
|
-
|
|
2066
|
-
Respond with valid JSON.`
|
|
2067
|
-
}
|
|
2068
|
-
});
|
|
1746
|
+
getNextStep() {
|
|
1747
|
+
if (!this.isInitialized) return null;
|
|
1748
|
+
const nextIndex = this.currentStepIndex + 1;
|
|
1749
|
+
return this.steps[nextIndex] || null;
|
|
2069
1750
|
}
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
return
|
|
1751
|
+
// Get the previous step in the workflow
|
|
1752
|
+
getPreviousStep() {
|
|
1753
|
+
if (!this.isInitialized) return null;
|
|
1754
|
+
const prevIndex = this.currentStepIndex - 1;
|
|
1755
|
+
return this.steps[prevIndex] || null;
|
|
2075
1756
|
}
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
result.isError = true;
|
|
2079
|
-
result.isComplete = false;
|
|
2080
|
-
return result;
|
|
1757
|
+
hasNextStep() {
|
|
1758
|
+
return this.getNextStep() !== null;
|
|
2081
1759
|
}
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
return
|
|
2085
|
-
content: [
|
|
2086
|
-
{
|
|
2087
|
-
type: "text",
|
|
2088
|
-
text: `${text}
|
|
2089
|
-
|
|
2090
|
-
**Execution Summary:**
|
|
2091
|
-
- Iterations used: ${this.currentIteration + 1}/${this.maxIterations}
|
|
2092
|
-
- Agent: ${this.name}
|
|
2093
|
-
${summary}`
|
|
2094
|
-
}
|
|
2095
|
-
],
|
|
2096
|
-
isError: false,
|
|
2097
|
-
isComplete: true
|
|
2098
|
-
};
|
|
1760
|
+
// Check if there is a previous step available
|
|
1761
|
+
hasPreviousStep() {
|
|
1762
|
+
return this.getPreviousStep() !== null;
|
|
2099
1763
|
}
|
|
2100
|
-
//
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
1764
|
+
// Check if currently at the first step
|
|
1765
|
+
isAtFirstStep() {
|
|
1766
|
+
return this.isInitialized && this.currentStepIndex === 0;
|
|
1767
|
+
}
|
|
1768
|
+
// Check if currently at the last step
|
|
1769
|
+
isAtLastStep() {
|
|
1770
|
+
return this.isInitialized && this.currentStepIndex >= this.steps.length - 1;
|
|
1771
|
+
}
|
|
1772
|
+
isWorkflowStarted() {
|
|
1773
|
+
return this.isStarted;
|
|
1774
|
+
}
|
|
1775
|
+
isCompleted() {
|
|
1776
|
+
return this.isInitialized && this.currentStepIndex > this.steps.length - 1;
|
|
1777
|
+
}
|
|
1778
|
+
// Mark workflow as completed by moving beyond the last step
|
|
1779
|
+
markCompleted() {
|
|
1780
|
+
if (this.isInitialized) {
|
|
1781
|
+
this.currentStepIndex = this.steps.length;
|
|
2104
1782
|
}
|
|
2105
|
-
|
|
2106
|
-
|
|
1783
|
+
}
|
|
1784
|
+
initialize(steps) {
|
|
1785
|
+
this.steps = steps;
|
|
1786
|
+
this.stepStatuses = new Array(steps.length).fill("pending");
|
|
1787
|
+
this.stepResults = new Array(steps.length).fill("");
|
|
1788
|
+
this.stepErrors = new Array(steps.length).fill("");
|
|
1789
|
+
this.currentStepIndex = 0;
|
|
1790
|
+
this.isInitialized = true;
|
|
1791
|
+
this.isStarted = false;
|
|
1792
|
+
}
|
|
1793
|
+
// Mark current step as running
|
|
1794
|
+
markCurrentStepRunning() {
|
|
1795
|
+
if (this.isInitialized && this.currentStepIndex >= 0 && this.currentStepIndex < this.steps.length) {
|
|
1796
|
+
this.stepStatuses[this.currentStepIndex] = "running";
|
|
2107
1797
|
}
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
messageCount: this.conversationHistory.length
|
|
2116
|
-
});
|
|
2117
|
-
const history = this.conversationHistory.map((msg, i) => {
|
|
2118
|
-
const prefix = `[${i + 1}] ${msg.role.toUpperCase()}`;
|
|
2119
|
-
return `${prefix}:
|
|
2120
|
-
${msg.content.text}`;
|
|
2121
|
-
}).join("\n\n---\n\n");
|
|
2122
|
-
const response = await this.server.createMessage({
|
|
2123
|
-
systemPrompt: `Summarize this agent execution:
|
|
2124
|
-
|
|
2125
|
-
Final Decision: (include complete JSON if present)
|
|
2126
|
-
Key Findings: (most important)
|
|
2127
|
-
Actions Taken: (high-level flow)
|
|
2128
|
-
Errors/Warnings: (if any)
|
|
2129
|
-
|
|
2130
|
-
${history}`,
|
|
2131
|
-
messages: [
|
|
2132
|
-
{
|
|
2133
|
-
role: "user",
|
|
2134
|
-
content: {
|
|
2135
|
-
type: "text",
|
|
2136
|
-
text: "Please provide a concise summary."
|
|
2137
|
-
}
|
|
2138
|
-
}
|
|
2139
|
-
],
|
|
2140
|
-
maxTokens: 3e3
|
|
2141
|
-
});
|
|
2142
|
-
const summary = "\n\n" + response.content.text;
|
|
2143
|
-
this.logger.debug({
|
|
2144
|
-
message: "Summarization completed",
|
|
2145
|
-
summaryLength: summary.length
|
|
2146
|
-
});
|
|
2147
|
-
if (summarizeSpan) {
|
|
2148
|
-
summarizeSpan.setAttributes({
|
|
2149
|
-
summaryLength: summary.length,
|
|
2150
|
-
summary,
|
|
2151
|
-
success: true
|
|
2152
|
-
});
|
|
2153
|
-
endSpan(summarizeSpan);
|
|
1798
|
+
}
|
|
1799
|
+
// Mark current step as completed
|
|
1800
|
+
markCurrentStepCompleted(result) {
|
|
1801
|
+
if (this.isInitialized && this.currentStepIndex >= 0 && this.currentStepIndex < this.steps.length) {
|
|
1802
|
+
this.stepStatuses[this.currentStepIndex] = "completed";
|
|
1803
|
+
if (result) {
|
|
1804
|
+
this.stepResults[this.currentStepIndex] = result;
|
|
2154
1805
|
}
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
if (
|
|
2162
|
-
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
// Mark current step as failed
|
|
1809
|
+
markCurrentStepFailed(error) {
|
|
1810
|
+
if (this.isInitialized && this.currentStepIndex >= 0 && this.currentStepIndex < this.steps.length) {
|
|
1811
|
+
this.stepStatuses[this.currentStepIndex] = "failed";
|
|
1812
|
+
if (error) {
|
|
1813
|
+
this.stepErrors[this.currentStepIndex] = error;
|
|
2163
1814
|
}
|
|
2164
|
-
return this.formatConversation();
|
|
2165
1815
|
}
|
|
2166
1816
|
}
|
|
2167
|
-
//
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
1817
|
+
// Get steps with their status
|
|
1818
|
+
getStepsWithStatus() {
|
|
1819
|
+
return this.steps.map((step, index) => ({
|
|
1820
|
+
...step,
|
|
1821
|
+
status: this.stepStatuses[index] || "pending",
|
|
1822
|
+
result: this.stepResults[index] || void 0,
|
|
1823
|
+
error: this.stepErrors[index] || void 0
|
|
1824
|
+
}));
|
|
1825
|
+
}
|
|
1826
|
+
// Get basic workflow progress data for template rendering
|
|
1827
|
+
getProgressData() {
|
|
1828
|
+
return {
|
|
1829
|
+
steps: this.steps,
|
|
1830
|
+
statuses: this.stepStatuses,
|
|
1831
|
+
results: this.stepResults,
|
|
1832
|
+
errors: this.stepErrors,
|
|
1833
|
+
currentStepIndex: this.currentStepIndex,
|
|
1834
|
+
totalSteps: this.steps.length
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
start() {
|
|
1838
|
+
this.isStarted = true;
|
|
1839
|
+
}
|
|
1840
|
+
moveToNextStep() {
|
|
1841
|
+
if (!this.hasNextStep()) {
|
|
1842
|
+
return false;
|
|
1843
|
+
}
|
|
1844
|
+
this.currentStepIndex++;
|
|
1845
|
+
return true;
|
|
1846
|
+
}
|
|
1847
|
+
// Move to the previous step in the workflow
|
|
1848
|
+
moveToPreviousStep() {
|
|
1849
|
+
if (!this.hasPreviousStep()) {
|
|
1850
|
+
return false;
|
|
2171
1851
|
}
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
try {
|
|
2175
|
-
const parsed = JSON.parse(msg.content.text);
|
|
2176
|
-
if (JSON.stringify(parsed).length < 100) {
|
|
2177
|
-
return `${header}
|
|
2178
|
-
${JSON.stringify(parsed)}`;
|
|
2179
|
-
}
|
|
2180
|
-
return `${header}
|
|
2181
|
-
\`\`\`json
|
|
2182
|
-
${JSON.stringify(parsed, null, 2)}
|
|
2183
|
-
\`\`\``;
|
|
2184
|
-
} catch {
|
|
2185
|
-
return `${header}
|
|
2186
|
-
${msg.content.text}`;
|
|
2187
|
-
}
|
|
2188
|
-
});
|
|
2189
|
-
return "\n\n**Conversation History:**\n" + messages.join("\n\n");
|
|
1852
|
+
this.currentStepIndex--;
|
|
1853
|
+
return true;
|
|
2190
1854
|
}
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
stopReason,
|
|
2199
|
-
role,
|
|
2200
|
-
result
|
|
2201
|
-
});
|
|
1855
|
+
// Move to a specific step by index (optional feature)
|
|
1856
|
+
moveToStep(stepIndex) {
|
|
1857
|
+
if (!this.isInitialized || stepIndex < 0 || stepIndex >= this.steps.length) {
|
|
1858
|
+
return false;
|
|
1859
|
+
}
|
|
1860
|
+
this.currentStepIndex = stepIndex;
|
|
1861
|
+
return true;
|
|
2202
1862
|
}
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
1863
|
+
reset() {
|
|
1864
|
+
this.currentStepIndex = -1;
|
|
1865
|
+
this.steps = [];
|
|
1866
|
+
this.stepStatuses = [];
|
|
1867
|
+
this.stepResults = [];
|
|
1868
|
+
this.stepErrors = [];
|
|
1869
|
+
this.isInitialized = false;
|
|
1870
|
+
this.isStarted = false;
|
|
1871
|
+
}
|
|
1872
|
+
getDebugInfo() {
|
|
1873
|
+
return {
|
|
1874
|
+
currentStepIndex: this.currentStepIndex,
|
|
1875
|
+
totalSteps: this.steps.length,
|
|
1876
|
+
isInitialized: this.isInitialized,
|
|
1877
|
+
currentStep: this.getCurrentStep()?.description,
|
|
1878
|
+
nextStep: this.getNextStep()?.description,
|
|
1879
|
+
previousStep: this.getPreviousStep()?.description,
|
|
1880
|
+
isAtFirstStep: this.isAtFirstStep(),
|
|
1881
|
+
hasPreviousStep: this.hasPreviousStep()
|
|
1882
|
+
};
|
|
1883
|
+
}
|
|
1884
|
+
};
|
|
2207
1885
|
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
1886
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/workflow/workflow-executor.js
|
|
1887
|
+
var WorkflowExecutor = class {
|
|
1888
|
+
name;
|
|
1889
|
+
allToolNames;
|
|
1890
|
+
toolNameToDetailList;
|
|
1891
|
+
createArgsDef;
|
|
1892
|
+
server;
|
|
1893
|
+
predefinedSteps;
|
|
1894
|
+
ensureStepActions;
|
|
1895
|
+
toolNameToIdMapping;
|
|
1896
|
+
constructor(name, allToolNames, toolNameToDetailList, createArgsDef, server, predefinedSteps, ensureStepActions, toolNameToIdMapping) {
|
|
1897
|
+
this.name = name;
|
|
1898
|
+
this.allToolNames = allToolNames;
|
|
1899
|
+
this.toolNameToDetailList = toolNameToDetailList;
|
|
1900
|
+
this.createArgsDef = createArgsDef;
|
|
1901
|
+
this.server = server;
|
|
1902
|
+
this.predefinedSteps = predefinedSteps;
|
|
1903
|
+
this.ensureStepActions = ensureStepActions;
|
|
1904
|
+
this.toolNameToIdMapping = toolNameToIdMapping;
|
|
2217
1905
|
}
|
|
2218
|
-
//
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
if (!validate(args)) {
|
|
2222
|
-
const errors = new AggregateAjvError2(validate.errors);
|
|
1906
|
+
// Helper method to validate required actions are present in workflow steps
|
|
1907
|
+
validateRequiredActions(steps) {
|
|
1908
|
+
if (!this.ensureStepActions || this.ensureStepActions.length === 0) {
|
|
2223
1909
|
return {
|
|
2224
|
-
valid:
|
|
2225
|
-
|
|
1910
|
+
valid: true,
|
|
1911
|
+
missing: []
|
|
2226
1912
|
};
|
|
2227
1913
|
}
|
|
1914
|
+
const allStepActions = /* @__PURE__ */ new Set();
|
|
1915
|
+
steps.forEach((step) => {
|
|
1916
|
+
step.actions.forEach((action) => allStepActions.add(action));
|
|
1917
|
+
});
|
|
1918
|
+
const missing = [];
|
|
1919
|
+
for (const requiredAction of this.ensureStepActions) {
|
|
1920
|
+
if (allStepActions.has(requiredAction)) {
|
|
1921
|
+
continue;
|
|
1922
|
+
}
|
|
1923
|
+
if (this.toolNameToIdMapping) {
|
|
1924
|
+
const mappedToolId = this.toolNameToIdMapping.get(requiredAction);
|
|
1925
|
+
if (mappedToolId && allStepActions.has(mappedToolId)) {
|
|
1926
|
+
continue;
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
missing.push(requiredAction);
|
|
1930
|
+
}
|
|
2228
1931
|
return {
|
|
2229
|
-
valid:
|
|
1932
|
+
valid: missing.length === 0,
|
|
1933
|
+
missing
|
|
2230
1934
|
};
|
|
2231
1935
|
}
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
agenticExecutor;
|
|
2237
|
-
constructor(name, description, allToolNames, toolNameToDetailList, server, config) {
|
|
2238
|
-
super(name, description, allToolNames, toolNameToDetailList, server, config);
|
|
2239
|
-
this.agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server);
|
|
1936
|
+
// Helper method to format workflow progress
|
|
1937
|
+
formatProgress(state) {
|
|
1938
|
+
const progressData = state.getProgressData();
|
|
1939
|
+
return PromptUtils.formatWorkflowProgress(progressData);
|
|
2240
1940
|
}
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
1941
|
+
async execute(args, state) {
|
|
1942
|
+
if (args.init) {
|
|
1943
|
+
state.reset();
|
|
1944
|
+
} else {
|
|
1945
|
+
if (!state.isWorkflowInitialized() && !args.init) {
|
|
1946
|
+
return {
|
|
1947
|
+
content: [
|
|
1948
|
+
{
|
|
1949
|
+
type: "text",
|
|
1950
|
+
text: this.predefinedSteps ? WorkflowPrompts.ERRORS.NOT_INITIALIZED.WITH_PREDEFINED : WorkflowPrompts.ERRORS.NOT_INITIALIZED.WITHOUT_PREDEFINED
|
|
1951
|
+
}
|
|
1952
|
+
],
|
|
1953
|
+
isError: true
|
|
2249
1954
|
};
|
|
2250
|
-
}
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
1955
|
+
}
|
|
1956
|
+
const decision2 = args.decision;
|
|
1957
|
+
if (decision2 === "proceed") {
|
|
1958
|
+
if (state.isAtLastStep() && state.isWorkflowStarted()) {
|
|
1959
|
+
state.markCompleted();
|
|
1960
|
+
return {
|
|
1961
|
+
content: [
|
|
1962
|
+
{
|
|
1963
|
+
type: "text",
|
|
1964
|
+
text: `## Workflow Completed!
|
|
1965
|
+
|
|
1966
|
+
${this.formatProgress(state)}
|
|
1967
|
+
|
|
1968
|
+
${CompiledPrompts.workflowCompleted({
|
|
1969
|
+
totalSteps: state.getSteps().length,
|
|
1970
|
+
toolName: this.name,
|
|
1971
|
+
newWorkflowInstructions: this.predefinedSteps ? "" : " and new `steps` array"
|
|
1972
|
+
})}`
|
|
1973
|
+
}
|
|
1974
|
+
],
|
|
1975
|
+
isError: false
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
if (state.isCompleted()) {
|
|
1979
|
+
return {
|
|
1980
|
+
content: [
|
|
1981
|
+
{
|
|
1982
|
+
type: "text",
|
|
1983
|
+
text: WorkflowPrompts.ERRORS.ALREADY_AT_FINAL
|
|
1984
|
+
}
|
|
1985
|
+
],
|
|
1986
|
+
isError: true
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
const currentStepIndex = state.getCurrentStepIndex();
|
|
1990
|
+
const wasStarted = state.isWorkflowStarted();
|
|
1991
|
+
if (state.isWorkflowStarted()) {
|
|
1992
|
+
state.moveToNextStep();
|
|
1993
|
+
} else {
|
|
1994
|
+
state.start();
|
|
1995
|
+
}
|
|
1996
|
+
const nextStepValidationSchema = this.createArgsDef.forCurrentState(state);
|
|
1997
|
+
const nextStepValidationResult = this.validateInput(args, nextStepValidationSchema);
|
|
1998
|
+
if (!nextStepValidationResult.valid) {
|
|
1999
|
+
if (wasStarted) {
|
|
2000
|
+
state.moveToStep(currentStepIndex);
|
|
2001
|
+
} else {
|
|
2002
|
+
state.moveToStep(currentStepIndex);
|
|
2003
|
+
}
|
|
2004
|
+
return {
|
|
2005
|
+
content: [
|
|
2006
|
+
{
|
|
2007
|
+
type: "text",
|
|
2008
|
+
text: CompiledPrompts.workflowErrorResponse({
|
|
2009
|
+
errorMessage: `Cannot proceed to next step: ${nextStepValidationResult.error || "Arguments validation failed"}`
|
|
2010
|
+
})
|
|
2011
|
+
}
|
|
2012
|
+
],
|
|
2013
|
+
isError: true
|
|
2014
|
+
};
|
|
2015
|
+
}
|
|
2016
|
+
} else if (decision2 === "complete") {
|
|
2017
|
+
if (state.isAtLastStep() && state.isWorkflowStarted()) {
|
|
2018
|
+
state.markCompleted();
|
|
2019
|
+
return {
|
|
2020
|
+
content: [
|
|
2021
|
+
{
|
|
2022
|
+
type: "text",
|
|
2023
|
+
text: `## Workflow Completed!
|
|
2024
|
+
|
|
2025
|
+
${this.formatProgress(state)}
|
|
2026
|
+
|
|
2027
|
+
${CompiledPrompts.workflowCompleted({
|
|
2028
|
+
totalSteps: state.getSteps().length,
|
|
2029
|
+
toolName: this.name,
|
|
2030
|
+
newWorkflowInstructions: this.predefinedSteps ? "" : " and new `steps` array"
|
|
2031
|
+
})}`
|
|
2032
|
+
}
|
|
2033
|
+
],
|
|
2034
|
+
isError: false
|
|
2035
|
+
};
|
|
2036
|
+
} else {
|
|
2037
|
+
return {
|
|
2038
|
+
content: [
|
|
2039
|
+
{
|
|
2040
|
+
type: "text",
|
|
2041
|
+
text: WorkflowPrompts.ERRORS.CANNOT_COMPLETE_NOT_AT_FINAL
|
|
2042
|
+
}
|
|
2043
|
+
],
|
|
2044
|
+
isError: true
|
|
2256
2045
|
};
|
|
2257
2046
|
}
|
|
2258
2047
|
}
|
|
2259
|
-
}
|
|
2260
|
-
|
|
2048
|
+
}
|
|
2049
|
+
const decision = args.decision;
|
|
2050
|
+
if (decision !== "proceed") {
|
|
2051
|
+
const validationSchema = this.createArgsDef.forCurrentState(state);
|
|
2052
|
+
const validationResult = this.validateInput(args, validationSchema);
|
|
2053
|
+
if (!validationResult.valid) {
|
|
2054
|
+
return {
|
|
2055
|
+
content: [
|
|
2056
|
+
{
|
|
2057
|
+
type: "text",
|
|
2058
|
+
text: CompiledPrompts.workflowErrorResponse({
|
|
2059
|
+
errorMessage: validationResult.error || "Arguments validation failed"
|
|
2060
|
+
})
|
|
2061
|
+
}
|
|
2062
|
+
],
|
|
2063
|
+
isError: true
|
|
2064
|
+
};
|
|
2065
|
+
}
|
|
2066
|
+
}
|
|
2067
|
+
if (args.init) {
|
|
2068
|
+
return this.initialize(args, state);
|
|
2069
|
+
}
|
|
2070
|
+
return await this.executeStep(args, state);
|
|
2261
2071
|
}
|
|
2262
|
-
|
|
2263
|
-
const
|
|
2264
|
-
if (!
|
|
2072
|
+
initialize(args, state) {
|
|
2073
|
+
const steps = args.steps ?? this.predefinedSteps;
|
|
2074
|
+
if (!steps || steps.length === 0) {
|
|
2265
2075
|
return {
|
|
2266
2076
|
content: [
|
|
2267
2077
|
{
|
|
2268
2078
|
type: "text",
|
|
2269
|
-
text:
|
|
2270
|
-
errorMessage: validationResult.error || "Validation failed"
|
|
2271
|
-
})
|
|
2079
|
+
text: WorkflowPrompts.ERRORS.NO_STEPS_PROVIDED
|
|
2272
2080
|
}
|
|
2273
2081
|
],
|
|
2274
2082
|
isError: true
|
|
2275
2083
|
};
|
|
2276
2084
|
}
|
|
2277
|
-
const
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
if (toolCallData.decision === "complete") {
|
|
2285
|
-
return await this.createCompletionResult("Task completed", parentSpan);
|
|
2286
|
-
}
|
|
2287
|
-
try {
|
|
2288
|
-
const { action: _action, decision: _decision, ..._toolArgs } = toolCallData;
|
|
2289
|
-
const toolResult = await this.agenticExecutor.execute(toolCallData, schema, parentSpan);
|
|
2290
|
-
const resultText = toolResult.content?.filter((content) => content.type === "text")?.map((content) => content.text)?.join("\n") || "No result";
|
|
2291
|
-
this.conversationHistory.push({
|
|
2292
|
-
role: "assistant",
|
|
2293
|
-
content: {
|
|
2294
|
-
type: "text",
|
|
2295
|
-
text: resultText
|
|
2296
|
-
}
|
|
2297
|
-
});
|
|
2298
|
-
return toolResult;
|
|
2299
|
-
} catch (error) {
|
|
2300
|
-
return this.createExecutionError(error, parentSpan);
|
|
2301
|
-
}
|
|
2302
|
-
}
|
|
2303
|
-
buildSystemPrompt(userRequest, agenticSchema, context2) {
|
|
2304
|
-
const toolList = this.allToolNames.map((name) => {
|
|
2305
|
-
const tool = this.toolNameToDetailList.find(([toolName]) => toolName === name);
|
|
2306
|
-
const toolSchema = this.server.getHiddenToolSchema(name);
|
|
2307
|
-
if (tool && tool[1]) {
|
|
2308
|
-
return `- ${name}: ${tool[1].description || `Tool: ${name}`}`;
|
|
2309
|
-
} else if (toolSchema) {
|
|
2310
|
-
return `- ${name}: ${toolSchema.description}`;
|
|
2311
|
-
}
|
|
2312
|
-
return `- ${name}`;
|
|
2313
|
-
}).join("\n");
|
|
2314
|
-
let contextInfo = "";
|
|
2315
|
-
if (context2 && typeof context2 === "object" && Object.keys(context2).length > 0) {
|
|
2316
|
-
contextInfo = `
|
|
2317
|
-
|
|
2318
|
-
Context:
|
|
2319
|
-
${JSON.stringify(context2, null, 2)}`;
|
|
2320
|
-
}
|
|
2321
|
-
const basePrompt = CompiledPrompts.samplingExecution({
|
|
2322
|
-
toolName: this.name,
|
|
2323
|
-
description: this.description,
|
|
2324
|
-
toolList
|
|
2325
|
-
});
|
|
2326
|
-
const taskPrompt = `
|
|
2327
|
-
|
|
2328
|
-
## Current Task
|
|
2329
|
-
You will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
|
|
2330
|
-
|
|
2331
|
-
When you need to use a tool, specify the tool name in 'action' and provide tool-specific parameters as additional properties.`;
|
|
2332
|
-
return this.injectJsonInstruction({
|
|
2333
|
-
prompt: basePrompt + taskPrompt,
|
|
2334
|
-
schema: agenticSchema
|
|
2335
|
-
});
|
|
2336
|
-
}
|
|
2337
|
-
};
|
|
2338
|
-
|
|
2339
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/agentic/agentic-tool-registrar.js
|
|
2340
|
-
function registerAgenticTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList, sampling = false }) {
|
|
2341
|
-
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
2342
|
-
const isSamplingMode = sampling === true || typeof sampling === "object";
|
|
2343
|
-
const samplingConfig = typeof sampling === "object" ? sampling : void 0;
|
|
2344
|
-
const agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server);
|
|
2345
|
-
const samplingExecutor = new SamplingExecutor(name, description, allToolNames, toolNameToDetailList, server, samplingConfig);
|
|
2346
|
-
description = isSamplingMode ? CompiledPrompts.samplingExecution({
|
|
2347
|
-
toolName: name,
|
|
2348
|
-
description,
|
|
2349
|
-
toolList: allToolNames.map((name2) => `- ${name2}`).join("\n")
|
|
2350
|
-
}) : CompiledPrompts.autonomousExecution({
|
|
2351
|
-
toolName: name,
|
|
2352
|
-
description
|
|
2353
|
-
});
|
|
2354
|
-
const agenticArgsDef = createArgsDef.forAgentic(toolNameToDetailList, false);
|
|
2355
|
-
const argsDef = isSamplingMode ? createArgsDef.forSampling() : agenticArgsDef;
|
|
2356
|
-
const schema = allToolNames.length > 0 ? argsDef : {
|
|
2357
|
-
type: "object",
|
|
2358
|
-
properties: {}
|
|
2359
|
-
};
|
|
2360
|
-
server.tool(name, description, jsonSchema(createGoogleCompatibleJSONSchema(schema)), async (args) => {
|
|
2361
|
-
if (isSamplingMode) {
|
|
2362
|
-
return await samplingExecutor.executeSampling(args, schema);
|
|
2363
|
-
} else {
|
|
2364
|
-
return await agenticExecutor.execute(args, schema);
|
|
2365
|
-
}
|
|
2366
|
-
});
|
|
2367
|
-
}
|
|
2085
|
+
const validation = this.validateRequiredActions(steps);
|
|
2086
|
+
if (!validation.valid) {
|
|
2087
|
+
return {
|
|
2088
|
+
content: [
|
|
2089
|
+
{
|
|
2090
|
+
type: "text",
|
|
2091
|
+
text: `## Workflow Validation Failed \u274C
|
|
2368
2092
|
|
|
2369
|
-
|
|
2370
|
-
init_schema();
|
|
2093
|
+
**Missing Required Actions:** The following actions must be included in the workflow steps:
|
|
2371
2094
|
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
getSteps() {
|
|
2390
|
-
return this.steps;
|
|
2391
|
-
}
|
|
2392
|
-
isWorkflowInitialized() {
|
|
2393
|
-
return this.isInitialized;
|
|
2394
|
-
}
|
|
2395
|
-
getCurrentStep() {
|
|
2396
|
-
if (!this.isInitialized || this.currentStepIndex < 0) {
|
|
2397
|
-
return null;
|
|
2398
|
-
}
|
|
2399
|
-
return this.steps[this.currentStepIndex] || null;
|
|
2400
|
-
}
|
|
2401
|
-
getNextStep() {
|
|
2402
|
-
if (!this.isInitialized) return null;
|
|
2403
|
-
const nextIndex = this.currentStepIndex + 1;
|
|
2404
|
-
return this.steps[nextIndex] || null;
|
|
2405
|
-
}
|
|
2406
|
-
// Get the previous step in the workflow
|
|
2407
|
-
getPreviousStep() {
|
|
2408
|
-
if (!this.isInitialized) return null;
|
|
2409
|
-
const prevIndex = this.currentStepIndex - 1;
|
|
2410
|
-
return this.steps[prevIndex] || null;
|
|
2411
|
-
}
|
|
2412
|
-
hasNextStep() {
|
|
2413
|
-
return this.getNextStep() !== null;
|
|
2414
|
-
}
|
|
2415
|
-
// Check if there is a previous step available
|
|
2416
|
-
hasPreviousStep() {
|
|
2417
|
-
return this.getPreviousStep() !== null;
|
|
2418
|
-
}
|
|
2419
|
-
// Check if currently at the first step
|
|
2420
|
-
isAtFirstStep() {
|
|
2421
|
-
return this.isInitialized && this.currentStepIndex === 0;
|
|
2422
|
-
}
|
|
2423
|
-
// Check if currently at the last step
|
|
2424
|
-
isAtLastStep() {
|
|
2425
|
-
return this.isInitialized && this.currentStepIndex >= this.steps.length - 1;
|
|
2426
|
-
}
|
|
2427
|
-
isWorkflowStarted() {
|
|
2428
|
-
return this.isStarted;
|
|
2429
|
-
}
|
|
2430
|
-
isCompleted() {
|
|
2431
|
-
return this.isInitialized && this.currentStepIndex > this.steps.length - 1;
|
|
2432
|
-
}
|
|
2433
|
-
// Mark workflow as completed by moving beyond the last step
|
|
2434
|
-
markCompleted() {
|
|
2435
|
-
if (this.isInitialized) {
|
|
2436
|
-
this.currentStepIndex = this.steps.length;
|
|
2437
|
-
}
|
|
2438
|
-
}
|
|
2439
|
-
initialize(steps) {
|
|
2440
|
-
this.steps = steps;
|
|
2441
|
-
this.stepStatuses = new Array(steps.length).fill("pending");
|
|
2442
|
-
this.stepResults = new Array(steps.length).fill("");
|
|
2443
|
-
this.stepErrors = new Array(steps.length).fill("");
|
|
2444
|
-
this.currentStepIndex = 0;
|
|
2445
|
-
this.isInitialized = true;
|
|
2446
|
-
this.isStarted = false;
|
|
2447
|
-
}
|
|
2448
|
-
// Mark current step as running
|
|
2449
|
-
markCurrentStepRunning() {
|
|
2450
|
-
if (this.isInitialized && this.currentStepIndex >= 0 && this.currentStepIndex < this.steps.length) {
|
|
2451
|
-
this.stepStatuses[this.currentStepIndex] = "running";
|
|
2452
|
-
}
|
|
2453
|
-
}
|
|
2454
|
-
// Mark current step as completed
|
|
2455
|
-
markCurrentStepCompleted(result) {
|
|
2456
|
-
if (this.isInitialized && this.currentStepIndex >= 0 && this.currentStepIndex < this.steps.length) {
|
|
2457
|
-
this.stepStatuses[this.currentStepIndex] = "completed";
|
|
2458
|
-
if (result) {
|
|
2459
|
-
this.stepResults[this.currentStepIndex] = result;
|
|
2460
|
-
}
|
|
2461
|
-
}
|
|
2462
|
-
}
|
|
2463
|
-
// Mark current step as failed
|
|
2464
|
-
markCurrentStepFailed(error) {
|
|
2465
|
-
if (this.isInitialized && this.currentStepIndex >= 0 && this.currentStepIndex < this.steps.length) {
|
|
2466
|
-
this.stepStatuses[this.currentStepIndex] = "failed";
|
|
2467
|
-
if (error) {
|
|
2468
|
-
this.stepErrors[this.currentStepIndex] = error;
|
|
2469
|
-
}
|
|
2470
|
-
}
|
|
2471
|
-
}
|
|
2472
|
-
// Get steps with their status
|
|
2473
|
-
getStepsWithStatus() {
|
|
2474
|
-
return this.steps.map((step, index) => ({
|
|
2475
|
-
...step,
|
|
2476
|
-
status: this.stepStatuses[index] || "pending",
|
|
2477
|
-
result: this.stepResults[index] || void 0,
|
|
2478
|
-
error: this.stepErrors[index] || void 0
|
|
2479
|
-
}));
|
|
2480
|
-
}
|
|
2481
|
-
// Get basic workflow progress data for template rendering
|
|
2482
|
-
getProgressData() {
|
|
2483
|
-
return {
|
|
2484
|
-
steps: this.steps,
|
|
2485
|
-
statuses: this.stepStatuses,
|
|
2486
|
-
results: this.stepResults,
|
|
2487
|
-
errors: this.stepErrors,
|
|
2488
|
-
currentStepIndex: this.currentStepIndex,
|
|
2489
|
-
totalSteps: this.steps.length
|
|
2095
|
+
${validation.missing.map((action) => `- \`${this.toolNameToIdMapping?.get(action) ?? action}\``).join("\n")}`
|
|
2096
|
+
}
|
|
2097
|
+
],
|
|
2098
|
+
isError: true
|
|
2099
|
+
};
|
|
2100
|
+
}
|
|
2101
|
+
state.initialize(steps);
|
|
2102
|
+
return {
|
|
2103
|
+
content: [
|
|
2104
|
+
{
|
|
2105
|
+
type: "text",
|
|
2106
|
+
text: `## Workflow Initialized
|
|
2107
|
+
${this.formatProgress(state)}
|
|
2108
|
+
${this.createArgsDef.forInitialStepDescription(steps, state)}`
|
|
2109
|
+
}
|
|
2110
|
+
],
|
|
2111
|
+
isError: false
|
|
2490
2112
|
};
|
|
2491
2113
|
}
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
|
|
2497
|
-
|
|
2114
|
+
async executeStep(args, state) {
|
|
2115
|
+
const currentStep = state.getCurrentStep();
|
|
2116
|
+
if (!currentStep) {
|
|
2117
|
+
return {
|
|
2118
|
+
content: [
|
|
2119
|
+
{
|
|
2120
|
+
type: "text",
|
|
2121
|
+
text: WorkflowPrompts.ERRORS.NO_CURRENT_STEP
|
|
2122
|
+
}
|
|
2123
|
+
],
|
|
2124
|
+
isError: true
|
|
2125
|
+
};
|
|
2498
2126
|
}
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
|
|
2504
|
-
|
|
2505
|
-
|
|
2127
|
+
state.markCurrentStepRunning();
|
|
2128
|
+
const results = {
|
|
2129
|
+
content: [],
|
|
2130
|
+
isError: false
|
|
2131
|
+
};
|
|
2132
|
+
for (const action of currentStep.actions) {
|
|
2133
|
+
try {
|
|
2134
|
+
const actionArgs = args[action] || {};
|
|
2135
|
+
const actionResult = await this.server.callTool(action, actionArgs);
|
|
2136
|
+
if (!results.isError) {
|
|
2137
|
+
results.isError = actionResult.isError;
|
|
2138
|
+
}
|
|
2139
|
+
results.content = results.content.concat(actionResult.content ?? []);
|
|
2140
|
+
results.content.push({
|
|
2141
|
+
type: "text",
|
|
2142
|
+
text: `Action \`${action}\` executed ${actionResult.isError ? "\u274C **FAILED**" : "\u2705 **SUCCESS**"}:`
|
|
2143
|
+
});
|
|
2144
|
+
} catch (error) {
|
|
2145
|
+
results.content.push({
|
|
2146
|
+
type: "text",
|
|
2147
|
+
text: `${error.message}`
|
|
2148
|
+
});
|
|
2149
|
+
results.content.push({
|
|
2150
|
+
type: "text",
|
|
2151
|
+
text: `Action \`${action}\` \u274C **FAILED** with error: `
|
|
2152
|
+
});
|
|
2153
|
+
results.isError = true;
|
|
2154
|
+
}
|
|
2506
2155
|
}
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
moveToStep(stepIndex) {
|
|
2512
|
-
if (!this.isInitialized || stepIndex < 0 || stepIndex >= this.steps.length) {
|
|
2513
|
-
return false;
|
|
2156
|
+
if (results.isError) {
|
|
2157
|
+
state.markCurrentStepFailed("Step execution failed");
|
|
2158
|
+
} else {
|
|
2159
|
+
state.markCurrentStepCompleted("Step completed successfully");
|
|
2514
2160
|
}
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2161
|
+
if (state.hasNextStep()) {
|
|
2162
|
+
const nextStepArgsDef = this.createArgsDef.forNextState(state);
|
|
2163
|
+
results.content.push({
|
|
2164
|
+
type: "text",
|
|
2165
|
+
text: CompiledPrompts.nextStepDecision({
|
|
2166
|
+
toolName: this.name,
|
|
2167
|
+
nextStepDescription: state.getNextStep()?.description || "Unknown step",
|
|
2168
|
+
nextStepSchema: JSON.stringify(nextStepArgsDef, null, 2)
|
|
2169
|
+
})
|
|
2170
|
+
});
|
|
2171
|
+
} else {
|
|
2172
|
+
results.content.push({
|
|
2173
|
+
type: "text",
|
|
2174
|
+
text: CompiledPrompts.finalStepCompletion({
|
|
2175
|
+
statusIcon: results.isError ? "\u274C" : "\u2705",
|
|
2176
|
+
statusText: results.isError ? "with errors" : "successfully",
|
|
2177
|
+
toolName: this.name,
|
|
2178
|
+
newWorkflowInstructions: this.predefinedSteps ? "" : " and new `steps` array"
|
|
2179
|
+
})
|
|
2180
|
+
});
|
|
2181
|
+
}
|
|
2182
|
+
results.content.push({
|
|
2183
|
+
type: "text",
|
|
2184
|
+
text: `## Workflow Progress
|
|
2185
|
+
${this.formatProgress(state)}`
|
|
2186
|
+
});
|
|
2187
|
+
return results;
|
|
2526
2188
|
}
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
totalSteps: this.steps.length,
|
|
2531
|
-
isInitialized: this.isInitialized,
|
|
2532
|
-
currentStep: this.getCurrentStep()?.description,
|
|
2533
|
-
nextStep: this.getNextStep()?.description,
|
|
2534
|
-
previousStep: this.getPreviousStep()?.description,
|
|
2535
|
-
isAtFirstStep: this.isAtFirstStep(),
|
|
2536
|
-
hasPreviousStep: this.hasPreviousStep()
|
|
2537
|
-
};
|
|
2189
|
+
// Validate arguments using JSON schema
|
|
2190
|
+
validateInput(args, schema) {
|
|
2191
|
+
return validateSchema(args, schema);
|
|
2538
2192
|
}
|
|
2539
2193
|
};
|
|
2540
2194
|
|
|
2541
2195
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/workflow/workflow-tool-registrar.js
|
|
2542
|
-
|
|
2196
|
+
function registerAgenticWorkflowTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList, predefinedSteps, ensureStepActions, toolNameToIdMapping }) {
|
|
2197
|
+
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, predefinedSteps, ensureStepActions);
|
|
2198
|
+
const workflowExecutor = new WorkflowExecutor(name, allToolNames, toolNameToDetailList, createArgsDef, server, predefinedSteps, ensureStepActions, toolNameToIdMapping);
|
|
2199
|
+
const workflowState = new WorkflowState();
|
|
2200
|
+
const planningInstructions = predefinedSteps ? "- Set `init: true` (steps are predefined)" : "- Set `init: true` and define complete `steps` array";
|
|
2201
|
+
const baseDescription = CompiledPrompts.workflowExecution({
|
|
2202
|
+
toolName: name,
|
|
2203
|
+
description,
|
|
2204
|
+
planningInstructions
|
|
2205
|
+
});
|
|
2206
|
+
const argsDef = createArgsDef.forTool();
|
|
2207
|
+
const toolDescription = createArgsDef.forToolDescription(baseDescription, workflowState);
|
|
2208
|
+
server.tool(name, toolDescription, jsonSchema(createGoogleCompatibleJSONSchema(argsDef)), async (args) => {
|
|
2209
|
+
try {
|
|
2210
|
+
return await workflowExecutor.execute(args, workflowState);
|
|
2211
|
+
} catch (error) {
|
|
2212
|
+
workflowState.reset();
|
|
2213
|
+
return {
|
|
2214
|
+
content: [
|
|
2215
|
+
{
|
|
2216
|
+
type: "text",
|
|
2217
|
+
text: `Workflow execution error: ${error.message}`
|
|
2218
|
+
}
|
|
2219
|
+
],
|
|
2220
|
+
isError: true
|
|
2221
|
+
};
|
|
2222
|
+
}
|
|
2223
|
+
});
|
|
2224
|
+
}
|
|
2543
2225
|
|
|
2544
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2549
|
-
|
|
2550
|
-
|
|
2226
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-workflow-plugin.js
|
|
2227
|
+
var createWorkflowModePlugin = () => ({
|
|
2228
|
+
name: "mode-workflow",
|
|
2229
|
+
version: "1.0.0",
|
|
2230
|
+
// Only apply to workflow mode
|
|
2231
|
+
apply: "agentic_workflow",
|
|
2232
|
+
// Register the agent tool
|
|
2233
|
+
registerAgentTool: (context2) => {
|
|
2234
|
+
registerAgenticWorkflowTool(context2.server, {
|
|
2235
|
+
description: context2.description,
|
|
2236
|
+
name: context2.name,
|
|
2237
|
+
allToolNames: context2.allToolNames,
|
|
2238
|
+
depGroups: context2.depGroups,
|
|
2239
|
+
toolNameToDetailList: context2.toolNameToDetailList,
|
|
2240
|
+
predefinedSteps: context2.options.steps,
|
|
2241
|
+
ensureStepActions: context2.options.ensureStepActions,
|
|
2242
|
+
toolNameToIdMapping: context2.toolNameToIdMapping
|
|
2243
|
+
});
|
|
2244
|
+
}
|
|
2551
2245
|
});
|
|
2552
|
-
|
|
2553
|
-
|
|
2246
|
+
var mode_workflow_plugin_default = createWorkflowModePlugin();
|
|
2247
|
+
|
|
2248
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/sampling/base-sampling-executor.js
|
|
2249
|
+
import process5 from "node:process";
|
|
2250
|
+
var BaseSamplingExecutor = class {
|
|
2554
2251
|
name;
|
|
2252
|
+
description;
|
|
2555
2253
|
allToolNames;
|
|
2556
2254
|
toolNameToDetailList;
|
|
2557
|
-
createArgsDef;
|
|
2558
2255
|
server;
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2256
|
+
conversationHistory;
|
|
2257
|
+
maxIterations;
|
|
2258
|
+
currentIteration;
|
|
2259
|
+
logger;
|
|
2260
|
+
tracingEnabled;
|
|
2261
|
+
summarize;
|
|
2262
|
+
constructor(name, description, allToolNames, toolNameToDetailList, server, config) {
|
|
2563
2263
|
this.name = name;
|
|
2264
|
+
this.description = description;
|
|
2564
2265
|
this.allToolNames = allToolNames;
|
|
2565
2266
|
this.toolNameToDetailList = toolNameToDetailList;
|
|
2566
|
-
this.createArgsDef = createArgsDef;
|
|
2567
2267
|
this.server = server;
|
|
2568
|
-
this.
|
|
2569
|
-
this.
|
|
2570
|
-
this.
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
return {
|
|
2576
|
-
valid: true,
|
|
2577
|
-
missing: []
|
|
2578
|
-
};
|
|
2268
|
+
this.conversationHistory = [];
|
|
2269
|
+
this.maxIterations = 55;
|
|
2270
|
+
this.currentIteration = 0;
|
|
2271
|
+
this.tracingEnabled = false;
|
|
2272
|
+
this.summarize = true;
|
|
2273
|
+
if (config?.maxIterations) {
|
|
2274
|
+
this.maxIterations = config.maxIterations;
|
|
2579
2275
|
}
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
});
|
|
2584
|
-
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
|
|
2276
|
+
if (config?.summarize !== void 0) {
|
|
2277
|
+
this.summarize = config.summarize;
|
|
2278
|
+
}
|
|
2279
|
+
this.logger = createLogger(`mcpc.sampling.${name}`, server);
|
|
2280
|
+
try {
|
|
2281
|
+
const tracingConfig = {
|
|
2282
|
+
enabled: process5.env.MCPC_TRACING_ENABLED === "true",
|
|
2283
|
+
serviceName: `mcpc-sampling-${name}`,
|
|
2284
|
+
exportTo: process5.env.MCPC_TRACING_EXPORT ?? "otlp",
|
|
2285
|
+
otlpEndpoint: process5.env.MCPC_TRACING_OTLP_ENDPOINT ?? "http://localhost:4318/v1/traces"
|
|
2286
|
+
};
|
|
2287
|
+
this.tracingEnabled = tracingConfig.enabled;
|
|
2288
|
+
if (this.tracingEnabled) {
|
|
2289
|
+
initializeTracing(tracingConfig);
|
|
2594
2290
|
}
|
|
2595
|
-
|
|
2291
|
+
} catch {
|
|
2292
|
+
this.tracingEnabled = false;
|
|
2596
2293
|
}
|
|
2597
|
-
return {
|
|
2598
|
-
valid: missing.length === 0,
|
|
2599
|
-
missing
|
|
2600
|
-
};
|
|
2601
|
-
}
|
|
2602
|
-
// Helper method to format workflow progress
|
|
2603
|
-
formatProgress(state) {
|
|
2604
|
-
const progressData = state.getProgressData();
|
|
2605
|
-
return PromptUtils.formatWorkflowProgress(progressData);
|
|
2606
2294
|
}
|
|
2607
|
-
async
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2295
|
+
async runSamplingLoop(systemPrompt, schema, state) {
|
|
2296
|
+
this.conversationHistory = [
|
|
2297
|
+
{
|
|
2298
|
+
role: "user",
|
|
2299
|
+
content: {
|
|
2300
|
+
type: "text",
|
|
2301
|
+
text: 'Return ONE AND ONLY ONE raw JSON object (no code fences, explanations, or multiple objects). During execution provide: {"action":"<tool>","decision":"proceed|retry","<tool>":{}}. When complete provide: {"decision":"complete"}'
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
];
|
|
2305
|
+
const loopSpan = this.tracingEnabled ? startSpan("mcpc.sampling_loop", {
|
|
2306
|
+
agent: this.name,
|
|
2307
|
+
maxIterations: this.maxIterations,
|
|
2308
|
+
systemPrompt: systemPrompt()
|
|
2309
|
+
}) : null;
|
|
2310
|
+
try {
|
|
2311
|
+
for (this.currentIteration = 0; this.currentIteration < this.maxIterations; this.currentIteration++) {
|
|
2312
|
+
let iterationSpan = null;
|
|
2313
|
+
try {
|
|
2314
|
+
const response = await this.server.createMessage({
|
|
2315
|
+
systemPrompt: systemPrompt(),
|
|
2316
|
+
messages: this.conversationHistory,
|
|
2317
|
+
maxTokens: 55e3
|
|
2318
|
+
});
|
|
2319
|
+
const responseContent = response.content.text || "{}";
|
|
2320
|
+
const model = response.model;
|
|
2321
|
+
const stopReason = response.stopReason;
|
|
2322
|
+
const role = response.role;
|
|
2323
|
+
let parsedData;
|
|
2324
|
+
try {
|
|
2325
|
+
parsedData = parseJSON(responseContent.trim(), true);
|
|
2326
|
+
} catch (parseError) {
|
|
2327
|
+
iterationSpan = this.tracingEnabled ? startSpan("mcpc.sampling_iteration.parse_error", {
|
|
2328
|
+
iteration: this.currentIteration + 1,
|
|
2329
|
+
agent: this.name,
|
|
2330
|
+
error: String(parseError),
|
|
2331
|
+
maxIterations: this.maxIterations
|
|
2332
|
+
}, loopSpan ?? void 0) : null;
|
|
2333
|
+
this.addParsingErrorToHistory(responseContent, parseError);
|
|
2334
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2335
|
+
continue;
|
|
2336
|
+
}
|
|
2337
|
+
this.conversationHistory.push({
|
|
2338
|
+
role: "assistant",
|
|
2339
|
+
content: {
|
|
2615
2340
|
type: "text",
|
|
2616
|
-
text:
|
|
2341
|
+
text: JSON.stringify(parsedData, null, 2)
|
|
2617
2342
|
}
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
state.markCompleted();
|
|
2626
|
-
return {
|
|
2627
|
-
content: [
|
|
2628
|
-
{
|
|
2629
|
-
type: "text",
|
|
2630
|
-
text: `## Workflow Completed!
|
|
2631
|
-
|
|
2632
|
-
${this.formatProgress(state)}
|
|
2633
|
-
|
|
2634
|
-
${CompiledPrompts.workflowCompleted({
|
|
2635
|
-
totalSteps: state.getSteps().length,
|
|
2636
|
-
toolName: this.name,
|
|
2637
|
-
newWorkflowInstructions: this.predefinedSteps ? "" : " and new `steps` array"
|
|
2638
|
-
})}`
|
|
2639
|
-
}
|
|
2640
|
-
],
|
|
2641
|
-
isError: false
|
|
2642
|
-
};
|
|
2643
|
-
}
|
|
2644
|
-
if (state.isCompleted()) {
|
|
2645
|
-
return {
|
|
2646
|
-
content: [
|
|
2647
|
-
{
|
|
2343
|
+
});
|
|
2344
|
+
const action = parsedData["action"];
|
|
2345
|
+
const decision = parsedData["decision"];
|
|
2346
|
+
if (typeof decision !== "string") {
|
|
2347
|
+
this.conversationHistory.push({
|
|
2348
|
+
role: "user",
|
|
2349
|
+
content: {
|
|
2648
2350
|
type: "text",
|
|
2649
|
-
text:
|
|
2351
|
+
text: 'Missing required field "decision". Provide: {"action":"<tool>","decision":"proceed|retry","<tool>":{}} or {"decision":"complete"}'
|
|
2650
2352
|
}
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
}
|
|
2655
|
-
const currentStepIndex = state.getCurrentStepIndex();
|
|
2656
|
-
const wasStarted = state.isWorkflowStarted();
|
|
2657
|
-
if (state.isWorkflowStarted()) {
|
|
2658
|
-
state.moveToNextStep();
|
|
2659
|
-
} else {
|
|
2660
|
-
state.start();
|
|
2661
|
-
}
|
|
2662
|
-
const nextStepValidationSchema = this.createArgsDef.forCurrentState(state);
|
|
2663
|
-
const nextStepValidationResult = this.validate(args, nextStepValidationSchema);
|
|
2664
|
-
if (!nextStepValidationResult.valid) {
|
|
2665
|
-
if (wasStarted) {
|
|
2666
|
-
state.moveToStep(currentStepIndex);
|
|
2667
|
-
} else {
|
|
2668
|
-
state.moveToStep(currentStepIndex);
|
|
2353
|
+
});
|
|
2354
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2355
|
+
continue;
|
|
2669
2356
|
}
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2357
|
+
if (decision === "complete" && action) {
|
|
2358
|
+
this.conversationHistory.push({
|
|
2359
|
+
role: "user",
|
|
2360
|
+
content: {
|
|
2673
2361
|
type: "text",
|
|
2674
|
-
text:
|
|
2675
|
-
errorMessage: `Cannot proceed to next step: ${nextStepValidationResult.error || "Arguments validation failed"}`
|
|
2676
|
-
})
|
|
2362
|
+
text: 'Invalid: Cannot have both "decision":"complete" and "action" field. When complete, only provide {"decision":"complete"}.'
|
|
2677
2363
|
}
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
content: [
|
|
2687
|
-
{
|
|
2364
|
+
});
|
|
2365
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2366
|
+
continue;
|
|
2367
|
+
}
|
|
2368
|
+
if (decision !== "complete" && !action) {
|
|
2369
|
+
this.conversationHistory.push({
|
|
2370
|
+
role: "user",
|
|
2371
|
+
content: {
|
|
2688
2372
|
type: "text",
|
|
2689
|
-
text:
|
|
2690
|
-
|
|
2691
|
-
${this.formatProgress(state)}
|
|
2692
|
-
|
|
2693
|
-
${CompiledPrompts.workflowCompleted({
|
|
2694
|
-
totalSteps: state.getSteps().length,
|
|
2695
|
-
toolName: this.name,
|
|
2696
|
-
newWorkflowInstructions: this.predefinedSteps ? "" : " and new `steps` array"
|
|
2697
|
-
})}`
|
|
2373
|
+
text: 'Missing required field "action". When executing, provide: {"action":"<tool>","decision":"proceed|retry","<tool>":{}}'
|
|
2698
2374
|
}
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2375
|
+
});
|
|
2376
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2377
|
+
continue;
|
|
2378
|
+
}
|
|
2379
|
+
const actionStr = decision === "complete" ? "completion" : action && typeof action === "string" ? String(action) : "unknown_action";
|
|
2380
|
+
const spanName = `mcpc.sampling_iteration.${actionStr}`;
|
|
2381
|
+
iterationSpan = this.tracingEnabled ? startSpan(spanName, {
|
|
2382
|
+
iteration: this.currentIteration + 1,
|
|
2383
|
+
agent: this.name,
|
|
2384
|
+
action: actionStr,
|
|
2385
|
+
systemPrompt: systemPrompt(),
|
|
2386
|
+
maxTokens: String(Number.MAX_SAFE_INTEGER),
|
|
2387
|
+
maxIterations: this.maxIterations,
|
|
2388
|
+
messages: JSON.stringify(this.conversationHistory)
|
|
2389
|
+
}, loopSpan ?? void 0) : null;
|
|
2390
|
+
const result = await this.processAction(parsedData, schema, state, iterationSpan);
|
|
2391
|
+
this.logIterationProgress(parsedData, result, model, stopReason, role);
|
|
2392
|
+
if (iterationSpan) {
|
|
2393
|
+
let rawJson = "{}";
|
|
2394
|
+
try {
|
|
2395
|
+
rawJson = parsedData ? JSON.stringify(parsedData) : "{}";
|
|
2396
|
+
} catch {
|
|
2397
|
+
}
|
|
2398
|
+
const attr = {
|
|
2399
|
+
isError: !!result.isError,
|
|
2400
|
+
isComplete: !!result.isComplete,
|
|
2401
|
+
iteration: this.currentIteration + 1,
|
|
2402
|
+
maxIterations: this.maxIterations,
|
|
2403
|
+
parsed: rawJson,
|
|
2404
|
+
action: typeof action === "string" ? action : String(action),
|
|
2405
|
+
decision: typeof decision === "string" ? decision : String(decision),
|
|
2406
|
+
samplingResponse: responseContent,
|
|
2407
|
+
toolResult: JSON.stringify(result),
|
|
2408
|
+
model,
|
|
2409
|
+
role
|
|
2410
|
+
};
|
|
2411
|
+
if (stopReason) {
|
|
2412
|
+
attr.stopReason = stopReason;
|
|
2413
|
+
}
|
|
2414
|
+
iterationSpan.setAttributes(attr);
|
|
2415
|
+
}
|
|
2416
|
+
if (result.isError) {
|
|
2417
|
+
this.conversationHistory.push({
|
|
2418
|
+
role: "user",
|
|
2419
|
+
content: {
|
|
2706
2420
|
type: "text",
|
|
2707
|
-
text:
|
|
2421
|
+
text: result.content[0].text
|
|
2708
2422
|
}
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2423
|
+
});
|
|
2424
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2425
|
+
continue;
|
|
2426
|
+
}
|
|
2427
|
+
if (result.isComplete) {
|
|
2428
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2429
|
+
if (loopSpan) endSpan(loopSpan);
|
|
2430
|
+
return result;
|
|
2431
|
+
}
|
|
2432
|
+
if (iterationSpan) endSpan(iterationSpan);
|
|
2433
|
+
} catch (iterError) {
|
|
2434
|
+
if (iterationSpan) endSpan(iterationSpan, iterError);
|
|
2435
|
+
throw iterError;
|
|
2712
2436
|
}
|
|
2713
2437
|
}
|
|
2438
|
+
if (loopSpan) endSpan(loopSpan);
|
|
2439
|
+
return await this.createMaxIterationsError(loopSpan);
|
|
2440
|
+
} catch (error) {
|
|
2441
|
+
if (loopSpan) endSpan(loopSpan, error);
|
|
2442
|
+
return await this.createExecutionError(error, loopSpan);
|
|
2714
2443
|
}
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
errorMessage: validationResult.error || "Arguments validation failed"
|
|
2726
|
-
})
|
|
2727
|
-
}
|
|
2728
|
-
],
|
|
2729
|
-
isError: true
|
|
2730
|
-
};
|
|
2444
|
+
}
|
|
2445
|
+
addParsingErrorToHistory(_responseText, parseError) {
|
|
2446
|
+
const errorMsg = parseError instanceof Error ? parseError.message : String(parseError);
|
|
2447
|
+
this.conversationHistory.push({
|
|
2448
|
+
role: "user",
|
|
2449
|
+
content: {
|
|
2450
|
+
type: "text",
|
|
2451
|
+
text: `Invalid JSON: ${errorMsg}
|
|
2452
|
+
|
|
2453
|
+
Respond with valid JSON.`
|
|
2731
2454
|
}
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2457
|
+
async createMaxIterationsError(parentSpan) {
|
|
2458
|
+
const result = await this.createCompletionResult(`Reached max iterations (${this.maxIterations}). Try a more specific request.`, parentSpan);
|
|
2459
|
+
result.isError = true;
|
|
2460
|
+
result.isComplete = false;
|
|
2461
|
+
return result;
|
|
2462
|
+
}
|
|
2463
|
+
async createExecutionError(error, parentSpan) {
|
|
2464
|
+
const result = await this.createCompletionResult(`Execution error: ${error instanceof Error ? error.message : String(error)}`, parentSpan);
|
|
2465
|
+
result.isError = true;
|
|
2466
|
+
result.isComplete = false;
|
|
2467
|
+
return result;
|
|
2468
|
+
}
|
|
2469
|
+
async createCompletionResult(text, parentSpan) {
|
|
2470
|
+
const summary = this.summarize ? await this.summarizeConversation(parentSpan) : this.formatConversation();
|
|
2471
|
+
return {
|
|
2472
|
+
content: [
|
|
2473
|
+
{
|
|
2474
|
+
type: "text",
|
|
2475
|
+
text: `${text}
|
|
2476
|
+
|
|
2477
|
+
**Execution Summary:**
|
|
2478
|
+
- Iterations used: ${this.currentIteration + 1}/${this.maxIterations}
|
|
2479
|
+
- Agent: ${this.name}
|
|
2480
|
+
${summary}`
|
|
2481
|
+
}
|
|
2482
|
+
],
|
|
2483
|
+
isError: false,
|
|
2484
|
+
isComplete: true
|
|
2485
|
+
};
|
|
2486
|
+
}
|
|
2487
|
+
// Use LLM to create high-signal summary for parent agent
|
|
2488
|
+
async summarizeConversation(parentSpan) {
|
|
2489
|
+
if (this.conversationHistory.length === 0) {
|
|
2490
|
+
return "\n\n**No conversation history**";
|
|
2732
2491
|
}
|
|
2733
|
-
if (
|
|
2734
|
-
return this.
|
|
2492
|
+
if (this.conversationHistory.length <= 3) {
|
|
2493
|
+
return this.formatConversation();
|
|
2735
2494
|
}
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2495
|
+
const summarizeSpan = this.tracingEnabled ? startSpan("mcpc.sampling_summarize", {
|
|
2496
|
+
agent: this.name,
|
|
2497
|
+
messageCount: this.conversationHistory.length
|
|
2498
|
+
}, parentSpan ?? void 0) : null;
|
|
2499
|
+
try {
|
|
2500
|
+
this.logger.debug({
|
|
2501
|
+
message: "Starting conversation summarization",
|
|
2502
|
+
messageCount: this.conversationHistory.length
|
|
2503
|
+
});
|
|
2504
|
+
const history = this.conversationHistory.map((msg, i) => {
|
|
2505
|
+
const prefix = `[${i + 1}] ${msg.role.toUpperCase()}`;
|
|
2506
|
+
return `${prefix}:
|
|
2507
|
+
${msg.content.text}`;
|
|
2508
|
+
}).join("\n\n---\n\n");
|
|
2509
|
+
const response = await this.server.createMessage({
|
|
2510
|
+
systemPrompt: `Summarize this agent execution:
|
|
2511
|
+
|
|
2512
|
+
Final Decision: (include complete JSON if present)
|
|
2513
|
+
Key Findings: (most important)
|
|
2514
|
+
Actions Taken: (high-level flow)
|
|
2515
|
+
Errors/Warnings: (if any)
|
|
2516
|
+
|
|
2517
|
+
${history}`,
|
|
2518
|
+
messages: [
|
|
2743
2519
|
{
|
|
2744
|
-
|
|
2745
|
-
|
|
2520
|
+
role: "user",
|
|
2521
|
+
content: {
|
|
2522
|
+
type: "text",
|
|
2523
|
+
text: "Please provide a concise summary."
|
|
2524
|
+
}
|
|
2746
2525
|
}
|
|
2747
2526
|
],
|
|
2748
|
-
|
|
2749
|
-
};
|
|
2527
|
+
maxTokens: 3e3
|
|
2528
|
+
});
|
|
2529
|
+
const summary = "\n\n" + response.content.text;
|
|
2530
|
+
this.logger.debug({
|
|
2531
|
+
message: "Summarization completed",
|
|
2532
|
+
summaryLength: summary.length
|
|
2533
|
+
});
|
|
2534
|
+
if (summarizeSpan) {
|
|
2535
|
+
summarizeSpan.setAttributes({
|
|
2536
|
+
summaryLength: summary.length,
|
|
2537
|
+
summary,
|
|
2538
|
+
success: true
|
|
2539
|
+
});
|
|
2540
|
+
endSpan(summarizeSpan);
|
|
2541
|
+
}
|
|
2542
|
+
return summary;
|
|
2543
|
+
} catch (error) {
|
|
2544
|
+
this.logger.warning({
|
|
2545
|
+
message: "Summarization failed, falling back to full history",
|
|
2546
|
+
error: String(error)
|
|
2547
|
+
});
|
|
2548
|
+
if (summarizeSpan) {
|
|
2549
|
+
endSpan(summarizeSpan, error);
|
|
2550
|
+
}
|
|
2551
|
+
return this.formatConversation();
|
|
2750
2552
|
}
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2553
|
+
}
|
|
2554
|
+
// Format full conversation history (for debugging)
|
|
2555
|
+
formatConversation() {
|
|
2556
|
+
if (this.conversationHistory.length === 0) {
|
|
2557
|
+
return "\n\n**No conversation history**";
|
|
2558
|
+
}
|
|
2559
|
+
const messages = this.conversationHistory.map((msg, i) => {
|
|
2560
|
+
const header = `### Message ${i + 1}: ${msg.role}`;
|
|
2561
|
+
try {
|
|
2562
|
+
const parsed = JSON.parse(msg.content.text);
|
|
2563
|
+
if (JSON.stringify(parsed).length < 100) {
|
|
2564
|
+
return `${header}
|
|
2565
|
+
${JSON.stringify(parsed)}`;
|
|
2566
|
+
}
|
|
2567
|
+
return `${header}
|
|
2568
|
+
\`\`\`json
|
|
2569
|
+
${JSON.stringify(parsed, null, 2)}
|
|
2570
|
+
\`\`\``;
|
|
2571
|
+
} catch {
|
|
2572
|
+
return `${header}
|
|
2573
|
+
${msg.content.text}`;
|
|
2574
|
+
}
|
|
2575
|
+
});
|
|
2576
|
+
return "\n\n**Conversation History:**\n" + messages.join("\n\n");
|
|
2577
|
+
}
|
|
2578
|
+
logIterationProgress(parsedData, result, model, stopReason, role) {
|
|
2579
|
+
this.logger.debug({
|
|
2580
|
+
iteration: `${this.currentIteration + 1}/${this.maxIterations}`,
|
|
2581
|
+
parsedData,
|
|
2582
|
+
isError: result.isError,
|
|
2583
|
+
isComplete: result.isComplete,
|
|
2584
|
+
model,
|
|
2585
|
+
stopReason,
|
|
2586
|
+
role,
|
|
2587
|
+
result
|
|
2588
|
+
});
|
|
2589
|
+
}
|
|
2590
|
+
injectJsonInstruction({ prompt, schema, schemaPrefix = "JSON schema:", schemaSuffix = `STRICT REQUIREMENTS:
|
|
2591
|
+
1. Return ONE AND ONLY ONE raw JSON object that passes JSON.parse() - no markdown, code blocks, explanatory text, or multiple JSON objects
|
|
2592
|
+
2. Include ALL required fields with correct data types and satisfy ALL schema constraints (anyOf, oneOf, allOf, not, enum, pattern, min/max, conditionals)
|
|
2593
|
+
3. Your response must be a single JSON object, nothing else
|
|
2758
2594
|
|
|
2759
|
-
|
|
2595
|
+
INVALID: \`\`\`json{"key":"value"}\`\`\` or "Here is: {"key":"value"}" or {"key":"value"}{"key":"value"}
|
|
2596
|
+
VALID: {"key":"value"}` }) {
|
|
2597
|
+
return [
|
|
2598
|
+
prompt != null && prompt.length > 0 ? prompt : void 0,
|
|
2599
|
+
prompt != null && prompt.length > 0 ? "" : void 0,
|
|
2600
|
+
schemaPrefix,
|
|
2601
|
+
schema != null ? JSON.stringify(schema, null, 2) : void 0,
|
|
2602
|
+
schemaSuffix
|
|
2603
|
+
].filter((line) => line != null).join("\n");
|
|
2604
|
+
}
|
|
2605
|
+
// Validate arguments using JSON schema
|
|
2606
|
+
validateInput(args, schema) {
|
|
2607
|
+
return validateSchema(args, schema);
|
|
2608
|
+
}
|
|
2609
|
+
};
|
|
2760
2610
|
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
${
|
|
2611
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/sampling/agentic-sampling-executor.js
|
|
2612
|
+
var SamplingExecutor = class extends BaseSamplingExecutor {
|
|
2613
|
+
agenticExecutor;
|
|
2614
|
+
constructor(name, description, allToolNames, toolNameToDetailList, server, config) {
|
|
2615
|
+
super(name, description, allToolNames, toolNameToDetailList, server, config);
|
|
2616
|
+
this.agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server);
|
|
2617
|
+
}
|
|
2618
|
+
buildDepGroups() {
|
|
2619
|
+
const depGroups = {};
|
|
2620
|
+
this.toolNameToDetailList.forEach(([toolName, tool]) => {
|
|
2621
|
+
if (tool?.inputSchema) {
|
|
2622
|
+
depGroups[toolName] = {
|
|
2623
|
+
type: "object",
|
|
2624
|
+
description: tool.description || `Tool: ${toolName}`,
|
|
2625
|
+
...tool.inputSchema
|
|
2626
|
+
};
|
|
2627
|
+
} else {
|
|
2628
|
+
const toolSchema = this.server.getHiddenToolSchema(toolName);
|
|
2629
|
+
if (toolSchema) {
|
|
2630
|
+
depGroups[toolName] = {
|
|
2631
|
+
...toolSchema.schema,
|
|
2632
|
+
description: toolSchema.description
|
|
2633
|
+
};
|
|
2775
2634
|
}
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2635
|
+
}
|
|
2636
|
+
});
|
|
2637
|
+
return depGroups;
|
|
2779
2638
|
}
|
|
2780
|
-
|
|
2781
|
-
const
|
|
2782
|
-
if (!
|
|
2639
|
+
executeSampling(args, schema) {
|
|
2640
|
+
const validationResult = validateSchema(args, schema);
|
|
2641
|
+
if (!validationResult.valid) {
|
|
2783
2642
|
return {
|
|
2784
2643
|
content: [
|
|
2785
2644
|
{
|
|
2786
2645
|
type: "text",
|
|
2787
|
-
text:
|
|
2646
|
+
text: CompiledPrompts.errorResponse({
|
|
2647
|
+
errorMessage: validationResult.error || "Validation failed"
|
|
2648
|
+
})
|
|
2788
2649
|
}
|
|
2789
2650
|
],
|
|
2790
2651
|
isError: true
|
|
2791
2652
|
};
|
|
2792
2653
|
}
|
|
2793
|
-
|
|
2794
|
-
const
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
text: `${error.message}`
|
|
2814
|
-
});
|
|
2815
|
-
results.content.push({
|
|
2816
|
-
type: "text",
|
|
2817
|
-
text: `Action \`${action}\` \u274C **FAILED** with error: `
|
|
2818
|
-
});
|
|
2819
|
-
results.isError = true;
|
|
2820
|
-
}
|
|
2821
|
-
}
|
|
2822
|
-
if (results.isError) {
|
|
2823
|
-
state.markCurrentStepFailed("Step execution failed");
|
|
2824
|
-
} else {
|
|
2825
|
-
state.markCurrentStepCompleted("Step completed successfully");
|
|
2826
|
-
}
|
|
2827
|
-
if (state.hasNextStep()) {
|
|
2828
|
-
const nextStepArgsDef = this.createArgsDef.forNextState(state);
|
|
2829
|
-
results.content.push({
|
|
2830
|
-
type: "text",
|
|
2831
|
-
text: CompiledPrompts.nextStepDecision({
|
|
2832
|
-
toolName: this.name,
|
|
2833
|
-
nextStepDescription: state.getNextStep()?.description || "Unknown step",
|
|
2834
|
-
nextStepSchema: JSON.stringify(nextStepArgsDef, null, 2)
|
|
2835
|
-
})
|
|
2836
|
-
});
|
|
2837
|
-
} else {
|
|
2838
|
-
results.content.push({
|
|
2839
|
-
type: "text",
|
|
2840
|
-
text: CompiledPrompts.finalStepCompletion({
|
|
2841
|
-
statusIcon: results.isError ? "\u274C" : "\u2705",
|
|
2842
|
-
statusText: results.isError ? "with errors" : "successfully",
|
|
2843
|
-
toolName: this.name,
|
|
2844
|
-
newWorkflowInstructions: this.predefinedSteps ? "" : " and new `steps` array"
|
|
2845
|
-
})
|
|
2654
|
+
const createArgsDef = createArgsDefFactory(this.name, this.allToolNames, this.buildDepGroups(), void 0, void 0);
|
|
2655
|
+
const agenticSchema = createArgsDef.forAgentic(this.toolNameToDetailList, true);
|
|
2656
|
+
const systemPrompt = this.buildSystemPrompt(args.userRequest, agenticSchema, args.context && typeof args.context === "object" ? args.context : void 0);
|
|
2657
|
+
return this.runSamplingLoop(() => systemPrompt, agenticSchema);
|
|
2658
|
+
}
|
|
2659
|
+
async processAction(parsedData, schema, _state, parentSpan) {
|
|
2660
|
+
const toolCallData = parsedData;
|
|
2661
|
+
if (toolCallData.decision === "complete") {
|
|
2662
|
+
return await this.createCompletionResult("Task completed", parentSpan);
|
|
2663
|
+
}
|
|
2664
|
+
try {
|
|
2665
|
+
const { action: _action, decision: _decision, ..._toolArgs } = toolCallData;
|
|
2666
|
+
const toolResult = await this.agenticExecutor.execute(toolCallData, schema, parentSpan);
|
|
2667
|
+
const resultText = toolResult.content?.filter((content) => content.type === "text")?.map((content) => content.text)?.join("\n") || "No result";
|
|
2668
|
+
this.conversationHistory.push({
|
|
2669
|
+
role: "assistant",
|
|
2670
|
+
content: {
|
|
2671
|
+
type: "text",
|
|
2672
|
+
text: resultText
|
|
2673
|
+
}
|
|
2846
2674
|
});
|
|
2675
|
+
return toolResult;
|
|
2676
|
+
} catch (error) {
|
|
2677
|
+
return this.createExecutionError(error, parentSpan);
|
|
2847
2678
|
}
|
|
2848
|
-
results.content.push({
|
|
2849
|
-
type: "text",
|
|
2850
|
-
text: `## Workflow Progress
|
|
2851
|
-
${this.formatProgress(state)}`
|
|
2852
|
-
});
|
|
2853
|
-
return results;
|
|
2854
2679
|
}
|
|
2855
|
-
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
}
|
|
2680
|
+
buildSystemPrompt(userRequest, agenticSchema, context2) {
|
|
2681
|
+
const toolList = this.allToolNames.map((name) => {
|
|
2682
|
+
const tool = this.toolNameToDetailList.find(([toolName]) => toolName === name);
|
|
2683
|
+
const toolSchema = this.server.getHiddenToolSchema(name);
|
|
2684
|
+
if (tool && tool[1]) {
|
|
2685
|
+
return `- ${name}: ${tool[1].description || `Tool: ${name}`}`;
|
|
2686
|
+
} else if (toolSchema) {
|
|
2687
|
+
return `- ${name}: ${toolSchema.description}`;
|
|
2688
|
+
}
|
|
2689
|
+
return `- ${name}`;
|
|
2690
|
+
}).join("\n");
|
|
2691
|
+
let contextInfo = "";
|
|
2692
|
+
if (context2 && typeof context2 === "object" && Object.keys(context2).length > 0) {
|
|
2693
|
+
contextInfo = `
|
|
2694
|
+
|
|
2695
|
+
Context:
|
|
2696
|
+
${JSON.stringify(context2, null, 2)}`;
|
|
2864
2697
|
}
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2698
|
+
const basePrompt = CompiledPrompts.samplingExecution({
|
|
2699
|
+
toolName: this.name,
|
|
2700
|
+
description: this.description,
|
|
2701
|
+
toolList
|
|
2702
|
+
});
|
|
2703
|
+
const taskPrompt = `
|
|
2704
|
+
|
|
2705
|
+
## Current Task
|
|
2706
|
+
You will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
|
|
2707
|
+
|
|
2708
|
+
When you need to use a tool, specify the tool name in 'action' and provide tool-specific parameters as additional properties.`;
|
|
2709
|
+
return this.injectJsonInstruction({
|
|
2710
|
+
prompt: basePrompt + taskPrompt,
|
|
2711
|
+
schema: agenticSchema
|
|
2712
|
+
});
|
|
2868
2713
|
}
|
|
2869
2714
|
};
|
|
2870
2715
|
|
|
2716
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/agentic/agentic-sampling-registrar.js
|
|
2717
|
+
function registerAgenticSamplingTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList, samplingConfig }) {
|
|
2718
|
+
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
2719
|
+
const samplingExecutor = new SamplingExecutor(name, description, allToolNames, toolNameToDetailList, server, samplingConfig);
|
|
2720
|
+
description = CompiledPrompts.samplingExecution({
|
|
2721
|
+
toolName: name,
|
|
2722
|
+
description,
|
|
2723
|
+
toolList: allToolNames.map((name2) => `- ${name2}`).join("\n")
|
|
2724
|
+
});
|
|
2725
|
+
const argsDef = createArgsDef.forSampling();
|
|
2726
|
+
const schema = allToolNames.length > 0 ? argsDef : {
|
|
2727
|
+
type: "object",
|
|
2728
|
+
properties: {}
|
|
2729
|
+
};
|
|
2730
|
+
server.tool(name, description, jsonSchema(createGoogleCompatibleJSONSchema(schema)), async (args) => {
|
|
2731
|
+
return await samplingExecutor.executeSampling(args, schema);
|
|
2732
|
+
});
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-agentic-sampling-plugin.js
|
|
2736
|
+
var createAgenticSamplingModePlugin = () => ({
|
|
2737
|
+
name: "mode-agentic-sampling",
|
|
2738
|
+
version: "1.0.0",
|
|
2739
|
+
// Only apply to agentic_sampling mode
|
|
2740
|
+
apply: "agentic_sampling",
|
|
2741
|
+
// Register the agent tool with sampling
|
|
2742
|
+
registerAgentTool: (context2) => {
|
|
2743
|
+
registerAgenticSamplingTool(context2.server, {
|
|
2744
|
+
description: context2.description,
|
|
2745
|
+
name: context2.name,
|
|
2746
|
+
allToolNames: context2.allToolNames,
|
|
2747
|
+
depGroups: context2.depGroups,
|
|
2748
|
+
toolNameToDetailList: context2.toolNameToDetailList,
|
|
2749
|
+
samplingConfig: context2.options.samplingConfig
|
|
2750
|
+
});
|
|
2751
|
+
}
|
|
2752
|
+
});
|
|
2753
|
+
var mode_agentic_sampling_plugin_default = createAgenticSamplingModePlugin();
|
|
2754
|
+
|
|
2871
2755
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/sampling/workflow-sampling-executor.js
|
|
2872
2756
|
var WorkflowSamplingExecutor = class extends BaseSamplingExecutor {
|
|
2873
2757
|
createArgsDef;
|
|
@@ -2878,7 +2762,7 @@ var WorkflowSamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
2878
2762
|
this.workflowExecutor = new WorkflowExecutor(name, allToolNames, toolNameToDetailList, createArgsDef, server, predefinedSteps);
|
|
2879
2763
|
}
|
|
2880
2764
|
async executeWorkflowSampling(args, schema, state) {
|
|
2881
|
-
const validationResult =
|
|
2765
|
+
const validationResult = validateSchema(args, schema);
|
|
2882
2766
|
if (!validationResult.valid) {
|
|
2883
2767
|
return {
|
|
2884
2768
|
content: [
|
|
@@ -2942,33 +2826,24 @@ Current Task: <user_request>${args.userRequest}</user_request>${contextInfo}`;
|
|
|
2942
2826
|
}
|
|
2943
2827
|
};
|
|
2944
2828
|
|
|
2945
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/workflow/workflow-
|
|
2946
|
-
function
|
|
2829
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/workflow/workflow-sampling-registrar.js
|
|
2830
|
+
function registerWorkflowSamplingTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList, predefinedSteps, samplingConfig, ensureStepActions, toolNameToIdMapping: _toolNameToIdMapping }) {
|
|
2947
2831
|
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, predefinedSteps, ensureStepActions);
|
|
2948
|
-
const isSamplingMode = sampling === true || typeof sampling === "object";
|
|
2949
|
-
const samplingConfig = typeof sampling === "object" ? sampling : void 0;
|
|
2950
|
-
const workflowExecutor = new WorkflowExecutor(name, allToolNames, toolNameToDetailList, createArgsDef, server, predefinedSteps, ensureStepActions, toolNameToIdMapping);
|
|
2951
2832
|
const workflowSamplingExecutor = new WorkflowSamplingExecutor(name, description, allToolNames, toolNameToDetailList, createArgsDef, server, predefinedSteps, samplingConfig);
|
|
2952
2833
|
const workflowState = new WorkflowState();
|
|
2953
|
-
const
|
|
2954
|
-
const baseDescription = isSamplingMode ? CompiledPrompts.samplingExecution({
|
|
2834
|
+
const baseDescription = CompiledPrompts.samplingExecution({
|
|
2955
2835
|
toolName: name,
|
|
2956
2836
|
description,
|
|
2957
2837
|
toolList: allToolNames.map((name2) => `- ${name2}`).join("\n")
|
|
2958
|
-
}) : CompiledPrompts.workflowExecution({
|
|
2959
|
-
toolName: name,
|
|
2960
|
-
description,
|
|
2961
|
-
planningInstructions
|
|
2962
2838
|
});
|
|
2963
|
-
const argsDef =
|
|
2964
|
-
const
|
|
2965
|
-
|
|
2839
|
+
const argsDef = createArgsDef.forSampling();
|
|
2840
|
+
const schema = allToolNames.length > 0 ? argsDef : {
|
|
2841
|
+
type: "object",
|
|
2842
|
+
properties: {}
|
|
2843
|
+
};
|
|
2844
|
+
server.tool(name, baseDescription, jsonSchema(createGoogleCompatibleJSONSchema(schema)), async (args) => {
|
|
2966
2845
|
try {
|
|
2967
|
-
|
|
2968
|
-
return await workflowSamplingExecutor.executeWorkflowSampling(args, argsDef, workflowState);
|
|
2969
|
-
} else {
|
|
2970
|
-
return await workflowExecutor.execute(args, workflowState);
|
|
2971
|
-
}
|
|
2846
|
+
return await workflowSamplingExecutor.executeWorkflowSampling(args, schema, workflowState);
|
|
2972
2847
|
} catch (error) {
|
|
2973
2848
|
workflowState.reset();
|
|
2974
2849
|
return {
|
|
@@ -2984,52 +2859,48 @@ function registerAgenticWorkflowTool(server, { description, name, allToolNames,
|
|
|
2984
2859
|
});
|
|
2985
2860
|
}
|
|
2986
2861
|
|
|
2987
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/
|
|
2988
|
-
var
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2862
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-workflow-sampling-plugin.js
|
|
2863
|
+
var createWorkflowSamplingModePlugin = () => ({
|
|
2864
|
+
name: "mode-agentic-workflow-sampling",
|
|
2865
|
+
version: "1.0.0",
|
|
2866
|
+
// Only apply to agentic_workflow_sampling mode
|
|
2867
|
+
apply: "agentic_workflow_sampling",
|
|
2868
|
+
// Register the agent tool with sampling
|
|
2869
|
+
registerAgentTool: (context2) => {
|
|
2870
|
+
registerWorkflowSamplingTool(context2.server, {
|
|
2871
|
+
description: context2.description,
|
|
2872
|
+
name: context2.name,
|
|
2873
|
+
allToolNames: context2.allToolNames,
|
|
2874
|
+
depGroups: context2.depGroups,
|
|
2875
|
+
toolNameToDetailList: context2.toolNameToDetailList,
|
|
2876
|
+
predefinedSteps: context2.options.steps,
|
|
2877
|
+
samplingConfig: context2.options.samplingConfig,
|
|
2878
|
+
ensureStepActions: context2.options.ensureStepActions,
|
|
2879
|
+
toolNameToIdMapping: context2.toolNameToIdMapping
|
|
2880
|
+
});
|
|
2993
2881
|
}
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
return toolName === id || toolName === dotNotation;
|
|
2997
|
-
});
|
|
2998
|
-
}
|
|
2999
|
-
function processToolTags({ description, tagToResults, $, tools, toolOverrides, toolNameMapping }) {
|
|
3000
|
-
tagToResults.tool.forEach((toolEl) => {
|
|
3001
|
-
const toolName = toolEl.attribs.name;
|
|
3002
|
-
if (!toolName || toolName.includes(ALL_TOOLS_PLACEHOLDER)) {
|
|
3003
|
-
$(toolEl).remove();
|
|
3004
|
-
return;
|
|
3005
|
-
}
|
|
3006
|
-
const override = toolOverrides.get(toolName);
|
|
3007
|
-
if (override?.visibility?.hidden) {
|
|
3008
|
-
$(toolEl).remove();
|
|
3009
|
-
} else if (override?.visibility?.public) {
|
|
3010
|
-
$(toolEl).replaceWith(`<tool name="${toolName}"/>`);
|
|
3011
|
-
} else {
|
|
3012
|
-
const toolId = findToolId(toolName, tools, toolNameMapping);
|
|
3013
|
-
if (toolId) {
|
|
3014
|
-
$(toolEl).replaceWith(`<action action="${toolId}"/>`);
|
|
3015
|
-
} else {
|
|
3016
|
-
$(toolEl).remove();
|
|
3017
|
-
}
|
|
3018
|
-
}
|
|
3019
|
-
});
|
|
3020
|
-
return $.root().html() ?? description;
|
|
3021
|
-
}
|
|
2882
|
+
});
|
|
2883
|
+
var mode_workflow_sampling_plugin_default = createWorkflowSamplingModePlugin();
|
|
3022
2884
|
|
|
3023
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/
|
|
3024
|
-
|
|
3025
|
-
|
|
2885
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/index.js
|
|
2886
|
+
function getBuiltInPlugins() {
|
|
2887
|
+
return [
|
|
2888
|
+
tool_name_mapping_plugin_default,
|
|
2889
|
+
config_plugin_default,
|
|
2890
|
+
mode_agentic_plugin_default,
|
|
2891
|
+
mode_workflow_plugin_default,
|
|
2892
|
+
mode_agentic_sampling_plugin_default,
|
|
2893
|
+
mode_workflow_sampling_plugin_default,
|
|
2894
|
+
logging_plugin_default
|
|
2895
|
+
];
|
|
2896
|
+
}
|
|
3026
2897
|
|
|
3027
2898
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugin-utils.js
|
|
3028
2899
|
var pluginCache = /* @__PURE__ */ new Map();
|
|
3029
2900
|
function shouldApplyPlugin(plugin, mode) {
|
|
3030
2901
|
if (!plugin.apply) return true;
|
|
3031
2902
|
if (typeof plugin.apply === "string") {
|
|
3032
|
-
return mode
|
|
2903
|
+
return mode === plugin.apply;
|
|
3033
2904
|
}
|
|
3034
2905
|
if (typeof plugin.apply === "function") {
|
|
3035
2906
|
try {
|
|
@@ -3079,7 +2950,7 @@ function isValidPlugin(plugin) {
|
|
|
3079
2950
|
if (!p2.name || typeof p2.name !== "string" || p2.name.trim() === "") {
|
|
3080
2951
|
return false;
|
|
3081
2952
|
}
|
|
3082
|
-
const hasHook = typeof p2.configureServer === "function" || typeof p2.composeStart === "function" || typeof p2.transformTool === "function" || typeof p2.finalizeComposition === "function" || typeof p2.composeEnd === "function" || typeof p2.transformInput === "function" || typeof p2.transformOutput === "function" || typeof p2.dispose === "function";
|
|
2953
|
+
const hasHook = typeof p2.configureServer === "function" || typeof p2.composeStart === "function" || typeof p2.transformTool === "function" || typeof p2.finalizeComposition === "function" || typeof p2.registerAgentTool === "function" || typeof p2.composeEnd === "function" || typeof p2.transformInput === "function" || typeof p2.transformOutput === "function" || typeof p2.dispose === "function";
|
|
3083
2954
|
if (!hasHook) return false;
|
|
3084
2955
|
if (p2.enforce && p2.enforce !== "pre" && p2.enforce !== "post") {
|
|
3085
2956
|
return false;
|
|
@@ -3216,7 +3087,6 @@ function validatePlugins(plugins) {
|
|
|
3216
3087
|
}
|
|
3217
3088
|
|
|
3218
3089
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/plugin-manager.js
|
|
3219
|
-
init_logger();
|
|
3220
3090
|
var PluginManager = class {
|
|
3221
3091
|
server;
|
|
3222
3092
|
plugins;
|
|
@@ -3364,6 +3234,29 @@ var PluginManager = class {
|
|
|
3364
3234
|
}
|
|
3365
3235
|
}
|
|
3366
3236
|
}
|
|
3237
|
+
/**
|
|
3238
|
+
* Trigger registerAgentTool hook - allows plugins to register the main agent tool
|
|
3239
|
+
* Returns true if any plugin handled the registration
|
|
3240
|
+
*/
|
|
3241
|
+
async triggerRegisterAgentTool(context2) {
|
|
3242
|
+
const registerPlugins = this.plugins.filter((p2) => p2.registerAgentTool && shouldApplyPlugin(p2, context2.mode));
|
|
3243
|
+
if (registerPlugins.length === 0) {
|
|
3244
|
+
return false;
|
|
3245
|
+
}
|
|
3246
|
+
const sortedPlugins = sortPluginsByOrder(registerPlugins).reverse();
|
|
3247
|
+
for (const plugin of sortedPlugins) {
|
|
3248
|
+
if (plugin.registerAgentTool) {
|
|
3249
|
+
try {
|
|
3250
|
+
await plugin.registerAgentTool(context2);
|
|
3251
|
+
return true;
|
|
3252
|
+
} catch (error) {
|
|
3253
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
3254
|
+
await this.logger.error(`Plugin "${plugin.name}" registerAgentTool failed: ${errorMsg}`);
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
}
|
|
3258
|
+
return false;
|
|
3259
|
+
}
|
|
3367
3260
|
/**
|
|
3368
3261
|
* Dispose all plugins and cleanup resources
|
|
3369
3262
|
*/
|
|
@@ -3383,7 +3276,6 @@ var PluginManager = class {
|
|
|
3383
3276
|
};
|
|
3384
3277
|
|
|
3385
3278
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/tool-manager.js
|
|
3386
|
-
init_schema();
|
|
3387
3279
|
var ToolManager = class {
|
|
3388
3280
|
toolRegistry = /* @__PURE__ */ new Map();
|
|
3389
3281
|
toolConfigs = /* @__PURE__ */ new Map();
|
|
@@ -3592,9 +3484,103 @@ var ToolManager = class {
|
|
|
3592
3484
|
}
|
|
3593
3485
|
};
|
|
3594
3486
|
|
|
3487
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/schema.js
|
|
3488
|
+
import traverse from "json-schema-traverse";
|
|
3489
|
+
function updateRefPaths(schema, wrapperPath) {
|
|
3490
|
+
if (!schema || typeof schema !== "object") {
|
|
3491
|
+
return schema;
|
|
3492
|
+
}
|
|
3493
|
+
if (!wrapperPath || typeof wrapperPath !== "string") {
|
|
3494
|
+
throw new Error("wrapperPath must be a non-empty string");
|
|
3495
|
+
}
|
|
3496
|
+
const clonedSchema = JSON.parse(JSON.stringify(schema));
|
|
3497
|
+
try {
|
|
3498
|
+
traverse(clonedSchema, {
|
|
3499
|
+
allKeys: true,
|
|
3500
|
+
cb: function(schemaNode, _jsonPtr, _rootSchema, _parentJsonPtr, _parentKeyword, _parentSchema, _keyIndex) {
|
|
3501
|
+
if (schemaNode && typeof schemaNode === "object" && schemaNode.$ref) {
|
|
3502
|
+
const ref = schemaNode.$ref;
|
|
3503
|
+
if (ref.startsWith("#/properties/")) {
|
|
3504
|
+
const relativePath = ref.substring(13);
|
|
3505
|
+
schemaNode.$ref = `#/properties/${wrapperPath}/properties/${relativePath}`;
|
|
3506
|
+
} else if (ref === "#") {
|
|
3507
|
+
schemaNode.$ref = `#/properties/${wrapperPath}`;
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3510
|
+
}
|
|
3511
|
+
});
|
|
3512
|
+
} catch (error) {
|
|
3513
|
+
console.warn(`Failed to traverse schema for path "${wrapperPath}":`, error);
|
|
3514
|
+
return clonedSchema;
|
|
3515
|
+
}
|
|
3516
|
+
return clonedSchema;
|
|
3517
|
+
}
|
|
3518
|
+
|
|
3519
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/compose-helpers.js
|
|
3520
|
+
async function processToolsWithPlugins(server, _externalTools, mode) {
|
|
3521
|
+
const toolManager = server.toolManager;
|
|
3522
|
+
const pluginManager = server.pluginManager;
|
|
3523
|
+
for (const [toolId, toolData] of toolManager.getToolEntries()) {
|
|
3524
|
+
const defaultSchema = {
|
|
3525
|
+
type: "object",
|
|
3526
|
+
properties: {},
|
|
3527
|
+
additionalProperties: true
|
|
3528
|
+
};
|
|
3529
|
+
const tempTool = {
|
|
3530
|
+
name: toolId,
|
|
3531
|
+
description: toolData.description,
|
|
3532
|
+
inputSchema: toolData.schema || defaultSchema,
|
|
3533
|
+
execute: toolData.callback
|
|
3534
|
+
};
|
|
3535
|
+
const processedTool = await pluginManager.applyTransformToolHooks(tempTool, {
|
|
3536
|
+
toolName: toolId,
|
|
3537
|
+
server,
|
|
3538
|
+
mode,
|
|
3539
|
+
originalTool: {
|
|
3540
|
+
...tempTool
|
|
3541
|
+
},
|
|
3542
|
+
transformationIndex: 0
|
|
3543
|
+
});
|
|
3544
|
+
toolManager.registerTool(toolId, processedTool.description || toolData.description, processedTool.inputSchema, processedTool.execute);
|
|
3545
|
+
}
|
|
3546
|
+
}
|
|
3547
|
+
function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicToolNames, server) {
|
|
3548
|
+
const depGroups = {};
|
|
3549
|
+
const toolManager = server.toolManager;
|
|
3550
|
+
toolNameToDetailList.forEach(([toolName, tool]) => {
|
|
3551
|
+
const resolvedName = toolManager.resolveToolName(toolName);
|
|
3552
|
+
if (hiddenToolNames.includes(resolvedName ?? "") || publicToolNames.includes(resolvedName ?? "")) {
|
|
3553
|
+
return;
|
|
3554
|
+
}
|
|
3555
|
+
if (!tool) {
|
|
3556
|
+
const allToolNames = [
|
|
3557
|
+
...toolNameToDetailList.map(([n]) => n)
|
|
3558
|
+
];
|
|
3559
|
+
throw new Error(`Action ${toolName} not found, available action list: ${allToolNames.join(", ")}`);
|
|
3560
|
+
}
|
|
3561
|
+
const baseSchema = tool.inputSchema.jsonSchema ?? tool.inputSchema ?? {
|
|
3562
|
+
type: "object",
|
|
3563
|
+
properties: {},
|
|
3564
|
+
required: []
|
|
3565
|
+
};
|
|
3566
|
+
const baseProperties = baseSchema.type === "object" && baseSchema.properties ? baseSchema.properties : {};
|
|
3567
|
+
const baseRequired = baseSchema.type === "object" && Array.isArray(baseSchema.required) ? baseSchema.required : [];
|
|
3568
|
+
const updatedProperties = updateRefPaths(baseProperties, toolName);
|
|
3569
|
+
const sanitizedKey = sanitizePropertyKey(toolName);
|
|
3570
|
+
depGroups[sanitizedKey] = {
|
|
3571
|
+
type: "object",
|
|
3572
|
+
description: tool.description,
|
|
3573
|
+
properties: updatedProperties,
|
|
3574
|
+
required: [
|
|
3575
|
+
...baseRequired
|
|
3576
|
+
],
|
|
3577
|
+
additionalProperties: false
|
|
3578
|
+
};
|
|
3579
|
+
});
|
|
3580
|
+
return depGroups;
|
|
3581
|
+
}
|
|
3582
|
+
|
|
3595
3583
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/compose.js
|
|
3596
|
-
init_compose_helpers();
|
|
3597
|
-
init_provider();
|
|
3598
3584
|
var ALL_TOOLS_PLACEHOLDER2 = "__ALL__";
|
|
3599
3585
|
var ComposableMCPServer = class extends Server {
|
|
3600
3586
|
pluginManager;
|
|
@@ -3809,8 +3795,7 @@ var ComposableMCPServer = class extends Server {
|
|
|
3809
3795
|
* Apply plugins to all tools in registry and handle visibility configurations
|
|
3810
3796
|
*/
|
|
3811
3797
|
async processToolsWithPlugins(externalTools, mode) {
|
|
3812
|
-
|
|
3813
|
-
await processTools(this, externalTools, mode);
|
|
3798
|
+
await processToolsWithPlugins(this, externalTools, mode);
|
|
3814
3799
|
}
|
|
3815
3800
|
/**
|
|
3816
3801
|
* Dispose all plugins and cleanup resources
|
|
@@ -3818,6 +3803,13 @@ var ComposableMCPServer = class extends Server {
|
|
|
3818
3803
|
async disposePlugins() {
|
|
3819
3804
|
await this.pluginManager.dispose();
|
|
3820
3805
|
}
|
|
3806
|
+
/**
|
|
3807
|
+
* Close the server and ensure all plugins are disposed
|
|
3808
|
+
*/
|
|
3809
|
+
async close() {
|
|
3810
|
+
await this.disposePlugins();
|
|
3811
|
+
await super.close();
|
|
3812
|
+
}
|
|
3821
3813
|
async compose(name, description, depsConfig = {
|
|
3822
3814
|
mcpServers: {}
|
|
3823
3815
|
}, options = {
|
|
@@ -3963,30 +3955,23 @@ var ComposableMCPServer = class extends Server {
|
|
|
3963
3955
|
});
|
|
3964
3956
|
const allToolNames = contextToolNames;
|
|
3965
3957
|
const depGroups = buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicToolNames, this);
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
|
|
3972
|
-
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
toolNameToDetailList,
|
|
3984
|
-
predefinedSteps: options.steps,
|
|
3985
|
-
sampling: options.sampling,
|
|
3986
|
-
ensureStepActions: options.ensureStepActions,
|
|
3987
|
-
toolNameToIdMapping
|
|
3988
|
-
});
|
|
3989
|
-
break;
|
|
3958
|
+
const mode = options.mode ?? "agentic";
|
|
3959
|
+
const context2 = {
|
|
3960
|
+
server: this,
|
|
3961
|
+
name,
|
|
3962
|
+
description,
|
|
3963
|
+
mode,
|
|
3964
|
+
allToolNames,
|
|
3965
|
+
toolNameToDetailList,
|
|
3966
|
+
depGroups,
|
|
3967
|
+
toolNameToIdMapping,
|
|
3968
|
+
publicToolNames,
|
|
3969
|
+
hiddenToolNames,
|
|
3970
|
+
options
|
|
3971
|
+
};
|
|
3972
|
+
const handled = await this.pluginManager.triggerRegisterAgentTool(context2);
|
|
3973
|
+
if (!handled) {
|
|
3974
|
+
throw new Error(`No plugin registered to handle execution mode "${mode}". Did you override the default mode plugin, but in the wrong way?`);
|
|
3990
3975
|
}
|
|
3991
3976
|
}
|
|
3992
3977
|
};
|
|
@@ -4002,13 +3987,6 @@ if (isSCF()) {
|
|
|
4002
3987
|
});
|
|
4003
3988
|
}
|
|
4004
3989
|
|
|
4005
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/mod.ts
|
|
4006
|
-
init_json();
|
|
4007
|
-
|
|
4008
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/mod.js
|
|
4009
|
-
init_json();
|
|
4010
|
-
init_schema();
|
|
4011
|
-
|
|
4012
3990
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/ai-sdk-adapter.js
|
|
4013
3991
|
function convertToAISDKTools(server, helpers) {
|
|
4014
3992
|
const { tool, jsonSchema: jsonSchema2 } = helpers;
|
|
@@ -4065,9 +4043,6 @@ async function mcpc(serverConf, composeConf, setupCallback) {
|
|
|
4065
4043
|
}
|
|
4066
4044
|
return server;
|
|
4067
4045
|
}
|
|
4068
|
-
|
|
4069
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/mod.ts
|
|
4070
|
-
init_schema();
|
|
4071
4046
|
export {
|
|
4072
4047
|
ComposableMCPServer,
|
|
4073
4048
|
composeMcpDepTools,
|