@mcpc-tech/core 0.3.17 → 0.3.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/index.cjs +422 -2260
- package/index.mjs +422 -2260
- package/package.json +2 -2
- package/types/src/compose.d.ts.map +1 -1
- package/types/src/prompts/types.d.ts +1 -1
- package/types/src/prompts/types.d.ts.map +1 -1
- package/types/src/set-up-mcp-compose.d.ts +8 -20
- package/types/src/set-up-mcp-compose.d.ts.map +1 -1
- package/types/src/types.d.ts.map +1 -1
- package/types/src/utils/state.d.ts +0 -5
- package/types/src/utils/state.d.ts.map +0 -1
package/index.cjs
CHANGED
|
@@ -394,7 +394,7 @@ var require_parse = __commonJS({
|
|
|
394
394
|
"use strict";
|
|
395
395
|
var path = require("path");
|
|
396
396
|
var resolveCommand = require_resolveCommand();
|
|
397
|
-
var
|
|
397
|
+
var escape = require_escape();
|
|
398
398
|
var readShebang = require_readShebang();
|
|
399
399
|
var isWin = process.platform === "win32";
|
|
400
400
|
var isExecutableRegExp = /\.(?:com|exe)$/i;
|
|
@@ -418,8 +418,8 @@ var require_parse = __commonJS({
|
|
|
418
418
|
if (parsed.options.forceShell || needsShell) {
|
|
419
419
|
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
|
|
420
420
|
parsed.command = path.normalize(parsed.command);
|
|
421
|
-
parsed.command =
|
|
422
|
-
parsed.args = parsed.args.map((arg) =>
|
|
421
|
+
parsed.command = escape.command(parsed.command);
|
|
422
|
+
parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
|
|
423
423
|
const shellCommand = [parsed.command].concat(parsed.args).join(" ");
|
|
424
424
|
parsed.args = ["/d", "/s", "/c", `"${shellCommand}"`];
|
|
425
425
|
parsed.command = process.env.comspec || "cmd.exe";
|
|
@@ -540,7 +540,7 @@ __export(mod_exports, {
|
|
|
540
540
|
jsonSchema: () => jsonSchema,
|
|
541
541
|
mcpc: () => mcpc,
|
|
542
542
|
optionalObject: () => optionalObject,
|
|
543
|
-
parseJSON: () =>
|
|
543
|
+
parseJSON: () => parseJSON,
|
|
544
544
|
parseMcpcConfigs: () => parseMcpcConfigs,
|
|
545
545
|
truncateJSON: () => truncateJSON
|
|
546
546
|
});
|
|
@@ -2783,15 +2783,15 @@ var $ZodDate = /* @__PURE__ */ $constructor("$ZodDate", (inst, def) => {
|
|
|
2783
2783
|
}
|
|
2784
2784
|
}
|
|
2785
2785
|
const input = payload.value;
|
|
2786
|
-
const
|
|
2787
|
-
const isValidDate =
|
|
2786
|
+
const isDate = input instanceof Date;
|
|
2787
|
+
const isValidDate = isDate && !Number.isNaN(input.getTime());
|
|
2788
2788
|
if (isValidDate)
|
|
2789
2789
|
return payload;
|
|
2790
2790
|
payload.issues.push({
|
|
2791
2791
|
expected: "date",
|
|
2792
2792
|
code: "invalid_type",
|
|
2793
2793
|
input,
|
|
2794
|
-
...
|
|
2794
|
+
...isDate ? { received: "Invalid Date" } : {},
|
|
2795
2795
|
inst
|
|
2796
2796
|
});
|
|
2797
2797
|
return payload;
|
|
@@ -3396,8 +3396,8 @@ var $ZodTuple = /* @__PURE__ */ $constructor("$ZodTuple", (inst, def) => {
|
|
|
3396
3396
|
}
|
|
3397
3397
|
}
|
|
3398
3398
|
if (def.rest) {
|
|
3399
|
-
const
|
|
3400
|
-
for (const el of
|
|
3399
|
+
const rest = input.slice(items.length);
|
|
3400
|
+
for (const el of rest) {
|
|
3401
3401
|
i++;
|
|
3402
3402
|
const result = def.rest._zod.run({
|
|
3403
3403
|
value: el,
|
|
@@ -5851,30 +5851,30 @@ var tupleProcessor = (schema, ctx, _json, params) => {
|
|
|
5851
5851
|
...params,
|
|
5852
5852
|
path: [...params.path, prefixPath, i]
|
|
5853
5853
|
}));
|
|
5854
|
-
const
|
|
5854
|
+
const rest = def.rest ? process2(def.rest, ctx, {
|
|
5855
5855
|
...params,
|
|
5856
5856
|
path: [...params.path, restPath, ...ctx.target === "openapi-3.0" ? [def.items.length] : []]
|
|
5857
5857
|
}) : null;
|
|
5858
5858
|
if (ctx.target === "draft-2020-12") {
|
|
5859
5859
|
json2.prefixItems = prefixItems;
|
|
5860
|
-
if (
|
|
5861
|
-
json2.items =
|
|
5860
|
+
if (rest) {
|
|
5861
|
+
json2.items = rest;
|
|
5862
5862
|
}
|
|
5863
5863
|
} else if (ctx.target === "openapi-3.0") {
|
|
5864
5864
|
json2.items = {
|
|
5865
5865
|
anyOf: prefixItems
|
|
5866
5866
|
};
|
|
5867
|
-
if (
|
|
5868
|
-
json2.items.anyOf.push(
|
|
5867
|
+
if (rest) {
|
|
5868
|
+
json2.items.anyOf.push(rest);
|
|
5869
5869
|
}
|
|
5870
5870
|
json2.minItems = prefixItems.length;
|
|
5871
|
-
if (!
|
|
5871
|
+
if (!rest) {
|
|
5872
5872
|
json2.maxItems = prefixItems.length;
|
|
5873
5873
|
}
|
|
5874
5874
|
} else {
|
|
5875
5875
|
json2.items = prefixItems;
|
|
5876
|
-
if (
|
|
5877
|
-
json2.additionalItems =
|
|
5876
|
+
if (rest) {
|
|
5877
|
+
json2.additionalItems = rest;
|
|
5878
5878
|
}
|
|
5879
5879
|
}
|
|
5880
5880
|
const { minimum, maximum } = schema._zod.bag;
|
|
@@ -6900,19 +6900,19 @@ var ZodTuple = /* @__PURE__ */ $constructor("ZodTuple", (inst, def) => {
|
|
|
6900
6900
|
$ZodTuple.init(inst, def);
|
|
6901
6901
|
ZodType.init(inst, def);
|
|
6902
6902
|
inst._zod.processJSONSchema = (ctx, json2, params) => tupleProcessor(inst, ctx, json2, params);
|
|
6903
|
-
inst.rest = (
|
|
6903
|
+
inst.rest = (rest) => inst.clone({
|
|
6904
6904
|
...inst._zod.def,
|
|
6905
|
-
rest
|
|
6905
|
+
rest
|
|
6906
6906
|
});
|
|
6907
6907
|
});
|
|
6908
6908
|
function tuple(items, _paramsOrRest, _params) {
|
|
6909
6909
|
const hasRest = _paramsOrRest instanceof $ZodType;
|
|
6910
6910
|
const params = hasRest ? _params : _paramsOrRest;
|
|
6911
|
-
const
|
|
6911
|
+
const rest = hasRest ? _paramsOrRest : null;
|
|
6912
6912
|
return new ZodTuple({
|
|
6913
6913
|
type: "tuple",
|
|
6914
6914
|
items,
|
|
6915
|
-
rest
|
|
6915
|
+
rest,
|
|
6916
6916
|
...util_exports.normalizeParams(params)
|
|
6917
6917
|
});
|
|
6918
6918
|
}
|
|
@@ -11856,8 +11856,8 @@ var ZodTuple2 = class _ZodTuple extends ZodType2 {
|
|
|
11856
11856
|
});
|
|
11857
11857
|
return INVALID;
|
|
11858
11858
|
}
|
|
11859
|
-
const
|
|
11860
|
-
if (!
|
|
11859
|
+
const rest = this._def.rest;
|
|
11860
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
11861
11861
|
addIssueToContext(ctx, {
|
|
11862
11862
|
code: ZodIssueCode2.too_big,
|
|
11863
11863
|
maximum: this._def.items.length,
|
|
@@ -11884,10 +11884,10 @@ var ZodTuple2 = class _ZodTuple extends ZodType2 {
|
|
|
11884
11884
|
get items() {
|
|
11885
11885
|
return this._def.items;
|
|
11886
11886
|
}
|
|
11887
|
-
rest(
|
|
11887
|
+
rest(rest) {
|
|
11888
11888
|
return new _ZodTuple({
|
|
11889
11889
|
...this._def,
|
|
11890
|
-
rest
|
|
11890
|
+
rest
|
|
11891
11891
|
});
|
|
11892
11892
|
}
|
|
11893
11893
|
};
|
|
@@ -13070,11 +13070,11 @@ var Protocol = class {
|
|
|
13070
13070
|
const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
|
|
13071
13071
|
controller?.abort(notification.params.reason);
|
|
13072
13072
|
}
|
|
13073
|
-
_setupTimeout(messageId,
|
|
13073
|
+
_setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
|
|
13074
13074
|
this._timeoutInfo.set(messageId, {
|
|
13075
|
-
timeoutId: setTimeout(onTimeout,
|
|
13075
|
+
timeoutId: setTimeout(onTimeout, timeout),
|
|
13076
13076
|
startTime: Date.now(),
|
|
13077
|
-
timeout
|
|
13077
|
+
timeout,
|
|
13078
13078
|
maxTotalTimeout,
|
|
13079
13079
|
resetTimeoutOnProgress,
|
|
13080
13080
|
onTimeout
|
|
@@ -13518,9 +13518,9 @@ var Protocol = class {
|
|
|
13518
13518
|
options?.signal?.addEventListener("abort", () => {
|
|
13519
13519
|
cancel(options?.signal?.reason);
|
|
13520
13520
|
});
|
|
13521
|
-
const
|
|
13522
|
-
const timeoutHandler = () => cancel(McpError.fromError(ErrorCode.RequestTimeout, "Request timed out", { timeout
|
|
13523
|
-
this._setupTimeout(messageId,
|
|
13521
|
+
const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
13522
|
+
const timeoutHandler = () => cancel(McpError.fromError(ErrorCode.RequestTimeout, "Request timed out", { timeout }));
|
|
13523
|
+
this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
|
|
13524
13524
|
const relatedTaskId = relatedTask?.taskId;
|
|
13525
13525
|
if (relatedTaskId) {
|
|
13526
13526
|
const responseResolver = (response) => {
|
|
@@ -14425,71 +14425,6 @@ var Server = class extends Protocol {
|
|
|
14425
14425
|
|
|
14426
14426
|
// __mcpc__core_latest/node_modules/@jsr/mcpc__utils/src/json.js
|
|
14427
14427
|
var import_jsonrepair = require("jsonrepair");
|
|
14428
|
-
function stripMarkdownAndText(text) {
|
|
14429
|
-
text = text.trim();
|
|
14430
|
-
text = text.replace(/^```(?:json)?\s*\n?/i, "");
|
|
14431
|
-
text = text.replace(/\n?```\s*$/, "");
|
|
14432
|
-
text = text.replace(/^(?:here is|here's|response|result|output|json):\s*/i, "");
|
|
14433
|
-
const firstJsonIndex = text.search(/[\{\[]/);
|
|
14434
|
-
if (firstJsonIndex >= 0) {
|
|
14435
|
-
text = text.slice(firstJsonIndex);
|
|
14436
|
-
let depth = 0;
|
|
14437
|
-
let inString = false;
|
|
14438
|
-
let escapeNext = false;
|
|
14439
|
-
const startChar = text[0];
|
|
14440
|
-
const endChar = startChar === "{" ? "}" : "]";
|
|
14441
|
-
for (let i = 0; i < text.length; i++) {
|
|
14442
|
-
const char = text[i];
|
|
14443
|
-
if (escapeNext) {
|
|
14444
|
-
escapeNext = false;
|
|
14445
|
-
continue;
|
|
14446
|
-
}
|
|
14447
|
-
if (char === "\\") {
|
|
14448
|
-
escapeNext = true;
|
|
14449
|
-
continue;
|
|
14450
|
-
}
|
|
14451
|
-
if (char === '"' && !inString) {
|
|
14452
|
-
inString = true;
|
|
14453
|
-
continue;
|
|
14454
|
-
}
|
|
14455
|
-
if (char === '"' && inString) {
|
|
14456
|
-
inString = false;
|
|
14457
|
-
continue;
|
|
14458
|
-
}
|
|
14459
|
-
if (inString) continue;
|
|
14460
|
-
if (char === startChar) {
|
|
14461
|
-
depth++;
|
|
14462
|
-
} else if (char === endChar) {
|
|
14463
|
-
depth--;
|
|
14464
|
-
if (depth === 0) {
|
|
14465
|
-
return text.slice(0, i + 1);
|
|
14466
|
-
}
|
|
14467
|
-
}
|
|
14468
|
-
}
|
|
14469
|
-
}
|
|
14470
|
-
return text.trim();
|
|
14471
|
-
}
|
|
14472
|
-
function parseJSON(text, throwError) {
|
|
14473
|
-
try {
|
|
14474
|
-
return JSON.parse(text);
|
|
14475
|
-
} catch (_error) {
|
|
14476
|
-
try {
|
|
14477
|
-
const cleanedText = stripMarkdownAndText(text);
|
|
14478
|
-
try {
|
|
14479
|
-
return JSON.parse(cleanedText);
|
|
14480
|
-
} catch {
|
|
14481
|
-
const repairedText = (0, import_jsonrepair.jsonrepair)(cleanedText);
|
|
14482
|
-
console.warn(`Failed to parse JSON, cleaned and repaired. Original: ${text.slice(0, 100)}...`);
|
|
14483
|
-
return JSON.parse(repairedText);
|
|
14484
|
-
}
|
|
14485
|
-
} catch (_repairError) {
|
|
14486
|
-
if (throwError) {
|
|
14487
|
-
throw new Error(`Failed to parse JSON after cleanup and repair. Original error: ${_error instanceof Error ? _error.message : String(_error)}`);
|
|
14488
|
-
}
|
|
14489
|
-
return null;
|
|
14490
|
-
}
|
|
14491
|
-
}
|
|
14492
|
-
}
|
|
14493
14428
|
|
|
14494
14429
|
// __mcpc__core_latest/node_modules/@jsr/mcpc__utils/src/ai.js
|
|
14495
14430
|
var p = (template, options = {}) => {
|
|
@@ -15263,8 +15198,8 @@ var import_node_stream = require("node:stream");
|
|
|
15263
15198
|
|
|
15264
15199
|
// __mcpc__core_latest/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
|
|
15265
15200
|
var ReadBuffer = class {
|
|
15266
|
-
append(
|
|
15267
|
-
this._buffer = this._buffer ? Buffer.concat([this._buffer,
|
|
15201
|
+
append(chunk) {
|
|
15202
|
+
this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
|
|
15268
15203
|
}
|
|
15269
15204
|
readMessage() {
|
|
15270
15205
|
if (!this._buffer) {
|
|
@@ -15363,8 +15298,8 @@ var StdioClientTransport = class {
|
|
|
15363
15298
|
this._process.stdin?.on("error", (error2) => {
|
|
15364
15299
|
this.onerror?.(error2);
|
|
15365
15300
|
});
|
|
15366
|
-
this._process.stdout?.on("data", (
|
|
15367
|
-
this._readBuffer.append(
|
|
15301
|
+
this._process.stdout?.on("data", (chunk) => {
|
|
15302
|
+
this._readBuffer.append(chunk);
|
|
15368
15303
|
this.processReadBuffer();
|
|
15369
15304
|
});
|
|
15370
15305
|
this._process.stdout?.on("error", (error2) => {
|
|
@@ -15473,7 +15408,7 @@ function createParser(callbacks) {
|
|
|
15473
15408
|
const { onEvent = noop, onError = noop, onRetry = noop, onComment } = callbacks;
|
|
15474
15409
|
let incompleteLine = "", isFirstChunk = true, id, data = "", eventType = "";
|
|
15475
15410
|
function feed(newChunk) {
|
|
15476
|
-
const
|
|
15411
|
+
const chunk = isFirstChunk ? newChunk.replace(/^\xEF\xBB\xBF/, "") : newChunk, [complete, incomplete] = splitLines(`${incompleteLine}${chunk}`);
|
|
15477
15412
|
for (const line of complete)
|
|
15478
15413
|
parseLine(line);
|
|
15479
15414
|
incompleteLine = incomplete, isFirstChunk = false;
|
|
@@ -15541,19 +15476,19 @@ function createParser(callbacks) {
|
|
|
15541
15476
|
}
|
|
15542
15477
|
return { feed, reset };
|
|
15543
15478
|
}
|
|
15544
|
-
function splitLines(
|
|
15479
|
+
function splitLines(chunk) {
|
|
15545
15480
|
const lines = [];
|
|
15546
15481
|
let incompleteLine = "", searchIndex = 0;
|
|
15547
|
-
for (; searchIndex <
|
|
15548
|
-
const crIndex =
|
|
15482
|
+
for (; searchIndex < chunk.length; ) {
|
|
15483
|
+
const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
|
|
15549
15484
|
`, searchIndex);
|
|
15550
15485
|
let lineEnd = -1;
|
|
15551
|
-
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex ===
|
|
15552
|
-
incompleteLine =
|
|
15486
|
+
if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
|
|
15487
|
+
incompleteLine = chunk.slice(searchIndex);
|
|
15553
15488
|
break;
|
|
15554
15489
|
} else {
|
|
15555
|
-
const line =
|
|
15556
|
-
lines.push(line), searchIndex = lineEnd + 1,
|
|
15490
|
+
const line = chunk.slice(searchIndex, lineEnd);
|
|
15491
|
+
lines.push(line), searchIndex = lineEnd + 1, chunk[searchIndex - 1] === "\r" && chunk[searchIndex] === `
|
|
15557
15492
|
` && searchIndex++;
|
|
15558
15493
|
}
|
|
15559
15494
|
}
|
|
@@ -16887,8 +16822,8 @@ var EventSourceParserStream = class extends TransformStream {
|
|
|
16887
16822
|
onComment
|
|
16888
16823
|
});
|
|
16889
16824
|
},
|
|
16890
|
-
transform(
|
|
16891
|
-
parser.feed(
|
|
16825
|
+
transform(chunk) {
|
|
16826
|
+
parser.feed(chunk);
|
|
16892
16827
|
}
|
|
16893
16828
|
});
|
|
16894
16829
|
}
|
|
@@ -16996,14 +16931,14 @@ var StreamableHTTPClientTransport = class {
|
|
|
16996
16931
|
* @param attempt Current reconnection attempt count for the specific stream
|
|
16997
16932
|
* @returns Time to wait in milliseconds before next reconnection attempt
|
|
16998
16933
|
*/
|
|
16999
|
-
_getNextReconnectionDelay(
|
|
16934
|
+
_getNextReconnectionDelay(attempt) {
|
|
17000
16935
|
if (this._serverRetryMs !== void 0) {
|
|
17001
16936
|
return this._serverRetryMs;
|
|
17002
16937
|
}
|
|
17003
16938
|
const initialDelay = this._reconnectionOptions.initialReconnectionDelay;
|
|
17004
16939
|
const growFactor = this._reconnectionOptions.reconnectionDelayGrowFactor;
|
|
17005
16940
|
const maxDelay = this._reconnectionOptions.maxReconnectionDelay;
|
|
17006
|
-
return Math.min(initialDelay * Math.pow(growFactor,
|
|
16941
|
+
return Math.min(initialDelay * Math.pow(growFactor, attempt), maxDelay);
|
|
17007
16942
|
}
|
|
17008
16943
|
/**
|
|
17009
16944
|
* Schedule a reconnection attempt using server-provided retry interval or backoff
|
|
@@ -17017,13 +16952,13 @@ var StreamableHTTPClientTransport = class {
|
|
|
17017
16952
|
this.onerror?.(new Error(`Maximum reconnection attempts (${maxRetries}) exceeded.`));
|
|
17018
16953
|
return;
|
|
17019
16954
|
}
|
|
17020
|
-
const
|
|
16955
|
+
const delay = this._getNextReconnectionDelay(attemptCount);
|
|
17021
16956
|
this._reconnectionTimeout = setTimeout(() => {
|
|
17022
16957
|
this._startOrAuthSse(options).catch((error2) => {
|
|
17023
16958
|
this.onerror?.(new Error(`Failed to reconnect SSE stream: ${error2 instanceof Error ? error2.message : String(error2)}`));
|
|
17024
16959
|
this._scheduleReconnection(options, attemptCount + 1);
|
|
17025
16960
|
});
|
|
17026
|
-
},
|
|
16961
|
+
}, delay);
|
|
17027
16962
|
}
|
|
17028
16963
|
_handleSseStream(stream, options, isReconnectable) {
|
|
17029
16964
|
if (!stream) {
|
|
@@ -17340,7 +17275,7 @@ var GEMINI_PREFERRED_FORMAT = import_node_process2.default.env.GEMINI_PREFERRED_
|
|
|
17340
17275
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/json.js
|
|
17341
17276
|
var import_jsonrepair2 = require("jsonrepair");
|
|
17342
17277
|
var import_node_util = require("node:util");
|
|
17343
|
-
function
|
|
17278
|
+
function parseJSON(text, throwError) {
|
|
17344
17279
|
try {
|
|
17345
17280
|
return JSON.parse(text);
|
|
17346
17281
|
} catch (_error) {
|
|
@@ -17390,8 +17325,8 @@ var createModelCompatibleJSONSchema = (schema) => {
|
|
|
17390
17325
|
]);
|
|
17391
17326
|
let cleanSchema = schema;
|
|
17392
17327
|
if (GEMINI_PREFERRED_FORMAT) {
|
|
17393
|
-
const { oneOf: _oneOf, allOf: _allOf, anyOf: _anyOf, ...
|
|
17394
|
-
cleanSchema =
|
|
17328
|
+
const { oneOf: _oneOf, allOf: _allOf, anyOf: _anyOf, ...rest } = schema;
|
|
17329
|
+
cleanSchema = rest;
|
|
17395
17330
|
}
|
|
17396
17331
|
const cleanRecursively = (obj) => {
|
|
17397
17332
|
if (Array.isArray(obj)) {
|
|
@@ -17410,6 +17345,34 @@ var createModelCompatibleJSONSchema = (schema) => {
|
|
|
17410
17345
|
};
|
|
17411
17346
|
return cleanRecursively(cleanSchema);
|
|
17412
17347
|
};
|
|
17348
|
+
var INTERNAL_SCHEMA_KEYS = /* @__PURE__ */ new Set([
|
|
17349
|
+
"$schema",
|
|
17350
|
+
"_originalName",
|
|
17351
|
+
"_type",
|
|
17352
|
+
"annotations"
|
|
17353
|
+
]);
|
|
17354
|
+
var cleanToolSchema = (schema) => {
|
|
17355
|
+
const cleanRecursively = (obj) => {
|
|
17356
|
+
if (Array.isArray(obj)) {
|
|
17357
|
+
return obj.map(cleanRecursively);
|
|
17358
|
+
}
|
|
17359
|
+
if (obj && typeof obj === "object") {
|
|
17360
|
+
const record2 = obj;
|
|
17361
|
+
if ("jsonSchema" in record2 && typeof record2.jsonSchema === "object" && record2.jsonSchema !== null) {
|
|
17362
|
+
return cleanRecursively(record2.jsonSchema);
|
|
17363
|
+
}
|
|
17364
|
+
const result = {};
|
|
17365
|
+
for (const [key, value] of Object.entries(record2)) {
|
|
17366
|
+
if (!INTERNAL_SCHEMA_KEYS.has(key)) {
|
|
17367
|
+
result[key] = cleanRecursively(value);
|
|
17368
|
+
}
|
|
17369
|
+
}
|
|
17370
|
+
return result;
|
|
17371
|
+
}
|
|
17372
|
+
return obj;
|
|
17373
|
+
};
|
|
17374
|
+
return cleanRecursively(schema);
|
|
17375
|
+
};
|
|
17413
17376
|
|
|
17414
17377
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/mcp.js
|
|
17415
17378
|
var import_node_process3 = require("node:process");
|
|
@@ -17758,14 +17721,14 @@ function createLogger(name, server) {
|
|
|
17758
17721
|
|
|
17759
17722
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/logging-plugin.js
|
|
17760
17723
|
var createLoggingPlugin = (options = {}) => {
|
|
17761
|
-
const { enabled = true, verbose = false, compact
|
|
17724
|
+
const { enabled = true, verbose = false, compact = true } = options;
|
|
17762
17725
|
return {
|
|
17763
17726
|
name: "built-in-logging",
|
|
17764
17727
|
version: "1.0.0",
|
|
17765
17728
|
composeEnd: async (context2) => {
|
|
17766
17729
|
if (!enabled) return;
|
|
17767
17730
|
const logger2 = createLogger("mcpc.plugin.logging", context2.server);
|
|
17768
|
-
if (
|
|
17731
|
+
if (compact) {
|
|
17769
17732
|
const pluginCount = context2.pluginNames.length;
|
|
17770
17733
|
const { stats } = context2;
|
|
17771
17734
|
await logger2.info(`[${context2.toolName}] ${pluginCount} plugins \u2022 ${stats.publicTools} public \u2022 ${stats.hiddenTools} hidden`);
|
|
@@ -17805,296 +17768,85 @@ var logging_plugin_default = createLoggingPlugin({
|
|
|
17805
17768
|
var SystemPrompts = {
|
|
17806
17769
|
/**
|
|
17807
17770
|
* Base system prompt for autonomous MCP execution
|
|
17771
|
+
*
|
|
17772
|
+
* Uses simplified Unix-style interface:
|
|
17773
|
+
* - `tool` + `args` for clean, consistent structure
|
|
17774
|
+
* - `man` command for fetching tool schemas (like Unix manual)
|
|
17775
|
+
* - No `hasDefinitions` - trusts model's context memory
|
|
17808
17776
|
*/
|
|
17809
|
-
AUTONOMOUS_EXECUTION: `Agentic tool \`{toolName}\` that executes complex tasks by iteratively selecting and calling tools
|
|
17777
|
+
AUTONOMOUS_EXECUTION: `Agentic tool \`{toolName}\` that executes complex tasks by iteratively selecting and calling tools.
|
|
17810
17778
|
|
|
17811
|
-
You must follow the <manual/>, obey the <
|
|
17779
|
+
You must follow the <manual/>, obey the <rules/>, and use the <format/>.
|
|
17812
17780
|
|
|
17813
17781
|
<manual>
|
|
17814
17782
|
{description}
|
|
17815
17783
|
</manual>
|
|
17816
17784
|
|
|
17817
17785
|
<parameters>
|
|
17818
|
-
\`
|
|
17819
|
-
\`
|
|
17820
|
-
\`definitionsOf\` - Tool names whose schemas you need
|
|
17786
|
+
\`tool\` - Which tool to execute: "man" to get schemas, or a tool name to execute
|
|
17787
|
+
\`args\` - For "man": array of tool names. For other tools: object with parameters.
|
|
17821
17788
|
</parameters>
|
|
17822
17789
|
|
|
17823
|
-
<
|
|
17824
|
-
1. **First call**:
|
|
17825
|
-
2. **
|
|
17826
|
-
3. **
|
|
17827
|
-
4.
|
|
17828
|
-
|
|
17829
|
-
6. **Select** one tool to execute per call using \`useTool\`
|
|
17830
|
-
7. **Provide** parameters matching the selected tool name
|
|
17831
|
-
8. Note: You are an agent exposed as an MCP tool - **\`useTool\` is an internal parameter for choosing which tool to execute, NOT an external MCP tool you can call**
|
|
17832
|
-
</execution_rules>
|
|
17790
|
+
<rules>
|
|
17791
|
+
1. **First call**: Use \`man\` to get tool schemas you need
|
|
17792
|
+
2. **Execute tools**: Use tool name in \`tool\` and parameters in \`args\`
|
|
17793
|
+
3. **Parallel calls**: If your client supports it, call \`man\` and execute tools simultaneously
|
|
17794
|
+
4. Note: You are an agent exposed as an MCP tool
|
|
17795
|
+
</rules>
|
|
17833
17796
|
|
|
17834
|
-
<
|
|
17835
|
-
|
|
17797
|
+
<format>
|
|
17798
|
+
Get tool schemas:
|
|
17836
17799
|
\`\`\`json
|
|
17837
17800
|
{
|
|
17838
|
-
"
|
|
17839
|
-
"
|
|
17801
|
+
"tool": "man",
|
|
17802
|
+
"args": ["tool1", "tool2"]
|
|
17840
17803
|
}
|
|
17841
17804
|
\`\`\`
|
|
17842
17805
|
|
|
17843
|
-
Execute tool
|
|
17806
|
+
Execute a tool:
|
|
17844
17807
|
\`\`\`json
|
|
17845
17808
|
{
|
|
17846
|
-
"
|
|
17847
|
-
"
|
|
17848
|
-
"hasDefinitions": ["tool1", "tool2"],
|
|
17849
|
-
"definitionsOf": ["tool3"]
|
|
17809
|
+
"tool": "tool_name",
|
|
17810
|
+
"args": { /* tool parameters */ }
|
|
17850
17811
|
}
|
|
17851
17812
|
\`\`\`
|
|
17852
|
-
</
|
|
17813
|
+
</format>`,
|
|
17853
17814
|
/**
|
|
17854
|
-
*
|
|
17855
|
-
|
|
17856
|
-
WORKFLOW_EXECUTION: `Workflow tool \`{toolName}\` that executes multi-step workflows. Use this when your task requires sequential steps.
|
|
17857
|
-
|
|
17858
|
-
<manual>
|
|
17859
|
-
{description}
|
|
17860
|
-
</manual>
|
|
17861
|
-
|
|
17862
|
-
<rules>
|
|
17863
|
-
1. First call: {planningInstructions}
|
|
17864
|
-
2. Subsequent calls: Provide only current step parameters
|
|
17865
|
-
3. Use \`decision: "proceed"\` to advance, \`"retry"\` to retry, \`"complete"\` when done
|
|
17866
|
-
4. Include \`steps\` ONLY with \`init: true\`, never during execution
|
|
17867
|
-
</rules>`,
|
|
17868
|
-
/**
|
|
17869
|
-
* Tool-based execution system prompt for autonomous sampling mode with native tools
|
|
17870
|
-
*
|
|
17871
|
-
* Note: Used when client supports sampling.tools capability
|
|
17815
|
+
* Tool description for sampling tools (shown in MCP tools list)
|
|
17816
|
+
* Explains how to use prompt and context parameters
|
|
17872
17817
|
*/
|
|
17873
|
-
|
|
17874
|
-
|
|
17875
|
-
<manual>
|
|
17876
|
-
{description}
|
|
17877
|
-
</manual>
|
|
17878
|
-
|
|
17879
|
-
<rules>
|
|
17880
|
-
1. Execute one action per iteration
|
|
17881
|
-
2. Adapt based on results from previous actions
|
|
17882
|
-
3. Continue until task is complete
|
|
17883
|
-
</rules>
|
|
17818
|
+
SAMPLING_TOOL_DESCRIPTION: `Subagent tool \`{toolName}\` that executes complex tasks.
|
|
17884
17819
|
|
|
17885
|
-
<
|
|
17886
|
-
{toolList}
|
|
17887
|
-
</tools>`,
|
|
17888
|
-
/**
|
|
17889
|
-
* JSON-only execution system prompt for autonomous sampling mode
|
|
17890
|
-
*
|
|
17891
|
-
* Note: Sampling mode runs an internal LLM loop that autonomously calls tools until complete.
|
|
17892
|
-
*/
|
|
17893
|
-
SAMPLING_EXECUTION: `Agent \`{toolName}\` that completes tasks by calling tools in an autonomous loop.
|
|
17820
|
+
You must follow the <manual/>, obey the <rules/>, and use the <format/>.
|
|
17894
17821
|
|
|
17895
17822
|
<manual>
|
|
17896
17823
|
{description}
|
|
17897
17824
|
</manual>
|
|
17898
17825
|
|
|
17899
|
-
<rules>
|
|
17900
|
-
1. **YOUR ENTIRE RESPONSE MUST BE A SINGLE JSON OBJECT** - no text before or after
|
|
17901
|
-
2. Execute one tool per iteration
|
|
17902
|
-
3. Specify which tool to use with \`useTool\`
|
|
17903
|
-
4. Adapt based on results from previous actions
|
|
17904
|
-
5. Continue until task is complete
|
|
17905
|
-
</rules>
|
|
17906
|
-
|
|
17907
17826
|
<format>
|
|
17908
|
-
|
|
17909
|
-
|
|
17910
|
-
{"useTool": "tool_name", "decision": "proceed", "tool_name": {...}}
|
|
17911
|
-
\`\`\`
|
|
17912
|
-
|
|
17913
|
-
WRONG - No explanations:
|
|
17914
|
-
\`\`\`
|
|
17915
|
-
I will list the directory
|
|
17916
|
-
{"useTool": "list_directory", ...}
|
|
17917
|
-
\`\`\`
|
|
17918
|
-
|
|
17919
|
-
During execution:
|
|
17920
|
-
\`\`\`json
|
|
17921
|
-
{
|
|
17922
|
-
"useTool": "tool_name",
|
|
17923
|
-
"decision": "proceed",
|
|
17924
|
-
"tool_name": { /* tool parameters */ }
|
|
17925
|
-
}
|
|
17926
|
-
\`\`\`
|
|
17927
|
-
|
|
17928
|
-
When complete:
|
|
17929
|
-
\`\`\`json
|
|
17930
|
-
{ "decision": "complete" }
|
|
17931
|
-
\`\`\`
|
|
17932
|
-
|
|
17933
|
-
Decisions:
|
|
17934
|
-
- \`proceed\` = action succeeded, continue
|
|
17935
|
-
- \`retry\` = action failed, try again
|
|
17936
|
-
- \`complete\` = task finished
|
|
17827
|
+
\`prompt\` - The task to be completed (e.g., "organize my desktop files")
|
|
17828
|
+
\`context\` - Execution context object (e.g., { cwd: "/path/to/dir" })
|
|
17937
17829
|
</format>
|
|
17938
17830
|
|
|
17939
|
-
<tools>
|
|
17940
|
-
{toolList}
|
|
17941
|
-
</tools>`,
|
|
17942
|
-
/**
|
|
17943
|
-
* Tool description for sampling tools (shown in MCP tools list)
|
|
17944
|
-
* Explains how to use userRequest and context parameters
|
|
17945
|
-
*/
|
|
17946
|
-
SAMPLING_TOOL_DESCRIPTION: `Subagent tool \`{toolName}\` that executes complex tasks.
|
|
17947
|
-
|
|
17948
|
-
<manual>
|
|
17949
|
-
{description}
|
|
17950
|
-
</manual>
|
|
17951
|
-
|
|
17952
|
-
<rules>
|
|
17953
|
-
Call this tool with:
|
|
17954
|
-
- **userRequest**: The task you want completed (e.g., "organize my desktop files", "create a project structure")
|
|
17955
|
-
- **context**: Relevant information needed for the task (e.g., working directory, file paths, preferences)
|
|
17956
|
-
</rules>`,
|
|
17957
|
-
/**
|
|
17958
|
-
* Tool-based workflow execution system prompt for sampling mode with native tools
|
|
17959
|
-
*
|
|
17960
|
-
* Note: Used when client supports sampling.tools capability
|
|
17961
|
-
*/
|
|
17962
|
-
SAMPLING_WORKFLOW_EXECUTION_TOOLS: `Workflow agent \`{toolName}\` that executes multi-step workflows.
|
|
17963
|
-
|
|
17964
|
-
<manual>
|
|
17965
|
-
{description}
|
|
17966
|
-
</manual>
|
|
17967
|
-
|
|
17968
17831
|
<rules>
|
|
17969
|
-
1.
|
|
17970
|
-
2.
|
|
17971
|
-
3.
|
|
17972
|
-
4. Continue until all steps complete
|
|
17832
|
+
1. Always provide both \`prompt\` and \`context\` parameters
|
|
17833
|
+
2. \`prompt\` must be a clear, actionable description
|
|
17834
|
+
3. \`context\` must include relevant environment info (e.g., working directory)
|
|
17973
17835
|
</rules>`,
|
|
17974
17836
|
/**
|
|
17975
|
-
*
|
|
17976
|
-
*
|
|
17977
|
-
* Note:
|
|
17837
|
+
* System prompt for AI sampling loop (ai_sampling/ai_acp modes)
|
|
17838
|
+
* Used inside the execution loop when AI calls native tools.
|
|
17839
|
+
* Note: Tool schemas are passed via AI SDK native tool calling, not in prompt.
|
|
17978
17840
|
*/
|
|
17979
|
-
|
|
17841
|
+
AI_LOOP_SYSTEM: `Agent \`{toolName}\` that completes tasks by calling tools.
|
|
17980
17842
|
|
|
17981
17843
|
<manual>
|
|
17982
17844
|
{description}
|
|
17983
17845
|
</manual>
|
|
17984
17846
|
|
|
17985
17847
|
<rules>
|
|
17986
|
-
|
|
17987
|
-
|
|
17988
|
-
3. Subsequent iterations: Execute current step
|
|
17989
|
-
4. Adapt based on step results
|
|
17990
|
-
5. Continue until all steps complete
|
|
17991
|
-
</rules>
|
|
17992
|
-
|
|
17993
|
-
<format>
|
|
17994
|
-
Initialize workflow (first iteration):
|
|
17995
|
-
\`\`\`json
|
|
17996
|
-
{
|
|
17997
|
-
"action": "{toolName}",
|
|
17998
|
-
"init": true,
|
|
17999
|
-
"steps": [/* workflow steps */]
|
|
18000
|
-
}
|
|
18001
|
-
\`\`\`
|
|
18002
|
-
|
|
18003
|
-
Execute step (subsequent iterations):
|
|
18004
|
-
\`\`\`json
|
|
18005
|
-
{
|
|
18006
|
-
"action": "{toolName}",
|
|
18007
|
-
"decision": "proceed|retry",
|
|
18008
|
-
/* step parameters */
|
|
18009
|
-
}
|
|
18010
|
-
\`\`\`
|
|
18011
|
-
|
|
18012
|
-
Complete workflow (omit action):
|
|
18013
|
-
\`\`\`json
|
|
18014
|
-
{ "decision": "complete" }
|
|
18015
|
-
\`\`\`
|
|
18016
|
-
|
|
18017
|
-
Decisions:
|
|
18018
|
-
- \`proceed\` = step succeeded, next step
|
|
18019
|
-
- \`retry\` = step failed, retry current
|
|
18020
|
-
- \`complete\` = workflow finished
|
|
18021
|
-
|
|
18022
|
-
Rules:
|
|
18023
|
-
- Include \`steps\` ONLY with \`init: true\`
|
|
18024
|
-
- Omit \`steps\` during step execution
|
|
18025
|
-
- Use \`decision: "retry"\` for failed steps
|
|
18026
|
-
</format>`
|
|
18027
|
-
};
|
|
18028
|
-
var WorkflowPrompts = {
|
|
18029
|
-
/**
|
|
18030
|
-
* Workflow initialization instructions
|
|
18031
|
-
*/
|
|
18032
|
-
WORKFLOW_INIT: `Workflow initialized with {stepCount} steps. Execute step 1: \`{currentStepDescription}\`
|
|
18033
|
-
|
|
18034
|
-
Schema: {schemaDefinition}
|
|
18035
|
-
|
|
18036
|
-
Call \`{toolName}\` with:
|
|
18037
|
-
- Parameters matching schema above
|
|
18038
|
-
- \`decision: "proceed"\` to advance, \`"retry"\` to retry, \`"complete"\` when done
|
|
18039
|
-
- Omit \`steps\` (only used with \`init: true\`)
|
|
18040
|
-
|
|
18041
|
-
{workflowSteps}`,
|
|
18042
|
-
/**
|
|
18043
|
-
* Tool description enhancement for workflow mode
|
|
18044
|
-
*/
|
|
18045
|
-
WORKFLOW_TOOL_DESCRIPTION: `{description}
|
|
18046
|
-
{initTitle}
|
|
18047
|
-
{ensureStepActions}
|
|
18048
|
-
{schemaDefinition}`,
|
|
18049
|
-
/**
|
|
18050
|
-
* Planning instructions for predefined workflows
|
|
18051
|
-
*/
|
|
18052
|
-
PREDEFINED_WORKFLOW_PLANNING: `- Set \`init: true\` (steps are predefined)`,
|
|
18053
|
-
/**
|
|
18054
|
-
* Planning instructions for dynamic workflows
|
|
18055
|
-
*/
|
|
18056
|
-
DYNAMIC_WORKFLOW_PLANNING: `- Set \`init: true\` and define complete \`steps\` array`,
|
|
18057
|
-
/**
|
|
18058
|
-
* Next step decision prompt
|
|
18059
|
-
*/
|
|
18060
|
-
NEXT_STEP_DECISION: `Previous step completed.
|
|
18061
|
-
|
|
18062
|
-
Choose action:
|
|
18063
|
-
- RETRY: Call \`{toolName}\` with \`decision: "retry"\`
|
|
18064
|
-
- PROCEED: Call \`{toolName}\` with \`decision: "proceed"\` and parameters below
|
|
18065
|
-
|
|
18066
|
-
Next: \`{nextStepDescription}\`
|
|
18067
|
-
{nextStepSchema}
|
|
18068
|
-
|
|
18069
|
-
(Omit \`steps\` parameter)`,
|
|
18070
|
-
/**
|
|
18071
|
-
* Final step completion prompt
|
|
18072
|
-
*/
|
|
18073
|
-
FINAL_STEP_COMPLETION: `Final step executed {statusIcon} - {statusText}
|
|
18074
|
-
|
|
18075
|
-
Choose:
|
|
18076
|
-
- RETRY: \`decision: "retry"\`
|
|
18077
|
-
- COMPLETE: \`decision: "complete"\`
|
|
18078
|
-
- NEW: \`init: true\`{newWorkflowInstructions}`,
|
|
18079
|
-
/**
|
|
18080
|
-
* Workflow completion success message
|
|
18081
|
-
*/
|
|
18082
|
-
WORKFLOW_COMPLETED: `Workflow completed ({totalSteps} steps)
|
|
18083
|
-
|
|
18084
|
-
Start new workflow: \`{toolName}\` with \`init: true\`{newWorkflowInstructions}`,
|
|
18085
|
-
/**
|
|
18086
|
-
* Error messages
|
|
18087
|
-
*/
|
|
18088
|
-
ERRORS: {
|
|
18089
|
-
NOT_INITIALIZED: {
|
|
18090
|
-
WITH_PREDEFINED: "Error: Workflow not initialized. Please provide 'init' parameter to start a new workflow.",
|
|
18091
|
-
WITHOUT_PREDEFINED: "Error: Workflow not initialized. Please provide 'init' and 'steps' parameter to start a new workflow."
|
|
18092
|
-
},
|
|
18093
|
-
ALREADY_AT_FINAL: "Error: Cannot proceed, already at the final step.",
|
|
18094
|
-
CANNOT_COMPLETE_NOT_AT_FINAL: "Error: Cannot complete workflow - you are not at the final step. Please use decision=proceed to continue to the next step.",
|
|
18095
|
-
NO_STEPS_PROVIDED: "Error: No steps provided",
|
|
18096
|
-
NO_CURRENT_STEP: "Error: No current step to execute"
|
|
18097
|
-
}
|
|
17848
|
+
{rules}
|
|
17849
|
+
</rules>{context}`
|
|
18098
17850
|
};
|
|
18099
17851
|
var ResponseTemplates = {
|
|
18100
17852
|
/**
|
|
@@ -18117,9 +17869,6 @@ Next: Execute \`{nextAction}\` by calling \`{toolName}\` again.`,
|
|
|
18117
17869
|
ERROR_RESPONSE: `Validation failed: {errorMessage}
|
|
18118
17870
|
|
|
18119
17871
|
Adjust parameters and retry.`,
|
|
18120
|
-
WORKFLOW_ERROR_RESPONSE: `Step failed: {errorMessage}
|
|
18121
|
-
|
|
18122
|
-
Fix parameters and call with \`decision: "retry"\``,
|
|
18123
17872
|
/**
|
|
18124
17873
|
* Completion message
|
|
18125
17874
|
*/
|
|
@@ -18138,78 +17887,16 @@ Fix parameters and call with \`decision: "retry"\``,
|
|
|
18138
17887
|
};
|
|
18139
17888
|
var CompiledPrompts = {
|
|
18140
17889
|
autonomousExecution: p(SystemPrompts.AUTONOMOUS_EXECUTION),
|
|
18141
|
-
workflowExecution: p(SystemPrompts.WORKFLOW_EXECUTION),
|
|
18142
|
-
samplingExecution: p(SystemPrompts.SAMPLING_EXECUTION),
|
|
18143
|
-
samplingExecutionTools: p(SystemPrompts.SAMPLING_EXECUTION_TOOLS),
|
|
18144
17890
|
samplingToolDescription: p(SystemPrompts.SAMPLING_TOOL_DESCRIPTION),
|
|
18145
|
-
|
|
18146
|
-
samplingWorkflowExecutionTools: p(SystemPrompts.SAMPLING_WORKFLOW_EXECUTION_TOOLS),
|
|
18147
|
-
workflowInit: p(WorkflowPrompts.WORKFLOW_INIT),
|
|
18148
|
-
workflowToolDescription: p(WorkflowPrompts.WORKFLOW_TOOL_DESCRIPTION),
|
|
18149
|
-
nextStepDecision: p(WorkflowPrompts.NEXT_STEP_DECISION),
|
|
18150
|
-
finalStepCompletion: p(WorkflowPrompts.FINAL_STEP_COMPLETION),
|
|
18151
|
-
workflowCompleted: p(WorkflowPrompts.WORKFLOW_COMPLETED),
|
|
17891
|
+
aiLoopSystem: p(SystemPrompts.AI_LOOP_SYSTEM),
|
|
18152
17892
|
actionSuccess: p(ResponseTemplates.ACTION_SUCCESS),
|
|
18153
17893
|
planningPrompt: p(ResponseTemplates.PLANNING_PROMPT),
|
|
18154
17894
|
errorResponse: p(ResponseTemplates.ERROR_RESPONSE),
|
|
18155
|
-
workflowErrorResponse: p(ResponseTemplates.WORKFLOW_ERROR_RESPONSE),
|
|
18156
17895
|
securityPassed: p(ResponseTemplates.SECURITY_VALIDATION.PASSED),
|
|
18157
17896
|
securityFailed: p(ResponseTemplates.SECURITY_VALIDATION.FAILED),
|
|
18158
17897
|
auditLog: p(ResponseTemplates.AUDIT_LOG),
|
|
18159
17898
|
completionMessage: () => ResponseTemplates.COMPLETION_MESSAGE
|
|
18160
17899
|
};
|
|
18161
|
-
var PromptUtils = {
|
|
18162
|
-
/**
|
|
18163
|
-
* Generate tool list for descriptions
|
|
18164
|
-
*/
|
|
18165
|
-
generateToolList: (tools) => {
|
|
18166
|
-
return tools.filter((tool2) => !tool2.hide).map((tool2) => `<tool name="${tool2.name}"${tool2.description ? ` description="${tool2.description}"` : ""}/>`).join("\n");
|
|
18167
|
-
},
|
|
18168
|
-
/**
|
|
18169
|
-
* Generate hidden tool list for descriptions
|
|
18170
|
-
*/
|
|
18171
|
-
generateHiddenToolList: (tools) => {
|
|
18172
|
-
return tools.filter((tool2) => tool2.hide).map((tool2) => `<tool name="${tool2.name}" hide/>`).join("\n");
|
|
18173
|
-
},
|
|
18174
|
-
/**
|
|
18175
|
-
* Format workflow steps for display
|
|
18176
|
-
*/
|
|
18177
|
-
formatWorkflowSteps: (steps) => {
|
|
18178
|
-
if (!steps.length) return "";
|
|
18179
|
-
return `## Workflow Steps
|
|
18180
|
-
${JSON.stringify(steps, null, 2)}`;
|
|
18181
|
-
},
|
|
18182
|
-
/**
|
|
18183
|
-
* Format workflow progress display with status icons
|
|
18184
|
-
*/
|
|
18185
|
-
formatWorkflowProgress: (progressData) => {
|
|
18186
|
-
const statusIcons = {
|
|
18187
|
-
pending: "[PENDING]",
|
|
18188
|
-
running: "[RUNNING]",
|
|
18189
|
-
completed: "[DONE]",
|
|
18190
|
-
failed: "[FAILED]"
|
|
18191
|
-
};
|
|
18192
|
-
return progressData.steps.map((step, index) => {
|
|
18193
|
-
const status = progressData.statuses[index] || "pending";
|
|
18194
|
-
const icon = statusIcons[status] || "[PENDING]";
|
|
18195
|
-
const current = index === progressData.currentStepIndex ? " **[CURRENT]**" : "";
|
|
18196
|
-
const actions = step.actions.length > 0 ? ` | Action: ${step.actions.join(", ")}` : "";
|
|
18197
|
-
return `${icon} **Step ${index + 1}:** ${step.description}${actions}${current}`;
|
|
18198
|
-
}).join("\n");
|
|
18199
|
-
},
|
|
18200
|
-
/**
|
|
18201
|
-
* Generate user info for audit logs
|
|
18202
|
-
*/
|
|
18203
|
-
formatUserInfo: (user) => {
|
|
18204
|
-
return user ? ` by ${user}` : "";
|
|
18205
|
-
},
|
|
18206
|
-
/**
|
|
18207
|
-
* Format timestamp for logs
|
|
18208
|
-
*/
|
|
18209
|
-
formatTimestamp: () => {
|
|
18210
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
18211
|
-
}
|
|
18212
|
-
};
|
|
18213
17900
|
|
|
18214
17901
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/schema-validator.js
|
|
18215
17902
|
var import_ajv2 = require("ajv");
|
|
@@ -18218,13 +17905,14 @@ var import_ajv_errors = __toESM(require("ajv-errors"), 1);
|
|
|
18218
17905
|
var import_ajv_human_errors = require("@segment/ajv-human-errors");
|
|
18219
17906
|
var ajv = new import_ajv2.Ajv({
|
|
18220
17907
|
allErrors: true,
|
|
18221
|
-
verbose: true
|
|
17908
|
+
verbose: true,
|
|
17909
|
+
strict: false
|
|
18222
17910
|
});
|
|
18223
17911
|
import_ajv_formats2.default.default(ajv);
|
|
18224
17912
|
import_ajv_errors.default.default(ajv);
|
|
18225
|
-
function validateSchema(
|
|
17913
|
+
function validateSchema(data, schema) {
|
|
18226
17914
|
const validate = ajv.compile(schema);
|
|
18227
|
-
if (!validate(
|
|
17915
|
+
if (!validate(data)) {
|
|
18228
17916
|
const errors = validate.errors;
|
|
18229
17917
|
const customErrors = errors.filter((err) => err.keyword === "errorMessage");
|
|
18230
17918
|
if (customErrors.length > 0) {
|
|
@@ -18321,17 +18009,17 @@ var AgenticExecutor = class {
|
|
|
18321
18009
|
allToolNames;
|
|
18322
18010
|
toolNameToDetailList;
|
|
18323
18011
|
server;
|
|
18324
|
-
USE_TOOL_KEY;
|
|
18325
18012
|
logger;
|
|
18326
18013
|
tracingEnabled;
|
|
18327
|
-
|
|
18014
|
+
toolSchemaMap;
|
|
18015
|
+
constructor(name, allToolNames, toolNameToDetailList, server) {
|
|
18328
18016
|
this.name = name;
|
|
18329
18017
|
this.allToolNames = allToolNames;
|
|
18330
18018
|
this.toolNameToDetailList = toolNameToDetailList;
|
|
18331
18019
|
this.server = server;
|
|
18332
|
-
this.USE_TOOL_KEY = USE_TOOL_KEY;
|
|
18333
18020
|
this.tracingEnabled = false;
|
|
18334
18021
|
this.logger = createLogger(`mcpc.agentic.${name}`, server);
|
|
18022
|
+
this.toolSchemaMap = new Map(toolNameToDetailList);
|
|
18335
18023
|
try {
|
|
18336
18024
|
this.tracingEnabled = import_node_process5.default.env.MCPC_TRACING_ENABLED === "true";
|
|
18337
18025
|
if (this.tracingEnabled) {
|
|
@@ -18349,7 +18037,7 @@ var AgenticExecutor = class {
|
|
|
18349
18037
|
async execute(args, schema, parentSpan) {
|
|
18350
18038
|
const executeSpan = this.tracingEnabled ? startSpan("mcpc.agentic_execute", {
|
|
18351
18039
|
agent: this.name,
|
|
18352
|
-
|
|
18040
|
+
tool: String(args.tool ?? "unknown"),
|
|
18353
18041
|
args: JSON.stringify(args)
|
|
18354
18042
|
}, parentSpan ?? void 0) : null;
|
|
18355
18043
|
try {
|
|
@@ -18364,7 +18052,7 @@ var AgenticExecutor = class {
|
|
|
18364
18052
|
}
|
|
18365
18053
|
this.logger.warning({
|
|
18366
18054
|
message: "Validation failed",
|
|
18367
|
-
|
|
18055
|
+
tool: args.tool,
|
|
18368
18056
|
error: validationResult.error
|
|
18369
18057
|
});
|
|
18370
18058
|
return {
|
|
@@ -18379,128 +18067,39 @@ var AgenticExecutor = class {
|
|
|
18379
18067
|
isError: true
|
|
18380
18068
|
};
|
|
18381
18069
|
}
|
|
18382
|
-
const
|
|
18383
|
-
|
|
18384
|
-
|
|
18385
|
-
|
|
18386
|
-
|
|
18387
|
-
|
|
18388
|
-
|
|
18389
|
-
|
|
18390
|
-
|
|
18391
|
-
|
|
18392
|
-
|
|
18393
|
-
|
|
18394
|
-
|
|
18395
|
-
|
|
18396
|
-
|
|
18397
|
-
if (result.content.length === 0 && definitionsOf.length > 0) {
|
|
18398
|
-
result.content.push({
|
|
18399
|
-
type: "text",
|
|
18400
|
-
text: `All requested tool schemas are already in hasDefinitions. You can now call a tool using "${this.USE_TOOL_KEY}".`
|
|
18401
|
-
});
|
|
18402
|
-
}
|
|
18403
|
-
return result;
|
|
18404
|
-
}
|
|
18405
|
-
if (executeSpan) {
|
|
18406
|
-
try {
|
|
18407
|
-
const safeTool = String(useTool).replace(/\s+/g, "_");
|
|
18408
|
-
if (typeof executeSpan.updateName === "function") {
|
|
18409
|
-
executeSpan.updateName(`mcpc.agentic_execute.${safeTool}`);
|
|
18410
|
-
}
|
|
18411
|
-
} catch {
|
|
18412
|
-
}
|
|
18413
|
-
}
|
|
18414
|
-
const currentTool = this.toolNameToDetailList.find(([name, _detail]) => name === useTool)?.[1];
|
|
18415
|
-
if (currentTool) {
|
|
18416
|
-
if (executeSpan) {
|
|
18417
|
-
executeSpan.setAttributes({
|
|
18418
|
-
toolType: "external",
|
|
18419
|
-
selectedTool: useTool
|
|
18420
|
-
});
|
|
18421
|
-
}
|
|
18422
|
-
this.logger.debug({
|
|
18423
|
-
message: "Executing external tool",
|
|
18424
|
-
selectTool: useTool
|
|
18425
|
-
});
|
|
18426
|
-
const currentResult = await currentTool.execute({
|
|
18427
|
-
...args[useTool]
|
|
18428
|
-
});
|
|
18429
|
-
this.appendToolSchemas(currentResult, definitionsOf, hasDefinitions);
|
|
18430
|
-
if (executeSpan) {
|
|
18431
|
-
executeSpan.setAttributes({
|
|
18432
|
-
success: true,
|
|
18433
|
-
isError: !!currentResult.isError,
|
|
18434
|
-
resultContentLength: currentResult.content?.length || 0,
|
|
18435
|
-
toolResult: JSON.stringify(currentResult)
|
|
18436
|
-
});
|
|
18437
|
-
endSpan(executeSpan);
|
|
18438
|
-
}
|
|
18439
|
-
return currentResult;
|
|
18440
|
-
}
|
|
18441
|
-
if (this.allToolNames.includes(useTool)) {
|
|
18442
|
-
if (executeSpan) {
|
|
18443
|
-
executeSpan.setAttributes({
|
|
18444
|
-
toolType: "internal",
|
|
18445
|
-
selectedTool: useTool
|
|
18446
|
-
});
|
|
18447
|
-
}
|
|
18448
|
-
this.logger.debug({
|
|
18449
|
-
message: "Executing internal tool",
|
|
18450
|
-
selectTool: useTool
|
|
18451
|
-
});
|
|
18452
|
-
try {
|
|
18453
|
-
const result = await this.server.callTool(useTool, args[useTool]);
|
|
18454
|
-
const callToolResult = result ?? {
|
|
18455
|
-
content: []
|
|
18456
|
-
};
|
|
18457
|
-
this.appendToolSchemas(callToolResult, definitionsOf, hasDefinitions);
|
|
18458
|
-
if (executeSpan) {
|
|
18459
|
-
executeSpan.setAttributes({
|
|
18460
|
-
success: true,
|
|
18461
|
-
isError: !!callToolResult.isError,
|
|
18462
|
-
resultContentLength: callToolResult.content?.length || 0,
|
|
18463
|
-
toolResult: JSON.stringify(callToolResult)
|
|
18464
|
-
});
|
|
18465
|
-
endSpan(executeSpan);
|
|
18466
|
-
}
|
|
18467
|
-
return callToolResult;
|
|
18468
|
-
} catch (error2) {
|
|
18469
|
-
if (executeSpan) {
|
|
18470
|
-
endSpan(executeSpan, error2);
|
|
18070
|
+
const tool2 = args.tool;
|
|
18071
|
+
if (tool2 === "man") {
|
|
18072
|
+
const manSchema = {
|
|
18073
|
+
type: "array",
|
|
18074
|
+
items: {
|
|
18075
|
+
type: "string",
|
|
18076
|
+
enum: this.allToolNames,
|
|
18077
|
+
errorMessage: {
|
|
18078
|
+
enum: `Invalid tool name. Available: ${this.allToolNames.join(", ")}`
|
|
18079
|
+
}
|
|
18080
|
+
},
|
|
18081
|
+
minItems: 1,
|
|
18082
|
+
errorMessage: {
|
|
18083
|
+
type: 'Expected an array of tool names, e.g. ["tool1", "tool2"]',
|
|
18084
|
+
minItems: "At least one tool name is required"
|
|
18471
18085
|
}
|
|
18472
|
-
|
|
18473
|
-
|
|
18474
|
-
|
|
18475
|
-
error: String(error2)
|
|
18476
|
-
});
|
|
18086
|
+
};
|
|
18087
|
+
const manValidation = validateSchema(args.args ?? [], manSchema);
|
|
18088
|
+
if (!manValidation.valid) {
|
|
18477
18089
|
return {
|
|
18478
18090
|
content: [
|
|
18479
18091
|
{
|
|
18480
18092
|
type: "text",
|
|
18481
|
-
text: `
|
|
18093
|
+
text: `Invalid args for "man": ${manValidation.error}`
|
|
18482
18094
|
}
|
|
18483
18095
|
],
|
|
18484
18096
|
isError: true
|
|
18485
18097
|
};
|
|
18486
18098
|
}
|
|
18099
|
+
return this.handleManCommand(args.args, executeSpan);
|
|
18487
18100
|
}
|
|
18488
|
-
|
|
18489
|
-
|
|
18490
|
-
toolType: "not_found",
|
|
18491
|
-
useTool
|
|
18492
|
-
});
|
|
18493
|
-
endSpan(executeSpan);
|
|
18494
|
-
}
|
|
18495
|
-
return {
|
|
18496
|
-
content: [
|
|
18497
|
-
{
|
|
18498
|
-
type: "text",
|
|
18499
|
-
text: `Tool "${useTool}" not found. Available tools: ${this.allToolNames.join(", ")}.`
|
|
18500
|
-
}
|
|
18501
|
-
],
|
|
18502
|
-
isError: true
|
|
18503
|
-
};
|
|
18101
|
+
const toolArgs = args.args || {};
|
|
18102
|
+
return await this.executeTool(tool2, toolArgs, executeSpan);
|
|
18504
18103
|
} catch (error2) {
|
|
18505
18104
|
if (executeSpan) {
|
|
18506
18105
|
endSpan(executeSpan, error2);
|
|
@@ -18520,1711 +18119,263 @@ var AgenticExecutor = class {
|
|
|
18520
18119
|
};
|
|
18521
18120
|
}
|
|
18522
18121
|
}
|
|
18523
|
-
|
|
18524
|
-
|
|
18525
|
-
|
|
18526
|
-
|
|
18527
|
-
|
|
18122
|
+
/**
|
|
18123
|
+
* Handle `man` command - return schemas for requested tools
|
|
18124
|
+
* @param requestedTools - Array of tool names (already validated via JSON Schema)
|
|
18125
|
+
*/
|
|
18126
|
+
handleManCommand(requestedTools, executeSpan) {
|
|
18127
|
+
if (executeSpan) {
|
|
18128
|
+
executeSpan.setAttributes({
|
|
18129
|
+
toolType: "man",
|
|
18130
|
+
requestedTools: requestedTools.join(",")
|
|
18131
|
+
});
|
|
18528
18132
|
}
|
|
18529
|
-
const
|
|
18530
|
-
|
|
18531
|
-
const toolDetail = this.toolNameToDetailList.find(([name]) => name === toolName);
|
|
18133
|
+
const schemas = requestedTools.map((toolName) => {
|
|
18134
|
+
const toolDetail = this.toolSchemaMap.get(toolName);
|
|
18532
18135
|
if (toolDetail) {
|
|
18533
|
-
const
|
|
18534
|
-
|
|
18535
|
-
|
|
18536
|
-
|
|
18537
|
-
</tool_definition>`);
|
|
18136
|
+
const cleanedSchema = cleanToolSchema(toolDetail);
|
|
18137
|
+
return `<tool_definition name="${toolName}">
|
|
18138
|
+
${JSON.stringify(cleanedSchema, null, 2)}
|
|
18139
|
+
</tool_definition>`;
|
|
18538
18140
|
}
|
|
18539
|
-
|
|
18540
|
-
|
|
18541
|
-
|
|
18542
|
-
|
|
18543
|
-
|
|
18141
|
+
return null;
|
|
18142
|
+
}).filter(Boolean);
|
|
18143
|
+
if (executeSpan) {
|
|
18144
|
+
executeSpan.setAttributes({
|
|
18145
|
+
schemasReturned: schemas.length,
|
|
18146
|
+
success: true
|
|
18544
18147
|
});
|
|
18148
|
+
endSpan(executeSpan);
|
|
18545
18149
|
}
|
|
18546
|
-
|
|
18547
|
-
|
|
18548
|
-
|
|
18549
|
-
|
|
18550
|
-
|
|
18551
|
-
}
|
|
18552
|
-
|
|
18553
|
-
|
|
18554
|
-
function partial2(func, ...partialArgs) {
|
|
18555
|
-
return partialImpl(func, placeholderSymbol, ...partialArgs);
|
|
18556
|
-
}
|
|
18557
|
-
function partialImpl(func, placeholder, ...partialArgs) {
|
|
18558
|
-
const partialed = function(...providedArgs) {
|
|
18559
|
-
let providedArgsIndex = 0;
|
|
18560
|
-
const substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg);
|
|
18561
|
-
const remainingArgs = providedArgs.slice(providedArgsIndex);
|
|
18562
|
-
return func.apply(this, substitutedArgs.concat(remainingArgs));
|
|
18563
|
-
};
|
|
18564
|
-
if (func.prototype) {
|
|
18565
|
-
partialed.prototype = Object.create(func.prototype);
|
|
18566
|
-
}
|
|
18567
|
-
return partialed;
|
|
18568
|
-
}
|
|
18569
|
-
var placeholderSymbol = Symbol("partial.placeholder");
|
|
18570
|
-
partial2.placeholder = placeholderSymbol;
|
|
18571
|
-
|
|
18572
|
-
// __mcpc__core_latest/node_modules/@jsr/es-toolkit__es-toolkit/src/function/partialRight.js
|
|
18573
|
-
function partialRight(func, ...partialArgs) {
|
|
18574
|
-
return partialRightImpl(func, placeholderSymbol2, ...partialArgs);
|
|
18575
|
-
}
|
|
18576
|
-
function partialRightImpl(func, placeholder, ...partialArgs) {
|
|
18577
|
-
const partialedRight = function(...providedArgs) {
|
|
18578
|
-
const placeholderLength = partialArgs.filter((arg) => arg === placeholder).length;
|
|
18579
|
-
const rangeLength = Math.max(providedArgs.length - placeholderLength, 0);
|
|
18580
|
-
const remainingArgs = providedArgs.slice(0, rangeLength);
|
|
18581
|
-
let providedArgsIndex = rangeLength;
|
|
18582
|
-
const substitutedArgs = partialArgs.slice().map((arg) => arg === placeholder ? providedArgs[providedArgsIndex++] : arg);
|
|
18583
|
-
return func.apply(this, remainingArgs.concat(substitutedArgs));
|
|
18584
|
-
};
|
|
18585
|
-
if (func.prototype) {
|
|
18586
|
-
partialedRight.prototype = Object.create(func.prototype);
|
|
18587
|
-
}
|
|
18588
|
-
return partialedRight;
|
|
18589
|
-
}
|
|
18590
|
-
var placeholderSymbol2 = Symbol("partialRight.placeholder");
|
|
18591
|
-
partialRight.placeholder = placeholderSymbol2;
|
|
18592
|
-
|
|
18593
|
-
// __mcpc__core_latest/node_modules/@jsr/es-toolkit__es-toolkit/src/function/retry.js
|
|
18594
|
-
var DEFAULT_RETRIES = Number.POSITIVE_INFINITY;
|
|
18595
|
-
|
|
18596
|
-
// __mcpc__core_latest/node_modules/@jsr/es-toolkit__es-toolkit/src/object/pick.js
|
|
18597
|
-
function pick2(obj, keys) {
|
|
18598
|
-
const result = {};
|
|
18599
|
-
for (let i = 0; i < keys.length; i++) {
|
|
18600
|
-
const key = keys[i];
|
|
18601
|
-
if (Object.hasOwn(obj, key)) {
|
|
18602
|
-
result[key] = obj[key];
|
|
18603
|
-
}
|
|
18604
|
-
}
|
|
18605
|
-
return result;
|
|
18606
|
-
}
|
|
18607
|
-
|
|
18608
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/factories/args-def-factory.js
|
|
18609
|
-
var DECISION_OPTIONS = {
|
|
18610
|
-
RETRY: "retry",
|
|
18611
|
-
PROCEED: "proceed",
|
|
18612
|
-
COMPLETE: "complete"
|
|
18613
|
-
};
|
|
18614
|
-
function createArgsDefFactory(name, allToolNames, depGroups, predefinedSteps, ensureStepActions) {
|
|
18615
|
-
const formatEnsureStepActions = () => {
|
|
18616
|
-
if (!ensureStepActions || ensureStepActions.length === 0) {
|
|
18617
|
-
return "";
|
|
18618
|
-
}
|
|
18619
|
-
return `
|
|
18620
|
-
|
|
18621
|
-
## Required Actions
|
|
18622
|
-
The workflow MUST include at least one of these actions:
|
|
18623
|
-
${ensureStepActions.map((action) => `- \`${action}\``).join("\n")}`;
|
|
18624
|
-
};
|
|
18625
|
-
return {
|
|
18626
|
-
common: (extra, optionalFields = []) => {
|
|
18627
|
-
const requiredFields = Object.keys(extra).filter((key) => !optionalFields.includes(key));
|
|
18628
|
-
return {
|
|
18629
|
-
type: "object",
|
|
18630
|
-
description: `**Tool parameters dynamically update per workflow step**`,
|
|
18631
|
-
properties: {
|
|
18632
|
-
...extra
|
|
18633
|
-
},
|
|
18634
|
-
required: requiredFields
|
|
18635
|
-
};
|
|
18636
|
-
},
|
|
18637
|
-
steps: () => ({
|
|
18638
|
-
type: "array",
|
|
18639
|
-
description: `
|
|
18640
|
-
Workflow step definitions - provide ONLY on initial call.
|
|
18641
|
-
|
|
18642
|
-
**CRITICAL RULES:**
|
|
18643
|
-
- **Sequential Dependency:** If Action B depends on Action A's result \u2192 separate steps
|
|
18644
|
-
- **Concurrent Actions:** Independent actions can share one step
|
|
18645
|
-
- **Complete Mapping:** Include ALL requested operations
|
|
18646
|
-
- **Predefined Steps:** Leave unspecified if predefined steps exist
|
|
18647
|
-
|
|
18648
|
-
**BEST PRACTICES:**
|
|
18649
|
-
- Atomic, focused steps
|
|
18650
|
-
- Idempotent actions for safe retries
|
|
18651
|
-
- Clear step descriptions with input/output context`,
|
|
18652
|
-
items: {
|
|
18653
|
-
type: "object",
|
|
18654
|
-
description: `A single step containing actions that execute concurrently. All actions in this step run simultaneously with no guaranteed order.`,
|
|
18655
|
-
properties: {
|
|
18656
|
-
description: {
|
|
18657
|
-
type: "string",
|
|
18658
|
-
description: `**Step purpose, required inputs, and expected outputs**`
|
|
18659
|
-
},
|
|
18660
|
-
actions: {
|
|
18661
|
-
type: "array",
|
|
18662
|
-
description: `Array of action names for this step. **CURRENT LIMITATION: Only 1 action per step is allowed.** Action names must match available tool names exactly.`,
|
|
18663
|
-
items: {
|
|
18664
|
-
...{
|
|
18665
|
-
enum: allToolNames
|
|
18666
|
-
},
|
|
18667
|
-
type: "string",
|
|
18668
|
-
description: `Individual action name from available tools. Must be exactly one of the allowed tool names.`
|
|
18669
|
-
},
|
|
18670
|
-
uniqueItems: true,
|
|
18671
|
-
minItems: 0,
|
|
18672
|
-
// TODO: remove this restriction when workflow planning is good enough
|
|
18673
|
-
maxItems: 1
|
|
18674
|
-
}
|
|
18675
|
-
},
|
|
18676
|
-
required: [
|
|
18677
|
-
"description",
|
|
18678
|
-
"actions"
|
|
18679
|
-
],
|
|
18680
|
-
additionalProperties: false
|
|
18681
|
-
},
|
|
18682
|
-
default: predefinedSteps ? predefinedSteps : void 0,
|
|
18683
|
-
minItems: 1
|
|
18684
|
-
}),
|
|
18685
|
-
init: () => ({
|
|
18686
|
-
type: "boolean",
|
|
18687
|
-
description: `Init a new workflow`,
|
|
18688
|
-
enum: [
|
|
18689
|
-
true
|
|
18690
|
-
]
|
|
18691
|
-
}),
|
|
18692
|
-
decision: () => ({
|
|
18693
|
-
type: "string",
|
|
18694
|
-
enum: Object.values(DECISION_OPTIONS),
|
|
18695
|
-
description: `**Step control: \`${DECISION_OPTIONS.PROCEED}\` = next step, \`${DECISION_OPTIONS.RETRY}\` = retry/repeat current, \`${DECISION_OPTIONS.COMPLETE}\` = finish workflow**`,
|
|
18696
|
-
errorMessage: {
|
|
18697
|
-
enum: `Invalid decision. Must be one of: ${Object.values(DECISION_OPTIONS).join(", ")}.`
|
|
18698
|
-
}
|
|
18699
|
-
}),
|
|
18700
|
-
action: () => ({
|
|
18701
|
-
type: "string",
|
|
18702
|
-
description: "Define the current workflow action to be performed",
|
|
18703
|
-
enum: allToolNames,
|
|
18704
|
-
required: [
|
|
18705
|
-
"action"
|
|
18706
|
-
],
|
|
18707
|
-
errorMessage: {
|
|
18708
|
-
enum: `Invalid action. Must be one of: ${allToolNames.join(", ")}.`
|
|
18709
|
-
}
|
|
18710
|
-
}),
|
|
18711
|
-
forTool: function() {
|
|
18712
|
-
return this.common({});
|
|
18713
|
-
},
|
|
18714
|
-
forCurrentState: function(state) {
|
|
18715
|
-
const currentStep = state.getCurrentStep();
|
|
18716
|
-
if (!state.isWorkflowInitialized() || !currentStep) {
|
|
18717
|
-
state.reset();
|
|
18718
|
-
const initSchema = {
|
|
18719
|
-
init: this.init()
|
|
18720
|
-
};
|
|
18721
|
-
if (!predefinedSteps) {
|
|
18722
|
-
initSchema.steps = this.steps();
|
|
18723
|
-
}
|
|
18724
|
-
return this.common(initSchema);
|
|
18725
|
-
}
|
|
18726
|
-
const stepDependencies = {
|
|
18727
|
-
...pick2(depGroups, currentStep.actions)
|
|
18728
|
-
};
|
|
18729
|
-
stepDependencies["decision"] = this.decision();
|
|
18730
|
-
stepDependencies["action"] = this.action();
|
|
18731
|
-
return this.common(stepDependencies);
|
|
18732
|
-
},
|
|
18733
|
-
forSampling: function() {
|
|
18734
|
-
return {
|
|
18735
|
-
type: "object",
|
|
18736
|
-
description: "Provide user request for autonomous tool execution",
|
|
18737
|
-
properties: {
|
|
18738
|
-
userRequest: {
|
|
18739
|
-
type: "string",
|
|
18740
|
-
description: "The task or request that should be completed autonomously by the agentic system using available tools"
|
|
18741
|
-
},
|
|
18742
|
-
context: {
|
|
18743
|
-
type: "object",
|
|
18744
|
-
description: "Necessary context for the request, e.g., the absolute path of the current working directory. This is just an example; any relevant context fields are allowed.",
|
|
18745
|
-
additionalProperties: true
|
|
18746
|
-
}
|
|
18747
|
-
},
|
|
18748
|
-
required: [
|
|
18749
|
-
"userRequest",
|
|
18750
|
-
"context"
|
|
18751
|
-
],
|
|
18752
|
-
errorMessage: {
|
|
18753
|
-
required: {
|
|
18754
|
-
userRequest: "Missing required field 'userRequest'. Please provide a clear task description.",
|
|
18755
|
-
context: "Missing required field 'context'. Please provide relevant context (e.g., current working directory)."
|
|
18756
|
-
}
|
|
18757
|
-
}
|
|
18758
|
-
};
|
|
18759
|
-
},
|
|
18760
|
-
forAgentic: function(toolNameToDetailList, _sampling = false, USE_TOOL_KEY = "useTool") {
|
|
18761
|
-
const allOf = [
|
|
18762
|
-
// When a specific tool is selected, its parameters must be provided
|
|
18763
|
-
...toolNameToDetailList.map(([toolName, _toolDetail]) => {
|
|
18764
|
-
return {
|
|
18765
|
-
if: {
|
|
18766
|
-
properties: {
|
|
18767
|
-
[USE_TOOL_KEY]: {
|
|
18768
|
-
const: toolName
|
|
18769
|
-
}
|
|
18770
|
-
},
|
|
18771
|
-
required: [
|
|
18772
|
-
USE_TOOL_KEY
|
|
18773
|
-
]
|
|
18774
|
-
},
|
|
18775
|
-
then: {
|
|
18776
|
-
required: [
|
|
18777
|
-
toolName
|
|
18778
|
-
],
|
|
18779
|
-
errorMessage: {
|
|
18780
|
-
required: {
|
|
18781
|
-
[toolName]: `Tool "${toolName}" is selected but its parameters are missing. Please provide "${toolName}": { ...parameters }.`
|
|
18782
|
-
}
|
|
18783
|
-
}
|
|
18784
|
-
}
|
|
18785
|
-
};
|
|
18786
|
-
})
|
|
18787
|
-
];
|
|
18788
|
-
const useToolDescription = `Specifies which tool to execute from the available options. **When setting \`useTool: "example_tool"\`, you MUST also provide \`"example_tool": { ...parameters }\` with that tool's parameters**`;
|
|
18789
|
-
const toolItems = allToolNames.length > 0 ? {
|
|
18790
|
-
type: "string",
|
|
18791
|
-
enum: allToolNames
|
|
18792
|
-
} : {
|
|
18793
|
-
type: "string"
|
|
18794
|
-
};
|
|
18795
|
-
const baseProperties = {
|
|
18796
|
-
[USE_TOOL_KEY]: {
|
|
18797
|
-
type: "string",
|
|
18798
|
-
enum: allToolNames,
|
|
18799
|
-
description: useToolDescription,
|
|
18800
|
-
errorMessage: {
|
|
18801
|
-
enum: `Invalid tool name. Available tools: ${allToolNames.join(", ")}.`
|
|
18802
|
-
}
|
|
18803
|
-
},
|
|
18804
|
-
hasDefinitions: {
|
|
18805
|
-
type: "array",
|
|
18806
|
-
items: toolItems,
|
|
18807
|
-
description: "Tool names whose schemas you already have. List all tools you have schemas for to avoid duplicate schema requests and reduce token usage."
|
|
18808
|
-
},
|
|
18809
|
-
definitionsOf: {
|
|
18810
|
-
type: "array",
|
|
18811
|
-
items: toolItems,
|
|
18812
|
-
description: "Tool names whose schemas you need. Request tool schemas before calling them to understand their parameters."
|
|
18813
|
-
}
|
|
18814
|
-
};
|
|
18815
|
-
const requiredFields = [];
|
|
18816
|
-
const schema = {
|
|
18817
|
-
additionalProperties: true,
|
|
18818
|
-
type: "object",
|
|
18819
|
-
properties: baseProperties,
|
|
18820
|
-
required: requiredFields
|
|
18821
|
-
};
|
|
18822
|
-
if (allOf.length > 0) {
|
|
18823
|
-
schema.allOf = allOf;
|
|
18824
|
-
}
|
|
18825
|
-
if (allToolNames.length > 0) {
|
|
18826
|
-
const thenClause = {
|
|
18827
|
-
required: [
|
|
18828
|
-
USE_TOOL_KEY
|
|
18829
|
-
],
|
|
18830
|
-
errorMessage: {
|
|
18831
|
-
required: {
|
|
18832
|
-
[USE_TOOL_KEY]: `No tool selected. Please specify "${USE_TOOL_KEY}" to select one of: ${allToolNames.join(", ")}. Or use "definitionsOf" with tool names to get their schemas first.`
|
|
18833
|
-
}
|
|
18834
|
-
}
|
|
18835
|
-
};
|
|
18836
|
-
Object.assign(schema, {
|
|
18837
|
-
if: {
|
|
18838
|
-
// definitionsOf is not provided OR is empty array
|
|
18839
|
-
anyOf: [
|
|
18840
|
-
{
|
|
18841
|
-
not: {
|
|
18842
|
-
required: [
|
|
18843
|
-
"definitionsOf"
|
|
18844
|
-
]
|
|
18845
|
-
}
|
|
18846
|
-
},
|
|
18847
|
-
{
|
|
18848
|
-
properties: {
|
|
18849
|
-
definitionsOf: {
|
|
18850
|
-
type: "array",
|
|
18851
|
-
maxItems: 0
|
|
18852
|
-
}
|
|
18853
|
-
}
|
|
18854
|
-
}
|
|
18855
|
-
]
|
|
18856
|
-
},
|
|
18857
|
-
then: thenClause
|
|
18858
|
-
});
|
|
18859
|
-
}
|
|
18860
|
-
return schema;
|
|
18861
|
-
},
|
|
18862
|
-
forNextState: function(state) {
|
|
18863
|
-
if (!state.isWorkflowInitialized() || !state.hasNextStep()) {
|
|
18864
|
-
throw new Error(`Cannot get next state schema: no next step available`);
|
|
18865
|
-
}
|
|
18866
|
-
const currentStepIndex = state.getCurrentStepIndex();
|
|
18867
|
-
const allSteps = state.getSteps();
|
|
18868
|
-
const nextStep = allSteps[currentStepIndex + 1];
|
|
18869
|
-
if (!nextStep) {
|
|
18870
|
-
throw new Error(`Next step not found`);
|
|
18871
|
-
}
|
|
18872
|
-
const stepDependencies = {
|
|
18873
|
-
...pick2(depGroups, nextStep.actions)
|
|
18874
|
-
};
|
|
18875
|
-
stepDependencies["decision"] = this.decision();
|
|
18876
|
-
stepDependencies["action"] = this.action();
|
|
18877
|
-
return this.common(stepDependencies);
|
|
18878
|
-
},
|
|
18879
|
-
forToolDescription: function(description, state) {
|
|
18880
|
-
const enforceToolArgs = this.forCurrentState(state);
|
|
18881
|
-
const initTitle = predefinedSteps ? `**YOU MUST execute this tool with following tool arguments to init the workflow**
|
|
18882
|
-
NOTE: The \`steps\` has been predefined` : `**You MUST execute this tool with following tool arguments to plan and init the workflow**`;
|
|
18883
|
-
return CompiledPrompts.workflowToolDescription({
|
|
18884
|
-
description,
|
|
18885
|
-
initTitle,
|
|
18886
|
-
ensureStepActions: formatEnsureStepActions(),
|
|
18887
|
-
schemaDefinition: JSON.stringify(enforceToolArgs, null, 2)
|
|
18888
|
-
});
|
|
18889
|
-
},
|
|
18890
|
-
forInitialStepDescription: function(steps, state) {
|
|
18891
|
-
return CompiledPrompts.workflowInit({
|
|
18892
|
-
stepCount: steps.length.toString(),
|
|
18893
|
-
currentStepDescription: state.getCurrentStep()?.description || "",
|
|
18894
|
-
toolName: name,
|
|
18895
|
-
schemaDefinition: JSON.stringify(this.forCurrentState(state), null, 2),
|
|
18896
|
-
// Remove redundant workflow steps display
|
|
18897
|
-
workflowSteps: ""
|
|
18898
|
-
});
|
|
18899
|
-
}
|
|
18900
|
-
};
|
|
18901
|
-
}
|
|
18902
|
-
|
|
18903
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/agentic/agentic-tool-registrar.js
|
|
18904
|
-
function registerAgenticTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList }) {
|
|
18905
|
-
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
18906
|
-
const agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server);
|
|
18907
|
-
description = CompiledPrompts.autonomousExecution({
|
|
18908
|
-
toolName: name,
|
|
18909
|
-
description
|
|
18910
|
-
});
|
|
18911
|
-
const agenticArgsDef = createArgsDef.forAgentic(toolNameToDetailList, false);
|
|
18912
|
-
const argsDef = agenticArgsDef;
|
|
18913
|
-
const schema = allToolNames.length > 0 ? argsDef : {
|
|
18914
|
-
type: "object",
|
|
18915
|
-
properties: {}
|
|
18916
|
-
};
|
|
18917
|
-
server.tool(name, description, jsonSchema(createModelCompatibleJSONSchema(schema)), async (args) => {
|
|
18918
|
-
return await agenticExecutor.execute(args, schema);
|
|
18919
|
-
});
|
|
18920
|
-
}
|
|
18921
|
-
|
|
18922
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-agentic-plugin.js
|
|
18923
|
-
var createAgenticModePlugin = () => ({
|
|
18924
|
-
name: "mode-agentic",
|
|
18925
|
-
version: "1.0.0",
|
|
18926
|
-
// Only apply to agentic mode
|
|
18927
|
-
apply: "agentic",
|
|
18928
|
-
// Register the agent tool
|
|
18929
|
-
registerAgentTool: (context2) => {
|
|
18930
|
-
registerAgenticTool(context2.server, {
|
|
18931
|
-
description: context2.description,
|
|
18932
|
-
name: context2.name,
|
|
18933
|
-
allToolNames: context2.allToolNames,
|
|
18934
|
-
depGroups: context2.depGroups,
|
|
18935
|
-
toolNameToDetailList: context2.toolNameToDetailList
|
|
18936
|
-
});
|
|
18937
|
-
}
|
|
18938
|
-
});
|
|
18939
|
-
var mode_agentic_plugin_default = createAgenticModePlugin();
|
|
18940
|
-
|
|
18941
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/state.js
|
|
18942
|
-
var WorkflowState = class {
|
|
18943
|
-
currentStepIndex = -1;
|
|
18944
|
-
steps = [];
|
|
18945
|
-
stepStatuses = [];
|
|
18946
|
-
stepResults = [];
|
|
18947
|
-
stepErrors = [];
|
|
18948
|
-
isInitialized = false;
|
|
18949
|
-
isStarted = false;
|
|
18950
|
-
constructor(steps) {
|
|
18951
|
-
if (steps) {
|
|
18952
|
-
this.initialize(steps);
|
|
18953
|
-
}
|
|
18954
|
-
}
|
|
18955
|
-
getCurrentStepIndex() {
|
|
18956
|
-
return this.currentStepIndex;
|
|
18957
|
-
}
|
|
18958
|
-
getSteps() {
|
|
18959
|
-
return this.steps;
|
|
18960
|
-
}
|
|
18961
|
-
isWorkflowInitialized() {
|
|
18962
|
-
return this.isInitialized;
|
|
18963
|
-
}
|
|
18964
|
-
getCurrentStep() {
|
|
18965
|
-
if (!this.isInitialized || this.currentStepIndex < 0) {
|
|
18966
|
-
return null;
|
|
18967
|
-
}
|
|
18968
|
-
return this.steps[this.currentStepIndex] || null;
|
|
18969
|
-
}
|
|
18970
|
-
getNextStep() {
|
|
18971
|
-
if (!this.isInitialized) return null;
|
|
18972
|
-
const nextIndex = this.currentStepIndex + 1;
|
|
18973
|
-
return this.steps[nextIndex] || null;
|
|
18974
|
-
}
|
|
18975
|
-
// Get the previous step in the workflow
|
|
18976
|
-
getPreviousStep() {
|
|
18977
|
-
if (!this.isInitialized) return null;
|
|
18978
|
-
const prevIndex = this.currentStepIndex - 1;
|
|
18979
|
-
return this.steps[prevIndex] || null;
|
|
18980
|
-
}
|
|
18981
|
-
hasNextStep() {
|
|
18982
|
-
return this.getNextStep() !== null;
|
|
18983
|
-
}
|
|
18984
|
-
// Check if there is a previous step available
|
|
18985
|
-
hasPreviousStep() {
|
|
18986
|
-
return this.getPreviousStep() !== null;
|
|
18987
|
-
}
|
|
18988
|
-
// Check if currently at the first step
|
|
18989
|
-
isAtFirstStep() {
|
|
18990
|
-
return this.isInitialized && this.currentStepIndex === 0;
|
|
18991
|
-
}
|
|
18992
|
-
// Check if currently at the last step
|
|
18993
|
-
isAtLastStep() {
|
|
18994
|
-
return this.isInitialized && this.currentStepIndex >= this.steps.length - 1;
|
|
18995
|
-
}
|
|
18996
|
-
isWorkflowStarted() {
|
|
18997
|
-
return this.isStarted;
|
|
18998
|
-
}
|
|
18999
|
-
isCompleted() {
|
|
19000
|
-
return this.isInitialized && this.currentStepIndex > this.steps.length - 1;
|
|
19001
|
-
}
|
|
19002
|
-
// Mark workflow as completed by moving beyond the last step
|
|
19003
|
-
markCompleted() {
|
|
19004
|
-
if (this.isInitialized) {
|
|
19005
|
-
this.currentStepIndex = this.steps.length;
|
|
19006
|
-
}
|
|
19007
|
-
}
|
|
19008
|
-
initialize(steps) {
|
|
19009
|
-
this.steps = steps;
|
|
19010
|
-
this.stepStatuses = new Array(steps.length).fill("pending");
|
|
19011
|
-
this.stepResults = new Array(steps.length).fill("");
|
|
19012
|
-
this.stepErrors = new Array(steps.length).fill("");
|
|
19013
|
-
this.currentStepIndex = 0;
|
|
19014
|
-
this.isInitialized = true;
|
|
19015
|
-
this.isStarted = false;
|
|
19016
|
-
}
|
|
19017
|
-
// Mark current step as running
|
|
19018
|
-
markCurrentStepRunning() {
|
|
19019
|
-
if (this.isInitialized && this.currentStepIndex >= 0 && this.currentStepIndex < this.steps.length) {
|
|
19020
|
-
this.stepStatuses[this.currentStepIndex] = "running";
|
|
19021
|
-
}
|
|
19022
|
-
}
|
|
19023
|
-
// Mark current step as completed
|
|
19024
|
-
markCurrentStepCompleted(result) {
|
|
19025
|
-
if (this.isInitialized && this.currentStepIndex >= 0 && this.currentStepIndex < this.steps.length) {
|
|
19026
|
-
this.stepStatuses[this.currentStepIndex] = "completed";
|
|
19027
|
-
if (result) {
|
|
19028
|
-
this.stepResults[this.currentStepIndex] = result;
|
|
19029
|
-
}
|
|
19030
|
-
}
|
|
19031
|
-
}
|
|
19032
|
-
// Mark current step as failed
|
|
19033
|
-
markCurrentStepFailed(error2) {
|
|
19034
|
-
if (this.isInitialized && this.currentStepIndex >= 0 && this.currentStepIndex < this.steps.length) {
|
|
19035
|
-
this.stepStatuses[this.currentStepIndex] = "failed";
|
|
19036
|
-
if (error2) {
|
|
19037
|
-
this.stepErrors[this.currentStepIndex] = error2;
|
|
19038
|
-
}
|
|
19039
|
-
}
|
|
19040
|
-
}
|
|
19041
|
-
// Get steps with their status
|
|
19042
|
-
getStepsWithStatus() {
|
|
19043
|
-
return this.steps.map((step, index) => ({
|
|
19044
|
-
...step,
|
|
19045
|
-
status: this.stepStatuses[index] || "pending",
|
|
19046
|
-
result: this.stepResults[index] || void 0,
|
|
19047
|
-
error: this.stepErrors[index] || void 0
|
|
19048
|
-
}));
|
|
19049
|
-
}
|
|
19050
|
-
// Get basic workflow progress data for template rendering
|
|
19051
|
-
getProgressData() {
|
|
19052
|
-
return {
|
|
19053
|
-
steps: this.steps,
|
|
19054
|
-
statuses: this.stepStatuses,
|
|
19055
|
-
results: this.stepResults,
|
|
19056
|
-
errors: this.stepErrors,
|
|
19057
|
-
currentStepIndex: this.currentStepIndex,
|
|
19058
|
-
totalSteps: this.steps.length
|
|
19059
|
-
};
|
|
19060
|
-
}
|
|
19061
|
-
start() {
|
|
19062
|
-
this.isStarted = true;
|
|
19063
|
-
}
|
|
19064
|
-
moveToNextStep() {
|
|
19065
|
-
if (!this.hasNextStep()) {
|
|
19066
|
-
return false;
|
|
19067
|
-
}
|
|
19068
|
-
this.currentStepIndex++;
|
|
19069
|
-
return true;
|
|
19070
|
-
}
|
|
19071
|
-
// Move to the previous step in the workflow
|
|
19072
|
-
moveToPreviousStep() {
|
|
19073
|
-
if (!this.hasPreviousStep()) {
|
|
19074
|
-
return false;
|
|
19075
|
-
}
|
|
19076
|
-
this.currentStepIndex--;
|
|
19077
|
-
return true;
|
|
19078
|
-
}
|
|
19079
|
-
// Move to a specific step by index (optional feature)
|
|
19080
|
-
moveToStep(stepIndex) {
|
|
19081
|
-
if (!this.isInitialized || stepIndex < 0 || stepIndex >= this.steps.length) {
|
|
19082
|
-
return false;
|
|
19083
|
-
}
|
|
19084
|
-
this.currentStepIndex = stepIndex;
|
|
19085
|
-
return true;
|
|
19086
|
-
}
|
|
19087
|
-
reset() {
|
|
19088
|
-
this.currentStepIndex = -1;
|
|
19089
|
-
this.steps = [];
|
|
19090
|
-
this.stepStatuses = [];
|
|
19091
|
-
this.stepResults = [];
|
|
19092
|
-
this.stepErrors = [];
|
|
19093
|
-
this.isInitialized = false;
|
|
19094
|
-
this.isStarted = false;
|
|
19095
|
-
}
|
|
19096
|
-
getDebugInfo() {
|
|
19097
|
-
return {
|
|
19098
|
-
currentStepIndex: this.currentStepIndex,
|
|
19099
|
-
totalSteps: this.steps.length,
|
|
19100
|
-
isInitialized: this.isInitialized,
|
|
19101
|
-
currentStep: this.getCurrentStep()?.description,
|
|
19102
|
-
nextStep: this.getNextStep()?.description,
|
|
19103
|
-
previousStep: this.getPreviousStep()?.description,
|
|
19104
|
-
isAtFirstStep: this.isAtFirstStep(),
|
|
19105
|
-
hasPreviousStep: this.hasPreviousStep()
|
|
19106
|
-
};
|
|
19107
|
-
}
|
|
19108
|
-
};
|
|
19109
|
-
|
|
19110
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/workflow/workflow-executor.js
|
|
19111
|
-
var WorkflowExecutor = class {
|
|
19112
|
-
name;
|
|
19113
|
-
allToolNames;
|
|
19114
|
-
toolNameToDetailList;
|
|
19115
|
-
createArgsDef;
|
|
19116
|
-
server;
|
|
19117
|
-
predefinedSteps;
|
|
19118
|
-
ensureStepActions;
|
|
19119
|
-
toolNameToIdMapping;
|
|
19120
|
-
constructor(name, allToolNames, toolNameToDetailList, createArgsDef, server, predefinedSteps, ensureStepActions, toolNameToIdMapping) {
|
|
19121
|
-
this.name = name;
|
|
19122
|
-
this.allToolNames = allToolNames;
|
|
19123
|
-
this.toolNameToDetailList = toolNameToDetailList;
|
|
19124
|
-
this.createArgsDef = createArgsDef;
|
|
19125
|
-
this.server = server;
|
|
19126
|
-
this.predefinedSteps = predefinedSteps;
|
|
19127
|
-
this.ensureStepActions = ensureStepActions;
|
|
19128
|
-
this.toolNameToIdMapping = toolNameToIdMapping;
|
|
19129
|
-
}
|
|
19130
|
-
// Helper method to validate required actions are present in workflow steps
|
|
19131
|
-
validateRequiredActions(steps) {
|
|
19132
|
-
if (!this.ensureStepActions || this.ensureStepActions.length === 0) {
|
|
19133
|
-
return {
|
|
19134
|
-
valid: true,
|
|
19135
|
-
missing: []
|
|
19136
|
-
};
|
|
19137
|
-
}
|
|
19138
|
-
const allStepActions = /* @__PURE__ */ new Set();
|
|
19139
|
-
steps.forEach((step) => {
|
|
19140
|
-
step.actions.forEach((action) => allStepActions.add(action));
|
|
19141
|
-
});
|
|
19142
|
-
const missing = [];
|
|
19143
|
-
for (const requiredAction of this.ensureStepActions) {
|
|
19144
|
-
if (allStepActions.has(requiredAction)) {
|
|
19145
|
-
continue;
|
|
19146
|
-
}
|
|
19147
|
-
if (this.toolNameToIdMapping) {
|
|
19148
|
-
const mappedToolId = this.toolNameToIdMapping.get(requiredAction);
|
|
19149
|
-
if (mappedToolId && allStepActions.has(mappedToolId)) {
|
|
19150
|
-
continue;
|
|
19151
|
-
}
|
|
19152
|
-
}
|
|
19153
|
-
missing.push(requiredAction);
|
|
19154
|
-
}
|
|
19155
|
-
return {
|
|
19156
|
-
valid: missing.length === 0,
|
|
19157
|
-
missing
|
|
19158
|
-
};
|
|
19159
|
-
}
|
|
19160
|
-
// Helper method to format workflow progress
|
|
19161
|
-
formatProgress(state) {
|
|
19162
|
-
const progressData = state.getProgressData();
|
|
19163
|
-
return PromptUtils.formatWorkflowProgress(progressData);
|
|
19164
|
-
}
|
|
19165
|
-
async execute(args, state) {
|
|
19166
|
-
if (args.init) {
|
|
19167
|
-
state.reset();
|
|
19168
|
-
} else {
|
|
19169
|
-
if (!state.isWorkflowInitialized() && !args.init) {
|
|
19170
|
-
return {
|
|
19171
|
-
content: [
|
|
19172
|
-
{
|
|
19173
|
-
type: "text",
|
|
19174
|
-
text: this.predefinedSteps ? WorkflowPrompts.ERRORS.NOT_INITIALIZED.WITH_PREDEFINED : WorkflowPrompts.ERRORS.NOT_INITIALIZED.WITHOUT_PREDEFINED
|
|
19175
|
-
}
|
|
19176
|
-
],
|
|
19177
|
-
isError: true
|
|
19178
|
-
};
|
|
19179
|
-
}
|
|
19180
|
-
const decision2 = args.decision;
|
|
19181
|
-
if (decision2 === "proceed") {
|
|
19182
|
-
if (state.isAtLastStep() && state.isWorkflowStarted()) {
|
|
19183
|
-
state.markCompleted();
|
|
19184
|
-
return {
|
|
19185
|
-
content: [
|
|
19186
|
-
{
|
|
19187
|
-
type: "text",
|
|
19188
|
-
text: `## Workflow Completed!
|
|
19189
|
-
|
|
19190
|
-
${this.formatProgress(state)}
|
|
19191
|
-
|
|
19192
|
-
${CompiledPrompts.workflowCompleted({
|
|
19193
|
-
totalSteps: state.getSteps().length,
|
|
19194
|
-
toolName: this.name,
|
|
19195
|
-
newWorkflowInstructions: this.predefinedSteps ? "" : " and new `steps` array"
|
|
19196
|
-
})}`
|
|
19197
|
-
}
|
|
19198
|
-
],
|
|
19199
|
-
isError: false
|
|
19200
|
-
};
|
|
19201
|
-
}
|
|
19202
|
-
if (state.isCompleted()) {
|
|
19203
|
-
return {
|
|
19204
|
-
content: [
|
|
19205
|
-
{
|
|
19206
|
-
type: "text",
|
|
19207
|
-
text: WorkflowPrompts.ERRORS.ALREADY_AT_FINAL
|
|
19208
|
-
}
|
|
19209
|
-
],
|
|
19210
|
-
isError: true
|
|
19211
|
-
};
|
|
19212
|
-
}
|
|
19213
|
-
const currentStepIndex = state.getCurrentStepIndex();
|
|
19214
|
-
const wasStarted = state.isWorkflowStarted();
|
|
19215
|
-
if (state.isWorkflowStarted()) {
|
|
19216
|
-
state.moveToNextStep();
|
|
19217
|
-
} else {
|
|
19218
|
-
state.start();
|
|
19219
|
-
}
|
|
19220
|
-
const nextStepValidationSchema = this.createArgsDef.forCurrentState(state);
|
|
19221
|
-
const nextStepValidationResult = this.validateInput(args, nextStepValidationSchema);
|
|
19222
|
-
if (!nextStepValidationResult.valid) {
|
|
19223
|
-
if (wasStarted) {
|
|
19224
|
-
state.moveToStep(currentStepIndex);
|
|
19225
|
-
} else {
|
|
19226
|
-
state.moveToStep(currentStepIndex);
|
|
19227
|
-
}
|
|
19228
|
-
return {
|
|
19229
|
-
content: [
|
|
19230
|
-
{
|
|
19231
|
-
type: "text",
|
|
19232
|
-
text: CompiledPrompts.workflowErrorResponse({
|
|
19233
|
-
errorMessage: `Cannot proceed to next step: ${nextStepValidationResult.error || "Arguments validation failed"}`
|
|
19234
|
-
})
|
|
19235
|
-
}
|
|
19236
|
-
],
|
|
19237
|
-
isError: true
|
|
19238
|
-
};
|
|
19239
|
-
}
|
|
19240
|
-
} else if (decision2 === "complete") {
|
|
19241
|
-
if (state.isAtLastStep() && state.isWorkflowStarted()) {
|
|
19242
|
-
state.markCompleted();
|
|
19243
|
-
return {
|
|
19244
|
-
content: [
|
|
19245
|
-
{
|
|
19246
|
-
type: "text",
|
|
19247
|
-
text: `## Workflow Completed!
|
|
19248
|
-
|
|
19249
|
-
${this.formatProgress(state)}
|
|
19250
|
-
|
|
19251
|
-
${CompiledPrompts.workflowCompleted({
|
|
19252
|
-
totalSteps: state.getSteps().length,
|
|
19253
|
-
toolName: this.name,
|
|
19254
|
-
newWorkflowInstructions: this.predefinedSteps ? "" : " and new `steps` array"
|
|
19255
|
-
})}`
|
|
19256
|
-
}
|
|
19257
|
-
],
|
|
19258
|
-
isError: false
|
|
19259
|
-
};
|
|
19260
|
-
} else {
|
|
19261
|
-
return {
|
|
19262
|
-
content: [
|
|
19263
|
-
{
|
|
19264
|
-
type: "text",
|
|
19265
|
-
text: WorkflowPrompts.ERRORS.CANNOT_COMPLETE_NOT_AT_FINAL
|
|
19266
|
-
}
|
|
19267
|
-
],
|
|
19268
|
-
isError: true
|
|
19269
|
-
};
|
|
19270
|
-
}
|
|
19271
|
-
}
|
|
19272
|
-
}
|
|
19273
|
-
const decision = args.decision;
|
|
19274
|
-
if (decision !== "proceed") {
|
|
19275
|
-
const validationSchema = this.createArgsDef.forCurrentState(state);
|
|
19276
|
-
const validationResult = this.validateInput(args, validationSchema);
|
|
19277
|
-
if (!validationResult.valid) {
|
|
19278
|
-
return {
|
|
19279
|
-
content: [
|
|
19280
|
-
{
|
|
19281
|
-
type: "text",
|
|
19282
|
-
text: CompiledPrompts.workflowErrorResponse({
|
|
19283
|
-
errorMessage: validationResult.error || "Arguments validation failed"
|
|
19284
|
-
})
|
|
19285
|
-
}
|
|
19286
|
-
],
|
|
19287
|
-
isError: true
|
|
19288
|
-
};
|
|
19289
|
-
}
|
|
19290
|
-
}
|
|
19291
|
-
if (args.init) {
|
|
19292
|
-
return this.initialize(args, state);
|
|
19293
|
-
}
|
|
19294
|
-
return await this.executeStep(args, state);
|
|
19295
|
-
}
|
|
19296
|
-
initialize(args, state) {
|
|
19297
|
-
const steps = args.steps ?? this.predefinedSteps;
|
|
19298
|
-
if (!steps || steps.length === 0) {
|
|
19299
|
-
return {
|
|
19300
|
-
content: [
|
|
19301
|
-
{
|
|
19302
|
-
type: "text",
|
|
19303
|
-
text: WorkflowPrompts.ERRORS.NO_STEPS_PROVIDED
|
|
19304
|
-
}
|
|
19305
|
-
],
|
|
19306
|
-
isError: true
|
|
19307
|
-
};
|
|
19308
|
-
}
|
|
19309
|
-
const validation = this.validateRequiredActions(steps);
|
|
19310
|
-
if (!validation.valid) {
|
|
19311
|
-
return {
|
|
19312
|
-
content: [
|
|
19313
|
-
{
|
|
19314
|
-
type: "text",
|
|
19315
|
-
text: `## Workflow Validation Failed \u274C
|
|
19316
|
-
|
|
19317
|
-
**Missing Required Actions:** The following actions must be included in the workflow steps:
|
|
19318
|
-
|
|
19319
|
-
${validation.missing.map((action) => `- \`${this.toolNameToIdMapping?.get(action) ?? action}\``).join("\n")}`
|
|
19320
|
-
}
|
|
19321
|
-
],
|
|
19322
|
-
isError: true
|
|
19323
|
-
};
|
|
19324
|
-
}
|
|
19325
|
-
state.initialize(steps);
|
|
19326
|
-
return {
|
|
19327
|
-
content: [
|
|
19328
|
-
{
|
|
19329
|
-
type: "text",
|
|
19330
|
-
text: `## Workflow Initialized
|
|
19331
|
-
${this.formatProgress(state)}
|
|
19332
|
-
${this.createArgsDef.forInitialStepDescription(steps, state)}`
|
|
19333
|
-
}
|
|
19334
|
-
],
|
|
19335
|
-
isError: false
|
|
19336
|
-
};
|
|
19337
|
-
}
|
|
19338
|
-
async executeStep(args, state) {
|
|
19339
|
-
const currentStep = state.getCurrentStep();
|
|
19340
|
-
if (!currentStep) {
|
|
19341
|
-
return {
|
|
19342
|
-
content: [
|
|
19343
|
-
{
|
|
19344
|
-
type: "text",
|
|
19345
|
-
text: WorkflowPrompts.ERRORS.NO_CURRENT_STEP
|
|
19346
|
-
}
|
|
19347
|
-
],
|
|
19348
|
-
isError: true
|
|
19349
|
-
};
|
|
19350
|
-
}
|
|
19351
|
-
state.markCurrentStepRunning();
|
|
19352
|
-
const results = {
|
|
19353
|
-
content: [],
|
|
19354
|
-
isError: false
|
|
19355
|
-
};
|
|
19356
|
-
for (const action of currentStep.actions) {
|
|
19357
|
-
try {
|
|
19358
|
-
const actionArgs = args[action] || {};
|
|
19359
|
-
const actionResult = await this.server.callTool(action, actionArgs);
|
|
19360
|
-
if (!results.isError) {
|
|
19361
|
-
results.isError = actionResult.isError;
|
|
19362
|
-
}
|
|
19363
|
-
results.content = results.content.concat(actionResult.content ?? []);
|
|
19364
|
-
results.content.push({
|
|
19365
|
-
type: "text",
|
|
19366
|
-
text: `Action \`${action}\` executed ${actionResult.isError ? "\u274C **FAILED**" : "\u2705 **SUCCESS**"}:`
|
|
19367
|
-
});
|
|
19368
|
-
} catch (error2) {
|
|
19369
|
-
results.content.push({
|
|
19370
|
-
type: "text",
|
|
19371
|
-
text: `${error2.message}`
|
|
19372
|
-
});
|
|
19373
|
-
results.content.push({
|
|
19374
|
-
type: "text",
|
|
19375
|
-
text: `Action \`${action}\` \u274C **FAILED** with error: `
|
|
19376
|
-
});
|
|
19377
|
-
results.isError = true;
|
|
19378
|
-
}
|
|
19379
|
-
}
|
|
19380
|
-
if (results.isError) {
|
|
19381
|
-
state.markCurrentStepFailed("Step execution failed");
|
|
19382
|
-
} else {
|
|
19383
|
-
state.markCurrentStepCompleted("Step completed successfully");
|
|
19384
|
-
}
|
|
19385
|
-
if (state.hasNextStep()) {
|
|
19386
|
-
const nextStepArgsDef = this.createArgsDef.forNextState(state);
|
|
19387
|
-
results.content.push({
|
|
19388
|
-
type: "text",
|
|
19389
|
-
text: CompiledPrompts.nextStepDecision({
|
|
19390
|
-
toolName: this.name,
|
|
19391
|
-
nextStepDescription: state.getNextStep()?.description || "Unknown step",
|
|
19392
|
-
nextStepSchema: JSON.stringify(nextStepArgsDef, null, 2)
|
|
19393
|
-
})
|
|
19394
|
-
});
|
|
19395
|
-
} else {
|
|
19396
|
-
results.content.push({
|
|
19397
|
-
type: "text",
|
|
19398
|
-
text: CompiledPrompts.finalStepCompletion({
|
|
19399
|
-
statusIcon: results.isError ? "\u274C" : "\u2705",
|
|
19400
|
-
statusText: results.isError ? "with errors" : "successfully",
|
|
19401
|
-
toolName: this.name,
|
|
19402
|
-
newWorkflowInstructions: this.predefinedSteps ? "" : " and new `steps` array"
|
|
19403
|
-
})
|
|
19404
|
-
});
|
|
19405
|
-
}
|
|
19406
|
-
results.content.push({
|
|
19407
|
-
type: "text",
|
|
19408
|
-
text: `## Workflow Progress
|
|
19409
|
-
${this.formatProgress(state)}`
|
|
19410
|
-
});
|
|
19411
|
-
return results;
|
|
19412
|
-
}
|
|
19413
|
-
// Validate arguments using JSON schema
|
|
19414
|
-
validateInput(args, schema) {
|
|
19415
|
-
return validateSchema(args, schema);
|
|
19416
|
-
}
|
|
19417
|
-
};
|
|
19418
|
-
|
|
19419
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/workflow/workflow-tool-registrar.js
|
|
19420
|
-
function registerAgenticWorkflowTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList, predefinedSteps, ensureStepActions, toolNameToIdMapping }) {
|
|
19421
|
-
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, predefinedSteps, ensureStepActions);
|
|
19422
|
-
const workflowExecutor = new WorkflowExecutor(name, allToolNames, toolNameToDetailList, createArgsDef, server, predefinedSteps, ensureStepActions, toolNameToIdMapping);
|
|
19423
|
-
const workflowState = new WorkflowState();
|
|
19424
|
-
const planningInstructions = predefinedSteps ? "- Set `init: true` (steps are predefined)" : "- Set `init: true` and define complete `steps` array";
|
|
19425
|
-
const baseDescription = CompiledPrompts.workflowExecution({
|
|
19426
|
-
toolName: name,
|
|
19427
|
-
description,
|
|
19428
|
-
planningInstructions
|
|
19429
|
-
});
|
|
19430
|
-
const argsDef = createArgsDef.forTool();
|
|
19431
|
-
const toolDescription = createArgsDef.forToolDescription(baseDescription, workflowState);
|
|
19432
|
-
server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(argsDef)), async (args) => {
|
|
19433
|
-
try {
|
|
19434
|
-
return await workflowExecutor.execute(args, workflowState);
|
|
19435
|
-
} catch (error2) {
|
|
19436
|
-
workflowState.reset();
|
|
19437
|
-
return {
|
|
19438
|
-
content: [
|
|
19439
|
-
{
|
|
19440
|
-
type: "text",
|
|
19441
|
-
text: `Workflow execution error: ${error2.message}`
|
|
19442
|
-
}
|
|
19443
|
-
],
|
|
19444
|
-
isError: true
|
|
19445
|
-
};
|
|
19446
|
-
}
|
|
19447
|
-
});
|
|
19448
|
-
}
|
|
19449
|
-
|
|
19450
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-workflow-plugin.js
|
|
19451
|
-
var createWorkflowModePlugin = () => ({
|
|
19452
|
-
name: "mode-workflow",
|
|
19453
|
-
version: "1.0.0",
|
|
19454
|
-
// Only apply to workflow mode
|
|
19455
|
-
apply: "agentic_workflow",
|
|
19456
|
-
// Register the agent tool
|
|
19457
|
-
registerAgentTool: (context2) => {
|
|
19458
|
-
registerAgenticWorkflowTool(context2.server, {
|
|
19459
|
-
description: context2.description,
|
|
19460
|
-
name: context2.name,
|
|
19461
|
-
allToolNames: context2.allToolNames,
|
|
19462
|
-
depGroups: context2.depGroups,
|
|
19463
|
-
toolNameToDetailList: context2.toolNameToDetailList,
|
|
19464
|
-
predefinedSteps: context2.options.steps,
|
|
19465
|
-
ensureStepActions: context2.options.ensureStepActions,
|
|
19466
|
-
toolNameToIdMapping: context2.toolNameToIdMapping
|
|
19467
|
-
});
|
|
19468
|
-
}
|
|
19469
|
-
});
|
|
19470
|
-
var mode_workflow_plugin_default = createWorkflowModePlugin();
|
|
19471
|
-
|
|
19472
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/sampling/base-sampling-executor.js
|
|
19473
|
-
var import_node_process6 = __toESM(require("node:process"), 1);
|
|
19474
|
-
var BaseSamplingExecutor = class {
|
|
19475
|
-
name;
|
|
19476
|
-
description;
|
|
19477
|
-
allToolNames;
|
|
19478
|
-
toolNameToDetailList;
|
|
19479
|
-
server;
|
|
19480
|
-
conversationHistory;
|
|
19481
|
-
maxIterations;
|
|
19482
|
-
currentIteration;
|
|
19483
|
-
logger;
|
|
19484
|
-
tracingEnabled;
|
|
19485
|
-
summarize;
|
|
19486
|
-
constructor(name, description, allToolNames, toolNameToDetailList, server, config2) {
|
|
19487
|
-
this.name = name;
|
|
19488
|
-
this.description = description;
|
|
19489
|
-
this.allToolNames = allToolNames;
|
|
19490
|
-
this.toolNameToDetailList = toolNameToDetailList;
|
|
19491
|
-
this.server = server;
|
|
19492
|
-
this.conversationHistory = [];
|
|
19493
|
-
this.maxIterations = 55;
|
|
19494
|
-
this.currentIteration = 0;
|
|
19495
|
-
this.tracingEnabled = false;
|
|
19496
|
-
this.summarize = true;
|
|
19497
|
-
if (config2?.maxIterations) {
|
|
19498
|
-
this.maxIterations = config2.maxIterations;
|
|
19499
|
-
}
|
|
19500
|
-
if (config2?.summarize !== void 0) {
|
|
19501
|
-
this.summarize = config2.summarize;
|
|
19502
|
-
}
|
|
19503
|
-
this.logger = createLogger(`mcpc.sampling.${name}`, server);
|
|
19504
|
-
try {
|
|
19505
|
-
const tracingConfig = {
|
|
19506
|
-
enabled: import_node_process6.default.env.MCPC_TRACING_ENABLED === "true",
|
|
19507
|
-
serviceName: `mcpc-sampling-${name}`,
|
|
19508
|
-
exportTo: import_node_process6.default.env.MCPC_TRACING_EXPORT ?? "otlp",
|
|
19509
|
-
otlpEndpoint: import_node_process6.default.env.MCPC_TRACING_OTLP_ENDPOINT ?? "http://localhost:4318/v1/traces"
|
|
19510
|
-
};
|
|
19511
|
-
this.tracingEnabled = tracingConfig.enabled;
|
|
19512
|
-
if (this.tracingEnabled) {
|
|
19513
|
-
initializeTracing(tracingConfig);
|
|
19514
|
-
}
|
|
19515
|
-
} catch {
|
|
19516
|
-
this.tracingEnabled = false;
|
|
19517
|
-
}
|
|
19518
|
-
}
|
|
19519
|
-
/**
|
|
19520
|
-
* Convert toolNameToDetailList to MCP Tool format for sampling
|
|
19521
|
-
*/
|
|
19522
|
-
convertToMcpTools() {
|
|
19523
|
-
return this.toolNameToDetailList.map(([name, detail]) => ({
|
|
19524
|
-
name,
|
|
19525
|
-
description: detail.description || `Tool: ${name}`,
|
|
19526
|
-
inputSchema: {
|
|
19527
|
-
type: "object",
|
|
19528
|
-
...detail.inputSchema
|
|
19529
|
-
}
|
|
19530
|
-
}));
|
|
19531
|
-
}
|
|
19532
|
-
/**
|
|
19533
|
-
* Check if client supports sampling with tools
|
|
19534
|
-
*/
|
|
19535
|
-
supportsSamplingTools() {
|
|
19536
|
-
const capabilities = this.server.getClientCapabilities();
|
|
19537
|
-
return !!capabilities?.sampling?.tools;
|
|
19538
|
-
}
|
|
19539
|
-
/**
|
|
19540
|
-
* Check if response contains tool use
|
|
19541
|
-
*/
|
|
19542
|
-
isToolUseResponse(response) {
|
|
19543
|
-
if (!response.content) return false;
|
|
19544
|
-
const content = Array.isArray(response.content) ? response.content : [
|
|
19545
|
-
response.content
|
|
19546
|
-
];
|
|
19547
|
-
return content.some((block) => block.type === "tool_use");
|
|
18150
|
+
return {
|
|
18151
|
+
content: [
|
|
18152
|
+
{
|
|
18153
|
+
type: "text",
|
|
18154
|
+
text: schemas.length > 0 ? schemas.join("\n\n") : "No schemas found for requested tools."
|
|
18155
|
+
}
|
|
18156
|
+
]
|
|
18157
|
+
};
|
|
19548
18158
|
}
|
|
19549
18159
|
/**
|
|
19550
|
-
*
|
|
18160
|
+
* Execute a tool with runtime validation
|
|
19551
18161
|
*/
|
|
19552
|
-
|
|
19553
|
-
|
|
19554
|
-
|
|
19555
|
-
|
|
19556
|
-
|
|
19557
|
-
|
|
19558
|
-
|
|
19559
|
-
|
|
19560
|
-
|
|
19561
|
-
} : {
|
|
19562
|
-
id: "",
|
|
19563
|
-
name: "",
|
|
19564
|
-
input: {}
|
|
19565
|
-
});
|
|
19566
|
-
}
|
|
19567
|
-
async runSamplingLoop(systemPrompt, schema, state) {
|
|
19568
|
-
const useTools = this.supportsSamplingTools();
|
|
19569
|
-
this.logger.debug({
|
|
19570
|
-
message: "Sampling mode determined",
|
|
19571
|
-
useTools,
|
|
19572
|
-
mode: useTools ? "native_tools" : "json_fallback"
|
|
19573
|
-
});
|
|
19574
|
-
this.conversationHistory = [
|
|
19575
|
-
{
|
|
19576
|
-
// Failed: 400 {"error":{"message":"messages: at least one message is required","code":"invalid_request_body"}}
|
|
19577
|
-
role: "user",
|
|
19578
|
-
content: {
|
|
19579
|
-
type: "text",
|
|
19580
|
-
text: `start`
|
|
19581
|
-
}
|
|
18162
|
+
async executeTool(tool2, toolArgs, executeSpan) {
|
|
18163
|
+
const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
|
|
18164
|
+
if (externalTool) {
|
|
18165
|
+
const [, toolDetail] = externalTool;
|
|
18166
|
+
if (executeSpan) {
|
|
18167
|
+
executeSpan.setAttributes({
|
|
18168
|
+
toolType: "external",
|
|
18169
|
+
selectedTool: tool2
|
|
18170
|
+
});
|
|
19582
18171
|
}
|
|
19583
|
-
|
|
19584
|
-
|
|
19585
|
-
|
|
19586
|
-
|
|
19587
|
-
|
|
19588
|
-
|
|
19589
|
-
|
|
19590
|
-
|
|
19591
|
-
let iterationSpan = null;
|
|
19592
|
-
try {
|
|
19593
|
-
let createMessageParams;
|
|
19594
|
-
if (useTools) {
|
|
19595
|
-
createMessageParams = {
|
|
19596
|
-
systemPrompt: systemPrompt(),
|
|
19597
|
-
messages: this.conversationHistory,
|
|
19598
|
-
maxTokens: 55e3,
|
|
19599
|
-
tools: this.convertToMcpTools(),
|
|
19600
|
-
toolChoice: {
|
|
19601
|
-
mode: "auto"
|
|
19602
|
-
}
|
|
19603
|
-
};
|
|
19604
|
-
} else {
|
|
19605
|
-
createMessageParams = {
|
|
19606
|
-
systemPrompt: systemPrompt(),
|
|
19607
|
-
messages: this.conversationHistory,
|
|
19608
|
-
maxTokens: 55e3
|
|
19609
|
-
};
|
|
19610
|
-
}
|
|
19611
|
-
const response = await this.server.createMessage(createMessageParams);
|
|
19612
|
-
const model = response.model;
|
|
19613
|
-
const stopReason = response.stopReason;
|
|
19614
|
-
const role = response.role;
|
|
19615
|
-
if (useTools && this.isToolUseResponse(response)) {
|
|
19616
|
-
const toolCalls = this.extractToolCalls(response);
|
|
19617
|
-
if (toolCalls.length === 0) {
|
|
19618
|
-
const contentArray = Array.isArray(response.content) ? response.content : [
|
|
19619
|
-
response.content
|
|
19620
|
-
];
|
|
19621
|
-
const textBlock = contentArray.find((c) => c.type === "text");
|
|
19622
|
-
const textContent2 = textBlock && "text" in textBlock ? textBlock.text : void 0;
|
|
19623
|
-
if (textContent2) {
|
|
19624
|
-
return await this.createCompletionResult(textContent2, loopSpan);
|
|
19625
|
-
}
|
|
19626
|
-
continue;
|
|
19627
|
-
}
|
|
19628
|
-
iterationSpan = this.tracingEnabled ? startSpan("mcpc.sampling_iteration.tool_use", {
|
|
19629
|
-
iteration: this.currentIteration + 1,
|
|
19630
|
-
agent: this.name,
|
|
19631
|
-
toolCalls: toolCalls.length,
|
|
19632
|
-
maxIterations: this.maxIterations
|
|
19633
|
-
}, loopSpan ?? void 0) : null;
|
|
19634
|
-
this.conversationHistory.push({
|
|
19635
|
-
role: "assistant",
|
|
19636
|
-
content: response.content
|
|
19637
|
-
});
|
|
19638
|
-
const toolResults = [];
|
|
19639
|
-
for (const toolCall of toolCalls) {
|
|
19640
|
-
try {
|
|
19641
|
-
const result2 = await this.server.callTool(toolCall.name, toolCall.input);
|
|
19642
|
-
toolResults.push({
|
|
19643
|
-
type: "tool_result",
|
|
19644
|
-
toolUseId: toolCall.id,
|
|
19645
|
-
content: result2.content || [],
|
|
19646
|
-
isError: result2.isError
|
|
19647
|
-
});
|
|
19648
|
-
} catch (error2) {
|
|
19649
|
-
toolResults.push({
|
|
19650
|
-
type: "tool_result",
|
|
19651
|
-
toolUseId: toolCall.id,
|
|
19652
|
-
content: [
|
|
19653
|
-
{
|
|
19654
|
-
type: "text",
|
|
19655
|
-
text: `Error: ${error2 instanceof Error ? error2.message : String(error2)}`
|
|
19656
|
-
}
|
|
19657
|
-
],
|
|
19658
|
-
isError: true
|
|
19659
|
-
});
|
|
19660
|
-
}
|
|
19661
|
-
}
|
|
19662
|
-
this.conversationHistory.push({
|
|
19663
|
-
role: "user",
|
|
19664
|
-
content: toolResults
|
|
19665
|
-
});
|
|
19666
|
-
if (iterationSpan) {
|
|
19667
|
-
iterationSpan.setAttributes({
|
|
19668
|
-
toolExecutions: toolResults.length,
|
|
19669
|
-
hasErrors: toolResults.some((r) => r.isError)
|
|
19670
|
-
});
|
|
19671
|
-
endSpan(iterationSpan);
|
|
19672
|
-
}
|
|
19673
|
-
continue;
|
|
19674
|
-
}
|
|
19675
|
-
const content = Array.isArray(response.content) ? response.content : [
|
|
19676
|
-
response.content
|
|
19677
|
-
];
|
|
19678
|
-
const textContent = content.find((c) => c.type === "text");
|
|
19679
|
-
const responseContent = textContent?.text || "{}";
|
|
19680
|
-
let parsedData;
|
|
19681
|
-
try {
|
|
19682
|
-
parsedData = parseJSON(responseContent.trim(), true);
|
|
19683
|
-
} catch (parseError) {
|
|
19684
|
-
iterationSpan = this.tracingEnabled ? startSpan("mcpc.sampling_iteration.parse_error", {
|
|
19685
|
-
iteration: this.currentIteration + 1,
|
|
19686
|
-
agent: this.name,
|
|
19687
|
-
error: String(parseError),
|
|
19688
|
-
maxIterations: this.maxIterations
|
|
19689
|
-
}, loopSpan ?? void 0) : null;
|
|
19690
|
-
this.addParsingErrorToHistory(responseContent, parseError);
|
|
19691
|
-
if (iterationSpan) endSpan(iterationSpan);
|
|
19692
|
-
continue;
|
|
19693
|
-
}
|
|
19694
|
-
this.conversationHistory.push({
|
|
19695
|
-
role: "assistant",
|
|
19696
|
-
content: {
|
|
19697
|
-
type: "text",
|
|
19698
|
-
text: JSON.stringify(parsedData, null, 2)
|
|
19699
|
-
}
|
|
19700
|
-
});
|
|
19701
|
-
const decision = parsedData["decision"];
|
|
19702
|
-
const useTool = parsedData["useTool"];
|
|
19703
|
-
const actionStr = decision === "complete" ? "completion" : useTool && typeof useTool === "string" ? String(useTool) : "unknown_action";
|
|
19704
|
-
const spanName = `mcpc.sampling_iteration.${actionStr}`;
|
|
19705
|
-
iterationSpan = this.tracingEnabled ? startSpan(spanName, {
|
|
19706
|
-
iteration: this.currentIteration + 1,
|
|
19707
|
-
agent: this.name,
|
|
19708
|
-
action: actionStr,
|
|
19709
|
-
systemPrompt: systemPrompt(),
|
|
19710
|
-
maxTokens: String(Number.MAX_SAFE_INTEGER),
|
|
19711
|
-
maxIterations: this.maxIterations,
|
|
19712
|
-
messages: JSON.stringify(this.conversationHistory)
|
|
19713
|
-
}, loopSpan ?? void 0) : null;
|
|
19714
|
-
const result = await this.processAction(parsedData, schema, state, iterationSpan);
|
|
19715
|
-
this.logIterationProgress(parsedData, result, model, stopReason, role);
|
|
19716
|
-
if (iterationSpan) {
|
|
19717
|
-
let rawJson = "{}";
|
|
19718
|
-
try {
|
|
19719
|
-
rawJson = parsedData ? JSON.stringify(parsedData) : "{}";
|
|
19720
|
-
} catch {
|
|
19721
|
-
}
|
|
19722
|
-
const attr = {
|
|
19723
|
-
isError: !!result.isError,
|
|
19724
|
-
isComplete: !!result.isComplete,
|
|
19725
|
-
iteration: this.currentIteration + 1,
|
|
19726
|
-
maxIterations: this.maxIterations,
|
|
19727
|
-
parsed: rawJson,
|
|
19728
|
-
action: typeof useTool === "string" ? useTool : String(useTool),
|
|
19729
|
-
decision: typeof decision === "string" ? decision : String(decision),
|
|
19730
|
-
samplingResponse: responseContent,
|
|
19731
|
-
toolResult: JSON.stringify(result),
|
|
19732
|
-
model,
|
|
19733
|
-
role
|
|
19734
|
-
};
|
|
19735
|
-
if (stopReason) {
|
|
19736
|
-
attr.stopReason = stopReason;
|
|
19737
|
-
}
|
|
19738
|
-
iterationSpan.setAttributes(attr);
|
|
19739
|
-
}
|
|
19740
|
-
if (result.isError) {
|
|
19741
|
-
const errorText = result.content?.[0] && "text" in result.content[0] ? result.content[0].text : "Unknown error";
|
|
19742
|
-
this.conversationHistory.push({
|
|
19743
|
-
role: "user",
|
|
19744
|
-
content: {
|
|
19745
|
-
type: "text",
|
|
19746
|
-
text: errorText
|
|
19747
|
-
}
|
|
18172
|
+
if (toolDetail.inputSchema) {
|
|
18173
|
+
const rawSchema = extractJsonSchema(toolDetail.inputSchema);
|
|
18174
|
+
const validation = validateSchema(toolArgs, rawSchema);
|
|
18175
|
+
if (!validation.valid) {
|
|
18176
|
+
if (executeSpan) {
|
|
18177
|
+
executeSpan.setAttributes({
|
|
18178
|
+
validationError: true,
|
|
18179
|
+
errorMessage: validation.error
|
|
19748
18180
|
});
|
|
19749
|
-
|
|
19750
|
-
continue;
|
|
19751
|
-
}
|
|
19752
|
-
if (result.isComplete) {
|
|
19753
|
-
if (iterationSpan) endSpan(iterationSpan);
|
|
19754
|
-
if (loopSpan) endSpan(loopSpan);
|
|
19755
|
-
return result;
|
|
19756
|
-
}
|
|
19757
|
-
if (iterationSpan) endSpan(iterationSpan);
|
|
19758
|
-
} catch (iterError) {
|
|
19759
|
-
if (iterationSpan) endSpan(iterationSpan, iterError);
|
|
19760
|
-
throw iterError;
|
|
19761
|
-
}
|
|
19762
|
-
}
|
|
19763
|
-
if (loopSpan) endSpan(loopSpan);
|
|
19764
|
-
return await this.createMaxIterationsError(loopSpan);
|
|
19765
|
-
} catch (error2) {
|
|
19766
|
-
if (loopSpan) endSpan(loopSpan, error2);
|
|
19767
|
-
return await this.createExecutionError(error2, loopSpan);
|
|
19768
|
-
}
|
|
19769
|
-
}
|
|
19770
|
-
addParsingErrorToHistory(_responseText, parseError) {
|
|
19771
|
-
const errorMsg = parseError instanceof Error ? parseError.message : String(parseError);
|
|
19772
|
-
this.conversationHistory.push({
|
|
19773
|
-
role: "user",
|
|
19774
|
-
content: {
|
|
19775
|
-
type: "text",
|
|
19776
|
-
text: `Invalid JSON: ${errorMsg}
|
|
19777
|
-
|
|
19778
|
-
Respond with valid JSON.`
|
|
19779
|
-
}
|
|
19780
|
-
});
|
|
19781
|
-
}
|
|
19782
|
-
async createMaxIterationsError(parentSpan) {
|
|
19783
|
-
const result = await this.createCompletionResult(`Reached max iterations (${this.maxIterations}). Try a more specific request.`, parentSpan);
|
|
19784
|
-
result.isError = true;
|
|
19785
|
-
result.isComplete = false;
|
|
19786
|
-
return result;
|
|
19787
|
-
}
|
|
19788
|
-
async createExecutionError(error2, parentSpan) {
|
|
19789
|
-
const result = await this.createCompletionResult(`Execution error: ${error2 instanceof Error ? error2.message : String(error2)}`, parentSpan);
|
|
19790
|
-
result.isError = true;
|
|
19791
|
-
result.isComplete = false;
|
|
19792
|
-
return result;
|
|
19793
|
-
}
|
|
19794
|
-
async createCompletionResult(text, parentSpan) {
|
|
19795
|
-
const summary = this.summarize ? await this.summarizeConversation(parentSpan) : this.formatConversation();
|
|
19796
|
-
return {
|
|
19797
|
-
content: [
|
|
19798
|
-
{
|
|
19799
|
-
type: "text",
|
|
19800
|
-
text: `${text}
|
|
19801
|
-
|
|
19802
|
-
**Execution Summary:**
|
|
19803
|
-
- Iterations used: ${this.currentIteration + 1}/${this.maxIterations}
|
|
19804
|
-
- Agent: ${this.name}
|
|
19805
|
-
${summary}`
|
|
19806
|
-
}
|
|
19807
|
-
],
|
|
19808
|
-
isError: false,
|
|
19809
|
-
isComplete: true
|
|
19810
|
-
};
|
|
19811
|
-
}
|
|
19812
|
-
// Use LLM to create high-signal summary for parent agent
|
|
19813
|
-
async summarizeConversation(parentSpan) {
|
|
19814
|
-
if (this.conversationHistory.length === 0) {
|
|
19815
|
-
return "\n\n**No conversation history**";
|
|
19816
|
-
}
|
|
19817
|
-
if (this.conversationHistory.length <= 3) {
|
|
19818
|
-
return this.formatConversation();
|
|
19819
|
-
}
|
|
19820
|
-
const summarizeSpan = this.tracingEnabled ? startSpan("mcpc.sampling_summarize", {
|
|
19821
|
-
agent: this.name,
|
|
19822
|
-
messageCount: this.conversationHistory.length
|
|
19823
|
-
}, parentSpan ?? void 0) : null;
|
|
19824
|
-
try {
|
|
19825
|
-
this.logger.debug({
|
|
19826
|
-
message: "Starting conversation summarization",
|
|
19827
|
-
messageCount: this.conversationHistory.length
|
|
19828
|
-
});
|
|
19829
|
-
const history = this.conversationHistory.map((msg, i) => {
|
|
19830
|
-
const prefix = `[${i + 1}] ${msg.role.toUpperCase()}`;
|
|
19831
|
-
const contentArray = Array.isArray(msg.content) ? msg.content : [
|
|
19832
|
-
msg.content
|
|
19833
|
-
];
|
|
19834
|
-
const textBlock = contentArray.find((c) => c.type === "text");
|
|
19835
|
-
const text = textBlock?.text || "(No text content)";
|
|
19836
|
-
return `${prefix}:
|
|
19837
|
-
${text}`;
|
|
19838
|
-
}).join("\n\n---\n\n");
|
|
19839
|
-
const response = await this.server.createMessage({
|
|
19840
|
-
systemPrompt: `Summarize this agent execution:
|
|
19841
|
-
|
|
19842
|
-
Final Decision: (include complete JSON if present)
|
|
19843
|
-
Key Findings: (most important)
|
|
19844
|
-
Actions Taken: (high-level flow)
|
|
19845
|
-
Errors/Warnings: (if any)
|
|
19846
|
-
|
|
19847
|
-
${history}`,
|
|
19848
|
-
messages: [
|
|
19849
|
-
{
|
|
19850
|
-
role: "user",
|
|
19851
|
-
content: {
|
|
19852
|
-
type: "text",
|
|
19853
|
-
text: "Please provide a concise summary."
|
|
19854
|
-
}
|
|
18181
|
+
endSpan(executeSpan);
|
|
19855
18182
|
}
|
|
19856
|
-
|
|
19857
|
-
|
|
19858
|
-
|
|
19859
|
-
|
|
19860
|
-
|
|
18183
|
+
return {
|
|
18184
|
+
content: [
|
|
18185
|
+
{
|
|
18186
|
+
type: "text",
|
|
18187
|
+
text: `Parameter validation failed for "${tool2}": ${validation.error}`
|
|
18188
|
+
}
|
|
18189
|
+
],
|
|
18190
|
+
isError: true
|
|
18191
|
+
};
|
|
18192
|
+
}
|
|
18193
|
+
}
|
|
19861
18194
|
this.logger.debug({
|
|
19862
|
-
message: "
|
|
19863
|
-
|
|
18195
|
+
message: "Executing external tool",
|
|
18196
|
+
tool: tool2
|
|
19864
18197
|
});
|
|
19865
|
-
|
|
19866
|
-
|
|
19867
|
-
|
|
19868
|
-
|
|
19869
|
-
|
|
18198
|
+
const result = await toolDetail.execute(toolArgs);
|
|
18199
|
+
if (executeSpan) {
|
|
18200
|
+
executeSpan.setAttributes({
|
|
18201
|
+
success: true,
|
|
18202
|
+
isError: !!result.isError,
|
|
18203
|
+
resultContentLength: result.content?.length || 0
|
|
19870
18204
|
});
|
|
19871
|
-
endSpan(
|
|
19872
|
-
}
|
|
19873
|
-
return summary;
|
|
19874
|
-
} catch (error2) {
|
|
19875
|
-
this.logger.warning({
|
|
19876
|
-
message: "Summarization failed, falling back to full history",
|
|
19877
|
-
error: String(error2)
|
|
19878
|
-
});
|
|
19879
|
-
if (summarizeSpan) {
|
|
19880
|
-
endSpan(summarizeSpan, error2);
|
|
18205
|
+
endSpan(executeSpan);
|
|
19881
18206
|
}
|
|
19882
|
-
return
|
|
19883
|
-
}
|
|
19884
|
-
}
|
|
19885
|
-
// Format full conversation history (for debugging)
|
|
19886
|
-
formatConversation() {
|
|
19887
|
-
if (this.conversationHistory.length === 0) {
|
|
19888
|
-
return "\n\n**No conversation history**";
|
|
18207
|
+
return result;
|
|
19889
18208
|
}
|
|
19890
|
-
|
|
19891
|
-
|
|
19892
|
-
|
|
19893
|
-
|
|
19894
|
-
|
|
19895
|
-
|
|
19896
|
-
const contentText = textBlock?.text;
|
|
19897
|
-
if (!contentText) {
|
|
19898
|
-
return `${header}\\n(No text content)`;
|
|
18209
|
+
if (this.allToolNames.includes(tool2)) {
|
|
18210
|
+
if (executeSpan) {
|
|
18211
|
+
executeSpan.setAttributes({
|
|
18212
|
+
toolType: "internal",
|
|
18213
|
+
selectedTool: tool2
|
|
18214
|
+
});
|
|
19899
18215
|
}
|
|
18216
|
+
this.logger.debug({
|
|
18217
|
+
message: "Executing internal tool",
|
|
18218
|
+
tool: tool2
|
|
18219
|
+
});
|
|
19900
18220
|
try {
|
|
19901
|
-
const
|
|
19902
|
-
|
|
19903
|
-
|
|
18221
|
+
const result = await this.server.callTool(tool2, toolArgs);
|
|
18222
|
+
const callToolResult = result ?? {
|
|
18223
|
+
content: []
|
|
18224
|
+
};
|
|
18225
|
+
if (executeSpan) {
|
|
18226
|
+
executeSpan.setAttributes({
|
|
18227
|
+
success: true,
|
|
18228
|
+
isError: !!callToolResult.isError,
|
|
18229
|
+
resultContentLength: callToolResult.content?.length || 0
|
|
18230
|
+
});
|
|
18231
|
+
endSpan(executeSpan);
|
|
19904
18232
|
}
|
|
19905
|
-
return
|
|
19906
|
-
} catch {
|
|
19907
|
-
|
|
18233
|
+
return callToolResult;
|
|
18234
|
+
} catch (error2) {
|
|
18235
|
+
if (executeSpan) {
|
|
18236
|
+
endSpan(executeSpan, error2);
|
|
18237
|
+
}
|
|
18238
|
+
this.logger.error({
|
|
18239
|
+
message: "Error executing internal tool",
|
|
18240
|
+
tool: tool2,
|
|
18241
|
+
error: String(error2)
|
|
18242
|
+
});
|
|
18243
|
+
return {
|
|
18244
|
+
content: [
|
|
18245
|
+
{
|
|
18246
|
+
type: "text",
|
|
18247
|
+
text: `Error executing tool "${tool2}": ${error2 instanceof Error ? error2.message : String(error2)}`
|
|
18248
|
+
}
|
|
18249
|
+
],
|
|
18250
|
+
isError: true
|
|
18251
|
+
};
|
|
19908
18252
|
}
|
|
19909
|
-
});
|
|
19910
|
-
return "\n\n**Conversation History:**\n" + messages.join("\n\n");
|
|
19911
|
-
}
|
|
19912
|
-
logIterationProgress(parsedData, result, model, stopReason, role) {
|
|
19913
|
-
this.logger.debug({
|
|
19914
|
-
iteration: `${this.currentIteration + 1}/${this.maxIterations}`,
|
|
19915
|
-
parsedData,
|
|
19916
|
-
isError: result.isError,
|
|
19917
|
-
isComplete: result.isComplete,
|
|
19918
|
-
model,
|
|
19919
|
-
stopReason,
|
|
19920
|
-
role,
|
|
19921
|
-
result
|
|
19922
|
-
});
|
|
19923
|
-
}
|
|
19924
|
-
formatPromptForMode({ prompt, schema, schemaPrefix = "JSON schema:", schemaSuffix = `STRICT REQUIREMENTS:
|
|
19925
|
-
1. Return ONE AND ONLY ONE raw JSON object that passes JSON.parse() - no markdown, code blocks, explanatory text, or multiple JSON objects
|
|
19926
|
-
2. Include ALL required fields with correct data types and satisfy ALL schema constraints (anyOf, oneOf, allOf, not, enum, pattern, min/max, conditionals)
|
|
19927
|
-
3. Your response must be a single JSON object, nothing else
|
|
19928
|
-
|
|
19929
|
-
INVALID: \`\`\`json{"key":"value"}\`\`\` or "Here is: {"key":"value"}" or {"key":"value"}{"key":"value"}
|
|
19930
|
-
VALID: {"key":"value"}` }) {
|
|
19931
|
-
if (this.supportsSamplingTools()) {
|
|
19932
|
-
return prompt && prompt.length > 0 ? prompt : "";
|
|
19933
18253
|
}
|
|
19934
|
-
|
|
19935
|
-
|
|
19936
|
-
|
|
19937
|
-
|
|
19938
|
-
|
|
19939
|
-
|
|
19940
|
-
|
|
19941
|
-
|
|
19942
|
-
|
|
19943
|
-
|
|
18254
|
+
if (executeSpan) {
|
|
18255
|
+
executeSpan.setAttributes({
|
|
18256
|
+
toolType: "not_found",
|
|
18257
|
+
tool: tool2
|
|
18258
|
+
});
|
|
18259
|
+
endSpan(executeSpan);
|
|
18260
|
+
}
|
|
18261
|
+
return {
|
|
18262
|
+
content: [
|
|
18263
|
+
{
|
|
18264
|
+
type: "text",
|
|
18265
|
+
text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
|
|
18266
|
+
}
|
|
18267
|
+
],
|
|
18268
|
+
isError: true
|
|
18269
|
+
};
|
|
18270
|
+
}
|
|
18271
|
+
validate(args, schema) {
|
|
19944
18272
|
return validateSchema(args, schema);
|
|
19945
18273
|
}
|
|
19946
18274
|
};
|
|
19947
18275
|
|
|
19948
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/
|
|
19949
|
-
|
|
19950
|
-
|
|
19951
|
-
|
|
19952
|
-
super(name, description, allToolNames, toolNameToDetailList, server, config2);
|
|
19953
|
-
this.agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server);
|
|
19954
|
-
}
|
|
19955
|
-
buildDepGroups() {
|
|
19956
|
-
const depGroups = {};
|
|
19957
|
-
this.toolNameToDetailList.forEach(([toolName, tool2]) => {
|
|
19958
|
-
if (tool2?.inputSchema) {
|
|
19959
|
-
depGroups[toolName] = {
|
|
19960
|
-
type: "object",
|
|
19961
|
-
description: tool2.description || `Tool: ${toolName}`,
|
|
19962
|
-
...tool2.inputSchema
|
|
19963
|
-
};
|
|
19964
|
-
} else {
|
|
19965
|
-
const toolSchema = this.server.getHiddenToolSchema(toolName);
|
|
19966
|
-
if (toolSchema) {
|
|
19967
|
-
depGroups[toolName] = {
|
|
19968
|
-
...toolSchema.schema,
|
|
19969
|
-
description: toolSchema.description
|
|
19970
|
-
};
|
|
19971
|
-
}
|
|
19972
|
-
}
|
|
19973
|
-
});
|
|
19974
|
-
return depGroups;
|
|
19975
|
-
}
|
|
19976
|
-
executeSampling(args, schema) {
|
|
19977
|
-
const validationResult = validateSchema(args, schema);
|
|
19978
|
-
if (!validationResult.valid) {
|
|
18276
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/factories/args-def-factory.js
|
|
18277
|
+
function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps, _ensureStepActions) {
|
|
18278
|
+
return {
|
|
18279
|
+
forSampling: function() {
|
|
19979
18280
|
return {
|
|
19980
|
-
|
|
19981
|
-
|
|
19982
|
-
|
|
19983
|
-
|
|
19984
|
-
|
|
19985
|
-
|
|
18281
|
+
type: "object",
|
|
18282
|
+
description: "Provide prompt for autonomous tool execution",
|
|
18283
|
+
properties: {
|
|
18284
|
+
prompt: {
|
|
18285
|
+
type: "string",
|
|
18286
|
+
description: "The task to be completed autonomously by the agentic system using available tools"
|
|
18287
|
+
},
|
|
18288
|
+
context: {
|
|
18289
|
+
type: "object",
|
|
18290
|
+
description: "Execution context, e.g., { cwd: '/path/to/dir' }. Any relevant fields allowed.",
|
|
18291
|
+
additionalProperties: true
|
|
19986
18292
|
}
|
|
18293
|
+
},
|
|
18294
|
+
required: [
|
|
18295
|
+
"prompt",
|
|
18296
|
+
"context"
|
|
19987
18297
|
],
|
|
19988
|
-
|
|
19989
|
-
|
|
19990
|
-
|
|
19991
|
-
|
|
19992
|
-
|
|
19993
|
-
const systemPrompt = this.buildSystemPrompt(args.userRequest, agenticSchema, args.context && typeof args.context === "object" ? args.context : void 0);
|
|
19994
|
-
return this.runSamplingLoop(() => systemPrompt, agenticSchema);
|
|
19995
|
-
}
|
|
19996
|
-
async processAction(parsedData, schema, _state, parentSpan) {
|
|
19997
|
-
const toolCallData = parsedData;
|
|
19998
|
-
if (toolCallData.decision === "complete") {
|
|
19999
|
-
return await this.createCompletionResult("Task completed", parentSpan);
|
|
20000
|
-
}
|
|
20001
|
-
try {
|
|
20002
|
-
const { action: _action, decision: _decision, ..._toolArgs } = toolCallData;
|
|
20003
|
-
const toolResult = await this.agenticExecutor.execute(toolCallData, schema, parentSpan);
|
|
20004
|
-
const resultText = toolResult.content?.filter((content) => content.type === "text")?.map((content) => content.text)?.join("\n") || "No result";
|
|
20005
|
-
this.conversationHistory.push({
|
|
20006
|
-
role: "assistant",
|
|
20007
|
-
content: {
|
|
20008
|
-
type: "text",
|
|
20009
|
-
text: resultText
|
|
18298
|
+
errorMessage: {
|
|
18299
|
+
required: {
|
|
18300
|
+
prompt: "Missing required field 'prompt'. Please provide a clear task description.",
|
|
18301
|
+
context: "Missing required field 'context'. Please provide relevant context (e.g., { cwd: '...' })."
|
|
18302
|
+
}
|
|
20010
18303
|
}
|
|
20011
|
-
}
|
|
20012
|
-
|
|
20013
|
-
|
|
20014
|
-
|
|
20015
|
-
|
|
20016
|
-
|
|
20017
|
-
|
|
20018
|
-
|
|
20019
|
-
|
|
20020
|
-
|
|
20021
|
-
|
|
20022
|
-
|
|
20023
|
-
|
|
20024
|
-
|
|
20025
|
-
}
|
|
20026
|
-
return `- ${name}`;
|
|
20027
|
-
}).join("\n");
|
|
20028
|
-
let contextInfo = "";
|
|
20029
|
-
if (context2 && typeof context2 === "object" && Object.keys(context2).length > 0) {
|
|
20030
|
-
contextInfo = `
|
|
20031
|
-
|
|
20032
|
-
Context:
|
|
20033
|
-
${JSON.stringify(context2, null, 2)}`;
|
|
20034
|
-
}
|
|
20035
|
-
const basePrompt = this.supportsSamplingTools() ? CompiledPrompts.samplingExecutionTools({
|
|
20036
|
-
toolName: this.name,
|
|
20037
|
-
description: this.description,
|
|
20038
|
-
toolList
|
|
20039
|
-
}) : CompiledPrompts.samplingExecution({
|
|
20040
|
-
toolName: this.name,
|
|
20041
|
-
description: this.description,
|
|
20042
|
-
toolList
|
|
20043
|
-
});
|
|
20044
|
-
const taskPrompt = `
|
|
20045
|
-
|
|
20046
|
-
## Current Task
|
|
20047
|
-
You will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
|
|
20048
|
-
|
|
20049
|
-
When you need to use a tool, specify the tool name in 'useTool' and provide tool-specific parameters as additional properties.`;
|
|
20050
|
-
return this.formatPromptForMode({
|
|
20051
|
-
prompt: basePrompt + taskPrompt,
|
|
20052
|
-
schema: agenticSchema
|
|
20053
|
-
});
|
|
20054
|
-
}
|
|
20055
|
-
};
|
|
20056
|
-
|
|
20057
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/agentic/agentic-sampling-registrar.js
|
|
20058
|
-
function registerAgenticSamplingTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList, samplingConfig }) {
|
|
20059
|
-
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
20060
|
-
const samplingExecutor = new SamplingExecutor(name, description, allToolNames, toolNameToDetailList, server, samplingConfig);
|
|
20061
|
-
const toolDescription = CompiledPrompts.samplingToolDescription({
|
|
20062
|
-
description,
|
|
20063
|
-
toolList: allToolNames.map((name2) => `- ${name2}`).join("\n")
|
|
20064
|
-
});
|
|
20065
|
-
const argsDef = createArgsDef.forSampling();
|
|
20066
|
-
const schema = allToolNames.length > 0 ? argsDef : {
|
|
20067
|
-
type: "object",
|
|
20068
|
-
properties: {}
|
|
20069
|
-
};
|
|
20070
|
-
server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), async (args) => {
|
|
20071
|
-
return await samplingExecutor.executeSampling(args, schema);
|
|
20072
|
-
});
|
|
20073
|
-
}
|
|
20074
|
-
|
|
20075
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-agentic-sampling-plugin.js
|
|
20076
|
-
var createAgenticSamplingModePlugin = () => ({
|
|
20077
|
-
name: "mode-agentic-sampling",
|
|
20078
|
-
version: "1.0.0",
|
|
20079
|
-
// Only apply to agentic_sampling mode
|
|
20080
|
-
apply: "agentic_sampling",
|
|
20081
|
-
// Register the agent tool with sampling
|
|
20082
|
-
registerAgentTool: (context2) => {
|
|
20083
|
-
registerAgenticSamplingTool(context2.server, {
|
|
20084
|
-
description: context2.description,
|
|
20085
|
-
name: context2.name,
|
|
20086
|
-
allToolNames: context2.allToolNames,
|
|
20087
|
-
depGroups: context2.depGroups,
|
|
20088
|
-
toolNameToDetailList: context2.toolNameToDetailList,
|
|
20089
|
-
samplingConfig: context2.options.samplingConfig
|
|
20090
|
-
});
|
|
20091
|
-
}
|
|
20092
|
-
});
|
|
20093
|
-
var mode_agentic_sampling_plugin_default = createAgenticSamplingModePlugin();
|
|
20094
|
-
|
|
20095
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/sampling/workflow-sampling-executor.js
|
|
20096
|
-
var WorkflowSamplingExecutor = class extends BaseSamplingExecutor {
|
|
20097
|
-
createArgsDef;
|
|
20098
|
-
predefinedSteps;
|
|
20099
|
-
workflowExecutor;
|
|
20100
|
-
constructor(name, description, allToolNames, toolNameToDetailList, createArgsDef, server, predefinedSteps, config2) {
|
|
20101
|
-
super(name, description, allToolNames, toolNameToDetailList, server, config2), this.createArgsDef = createArgsDef, this.predefinedSteps = predefinedSteps;
|
|
20102
|
-
this.workflowExecutor = new WorkflowExecutor(name, allToolNames, toolNameToDetailList, createArgsDef, server, predefinedSteps);
|
|
20103
|
-
}
|
|
20104
|
-
async executeWorkflowSampling(args, schema, state) {
|
|
20105
|
-
const validationResult = validateSchema(args, schema);
|
|
20106
|
-
if (!validationResult.valid) {
|
|
18304
|
+
};
|
|
18305
|
+
},
|
|
18306
|
+
/**
|
|
18307
|
+
* Agentic schema - simplified Unix-style interface
|
|
18308
|
+
*
|
|
18309
|
+
* Only two fields:
|
|
18310
|
+
* - `tool`: which tool to execute (enum includes "man" + all tool names)
|
|
18311
|
+
* - `args`: parameters for the tool (array for "man", object for others)
|
|
18312
|
+
*/
|
|
18313
|
+
forAgentic: function(allToolNames) {
|
|
18314
|
+
const toolEnum = [
|
|
18315
|
+
"man",
|
|
18316
|
+
...allToolNames
|
|
18317
|
+
];
|
|
20107
18318
|
return {
|
|
20108
|
-
|
|
20109
|
-
|
|
20110
|
-
|
|
20111
|
-
|
|
20112
|
-
|
|
20113
|
-
|
|
18319
|
+
type: "object",
|
|
18320
|
+
properties: {
|
|
18321
|
+
tool: {
|
|
18322
|
+
type: "string",
|
|
18323
|
+
enum: toolEnum,
|
|
18324
|
+
description: 'Which tool to execute. Use "man" to get tool schemas, or a tool name to execute.',
|
|
18325
|
+
errorMessage: {
|
|
18326
|
+
enum: `Invalid tool. Available: ${toolEnum.join(", ")}`
|
|
18327
|
+
}
|
|
18328
|
+
},
|
|
18329
|
+
args: {
|
|
18330
|
+
description: 'For "man": array of tool names ["tool1", "tool2"]. For other tools: object with parameters.'
|
|
20114
18331
|
}
|
|
18332
|
+
},
|
|
18333
|
+
required: [
|
|
18334
|
+
"tool"
|
|
20115
18335
|
],
|
|
20116
|
-
|
|
18336
|
+
additionalProperties: false
|
|
20117
18337
|
};
|
|
20118
18338
|
}
|
|
20119
|
-
|
|
20120
|
-
|
|
20121
|
-
async processAction(parsedData, _schema, state, parentSpan) {
|
|
20122
|
-
const workflowState = state;
|
|
20123
|
-
if (!workflowState) {
|
|
20124
|
-
throw new Error("WorkflowState is required for workflow");
|
|
20125
|
-
}
|
|
20126
|
-
const toolCallData = parsedData;
|
|
20127
|
-
if (toolCallData.decision === "complete") {
|
|
20128
|
-
return await this.createCompletionResult("Task completed", parentSpan);
|
|
20129
|
-
}
|
|
20130
|
-
try {
|
|
20131
|
-
const workflowResult = await this.workflowExecutor.execute(parsedData, workflowState);
|
|
20132
|
-
const resultText = workflowResult.content?.filter((content) => content.type === "text")?.map((content) => content.text)?.join("\n") || "No result";
|
|
20133
|
-
this.conversationHistory.push({
|
|
20134
|
-
role: "assistant",
|
|
20135
|
-
content: {
|
|
20136
|
-
type: "text",
|
|
20137
|
-
text: resultText
|
|
20138
|
-
}
|
|
20139
|
-
});
|
|
20140
|
-
return workflowResult;
|
|
20141
|
-
} catch (error2) {
|
|
20142
|
-
return this.createExecutionError(error2, parentSpan);
|
|
20143
|
-
}
|
|
20144
|
-
}
|
|
20145
|
-
buildWorkflowSystemPrompt(args, state) {
|
|
20146
|
-
const workflowSchema = this.createArgsDef.forCurrentState(state);
|
|
20147
|
-
const basePrompt = this.supportsSamplingTools() ? CompiledPrompts.samplingWorkflowExecutionTools({
|
|
20148
|
-
toolName: this.name,
|
|
20149
|
-
description: this.description,
|
|
20150
|
-
workflowSchema: `${JSON.stringify(workflowSchema, null, 2)}`
|
|
20151
|
-
}) : CompiledPrompts.samplingWorkflowExecution({
|
|
20152
|
-
toolName: this.name,
|
|
20153
|
-
description: this.description,
|
|
20154
|
-
workflowSchema: `${JSON.stringify(workflowSchema, null, 2)}`
|
|
20155
|
-
});
|
|
20156
|
-
let contextInfo = "";
|
|
20157
|
-
if (args.context && typeof args.context === "object" && Object.keys(args.context).length > 0) {
|
|
20158
|
-
contextInfo = `
|
|
20159
|
-
|
|
20160
|
-
Context:
|
|
20161
|
-
${JSON.stringify(args.context, null, 2)}`;
|
|
20162
|
-
}
|
|
20163
|
-
const workflowPrompt = `
|
|
20164
|
-
|
|
20165
|
-
Current Task: <user_request>${args.userRequest}</user_request>${contextInfo}`;
|
|
20166
|
-
return this.formatPromptForMode({
|
|
20167
|
-
prompt: basePrompt + workflowPrompt,
|
|
20168
|
-
schema: workflowSchema
|
|
20169
|
-
});
|
|
20170
|
-
}
|
|
20171
|
-
};
|
|
18339
|
+
};
|
|
18340
|
+
}
|
|
20172
18341
|
|
|
20173
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/
|
|
20174
|
-
function
|
|
20175
|
-
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups,
|
|
20176
|
-
const
|
|
20177
|
-
|
|
20178
|
-
const baseDescription = CompiledPrompts.samplingExecution({
|
|
18342
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/agentic/agentic-tool-registrar.js
|
|
18343
|
+
function registerAgenticTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList }) {
|
|
18344
|
+
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
18345
|
+
const agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server);
|
|
18346
|
+
description = CompiledPrompts.autonomousExecution({
|
|
20179
18347
|
toolName: name,
|
|
20180
|
-
description
|
|
20181
|
-
toolList: allToolNames.map((name2) => `- ${name2}`).join("\n")
|
|
18348
|
+
description
|
|
20182
18349
|
});
|
|
20183
|
-
const
|
|
18350
|
+
const agenticArgsDef = createArgsDef.forAgentic(allToolNames);
|
|
18351
|
+
const argsDef = agenticArgsDef;
|
|
20184
18352
|
const schema = allToolNames.length > 0 ? argsDef : {
|
|
20185
18353
|
type: "object",
|
|
20186
18354
|
properties: {}
|
|
20187
18355
|
};
|
|
20188
|
-
server.tool(name,
|
|
20189
|
-
|
|
20190
|
-
return await workflowSamplingExecutor.executeWorkflowSampling(args, schema, workflowState);
|
|
20191
|
-
} catch (error2) {
|
|
20192
|
-
workflowState.reset();
|
|
20193
|
-
return {
|
|
20194
|
-
content: [
|
|
20195
|
-
{
|
|
20196
|
-
type: "text",
|
|
20197
|
-
text: `Workflow execution error: ${error2.message}`
|
|
20198
|
-
}
|
|
20199
|
-
],
|
|
20200
|
-
isError: true
|
|
20201
|
-
};
|
|
20202
|
-
}
|
|
18356
|
+
server.tool(name, description, jsonSchema(createModelCompatibleJSONSchema(schema)), async (args) => {
|
|
18357
|
+
return await agenticExecutor.execute(args, schema);
|
|
20203
18358
|
});
|
|
20204
18359
|
}
|
|
20205
18360
|
|
|
20206
|
-
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-
|
|
20207
|
-
var
|
|
20208
|
-
name: "mode-agentic
|
|
20209
|
-
version: "
|
|
20210
|
-
// Only apply to
|
|
20211
|
-
apply: "
|
|
20212
|
-
// Register the agent tool
|
|
18361
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-agentic-plugin.js
|
|
18362
|
+
var createAgenticModePlugin = () => ({
|
|
18363
|
+
name: "mode-agentic",
|
|
18364
|
+
version: "2.0.0",
|
|
18365
|
+
// Only apply to agentic mode
|
|
18366
|
+
apply: "agentic",
|
|
18367
|
+
// Register the agent tool
|
|
20213
18368
|
registerAgentTool: (context2) => {
|
|
20214
|
-
|
|
18369
|
+
registerAgenticTool(context2.server, {
|
|
20215
18370
|
description: context2.description,
|
|
20216
18371
|
name: context2.name,
|
|
20217
18372
|
allToolNames: context2.allToolNames,
|
|
20218
18373
|
depGroups: context2.depGroups,
|
|
20219
|
-
toolNameToDetailList: context2.toolNameToDetailList
|
|
20220
|
-
predefinedSteps: context2.options.steps,
|
|
20221
|
-
samplingConfig: context2.options.samplingConfig,
|
|
20222
|
-
ensureStepActions: context2.options.ensureStepActions,
|
|
20223
|
-
toolNameToIdMapping: context2.toolNameToIdMapping
|
|
18374
|
+
toolNameToDetailList: context2.toolNameToDetailList
|
|
20224
18375
|
});
|
|
20225
18376
|
}
|
|
20226
18377
|
});
|
|
20227
|
-
var
|
|
18378
|
+
var mode_agentic_plugin_default = createAgenticModePlugin();
|
|
20228
18379
|
|
|
20229
18380
|
// __mcpc__core_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/utils.js
|
|
20230
18381
|
function convertAISDKToMCPMessages(prompt) {
|
|
@@ -20281,6 +18432,7 @@ function convertMCPStopReasonToAISDK(stopReason) {
|
|
|
20281
18432
|
}
|
|
20282
18433
|
|
|
20283
18434
|
// __mcpc__core_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/language-model.js
|
|
18435
|
+
var DEFAULT_MAX_TOKENS = 128e3;
|
|
20284
18436
|
var MCPSamplingLanguageModel = class {
|
|
20285
18437
|
specificationVersion = "v2";
|
|
20286
18438
|
provider;
|
|
@@ -20288,11 +18440,13 @@ var MCPSamplingLanguageModel = class {
|
|
|
20288
18440
|
supportedUrls = {};
|
|
20289
18441
|
server;
|
|
20290
18442
|
modelPreferences;
|
|
18443
|
+
maxTokens;
|
|
20291
18444
|
constructor(config2) {
|
|
20292
18445
|
this.server = config2.server;
|
|
20293
18446
|
this.modelId = "";
|
|
20294
18447
|
this.provider = "mcp-client";
|
|
20295
18448
|
this.modelPreferences = config2.modelPreferences;
|
|
18449
|
+
this.maxTokens = config2.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
20296
18450
|
}
|
|
20297
18451
|
/**
|
|
20298
18452
|
* Generate a response using MCP's createMessage capability
|
|
@@ -20324,7 +18478,7 @@ var MCPSamplingLanguageModel = class {
|
|
|
20324
18478
|
const createMessageParams = {
|
|
20325
18479
|
systemPrompt,
|
|
20326
18480
|
messages,
|
|
20327
|
-
maxTokens: options.maxOutputTokens ??
|
|
18481
|
+
maxTokens: options.maxOutputTokens ?? this.maxTokens,
|
|
20328
18482
|
modelPreferences: this.modelPreferences
|
|
20329
18483
|
};
|
|
20330
18484
|
if (useNativeTools && options.tools && options.tools.length > 0) {
|
|
@@ -20702,7 +18856,8 @@ var MCPSamplingProvider = class {
|
|
|
20702
18856
|
languageModel(options) {
|
|
20703
18857
|
return new MCPSamplingLanguageModel({
|
|
20704
18858
|
server: this.config.server,
|
|
20705
|
-
modelPreferences: options?.modelPreferences
|
|
18859
|
+
modelPreferences: options?.modelPreferences,
|
|
18860
|
+
maxTokens: this.config.maxTokens
|
|
20706
18861
|
});
|
|
20707
18862
|
}
|
|
20708
18863
|
/**
|
|
@@ -20763,7 +18918,7 @@ var BaseAIExecutor = class {
|
|
|
20763
18918
|
messages: [
|
|
20764
18919
|
{
|
|
20765
18920
|
role: "user",
|
|
20766
|
-
content: args.
|
|
18921
|
+
content: args.prompt
|
|
20767
18922
|
}
|
|
20768
18923
|
],
|
|
20769
18924
|
tools: this.buildTools(),
|
|
@@ -20808,19 +18963,12 @@ var BaseAIExecutor = class {
|
|
|
20808
18963
|
}
|
|
20809
18964
|
}
|
|
20810
18965
|
buildSystemPrompt(args) {
|
|
20811
|
-
return
|
|
20812
|
-
|
|
20813
|
-
|
|
20814
|
-
|
|
20815
|
-
|
|
20816
|
-
|
|
20817
|
-
<rules>
|
|
20818
|
-
${this.getRules()}
|
|
20819
|
-
</rules>
|
|
20820
|
-
|
|
20821
|
-
<tools>
|
|
20822
|
-
${this.getToolListDescription()}
|
|
20823
|
-
</tools>${args.context ? this.formatContext(args.context) : ""}`;
|
|
18966
|
+
return CompiledPrompts.aiLoopSystem({
|
|
18967
|
+
toolName: this.config.name,
|
|
18968
|
+
description: this.config.description,
|
|
18969
|
+
rules: this.getRules(),
|
|
18970
|
+
context: this.formatContext(args.context)
|
|
18971
|
+
});
|
|
20824
18972
|
}
|
|
20825
18973
|
getRules() {
|
|
20826
18974
|
return `1. Use tools to complete the user's request
|
|
@@ -20829,10 +18977,10 @@ ${this.getToolListDescription()}
|
|
|
20829
18977
|
4. Continue until task is complete
|
|
20830
18978
|
5. When complete, provide a summary WITHOUT calling more tools`;
|
|
20831
18979
|
}
|
|
20832
|
-
getToolListDescription() {
|
|
20833
|
-
return "Tools will be provided by AI SDK";
|
|
20834
|
-
}
|
|
20835
18980
|
formatContext(context2) {
|
|
18981
|
+
if (!context2 || Object.keys(context2).length === 0) {
|
|
18982
|
+
return "";
|
|
18983
|
+
}
|
|
20836
18984
|
return `
|
|
20837
18985
|
|
|
20838
18986
|
<context>
|
|
@@ -20840,11 +18988,12 @@ ${JSON.stringify(context2, null, 2)}
|
|
|
20840
18988
|
</context>`;
|
|
20841
18989
|
}
|
|
20842
18990
|
convertToAISDKTool(name, toolDetail, execute) {
|
|
18991
|
+
const cleanedSchema = toolDetail.inputSchema ? cleanToolSchema(toolDetail.inputSchema) : {
|
|
18992
|
+
type: "object"
|
|
18993
|
+
};
|
|
20843
18994
|
return (0, import_ai.tool)({
|
|
20844
18995
|
description: toolDetail.description || `Tool: ${name}`,
|
|
20845
|
-
inputSchema: (0, import_ai.jsonSchema)(
|
|
20846
|
-
type: "object"
|
|
20847
|
-
}),
|
|
18996
|
+
inputSchema: (0, import_ai.jsonSchema)(cleanedSchema),
|
|
20848
18997
|
execute
|
|
20849
18998
|
});
|
|
20850
18999
|
}
|
|
@@ -20855,17 +19004,20 @@ var AISamplingExecutor = class extends BaseAIExecutor {
|
|
|
20855
19004
|
server;
|
|
20856
19005
|
tools;
|
|
20857
19006
|
providerOptions;
|
|
19007
|
+
maxTokens;
|
|
20858
19008
|
model = null;
|
|
20859
19009
|
constructor(config2) {
|
|
20860
19010
|
super(config2, "callTool" in config2.server ? config2.server : void 0);
|
|
20861
19011
|
this.server = config2.server;
|
|
20862
19012
|
this.tools = config2.tools;
|
|
20863
19013
|
this.providerOptions = config2.providerOptions;
|
|
19014
|
+
this.maxTokens = config2.maxTokens;
|
|
20864
19015
|
}
|
|
20865
19016
|
initProvider() {
|
|
20866
19017
|
if (!this.model) {
|
|
20867
19018
|
const provider = new MCPSamplingProvider({
|
|
20868
|
-
server: this.server
|
|
19019
|
+
server: this.server,
|
|
19020
|
+
maxTokens: this.maxTokens
|
|
20869
19021
|
});
|
|
20870
19022
|
this.model = provider.languageModel(this.providerOptions);
|
|
20871
19023
|
}
|
|
@@ -20878,9 +19030,6 @@ var AISamplingExecutor = class extends BaseAIExecutor {
|
|
|
20878
19030
|
getExecutorType() {
|
|
20879
19031
|
return "mcp";
|
|
20880
19032
|
}
|
|
20881
|
-
getToolListDescription() {
|
|
20882
|
-
return this.tools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
|
|
20883
|
-
}
|
|
20884
19033
|
buildTools() {
|
|
20885
19034
|
const aiTools = {};
|
|
20886
19035
|
for (const [name, detail] of this.tools) {
|
|
@@ -20911,7 +19060,7 @@ var AISamplingExecutor = class extends BaseAIExecutor {
|
|
|
20911
19060
|
|
|
20912
19061
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/ai/ai-sampling-registrar.js
|
|
20913
19062
|
function registerAISamplingTool(server, params) {
|
|
20914
|
-
const { name, description, allToolNames, depGroups, toolNameToDetailList, providerOptions, maxSteps = 50, tracingEnabled = false } = params;
|
|
19063
|
+
const { name, description, allToolNames, depGroups, toolNameToDetailList, providerOptions, maxSteps = 50, tracingEnabled = false, maxTokens } = params;
|
|
20915
19064
|
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
20916
19065
|
const executor = new AISamplingExecutor({
|
|
20917
19066
|
name,
|
|
@@ -20920,7 +19069,8 @@ function registerAISamplingTool(server, params) {
|
|
|
20920
19069
|
tools: toolNameToDetailList,
|
|
20921
19070
|
providerOptions,
|
|
20922
19071
|
maxSteps,
|
|
20923
|
-
tracingEnabled
|
|
19072
|
+
tracingEnabled,
|
|
19073
|
+
maxTokens
|
|
20924
19074
|
});
|
|
20925
19075
|
const toolDescription = CompiledPrompts.samplingToolDescription({
|
|
20926
19076
|
toolName: name,
|
|
@@ -20933,9 +19083,23 @@ function registerAISamplingTool(server, params) {
|
|
|
20933
19083
|
properties: {}
|
|
20934
19084
|
};
|
|
20935
19085
|
server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
|
|
20936
|
-
const
|
|
19086
|
+
const validationResult = validateSchema(args, schema);
|
|
19087
|
+
if (!validationResult.valid) {
|
|
19088
|
+
return {
|
|
19089
|
+
content: [
|
|
19090
|
+
{
|
|
19091
|
+
type: "text",
|
|
19092
|
+
text: CompiledPrompts.errorResponse({
|
|
19093
|
+
errorMessage: validationResult.error || "Validation failed"
|
|
19094
|
+
})
|
|
19095
|
+
}
|
|
19096
|
+
],
|
|
19097
|
+
isError: true
|
|
19098
|
+
};
|
|
19099
|
+
}
|
|
19100
|
+
const prompt = typeof args.prompt === "string" ? args.prompt : JSON.stringify(args);
|
|
20937
19101
|
return executor.execute({
|
|
20938
|
-
|
|
19102
|
+
prompt,
|
|
20939
19103
|
context: args.context
|
|
20940
19104
|
});
|
|
20941
19105
|
});
|
|
@@ -20956,7 +19120,8 @@ var createAISamplingModePlugin = () => ({
|
|
|
20956
19120
|
toolNameToDetailList: context2.toolNameToDetailList,
|
|
20957
19121
|
providerOptions: opts.providerOptions,
|
|
20958
19122
|
maxSteps: opts.maxSteps,
|
|
20959
|
-
tracingEnabled: opts.tracingEnabled
|
|
19123
|
+
tracingEnabled: opts.tracingEnabled,
|
|
19124
|
+
maxTokens: opts.maxTokens
|
|
20960
19125
|
});
|
|
20961
19126
|
}
|
|
20962
19127
|
});
|
|
@@ -20988,12 +19153,6 @@ var AIACPExecutor = class extends BaseAIExecutor {
|
|
|
20988
19153
|
getExecutorType() {
|
|
20989
19154
|
return "acp";
|
|
20990
19155
|
}
|
|
20991
|
-
getToolListDescription() {
|
|
20992
|
-
if (this.tools.length === 0) {
|
|
20993
|
-
return "Tools will be provided by ACP agent";
|
|
20994
|
-
}
|
|
20995
|
-
return this.tools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
|
|
20996
|
-
}
|
|
20997
19156
|
buildTools() {
|
|
20998
19157
|
const aiTools = {};
|
|
20999
19158
|
for (const [name, detail] of this.tools) {
|
|
@@ -21045,9 +19204,23 @@ function registerAIACPTool(server, params) {
|
|
|
21045
19204
|
properties: {}
|
|
21046
19205
|
};
|
|
21047
19206
|
server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
|
|
21048
|
-
const
|
|
19207
|
+
const validationResult = validateSchema(args, schema);
|
|
19208
|
+
if (!validationResult.valid) {
|
|
19209
|
+
return {
|
|
19210
|
+
content: [
|
|
19211
|
+
{
|
|
19212
|
+
type: "text",
|
|
19213
|
+
text: CompiledPrompts.errorResponse({
|
|
19214
|
+
errorMessage: validationResult.error || "Validation failed"
|
|
19215
|
+
})
|
|
19216
|
+
}
|
|
19217
|
+
],
|
|
19218
|
+
isError: true
|
|
19219
|
+
};
|
|
19220
|
+
}
|
|
19221
|
+
const prompt = typeof args.prompt === "string" ? args.prompt : JSON.stringify(args);
|
|
21049
19222
|
return executor.execute({
|
|
21050
|
-
|
|
19223
|
+
prompt,
|
|
21051
19224
|
context: args.context
|
|
21052
19225
|
});
|
|
21053
19226
|
});
|
|
@@ -21084,9 +19257,6 @@ function getBuiltInPlugins() {
|
|
|
21084
19257
|
tool_name_mapping_plugin_default,
|
|
21085
19258
|
config_plugin_default,
|
|
21086
19259
|
mode_agentic_plugin_default,
|
|
21087
|
-
mode_workflow_plugin_default,
|
|
21088
|
-
mode_agentic_sampling_plugin_default,
|
|
21089
|
-
mode_workflow_sampling_plugin_default,
|
|
21090
19260
|
mode_ai_sampling_plugin_default,
|
|
21091
19261
|
mode_ai_acp_plugin_default,
|
|
21092
19262
|
logging_plugin_default
|
|
@@ -22064,14 +20234,6 @@ var ComposableMCPServer = class extends Server {
|
|
|
22064
20234
|
if (!this.toolNameMapping.has(internalName)) {
|
|
22065
20235
|
this.toolManager.setToolNameMapping(internalName, toolId);
|
|
22066
20236
|
}
|
|
22067
|
-
const matchingStep = options.steps?.find((step) => step.actions.includes(toolNameWithScope));
|
|
22068
|
-
if (matchingStep) {
|
|
22069
|
-
const actionIndex = matchingStep.actions.indexOf(toolNameWithScope);
|
|
22070
|
-
if (actionIndex !== -1) {
|
|
22071
|
-
matchingStep.actions[actionIndex] = toolId;
|
|
22072
|
-
}
|
|
22073
|
-
return true;
|
|
22074
|
-
}
|
|
22075
20237
|
return tagToResults.tool.find((tool2) => {
|
|
22076
20238
|
const selectAll = tool2.attribs.name === `${mcpName}.${ALL_TOOLS_PLACEHOLDER2}` || tool2.attribs.name === `${mcpName}`;
|
|
22077
20239
|
if (selectAll) {
|
|
@@ -22190,13 +20352,13 @@ var ComposableMCPServer = class extends Server {
|
|
|
22190
20352
|
};
|
|
22191
20353
|
|
|
22192
20354
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/env.js
|
|
22193
|
-
var
|
|
22194
|
-
var isProdEnv = () =>
|
|
22195
|
-
var isSCF = () => Boolean(
|
|
20355
|
+
var import_node_process6 = __toESM(require("node:process"), 1);
|
|
20356
|
+
var isProdEnv = () => import_node_process6.default.env.NODE_ENV === "production";
|
|
20357
|
+
var isSCF = () => Boolean(import_node_process6.default.env.SCF_RUNTIME || import_node_process6.default.env.PROD_SCF);
|
|
22196
20358
|
if (isSCF()) {
|
|
22197
20359
|
console.log({
|
|
22198
20360
|
isSCF: isSCF(),
|
|
22199
|
-
SCF_RUNTIME:
|
|
20361
|
+
SCF_RUNTIME: import_node_process6.default.env.SCF_RUNTIME
|
|
22200
20362
|
});
|
|
22201
20363
|
}
|
|
22202
20364
|
|