@mcpc-tech/plugin-markdown-loader 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +10 -2005
- package/index.mjs +9 -2003
- package/package.json +1 -1
- package/types/mod.d.ts +1 -2
- package/types/mod.d.ts.map +1 -1
- package/types/src/markdown-loader.d.ts +4 -1
- package/types/src/markdown-loader.d.ts.map +1 -1
package/index.cjs
CHANGED
|
@@ -38,2008 +38,10 @@ __export(mod_exports, {
|
|
|
38
38
|
loadMarkdownAgentFile: () => loadMarkdownAgentFile,
|
|
39
39
|
markdownAgentToComposeDefinition: () => markdownAgentToComposeDefinition,
|
|
40
40
|
markdownLoaderPlugin: () => markdownLoaderPlugin,
|
|
41
|
-
parseMarkdownAgent: () => parseMarkdownAgent
|
|
42
|
-
setMarkdownAgentLoader: () => setMarkdownAgentLoader
|
|
41
|
+
parseMarkdownAgent: () => parseMarkdownAgent
|
|
43
42
|
});
|
|
44
43
|
module.exports = __toCommonJS(mod_exports);
|
|
45
44
|
|
|
46
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/compose.js
|
|
47
|
-
var import_types3 = require("@modelcontextprotocol/sdk/types.js");
|
|
48
|
-
|
|
49
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/schema.js
|
|
50
|
-
var schemaSymbol = Symbol.for("mcpc.schema");
|
|
51
|
-
var vercelSchemaSymbol = Symbol.for("vercel.ai.schema");
|
|
52
|
-
var validatorSymbol = Symbol.for("mcpc.validator");
|
|
53
|
-
function jsonSchema(schema, options = {}) {
|
|
54
|
-
if (isWrappedSchema(schema)) {
|
|
55
|
-
return schema;
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
[schemaSymbol]: true,
|
|
59
|
-
[validatorSymbol]: true,
|
|
60
|
-
_type: void 0,
|
|
61
|
-
jsonSchema: schema,
|
|
62
|
-
validate: options.validate
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
function isWrappedSchema(value) {
|
|
66
|
-
return typeof value === "object" && value !== null && (schemaSymbol in value && value[schemaSymbol] === true || vercelSchemaSymbol in value && value[vercelSchemaSymbol] === true);
|
|
67
|
-
}
|
|
68
|
-
function extractJsonSchema(schema) {
|
|
69
|
-
if (isWrappedSchema(schema)) {
|
|
70
|
-
return schema.jsonSchema;
|
|
71
|
-
}
|
|
72
|
-
return schema;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/compose.js
|
|
76
|
-
var import_server = require("@modelcontextprotocol/sdk/server/index.js");
|
|
77
|
-
|
|
78
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__utils/src/json.js
|
|
79
|
-
var import_jsonrepair = require("jsonrepair");
|
|
80
|
-
|
|
81
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__utils/src/ai.js
|
|
82
|
-
var p = (template, options = {}) => {
|
|
83
|
-
const { missingVariableHandling = "warn" } = options;
|
|
84
|
-
const names = /* @__PURE__ */ new Set();
|
|
85
|
-
const regex = /\{((\w|\.)+)\}/g;
|
|
86
|
-
let match;
|
|
87
|
-
while ((match = regex.exec(template)) !== null) {
|
|
88
|
-
names.add(match[1]);
|
|
89
|
-
}
|
|
90
|
-
const required = Array.from(names);
|
|
91
|
-
return (input) => {
|
|
92
|
-
let result = template;
|
|
93
|
-
for (const name of required) {
|
|
94
|
-
const key = name;
|
|
95
|
-
const value = input[key];
|
|
96
|
-
const re = new RegExp(`\\{${String(name)}\\}`, "g");
|
|
97
|
-
if (value !== void 0 && value !== null) {
|
|
98
|
-
result = result.replace(re, String(value));
|
|
99
|
-
} else {
|
|
100
|
-
switch (missingVariableHandling) {
|
|
101
|
-
case "error":
|
|
102
|
-
throw new Error(`Missing variable "${String(name)}" in input for template.`);
|
|
103
|
-
case "empty":
|
|
104
|
-
result = result.replace(re, "");
|
|
105
|
-
break;
|
|
106
|
-
case "warn":
|
|
107
|
-
case "ignore":
|
|
108
|
-
default:
|
|
109
|
-
break;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
return result;
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__utils/src/tool-tags.js
|
|
118
|
-
var import_cheerio = require("cheerio");
|
|
119
|
-
|
|
120
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__utils/src/transport/sse.js
|
|
121
|
-
var import_types = require("@modelcontextprotocol/sdk/types.js");
|
|
122
|
-
|
|
123
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/std__http/server_sent_event_stream.js
|
|
124
|
-
var NEWLINE_REGEXP = /\r\n|\r|\n/;
|
|
125
|
-
var encoder = new TextEncoder();
|
|
126
|
-
function assertHasNoNewline(value, varName, errPrefix) {
|
|
127
|
-
if (value.match(NEWLINE_REGEXP) !== null) {
|
|
128
|
-
throw new SyntaxError(`${errPrefix}: ${varName} cannot contain a newline`);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
function stringify(message) {
|
|
132
|
-
const lines = [];
|
|
133
|
-
if (message.comment) {
|
|
134
|
-
assertHasNoNewline(message.comment, "`message.comment`", "Cannot serialize message");
|
|
135
|
-
lines.push(`:${message.comment}`);
|
|
136
|
-
}
|
|
137
|
-
if (message.event) {
|
|
138
|
-
assertHasNoNewline(message.event, "`message.event`", "Cannot serialize message");
|
|
139
|
-
lines.push(`event:${message.event}`);
|
|
140
|
-
}
|
|
141
|
-
if (message.data) {
|
|
142
|
-
message.data.split(NEWLINE_REGEXP).forEach((line) => lines.push(`data:${line}`));
|
|
143
|
-
}
|
|
144
|
-
if (message.id) {
|
|
145
|
-
assertHasNoNewline(message.id.toString(), "`message.id`", "Cannot serialize message");
|
|
146
|
-
lines.push(`id:${message.id}`);
|
|
147
|
-
}
|
|
148
|
-
if (message.retry) lines.push(`retry:${message.retry}`);
|
|
149
|
-
return encoder.encode(lines.join("\n") + "\n\n");
|
|
150
|
-
}
|
|
151
|
-
var ServerSentEventStream = class extends TransformStream {
|
|
152
|
-
constructor() {
|
|
153
|
-
super({
|
|
154
|
-
transform: (message, controller) => {
|
|
155
|
-
controller.enqueue(stringify(message));
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/common/mcp.js
|
|
162
|
-
var import_client = require("@modelcontextprotocol/sdk/client/index.js");
|
|
163
|
-
var import_stdio = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
164
|
-
var import_sse = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
165
|
-
var import_streamableHttp = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
166
|
-
var import_inMemory = require("@modelcontextprotocol/sdk/inMemory.js");
|
|
167
|
-
|
|
168
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/common/config.js
|
|
169
|
-
var import_node_process = __toESM(require("node:process"), 1);
|
|
170
|
-
var GEMINI_PREFERRED_FORMAT = import_node_process.default.env.GEMINI_PREFERRED_FORMAT === "0" ? false : true;
|
|
171
|
-
|
|
172
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/common/json.js
|
|
173
|
-
var import_jsonrepair2 = require("jsonrepair");
|
|
174
|
-
|
|
175
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/common/provider.js
|
|
176
|
-
var createModelCompatibleJSONSchema = (schema) => {
|
|
177
|
-
const validatorOnlyKeys = [
|
|
178
|
-
"errorMessage"
|
|
179
|
-
];
|
|
180
|
-
const geminiRestrictedKeys = GEMINI_PREFERRED_FORMAT ? [
|
|
181
|
-
"additionalProperties"
|
|
182
|
-
] : [];
|
|
183
|
-
const keysToRemove = /* @__PURE__ */ new Set([
|
|
184
|
-
...validatorOnlyKeys,
|
|
185
|
-
...geminiRestrictedKeys
|
|
186
|
-
]);
|
|
187
|
-
let cleanSchema = schema;
|
|
188
|
-
if (GEMINI_PREFERRED_FORMAT) {
|
|
189
|
-
const { oneOf: _oneOf, allOf: _allOf, anyOf: _anyOf, ...rest } = schema;
|
|
190
|
-
cleanSchema = rest;
|
|
191
|
-
}
|
|
192
|
-
const cleanRecursively = (obj) => {
|
|
193
|
-
if (Array.isArray(obj)) {
|
|
194
|
-
return obj.map(cleanRecursively);
|
|
195
|
-
}
|
|
196
|
-
if (obj && typeof obj === "object") {
|
|
197
|
-
const result = {};
|
|
198
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
199
|
-
if (!keysToRemove.has(key)) {
|
|
200
|
-
result[key] = cleanRecursively(value);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return result;
|
|
204
|
-
}
|
|
205
|
-
return obj;
|
|
206
|
-
};
|
|
207
|
-
return cleanRecursively(cleanSchema);
|
|
208
|
-
};
|
|
209
|
-
var INTERNAL_SCHEMA_KEYS = /* @__PURE__ */ new Set([
|
|
210
|
-
"$schema",
|
|
211
|
-
"_originalName",
|
|
212
|
-
"_type",
|
|
213
|
-
"annotations"
|
|
214
|
-
]);
|
|
215
|
-
var cleanToolSchema = (schema) => {
|
|
216
|
-
const cleanRecursively = (obj) => {
|
|
217
|
-
if (Array.isArray(obj)) {
|
|
218
|
-
return obj.map(cleanRecursively);
|
|
219
|
-
}
|
|
220
|
-
if (obj && typeof obj === "object") {
|
|
221
|
-
const record = obj;
|
|
222
|
-
if ("jsonSchema" in record && typeof record.jsonSchema === "object" && record.jsonSchema !== null) {
|
|
223
|
-
return cleanRecursively(record.jsonSchema);
|
|
224
|
-
}
|
|
225
|
-
const result = {};
|
|
226
|
-
for (const [key, value] of Object.entries(record)) {
|
|
227
|
-
if (!INTERNAL_SCHEMA_KEYS.has(key)) {
|
|
228
|
-
result[key] = cleanRecursively(value);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
return result;
|
|
232
|
-
}
|
|
233
|
-
return obj;
|
|
234
|
-
};
|
|
235
|
-
return cleanRecursively(schema);
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/common/mcp.js
|
|
239
|
-
var import_node_process2 = __toESM(require("node:process"), 1);
|
|
240
|
-
var mcpClientPool = /* @__PURE__ */ new Map();
|
|
241
|
-
var cleanupAllPooledClients = async () => {
|
|
242
|
-
const entries = Array.from(mcpClientPool.entries());
|
|
243
|
-
mcpClientPool.clear();
|
|
244
|
-
await Promise.all(entries.map(async ([, { client }]) => {
|
|
245
|
-
try {
|
|
246
|
-
await client.close();
|
|
247
|
-
} catch (err) {
|
|
248
|
-
console.error("Error closing MCP client:", err);
|
|
249
|
-
}
|
|
250
|
-
}));
|
|
251
|
-
};
|
|
252
|
-
import_node_process2.default.once?.("exit", () => {
|
|
253
|
-
cleanupAllPooledClients();
|
|
254
|
-
});
|
|
255
|
-
import_node_process2.default.once?.("SIGINT", () => {
|
|
256
|
-
cleanupAllPooledClients().finally(() => import_node_process2.default.exit(0));
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/config-plugin.js
|
|
260
|
-
var createConfigPlugin = () => ({
|
|
261
|
-
name: "built-in-config",
|
|
262
|
-
version: "1.0.0",
|
|
263
|
-
enforce: "pre",
|
|
264
|
-
transformTool: (tool2, context2) => {
|
|
265
|
-
const server = context2.server;
|
|
266
|
-
const config = server.findToolConfig?.(context2.toolName);
|
|
267
|
-
if (config?.description) {
|
|
268
|
-
tool2.description = config.description;
|
|
269
|
-
}
|
|
270
|
-
return tool2;
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
var config_plugin_default = createConfigPlugin();
|
|
274
|
-
|
|
275
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/tool-name-mapping-plugin.js
|
|
276
|
-
var createToolNameMappingPlugin = () => ({
|
|
277
|
-
name: "built-in-tool-name-mapping",
|
|
278
|
-
version: "1.0.0",
|
|
279
|
-
enforce: "pre",
|
|
280
|
-
transformTool: (tool2, context2) => {
|
|
281
|
-
const server = context2.server;
|
|
282
|
-
const toolName = context2.toolName;
|
|
283
|
-
const originalName = tool2._originalName || toolName;
|
|
284
|
-
const dotNotation = originalName.replace(/_/g, ".");
|
|
285
|
-
const underscoreNotation = originalName.replace(/\./g, "_");
|
|
286
|
-
if (dotNotation !== originalName && server.toolNameMapping) {
|
|
287
|
-
server.toolNameMapping.set(dotNotation, toolName);
|
|
288
|
-
}
|
|
289
|
-
if (underscoreNotation !== originalName && server.toolNameMapping) {
|
|
290
|
-
server.toolNameMapping.set(underscoreNotation, toolName);
|
|
291
|
-
}
|
|
292
|
-
if (originalName !== toolName && server.toolNameMapping) {
|
|
293
|
-
server.toolNameMapping.set(originalName, toolName);
|
|
294
|
-
}
|
|
295
|
-
return tool2;
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
var tool_name_mapping_plugin_default = createToolNameMappingPlugin();
|
|
299
|
-
|
|
300
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/logger.js
|
|
301
|
-
var LOG_LEVELS = {
|
|
302
|
-
debug: 0,
|
|
303
|
-
info: 1,
|
|
304
|
-
notice: 2,
|
|
305
|
-
warning: 3,
|
|
306
|
-
error: 4,
|
|
307
|
-
critical: 5,
|
|
308
|
-
alert: 6,
|
|
309
|
-
emergency: 7
|
|
310
|
-
};
|
|
311
|
-
var MCPLogger = class _MCPLogger {
|
|
312
|
-
server;
|
|
313
|
-
loggerName;
|
|
314
|
-
minLevel = "debug";
|
|
315
|
-
constructor(loggerName = "mcpc", server) {
|
|
316
|
-
this.loggerName = loggerName;
|
|
317
|
-
this.server = server;
|
|
318
|
-
}
|
|
319
|
-
setServer(server) {
|
|
320
|
-
this.server = server;
|
|
321
|
-
}
|
|
322
|
-
setLevel(level) {
|
|
323
|
-
this.minLevel = level;
|
|
324
|
-
}
|
|
325
|
-
async log(level, data) {
|
|
326
|
-
if (LOG_LEVELS[level] < LOG_LEVELS[this.minLevel]) {
|
|
327
|
-
return;
|
|
328
|
-
}
|
|
329
|
-
this.logToConsole(level, data);
|
|
330
|
-
if (this.server) {
|
|
331
|
-
try {
|
|
332
|
-
await this.server.sendLoggingMessage({
|
|
333
|
-
level,
|
|
334
|
-
logger: this.loggerName,
|
|
335
|
-
data
|
|
336
|
-
});
|
|
337
|
-
} catch {
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
logToConsole(level, data) {
|
|
342
|
-
const message = typeof data === "string" ? data : JSON.stringify(data);
|
|
343
|
-
const prefix = `[${this.loggerName}:${level}]`;
|
|
344
|
-
console.error(prefix, message);
|
|
345
|
-
}
|
|
346
|
-
debug(data) {
|
|
347
|
-
return this.log("debug", data);
|
|
348
|
-
}
|
|
349
|
-
info(data) {
|
|
350
|
-
return this.log("info", data);
|
|
351
|
-
}
|
|
352
|
-
notice(data) {
|
|
353
|
-
return this.log("notice", data);
|
|
354
|
-
}
|
|
355
|
-
warning(data) {
|
|
356
|
-
return this.log("warning", data);
|
|
357
|
-
}
|
|
358
|
-
error(data) {
|
|
359
|
-
return this.log("error", data);
|
|
360
|
-
}
|
|
361
|
-
critical(data) {
|
|
362
|
-
return this.log("critical", data);
|
|
363
|
-
}
|
|
364
|
-
alert(data) {
|
|
365
|
-
return this.log("alert", data);
|
|
366
|
-
}
|
|
367
|
-
emergency(data) {
|
|
368
|
-
return this.log("emergency", data);
|
|
369
|
-
}
|
|
370
|
-
child(name) {
|
|
371
|
-
const child = new _MCPLogger(`${this.loggerName}.${name}`, this.server);
|
|
372
|
-
child.setLevel(this.minLevel);
|
|
373
|
-
return child;
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
var logger = new MCPLogger("mcpc");
|
|
377
|
-
function createLogger(name, server) {
|
|
378
|
-
return new MCPLogger(name, server);
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/logging-plugin.js
|
|
382
|
-
var createLoggingPlugin = (options = {}) => {
|
|
383
|
-
const { enabled = true, verbose = false, compact = true } = options;
|
|
384
|
-
return {
|
|
385
|
-
name: "built-in-logging",
|
|
386
|
-
version: "1.0.0",
|
|
387
|
-
composeEnd: async (context2) => {
|
|
388
|
-
if (!enabled) return;
|
|
389
|
-
const logger2 = createLogger("mcpc.plugin.logging", context2.server);
|
|
390
|
-
if (compact) {
|
|
391
|
-
const pluginCount = context2.pluginNames.length;
|
|
392
|
-
const { stats } = context2;
|
|
393
|
-
await logger2.info(`[${context2.toolName}] ${pluginCount} plugins \u2022 ${stats.publicTools} public \u2022 ${stats.hiddenTools} hidden`);
|
|
394
|
-
} else if (verbose) {
|
|
395
|
-
await logger2.info(`[${context2.toolName}] Composition complete`);
|
|
396
|
-
await logger2.info(` \u251C\u2500 Plugins: ${context2.pluginNames.join(", ")}`);
|
|
397
|
-
const { stats } = context2;
|
|
398
|
-
const server = context2.server;
|
|
399
|
-
const publicTools = Array.from(new Set(server.getPublicToolNames().map(String)));
|
|
400
|
-
const internalTools = Array.from(new Set(server.getInternalToolNames().map(String)));
|
|
401
|
-
const hiddenTools = Array.from(new Set(server.getHiddenToolNames().map(String)));
|
|
402
|
-
const normalInternal = internalTools.filter((name) => !hiddenTools.includes(name));
|
|
403
|
-
if (publicTools.length > 0) {
|
|
404
|
-
await logger2.info(` \u251C\u2500 Public: ${publicTools.join(", ")}`);
|
|
405
|
-
}
|
|
406
|
-
if (internalTools.length > 0) {
|
|
407
|
-
const parts = [];
|
|
408
|
-
if (normalInternal.length > 0) {
|
|
409
|
-
parts.push(normalInternal.join(", "));
|
|
410
|
-
}
|
|
411
|
-
if (hiddenTools.length > 0) {
|
|
412
|
-
parts.push(`(${hiddenTools.join(", ")})`);
|
|
413
|
-
}
|
|
414
|
-
await logger2.info(` \u251C\u2500 Internal: ${parts.join(", ")}`);
|
|
415
|
-
}
|
|
416
|
-
await logger2.info(` \u2514\u2500 Total: ${stats.totalTools} tools`);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
};
|
|
420
|
-
};
|
|
421
|
-
var logging_plugin_default = createLoggingPlugin({
|
|
422
|
-
verbose: true,
|
|
423
|
-
compact: false
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/prompts/index.js
|
|
427
|
-
var SystemPrompts = {
|
|
428
|
-
/**
|
|
429
|
-
* Base system prompt for autonomous MCP execution
|
|
430
|
-
*
|
|
431
|
-
* Uses simplified Unix-style interface:
|
|
432
|
-
* - `tool` + `args` for clean, consistent structure
|
|
433
|
-
* - `man` command for fetching tool schemas (like Unix manual)
|
|
434
|
-
* - No `hasDefinitions` - trusts model's context memory
|
|
435
|
-
*/
|
|
436
|
-
AUTONOMOUS_EXECUTION: `Agentic tool \`{toolName}\` that executes tasks by calling its tools, following the <manual/>, obeying the <rules/>, and using the <format/>.
|
|
437
|
-
|
|
438
|
-
<manual>
|
|
439
|
-
{description}
|
|
440
|
-
</manual>
|
|
441
|
-
|
|
442
|
-
<parameters>
|
|
443
|
-
\`tool\` - Which tool to execute: "man" to get schemas, or a tool name to execute
|
|
444
|
-
\`args\` - For "man": { tools: ["tool1", "tool2"] }. For other tools: tool parameters that strictly adhere to the tool's JSON schema.
|
|
445
|
-
</parameters>
|
|
446
|
-
|
|
447
|
-
<rules>
|
|
448
|
-
1. **First call**: Use \`man\` to get tool schemas you need
|
|
449
|
-
2. **Execute tools**: Use tool name in \`tool\` and parameters in \`args\`
|
|
450
|
-
</rules>
|
|
451
|
-
|
|
452
|
-
<format>
|
|
453
|
-
Get tool schemas: \`{ "tool": "man", "args": { "tools": ["tool1", "tool2"] } }\`
|
|
454
|
-
Execute a tool: \`{ "tool": "tool_name", "args": { /* parameters */ } }\`
|
|
455
|
-
</format>`,
|
|
456
|
-
/**
|
|
457
|
-
* Compact system prompt for autonomous MCP execution (when manual is provided)
|
|
458
|
-
*
|
|
459
|
-
* Uses simplified description with progressive disclosure:
|
|
460
|
-
* - Short description shown by default
|
|
461
|
-
* - Use `man` command with args `{ manual: true }` to get full manual
|
|
462
|
-
*/
|
|
463
|
-
AUTONOMOUS_EXECUTION_COMPACT: `Agentic tool \`{toolName}\` that executes tasks by calling its tools, following the <rules/> and using the <format/>.
|
|
464
|
-
|
|
465
|
-
{description}
|
|
466
|
-
|
|
467
|
-
<rules>
|
|
468
|
-
1. **First call**: Use \`man\` to get tool schemas and full manual
|
|
469
|
-
2. **Execute tools**: Use tool name in \`tool\` and parameters in \`args\`
|
|
470
|
-
</rules>
|
|
471
|
-
|
|
472
|
-
<format>
|
|
473
|
-
Get manual + schemas: \`{ "tool": "man", "args": { "tools": ["tool1"], "manual": true } }\`
|
|
474
|
-
Execute a tool: \`{ "tool": "tool_name", "args": { /* parameters */ } }\`
|
|
475
|
-
</format>`,
|
|
476
|
-
/**
|
|
477
|
-
* Tool description for sampling tools (shown in MCP tools list)
|
|
478
|
-
* Explains how to use prompt and context parameters
|
|
479
|
-
*/
|
|
480
|
-
SAMPLING_TOOL_DESCRIPTION: `Subagent tool \`{toolName}\` that executes complex tasks.
|
|
481
|
-
|
|
482
|
-
You must follow the <manual/>, obey the <rules/>, and use the <format/>.
|
|
483
|
-
|
|
484
|
-
<manual>
|
|
485
|
-
{description}
|
|
486
|
-
</manual>
|
|
487
|
-
|
|
488
|
-
<format>
|
|
489
|
-
\`prompt\` - The task to be completed (e.g., "organize my desktop files")
|
|
490
|
-
\`context\` - Execution context object (e.g., { cwd: "/path/to/dir" })
|
|
491
|
-
</format>
|
|
492
|
-
|
|
493
|
-
<rules>
|
|
494
|
-
1. Always provide both \`prompt\` and \`context\` parameters
|
|
495
|
-
2. \`prompt\` must be a clear, actionable description
|
|
496
|
-
3. \`context\` must include relevant environment info (e.g., working directory)
|
|
497
|
-
</rules>`,
|
|
498
|
-
/**
|
|
499
|
-
* System prompt for AI sampling loop (ai_sampling/ai_acp modes)
|
|
500
|
-
* Used inside the execution loop when AI calls native tools.
|
|
501
|
-
* Note: Tool schemas are passed via AI SDK native tool calling, not in prompt.
|
|
502
|
-
*/
|
|
503
|
-
AI_LOOP_SYSTEM: `Agent \`{toolName}\` that completes tasks by calling tools.
|
|
504
|
-
|
|
505
|
-
<manual>
|
|
506
|
-
{description}
|
|
507
|
-
</manual>
|
|
508
|
-
|
|
509
|
-
<rules>
|
|
510
|
-
{rules}
|
|
511
|
-
</rules>{context}`
|
|
512
|
-
};
|
|
513
|
-
var ResponseTemplates = {
|
|
514
|
-
/**
|
|
515
|
-
* Error response templates
|
|
516
|
-
*/
|
|
517
|
-
ERROR_RESPONSE: `Validation failed: {errorMessage}
|
|
518
|
-
|
|
519
|
-
Adjust parameters and retry.`,
|
|
520
|
-
/**
|
|
521
|
-
* Security validation messages
|
|
522
|
-
*/
|
|
523
|
-
SECURITY_VALIDATION: {
|
|
524
|
-
PASSED: `Security check passed: {operation} on {path}`,
|
|
525
|
-
FAILED: `Security check failed: {operation} on {path}`
|
|
526
|
-
},
|
|
527
|
-
/**
|
|
528
|
-
* Audit log messages
|
|
529
|
-
*/
|
|
530
|
-
AUDIT_LOG: `[{timestamp}] {level}: {action} on {resource}{userInfo}`
|
|
531
|
-
};
|
|
532
|
-
var CompiledPrompts = {
|
|
533
|
-
autonomousExecution: p(SystemPrompts.AUTONOMOUS_EXECUTION),
|
|
534
|
-
autonomousExecutionCompact: p(SystemPrompts.AUTONOMOUS_EXECUTION_COMPACT),
|
|
535
|
-
samplingToolDescription: p(SystemPrompts.SAMPLING_TOOL_DESCRIPTION),
|
|
536
|
-
aiLoopSystem: p(SystemPrompts.AI_LOOP_SYSTEM),
|
|
537
|
-
errorResponse: p(ResponseTemplates.ERROR_RESPONSE),
|
|
538
|
-
securityPassed: p(ResponseTemplates.SECURITY_VALIDATION.PASSED),
|
|
539
|
-
securityFailed: p(ResponseTemplates.SECURITY_VALIDATION.FAILED),
|
|
540
|
-
auditLog: p(ResponseTemplates.AUDIT_LOG)
|
|
541
|
-
};
|
|
542
|
-
|
|
543
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/factories/args-def-factory.js
|
|
544
|
-
function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps, _ensureStepActions) {
|
|
545
|
-
return {
|
|
546
|
-
forSampling: function() {
|
|
547
|
-
return {
|
|
548
|
-
type: "object",
|
|
549
|
-
description: "Provide prompt for autonomous tool execution",
|
|
550
|
-
properties: {
|
|
551
|
-
prompt: {
|
|
552
|
-
type: "string",
|
|
553
|
-
description: "The task to be completed autonomously by the agentic system using available tools"
|
|
554
|
-
},
|
|
555
|
-
context: {
|
|
556
|
-
type: "object",
|
|
557
|
-
description: "Execution context, e.g., { cwd: '/path/to/dir' }. Any relevant fields allowed.",
|
|
558
|
-
additionalProperties: true
|
|
559
|
-
}
|
|
560
|
-
},
|
|
561
|
-
required: [
|
|
562
|
-
"prompt",
|
|
563
|
-
"context"
|
|
564
|
-
],
|
|
565
|
-
errorMessage: {
|
|
566
|
-
required: {
|
|
567
|
-
prompt: "Missing required field 'prompt'. Please provide a clear task description.",
|
|
568
|
-
context: "Missing required field 'context'. Please provide relevant context (e.g., { cwd: '...' })."
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
};
|
|
572
|
-
},
|
|
573
|
-
/**
|
|
574
|
-
* Agentic schema - simplified Unix-style interface
|
|
575
|
-
*
|
|
576
|
-
* Only two fields:
|
|
577
|
-
* - `tool`: which tool to execute (enum includes "man" + all tool names)
|
|
578
|
-
* - `args`: object with parameters. For "man": { tools: ["a", "b"] }. For others: tool parameters.
|
|
579
|
-
*/
|
|
580
|
-
forAgentic: function(allToolNames) {
|
|
581
|
-
const toolEnum = [
|
|
582
|
-
"man",
|
|
583
|
-
...allToolNames
|
|
584
|
-
];
|
|
585
|
-
return {
|
|
586
|
-
type: "object",
|
|
587
|
-
properties: {
|
|
588
|
-
tool: {
|
|
589
|
-
type: "string",
|
|
590
|
-
enum: toolEnum,
|
|
591
|
-
description: 'Which tool to execute. Use "man" to get tool schemas, or a tool name to execute.',
|
|
592
|
-
errorMessage: {
|
|
593
|
-
enum: `Invalid tool. Available: ${toolEnum.join(", ")}`
|
|
594
|
-
}
|
|
595
|
-
},
|
|
596
|
-
args: {
|
|
597
|
-
type: "object",
|
|
598
|
-
description: `For "man": { tools: ["tool1", "tool2"], manual?: true }. For other tools: tool parameters that strictly adhere to the tool's JSON schema.`
|
|
599
|
-
}
|
|
600
|
-
},
|
|
601
|
-
required: [
|
|
602
|
-
"tool"
|
|
603
|
-
],
|
|
604
|
-
additionalProperties: false
|
|
605
|
-
};
|
|
606
|
-
},
|
|
607
|
-
/**
|
|
608
|
-
* Schema for "man" command args validation
|
|
609
|
-
* Expected format: { tools: ["tool1", "tool2"], manual?: true }
|
|
610
|
-
*
|
|
611
|
-
* - Always require `tools`
|
|
612
|
-
* - Allow empty tools only when `manual: true`
|
|
613
|
-
*/
|
|
614
|
-
forMan: function(allToolNames) {
|
|
615
|
-
return {
|
|
616
|
-
type: "object",
|
|
617
|
-
properties: {
|
|
618
|
-
tools: {
|
|
619
|
-
type: "array",
|
|
620
|
-
items: {
|
|
621
|
-
type: "string",
|
|
622
|
-
enum: allToolNames,
|
|
623
|
-
errorMessage: {
|
|
624
|
-
enum: `Invalid tool name. Available: ${allToolNames.join(", ")}`
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
},
|
|
628
|
-
manual: {
|
|
629
|
-
type: "boolean",
|
|
630
|
-
description: "Set to true to get the full manual for this agent (progressive disclosure)."
|
|
631
|
-
}
|
|
632
|
-
},
|
|
633
|
-
required: [
|
|
634
|
-
"tools"
|
|
635
|
-
],
|
|
636
|
-
additionalProperties: false,
|
|
637
|
-
anyOf: [
|
|
638
|
-
// manual-only (tools can be empty)
|
|
639
|
-
{
|
|
640
|
-
properties: {
|
|
641
|
-
manual: {
|
|
642
|
-
enum: [
|
|
643
|
-
true
|
|
644
|
-
]
|
|
645
|
-
},
|
|
646
|
-
tools: {
|
|
647
|
-
minItems: 0
|
|
648
|
-
}
|
|
649
|
-
},
|
|
650
|
-
required: [
|
|
651
|
-
"tools",
|
|
652
|
-
"manual"
|
|
653
|
-
]
|
|
654
|
-
},
|
|
655
|
-
// tool schemas (require at least one tool)
|
|
656
|
-
{
|
|
657
|
-
properties: {
|
|
658
|
-
tools: {
|
|
659
|
-
minItems: 1,
|
|
660
|
-
errorMessage: {
|
|
661
|
-
minItems: "At least one tool name is required"
|
|
662
|
-
}
|
|
663
|
-
}
|
|
664
|
-
},
|
|
665
|
-
required: [
|
|
666
|
-
"tools"
|
|
667
|
-
]
|
|
668
|
-
}
|
|
669
|
-
],
|
|
670
|
-
errorMessage: {
|
|
671
|
-
required: {
|
|
672
|
-
tools: 'Missing "tools" field. Expected: { tools: ["tool1", "tool2"] }'
|
|
673
|
-
}
|
|
674
|
-
}
|
|
675
|
-
};
|
|
676
|
-
}
|
|
677
|
-
};
|
|
678
|
-
}
|
|
679
|
-
|
|
680
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/schema-validator.js
|
|
681
|
-
var import_ajv = require("ajv");
|
|
682
|
-
var import_ajv_formats = __toESM(require("ajv-formats"), 1);
|
|
683
|
-
var import_ajv_errors = __toESM(require("ajv-errors"), 1);
|
|
684
|
-
var import_ajv_human_errors = require("@segment/ajv-human-errors");
|
|
685
|
-
var ajv = new import_ajv.Ajv({
|
|
686
|
-
allErrors: true,
|
|
687
|
-
verbose: true,
|
|
688
|
-
strict: false
|
|
689
|
-
});
|
|
690
|
-
import_ajv_formats.default.default(ajv);
|
|
691
|
-
import_ajv_errors.default.default(ajv);
|
|
692
|
-
function validateSchema(data, schema) {
|
|
693
|
-
const validate = ajv.compile(schema);
|
|
694
|
-
if (!validate(data)) {
|
|
695
|
-
const errors = validate.errors;
|
|
696
|
-
const customErrors = errors.filter((err) => err.keyword === "errorMessage");
|
|
697
|
-
if (customErrors.length > 0) {
|
|
698
|
-
const messages = [
|
|
699
|
-
...new Set(customErrors.map((err) => err.message))
|
|
700
|
-
];
|
|
701
|
-
return {
|
|
702
|
-
valid: false,
|
|
703
|
-
error: messages.join("; ")
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
|
-
const aggregateError = new import_ajv_human_errors.AggregateAjvError(errors);
|
|
707
|
-
return {
|
|
708
|
-
valid: false,
|
|
709
|
-
error: aggregateError.message
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
return {
|
|
713
|
-
valid: true
|
|
714
|
-
};
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/tracing.js
|
|
718
|
-
var import_api = require("@opentelemetry/api");
|
|
719
|
-
var import_sdk_trace_node = require("@opentelemetry/sdk-trace-node");
|
|
720
|
-
var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
|
|
721
|
-
var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
|
|
722
|
-
var import_resources = require("@opentelemetry/resources");
|
|
723
|
-
var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
|
|
724
|
-
var tracerProvider = null;
|
|
725
|
-
var tracer = null;
|
|
726
|
-
var isInitialized = false;
|
|
727
|
-
function initializeTracing(config = {}) {
|
|
728
|
-
if (isInitialized) {
|
|
729
|
-
return;
|
|
730
|
-
}
|
|
731
|
-
const { enabled = true, serviceName = "mcpc-sampling", serviceVersion = "0.2.0", exportTo = "console", otlpEndpoint = "http://localhost:4318/v1/traces", otlpHeaders = {} } = config;
|
|
732
|
-
if (!enabled) {
|
|
733
|
-
isInitialized = true;
|
|
734
|
-
return;
|
|
735
|
-
}
|
|
736
|
-
const resource = import_resources.Resource.default().merge(new import_resources.Resource({
|
|
737
|
-
[import_semantic_conventions.ATTR_SERVICE_NAME]: serviceName,
|
|
738
|
-
[import_semantic_conventions.ATTR_SERVICE_VERSION]: serviceVersion
|
|
739
|
-
}));
|
|
740
|
-
tracerProvider = new import_sdk_trace_node.NodeTracerProvider({
|
|
741
|
-
resource
|
|
742
|
-
});
|
|
743
|
-
if (exportTo === "console") {
|
|
744
|
-
tracerProvider.addSpanProcessor(new import_sdk_trace_base.SimpleSpanProcessor(new import_sdk_trace_base.ConsoleSpanExporter()));
|
|
745
|
-
} else if (exportTo === "otlp") {
|
|
746
|
-
const otlpExporter = new import_exporter_trace_otlp_http.OTLPTraceExporter({
|
|
747
|
-
url: otlpEndpoint,
|
|
748
|
-
headers: otlpHeaders
|
|
749
|
-
});
|
|
750
|
-
tracerProvider.addSpanProcessor(new import_sdk_trace_base.BatchSpanProcessor(otlpExporter));
|
|
751
|
-
}
|
|
752
|
-
tracerProvider.register();
|
|
753
|
-
tracer = import_api.trace.getTracer(serviceName, serviceVersion);
|
|
754
|
-
isInitialized = true;
|
|
755
|
-
}
|
|
756
|
-
function getTracer() {
|
|
757
|
-
if (!isInitialized) {
|
|
758
|
-
initializeTracing();
|
|
759
|
-
}
|
|
760
|
-
return tracer;
|
|
761
|
-
}
|
|
762
|
-
function startSpan(name, attributes, parent) {
|
|
763
|
-
const tracer2 = getTracer();
|
|
764
|
-
const ctx = parent ? import_api.trace.setSpan(import_api.context.active(), parent) : void 0;
|
|
765
|
-
return tracer2.startSpan(name, {
|
|
766
|
-
attributes
|
|
767
|
-
}, ctx);
|
|
768
|
-
}
|
|
769
|
-
function endSpan(span, error) {
|
|
770
|
-
if (error) {
|
|
771
|
-
span.setStatus({
|
|
772
|
-
code: import_api.SpanStatusCode.ERROR,
|
|
773
|
-
message: error.message
|
|
774
|
-
});
|
|
775
|
-
span.recordException(error);
|
|
776
|
-
} else {
|
|
777
|
-
span.setStatus({
|
|
778
|
-
code: import_api.SpanStatusCode.OK
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
span.end();
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/agentic/agentic-executor.js
|
|
785
|
-
var import_node_process3 = __toESM(require("node:process"), 1);
|
|
786
|
-
var AgenticExecutor = class {
|
|
787
|
-
name;
|
|
788
|
-
allToolNames;
|
|
789
|
-
toolNameToDetailList;
|
|
790
|
-
server;
|
|
791
|
-
manual;
|
|
792
|
-
logger;
|
|
793
|
-
tracingEnabled;
|
|
794
|
-
toolSchemaMap;
|
|
795
|
-
constructor(name, allToolNames, toolNameToDetailList, server, manual) {
|
|
796
|
-
this.name = name;
|
|
797
|
-
this.allToolNames = allToolNames;
|
|
798
|
-
this.toolNameToDetailList = toolNameToDetailList;
|
|
799
|
-
this.server = server;
|
|
800
|
-
this.manual = manual;
|
|
801
|
-
this.tracingEnabled = false;
|
|
802
|
-
this.logger = createLogger(`mcpc.agentic.${name}`, server);
|
|
803
|
-
this.toolSchemaMap = new Map(toolNameToDetailList);
|
|
804
|
-
try {
|
|
805
|
-
this.tracingEnabled = import_node_process3.default.env.MCPC_TRACING_ENABLED === "true";
|
|
806
|
-
if (this.tracingEnabled) {
|
|
807
|
-
initializeTracing({
|
|
808
|
-
enabled: true,
|
|
809
|
-
serviceName: `mcpc-agentic-${name}`,
|
|
810
|
-
exportTo: import_node_process3.default.env.MCPC_TRACING_EXPORT ?? "otlp",
|
|
811
|
-
otlpEndpoint: import_node_process3.default.env.MCPC_TRACING_OTLP_ENDPOINT ?? "http://localhost:4318/v1/traces"
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
|
-
} catch {
|
|
815
|
-
this.tracingEnabled = false;
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
async execute(args, schema, parentSpan) {
|
|
819
|
-
const executeSpan = this.tracingEnabled ? startSpan("mcpc.agentic_execute", {
|
|
820
|
-
agent: this.name,
|
|
821
|
-
tool: String(args.tool ?? "unknown"),
|
|
822
|
-
args: JSON.stringify(args)
|
|
823
|
-
}, parentSpan ?? void 0) : null;
|
|
824
|
-
try {
|
|
825
|
-
const validationResult = this.validate(args, schema);
|
|
826
|
-
if (!validationResult.valid) {
|
|
827
|
-
if (executeSpan) {
|
|
828
|
-
executeSpan.setAttributes({
|
|
829
|
-
validationError: true,
|
|
830
|
-
errorMessage: validationResult.error || "Validation failed"
|
|
831
|
-
});
|
|
832
|
-
endSpan(executeSpan);
|
|
833
|
-
}
|
|
834
|
-
this.logger.warning({
|
|
835
|
-
message: "Validation failed",
|
|
836
|
-
tool: args.tool,
|
|
837
|
-
error: validationResult.error
|
|
838
|
-
});
|
|
839
|
-
return {
|
|
840
|
-
content: [
|
|
841
|
-
{
|
|
842
|
-
type: "text",
|
|
843
|
-
text: CompiledPrompts.errorResponse({
|
|
844
|
-
errorMessage: validationResult.error || "Validation failed"
|
|
845
|
-
})
|
|
846
|
-
}
|
|
847
|
-
],
|
|
848
|
-
isError: true
|
|
849
|
-
};
|
|
850
|
-
}
|
|
851
|
-
const tool2 = args.tool;
|
|
852
|
-
if (tool2 === "man") {
|
|
853
|
-
const createArgsDef = createArgsDefFactory(this.name, this.allToolNames, {});
|
|
854
|
-
const manSchema = createArgsDef.forMan(this.allToolNames);
|
|
855
|
-
const manValidation = validateSchema(args.args ?? {}, manSchema);
|
|
856
|
-
if (!manValidation.valid) {
|
|
857
|
-
return {
|
|
858
|
-
content: [
|
|
859
|
-
{
|
|
860
|
-
type: "text",
|
|
861
|
-
text: `Invalid args for "man": ${manValidation.error}`
|
|
862
|
-
}
|
|
863
|
-
],
|
|
864
|
-
isError: true
|
|
865
|
-
};
|
|
866
|
-
}
|
|
867
|
-
const argsObj = args.args;
|
|
868
|
-
const tools = argsObj.tools ?? [];
|
|
869
|
-
const wantManual = argsObj.manual === true;
|
|
870
|
-
const wantTools = tools.length > 0;
|
|
871
|
-
if (wantTools && wantManual) {
|
|
872
|
-
const toolSchemas = this.handleManCommand(tools, null);
|
|
873
|
-
const manualResult = this.handleManualRequest(null);
|
|
874
|
-
if (executeSpan) {
|
|
875
|
-
executeSpan.setAttributes({
|
|
876
|
-
toolType: "man",
|
|
877
|
-
requestType: "tools+manual"
|
|
878
|
-
});
|
|
879
|
-
endSpan(executeSpan);
|
|
880
|
-
}
|
|
881
|
-
return {
|
|
882
|
-
content: [
|
|
883
|
-
...toolSchemas.content,
|
|
884
|
-
{
|
|
885
|
-
type: "text",
|
|
886
|
-
text: "\n---\n"
|
|
887
|
-
},
|
|
888
|
-
...manualResult.content
|
|
889
|
-
]
|
|
890
|
-
};
|
|
891
|
-
}
|
|
892
|
-
if (wantManual) {
|
|
893
|
-
return this.handleManualRequest(executeSpan);
|
|
894
|
-
}
|
|
895
|
-
return this.handleManCommand(tools, executeSpan);
|
|
896
|
-
}
|
|
897
|
-
const toolArgs = args.args || {};
|
|
898
|
-
return await this.executeTool(tool2, toolArgs, executeSpan);
|
|
899
|
-
} catch (error) {
|
|
900
|
-
if (executeSpan) {
|
|
901
|
-
endSpan(executeSpan, error);
|
|
902
|
-
}
|
|
903
|
-
this.logger.error({
|
|
904
|
-
message: "Unexpected error in execute",
|
|
905
|
-
error: String(error)
|
|
906
|
-
});
|
|
907
|
-
return {
|
|
908
|
-
content: [
|
|
909
|
-
{
|
|
910
|
-
type: "text",
|
|
911
|
-
text: `Unexpected error: ${error instanceof Error ? error.message : String(error)}`
|
|
912
|
-
}
|
|
913
|
-
],
|
|
914
|
-
isError: true
|
|
915
|
-
};
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
/**
|
|
919
|
-
* Handle `man { manual: true }` - return full manual for progressive disclosure
|
|
920
|
-
*/
|
|
921
|
-
handleManualRequest(executeSpan) {
|
|
922
|
-
if (executeSpan) {
|
|
923
|
-
executeSpan.setAttributes({
|
|
924
|
-
toolType: "man",
|
|
925
|
-
requestType: "manual"
|
|
926
|
-
});
|
|
927
|
-
}
|
|
928
|
-
if (!this.manual) {
|
|
929
|
-
if (executeSpan) {
|
|
930
|
-
endSpan(executeSpan);
|
|
931
|
-
}
|
|
932
|
-
return {
|
|
933
|
-
content: [
|
|
934
|
-
{
|
|
935
|
-
type: "text",
|
|
936
|
-
text: "No manual available for this agent."
|
|
937
|
-
}
|
|
938
|
-
]
|
|
939
|
-
};
|
|
940
|
-
}
|
|
941
|
-
if (executeSpan) {
|
|
942
|
-
executeSpan.setAttributes({
|
|
943
|
-
success: true
|
|
944
|
-
});
|
|
945
|
-
endSpan(executeSpan);
|
|
946
|
-
}
|
|
947
|
-
return {
|
|
948
|
-
content: [
|
|
949
|
-
{
|
|
950
|
-
type: "text",
|
|
951
|
-
text: this.manual
|
|
952
|
-
}
|
|
953
|
-
]
|
|
954
|
-
};
|
|
955
|
-
}
|
|
956
|
-
/**
|
|
957
|
-
* Handle `man` command - return schemas for requested tools
|
|
958
|
-
* @param requestedTools - Array of tool names (already validated via JSON Schema)
|
|
959
|
-
*/
|
|
960
|
-
handleManCommand(requestedTools, executeSpan) {
|
|
961
|
-
if (executeSpan) {
|
|
962
|
-
executeSpan.setAttributes({
|
|
963
|
-
toolType: "man",
|
|
964
|
-
requestedTools: requestedTools.join(",")
|
|
965
|
-
});
|
|
966
|
-
}
|
|
967
|
-
const schemas = requestedTools.map((toolName) => {
|
|
968
|
-
const toolDetail = this.toolSchemaMap.get(toolName);
|
|
969
|
-
if (toolDetail) {
|
|
970
|
-
const cleanedSchema = cleanToolSchema(toolDetail);
|
|
971
|
-
return `<tool_definition name="${toolName}">
|
|
972
|
-
${JSON.stringify(cleanedSchema, null, 2)}
|
|
973
|
-
</tool_definition>`;
|
|
974
|
-
}
|
|
975
|
-
return null;
|
|
976
|
-
}).filter(Boolean);
|
|
977
|
-
if (executeSpan) {
|
|
978
|
-
executeSpan.setAttributes({
|
|
979
|
-
schemasReturned: schemas.length,
|
|
980
|
-
success: true
|
|
981
|
-
});
|
|
982
|
-
endSpan(executeSpan);
|
|
983
|
-
}
|
|
984
|
-
return {
|
|
985
|
-
content: [
|
|
986
|
-
{
|
|
987
|
-
type: "text",
|
|
988
|
-
text: schemas.length > 0 ? schemas.join("\n\n") : "No schemas found for requested tools."
|
|
989
|
-
}
|
|
990
|
-
]
|
|
991
|
-
};
|
|
992
|
-
}
|
|
993
|
-
/**
|
|
994
|
-
* Execute a tool with runtime validation
|
|
995
|
-
*/
|
|
996
|
-
async executeTool(tool2, toolArgs, executeSpan) {
|
|
997
|
-
const isExternalTool = this.toolNameToDetailList.some(([name]) => name === tool2);
|
|
998
|
-
const isInternalTool = this.allToolNames.includes(tool2);
|
|
999
|
-
if (!isExternalTool && !isInternalTool) {
|
|
1000
|
-
if (executeSpan) {
|
|
1001
|
-
executeSpan.setAttributes({
|
|
1002
|
-
toolType: "not_found",
|
|
1003
|
-
tool: tool2
|
|
1004
|
-
});
|
|
1005
|
-
endSpan(executeSpan);
|
|
1006
|
-
}
|
|
1007
|
-
return {
|
|
1008
|
-
content: [
|
|
1009
|
-
{
|
|
1010
|
-
type: "text",
|
|
1011
|
-
text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
|
|
1012
|
-
}
|
|
1013
|
-
],
|
|
1014
|
-
isError: true
|
|
1015
|
-
};
|
|
1016
|
-
}
|
|
1017
|
-
if (isExternalTool) {
|
|
1018
|
-
const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
|
|
1019
|
-
const [, toolDetail] = externalTool;
|
|
1020
|
-
if (toolDetail.inputSchema) {
|
|
1021
|
-
const rawSchema = extractJsonSchema(toolDetail.inputSchema);
|
|
1022
|
-
const validation = validateSchema(toolArgs, rawSchema);
|
|
1023
|
-
if (!validation.valid) {
|
|
1024
|
-
if (executeSpan) {
|
|
1025
|
-
executeSpan.setAttributes({
|
|
1026
|
-
validationError: true,
|
|
1027
|
-
errorMessage: validation.error
|
|
1028
|
-
});
|
|
1029
|
-
endSpan(executeSpan);
|
|
1030
|
-
}
|
|
1031
|
-
return {
|
|
1032
|
-
content: [
|
|
1033
|
-
{
|
|
1034
|
-
type: "text",
|
|
1035
|
-
text: `Parameter validation failed for "${tool2}": ${validation.error}`
|
|
1036
|
-
}
|
|
1037
|
-
],
|
|
1038
|
-
isError: true
|
|
1039
|
-
};
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
const toolType = isExternalTool ? "external" : "internal";
|
|
1044
|
-
if (executeSpan) {
|
|
1045
|
-
executeSpan.setAttributes({
|
|
1046
|
-
toolType,
|
|
1047
|
-
selectedTool: tool2
|
|
1048
|
-
});
|
|
1049
|
-
}
|
|
1050
|
-
this.logger.debug({
|
|
1051
|
-
message: `Executing ${toolType} tool`,
|
|
1052
|
-
tool: tool2
|
|
1053
|
-
});
|
|
1054
|
-
try {
|
|
1055
|
-
const result = await this.server.callTool(tool2, toolArgs, {
|
|
1056
|
-
agentName: this.name
|
|
1057
|
-
});
|
|
1058
|
-
const callToolResult = result ?? {
|
|
1059
|
-
content: []
|
|
1060
|
-
};
|
|
1061
|
-
if (executeSpan) {
|
|
1062
|
-
executeSpan.setAttributes({
|
|
1063
|
-
success: true,
|
|
1064
|
-
isError: !!callToolResult.isError,
|
|
1065
|
-
resultContentLength: callToolResult.content?.length || 0
|
|
1066
|
-
});
|
|
1067
|
-
endSpan(executeSpan);
|
|
1068
|
-
}
|
|
1069
|
-
return callToolResult;
|
|
1070
|
-
} catch (error) {
|
|
1071
|
-
if (executeSpan) {
|
|
1072
|
-
endSpan(executeSpan, error);
|
|
1073
|
-
}
|
|
1074
|
-
this.logger.error({
|
|
1075
|
-
message: `Error executing ${toolType} tool`,
|
|
1076
|
-
tool: tool2,
|
|
1077
|
-
error: String(error)
|
|
1078
|
-
});
|
|
1079
|
-
return {
|
|
1080
|
-
content: [
|
|
1081
|
-
{
|
|
1082
|
-
type: "text",
|
|
1083
|
-
text: `Error executing tool "${tool2}": ${error instanceof Error ? error.message : String(error)}`
|
|
1084
|
-
}
|
|
1085
|
-
],
|
|
1086
|
-
isError: true
|
|
1087
|
-
};
|
|
1088
|
-
}
|
|
1089
|
-
}
|
|
1090
|
-
validate(args, schema) {
|
|
1091
|
-
return validateSchema(args, schema);
|
|
1092
|
-
}
|
|
1093
|
-
};
|
|
1094
|
-
|
|
1095
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/agentic/agentic-tool-registrar.js
|
|
1096
|
-
function registerAgenticTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList, manual }) {
|
|
1097
|
-
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
1098
|
-
const agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server, manual);
|
|
1099
|
-
description = manual ? CompiledPrompts.autonomousExecutionCompact({
|
|
1100
|
-
toolName: name,
|
|
1101
|
-
description
|
|
1102
|
-
}) : CompiledPrompts.autonomousExecution({
|
|
1103
|
-
toolName: name,
|
|
1104
|
-
description
|
|
1105
|
-
});
|
|
1106
|
-
const agenticArgsDef = createArgsDef.forAgentic(allToolNames);
|
|
1107
|
-
const schema = agenticArgsDef;
|
|
1108
|
-
server.tool(name, description, jsonSchema(createModelCompatibleJSONSchema(schema)), async (args) => {
|
|
1109
|
-
return await agenticExecutor.execute(args, schema);
|
|
1110
|
-
});
|
|
1111
|
-
}
|
|
1112
|
-
|
|
1113
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/mode-agentic-plugin.js
|
|
1114
|
-
var createAgenticModePlugin = () => ({
|
|
1115
|
-
name: "mode-agentic",
|
|
1116
|
-
version: "2.0.0",
|
|
1117
|
-
// Only apply to agentic mode
|
|
1118
|
-
apply: "agentic",
|
|
1119
|
-
// Register the agent tool
|
|
1120
|
-
registerAgentTool: (context2) => {
|
|
1121
|
-
registerAgenticTool(context2.server, {
|
|
1122
|
-
description: context2.description,
|
|
1123
|
-
name: context2.name,
|
|
1124
|
-
allToolNames: context2.allToolNames,
|
|
1125
|
-
depGroups: context2.depGroups,
|
|
1126
|
-
toolNameToDetailList: context2.toolNameToDetailList,
|
|
1127
|
-
manual: context2.manual
|
|
1128
|
-
});
|
|
1129
|
-
}
|
|
1130
|
-
});
|
|
1131
|
-
var mode_agentic_plugin_default = createAgenticModePlugin();
|
|
1132
|
-
|
|
1133
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/utils.js
|
|
1134
|
-
function convertAISDKToMCPMessages(prompt) {
|
|
1135
|
-
const messages = [];
|
|
1136
|
-
for (const msg of prompt) {
|
|
1137
|
-
if (msg.role === "system") continue;
|
|
1138
|
-
const role = msg.role === "assistant" ? "assistant" : "user";
|
|
1139
|
-
const textParts = msg.content.filter((c) => c.type === "text");
|
|
1140
|
-
const toolCalls = msg.content.filter((c) => c.type === "tool-call");
|
|
1141
|
-
const toolResults = msg.content.filter((c) => c.type === "tool-result");
|
|
1142
|
-
const parts = [];
|
|
1143
|
-
if (textParts.length > 0) {
|
|
1144
|
-
parts.push(textParts.map((c) => c.text).join("\n"));
|
|
1145
|
-
}
|
|
1146
|
-
if (toolCalls.length > 0) {
|
|
1147
|
-
const calls = toolCalls.map((c) => {
|
|
1148
|
-
const call = c;
|
|
1149
|
-
const toolArgs = call.args ?? call.input ?? {};
|
|
1150
|
-
return `<use_tool tool="${call.toolName}">
|
|
1151
|
-
${JSON.stringify(toolArgs)}
|
|
1152
|
-
</use_tool>`;
|
|
1153
|
-
});
|
|
1154
|
-
parts.push(calls.join("\n"));
|
|
1155
|
-
}
|
|
1156
|
-
if (toolResults.length > 0) {
|
|
1157
|
-
const results = toolResults.map((c) => {
|
|
1158
|
-
const result = c;
|
|
1159
|
-
const resultValue = result.result ?? result.output ?? "undefined";
|
|
1160
|
-
const output = JSON.stringify(resultValue);
|
|
1161
|
-
return `Tool "${result.toolName}" result:
|
|
1162
|
-
${output}`;
|
|
1163
|
-
});
|
|
1164
|
-
parts.push(results.join("\n\n"));
|
|
1165
|
-
}
|
|
1166
|
-
const text = parts.join("\n\n");
|
|
1167
|
-
if (text) {
|
|
1168
|
-
messages.push({
|
|
1169
|
-
role,
|
|
1170
|
-
content: {
|
|
1171
|
-
type: "text",
|
|
1172
|
-
text
|
|
1173
|
-
}
|
|
1174
|
-
});
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
return messages;
|
|
1178
|
-
}
|
|
1179
|
-
function convertMCPStopReasonToAISDK(stopReason) {
|
|
1180
|
-
if (stopReason === "endTurn" || stopReason === "stopSequence") {
|
|
1181
|
-
return "stop";
|
|
1182
|
-
}
|
|
1183
|
-
if (stopReason === "maxTokens") return "length";
|
|
1184
|
-
return stopReason ?? "unknown";
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/language-model.js
|
|
1188
|
-
var DEFAULT_MAX_TOKENS = 128e3;
|
|
1189
|
-
var MCPSamplingLanguageModel = class {
|
|
1190
|
-
specificationVersion = "v2";
|
|
1191
|
-
provider;
|
|
1192
|
-
modelId;
|
|
1193
|
-
supportedUrls = {};
|
|
1194
|
-
server;
|
|
1195
|
-
modelPreferences;
|
|
1196
|
-
maxTokens;
|
|
1197
|
-
constructor(config) {
|
|
1198
|
-
this.server = config.server;
|
|
1199
|
-
this.modelId = "";
|
|
1200
|
-
this.provider = "mcp-client";
|
|
1201
|
-
this.modelPreferences = config.modelPreferences;
|
|
1202
|
-
this.maxTokens = config.maxTokens ?? DEFAULT_MAX_TOKENS;
|
|
1203
|
-
}
|
|
1204
|
-
/**
|
|
1205
|
-
* Generate a response using MCP's createMessage capability
|
|
1206
|
-
*/
|
|
1207
|
-
async doGenerate(options) {
|
|
1208
|
-
const useNativeTools = this.supportsSamplingTools();
|
|
1209
|
-
this.server.sendLoggingMessage({
|
|
1210
|
-
level: "info",
|
|
1211
|
-
data: `Client supports native tools: ${useNativeTools}`
|
|
1212
|
-
});
|
|
1213
|
-
const messages = this.convertMessages(options.prompt, useNativeTools);
|
|
1214
|
-
this.server.sendLoggingMessage({
|
|
1215
|
-
level: "info",
|
|
1216
|
-
data: `Converted messages for MCP: ${JSON.stringify(messages)}`
|
|
1217
|
-
});
|
|
1218
|
-
let systemPrompt;
|
|
1219
|
-
for (const msg of options.prompt) {
|
|
1220
|
-
if (msg.role === "system") {
|
|
1221
|
-
systemPrompt = msg.content;
|
|
1222
|
-
break;
|
|
1223
|
-
}
|
|
1224
|
-
}
|
|
1225
|
-
this.server.sendLoggingMessage({
|
|
1226
|
-
level: "info",
|
|
1227
|
-
data: `Client supports native tools: ${useNativeTools}`
|
|
1228
|
-
});
|
|
1229
|
-
systemPrompt = this.injectResponseFormatInstructions(systemPrompt, options.responseFormat, useNativeTools);
|
|
1230
|
-
systemPrompt = this.injectToolInstructions(systemPrompt, options.tools, useNativeTools);
|
|
1231
|
-
const createMessageParams = {
|
|
1232
|
-
systemPrompt,
|
|
1233
|
-
messages,
|
|
1234
|
-
maxTokens: options.maxOutputTokens ?? this.maxTokens,
|
|
1235
|
-
modelPreferences: this.modelPreferences
|
|
1236
|
-
};
|
|
1237
|
-
if (useNativeTools && options.tools && options.tools.length > 0) {
|
|
1238
|
-
createMessageParams.tools = this.convertAISDKToolsToMCP(options.tools);
|
|
1239
|
-
createMessageParams.toolChoice = {
|
|
1240
|
-
mode: "auto"
|
|
1241
|
-
};
|
|
1242
|
-
this.server.sendLoggingMessage({
|
|
1243
|
-
level: "info",
|
|
1244
|
-
data: `Converted ${options.tools.length} tools to MCP format: ${JSON.stringify(createMessageParams.tools?.map((t) => t.name))}`
|
|
1245
|
-
});
|
|
1246
|
-
} else if (options.tools && options.tools.length > 0) {
|
|
1247
|
-
this.server.sendLoggingMessage({
|
|
1248
|
-
level: "info",
|
|
1249
|
-
data: `Tools provided but not using native mode - injecting into system prompt instead`
|
|
1250
|
-
});
|
|
1251
|
-
}
|
|
1252
|
-
this.server.sendLoggingMessage({
|
|
1253
|
-
level: "info",
|
|
1254
|
-
data: `Calling createMessage with params: ${JSON.stringify({
|
|
1255
|
-
hasSystemPrompt: !!systemPrompt,
|
|
1256
|
-
hasTools: !!createMessageParams.tools,
|
|
1257
|
-
toolCount: createMessageParams.tools?.length || 0,
|
|
1258
|
-
createMessageParams
|
|
1259
|
-
}, null, 2)}`
|
|
1260
|
-
});
|
|
1261
|
-
const result = await this.server.createMessage(createMessageParams);
|
|
1262
|
-
this.server.sendLoggingMessage({
|
|
1263
|
-
level: "info",
|
|
1264
|
-
data: `createMessage result: ${JSON.stringify({
|
|
1265
|
-
contentType: result.content.type,
|
|
1266
|
-
stopReason: result.stopReason,
|
|
1267
|
-
text: result.content
|
|
1268
|
-
})}`
|
|
1269
|
-
});
|
|
1270
|
-
const content = [];
|
|
1271
|
-
if (useNativeTools) {
|
|
1272
|
-
const contentArray = Array.isArray(result.content) ? result.content : [
|
|
1273
|
-
result.content
|
|
1274
|
-
];
|
|
1275
|
-
for (const block of contentArray) {
|
|
1276
|
-
if (block.type === "text" && "text" in block) {
|
|
1277
|
-
content.push({
|
|
1278
|
-
type: "text",
|
|
1279
|
-
text: block.text
|
|
1280
|
-
});
|
|
1281
|
-
} else if (block.type === "tool_use" && "id" in block && "name" in block) {
|
|
1282
|
-
const toolInput = block.input || {};
|
|
1283
|
-
content.push({
|
|
1284
|
-
type: "tool-call",
|
|
1285
|
-
toolCallId: block.id,
|
|
1286
|
-
toolName: block.name,
|
|
1287
|
-
input: JSON.stringify(toolInput)
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
} else {
|
|
1292
|
-
if (result.content.type === "text" && result.content.text) {
|
|
1293
|
-
const { text, toolCalls } = this.extractToolCalls(result.content.text, options.tools);
|
|
1294
|
-
if (text.trim()) {
|
|
1295
|
-
const textContent = {
|
|
1296
|
-
type: "text",
|
|
1297
|
-
text
|
|
1298
|
-
};
|
|
1299
|
-
content.push(textContent);
|
|
1300
|
-
}
|
|
1301
|
-
content.push(...toolCalls);
|
|
1302
|
-
}
|
|
1303
|
-
}
|
|
1304
|
-
const finishReason = this.mapStopReason(result.stopReason);
|
|
1305
|
-
return {
|
|
1306
|
-
content,
|
|
1307
|
-
finishReason,
|
|
1308
|
-
usage: {
|
|
1309
|
-
inputTokens: void 0,
|
|
1310
|
-
outputTokens: void 0,
|
|
1311
|
-
totalTokens: 0
|
|
1312
|
-
},
|
|
1313
|
-
request: {
|
|
1314
|
-
body: JSON.stringify({
|
|
1315
|
-
systemPrompt,
|
|
1316
|
-
messages
|
|
1317
|
-
})
|
|
1318
|
-
},
|
|
1319
|
-
response: {
|
|
1320
|
-
modelId: result.model
|
|
1321
|
-
},
|
|
1322
|
-
warnings: []
|
|
1323
|
-
};
|
|
1324
|
-
}
|
|
1325
|
-
/**
|
|
1326
|
-
* Stream a response using MCP's createMessage capability
|
|
1327
|
-
*
|
|
1328
|
-
* Since MCP doesn't support native streaming, we generate the full response
|
|
1329
|
-
* and emit it as stream events following AI SDK's protocol.
|
|
1330
|
-
*/
|
|
1331
|
-
async doStream(options) {
|
|
1332
|
-
const result = await this.doGenerate(options);
|
|
1333
|
-
const stream = new ReadableStream({
|
|
1334
|
-
start(controller) {
|
|
1335
|
-
if (result.response?.modelId) {
|
|
1336
|
-
controller.enqueue({
|
|
1337
|
-
type: "response-metadata",
|
|
1338
|
-
modelId: result.response.modelId,
|
|
1339
|
-
...result.response.headers && {
|
|
1340
|
-
headers: result.response.headers
|
|
1341
|
-
}
|
|
1342
|
-
});
|
|
1343
|
-
}
|
|
1344
|
-
let textIndex = 0;
|
|
1345
|
-
for (const part of result.content) {
|
|
1346
|
-
if (part.type === "text") {
|
|
1347
|
-
const id = `text-${++textIndex}`;
|
|
1348
|
-
controller.enqueue({
|
|
1349
|
-
type: "text-start",
|
|
1350
|
-
id
|
|
1351
|
-
});
|
|
1352
|
-
controller.enqueue({
|
|
1353
|
-
type: "text-delta",
|
|
1354
|
-
id,
|
|
1355
|
-
delta: part.text
|
|
1356
|
-
});
|
|
1357
|
-
controller.enqueue({
|
|
1358
|
-
type: "text-end",
|
|
1359
|
-
id
|
|
1360
|
-
});
|
|
1361
|
-
} else if (part.type === "tool-call") {
|
|
1362
|
-
controller.enqueue({
|
|
1363
|
-
type: "tool-call",
|
|
1364
|
-
toolCallId: part.toolCallId,
|
|
1365
|
-
toolName: part.toolName,
|
|
1366
|
-
input: part.input
|
|
1367
|
-
});
|
|
1368
|
-
}
|
|
1369
|
-
}
|
|
1370
|
-
controller.enqueue({
|
|
1371
|
-
type: "finish",
|
|
1372
|
-
finishReason: result.finishReason,
|
|
1373
|
-
usage: result.usage
|
|
1374
|
-
});
|
|
1375
|
-
controller.close();
|
|
1376
|
-
}
|
|
1377
|
-
});
|
|
1378
|
-
return {
|
|
1379
|
-
stream,
|
|
1380
|
-
request: result.request,
|
|
1381
|
-
warnings: result.warnings
|
|
1382
|
-
};
|
|
1383
|
-
}
|
|
1384
|
-
/**
|
|
1385
|
-
* Convert AI SDK messages to MCP sampling format
|
|
1386
|
-
*/
|
|
1387
|
-
convertMessages(prompt, useNativeTools) {
|
|
1388
|
-
if (!useNativeTools) {
|
|
1389
|
-
return convertAISDKToMCPMessages(prompt);
|
|
1390
|
-
}
|
|
1391
|
-
const messages = [];
|
|
1392
|
-
for (const msg of prompt) {
|
|
1393
|
-
if (msg.role === "system") continue;
|
|
1394
|
-
const role = msg.role === "assistant" ? "assistant" : "user";
|
|
1395
|
-
const contentBlocks = [];
|
|
1396
|
-
for (const part of msg.content) {
|
|
1397
|
-
if (part.type === "text") {
|
|
1398
|
-
contentBlocks.push({
|
|
1399
|
-
type: "text",
|
|
1400
|
-
text: part.text
|
|
1401
|
-
});
|
|
1402
|
-
} else if (part.type === "tool-call") {
|
|
1403
|
-
const call = part;
|
|
1404
|
-
contentBlocks.push({
|
|
1405
|
-
type: "tool_use",
|
|
1406
|
-
id: call.toolCallId,
|
|
1407
|
-
name: call.toolName,
|
|
1408
|
-
input: call.args ?? call.input ?? {}
|
|
1409
|
-
});
|
|
1410
|
-
} else if (part.type === "tool-result") {
|
|
1411
|
-
const result = part;
|
|
1412
|
-
contentBlocks.push({
|
|
1413
|
-
type: "tool_result",
|
|
1414
|
-
toolUseId: result.toolCallId,
|
|
1415
|
-
// TODO: Handle different result types properly
|
|
1416
|
-
content: [
|
|
1417
|
-
{
|
|
1418
|
-
type: "text",
|
|
1419
|
-
text: result.output.type === "text" ? result.output.value?.toString() : JSON.stringify(result.output)
|
|
1420
|
-
}
|
|
1421
|
-
]
|
|
1422
|
-
});
|
|
1423
|
-
}
|
|
1424
|
-
}
|
|
1425
|
-
if (contentBlocks.length > 0) {
|
|
1426
|
-
messages.push({
|
|
1427
|
-
role,
|
|
1428
|
-
content: contentBlocks
|
|
1429
|
-
});
|
|
1430
|
-
}
|
|
1431
|
-
}
|
|
1432
|
-
return messages;
|
|
1433
|
-
}
|
|
1434
|
-
/**
|
|
1435
|
-
* Map MCP stop reason to AI SDK finish reason
|
|
1436
|
-
*/
|
|
1437
|
-
mapStopReason(stopReason) {
|
|
1438
|
-
return convertMCPStopReasonToAISDK(stopReason);
|
|
1439
|
-
}
|
|
1440
|
-
/**
|
|
1441
|
-
* Check if client supports native tool use in sampling
|
|
1442
|
-
*/
|
|
1443
|
-
supportsSamplingTools() {
|
|
1444
|
-
const capabilities = this.server.getClientCapabilities();
|
|
1445
|
-
const supportsTools = !!capabilities?.sampling?.tools;
|
|
1446
|
-
this.server.sendLoggingMessage({
|
|
1447
|
-
level: "info",
|
|
1448
|
-
data: `Client capabilities check: sampling=${!!capabilities?.sampling}, tools=${supportsTools}`
|
|
1449
|
-
});
|
|
1450
|
-
return supportsTools;
|
|
1451
|
-
}
|
|
1452
|
-
/**
|
|
1453
|
-
* Convert AI SDK tools to MCP Tool format
|
|
1454
|
-
*/
|
|
1455
|
-
convertAISDKToolsToMCP(tools) {
|
|
1456
|
-
if (!tools || tools.length === 0) return [];
|
|
1457
|
-
return tools.filter((tool2) => tool2.type === "function").map((tool2) => {
|
|
1458
|
-
const toolAny = tool2;
|
|
1459
|
-
return {
|
|
1460
|
-
name: tool2.name,
|
|
1461
|
-
description: toolAny.description || `Tool: ${tool2.name}`,
|
|
1462
|
-
inputSchema: {
|
|
1463
|
-
type: "object",
|
|
1464
|
-
...toolAny.inputSchema || toolAny.parameters
|
|
1465
|
-
}
|
|
1466
|
-
};
|
|
1467
|
-
});
|
|
1468
|
-
}
|
|
1469
|
-
/**
|
|
1470
|
-
* Inject response format instructions into system prompt
|
|
1471
|
-
*
|
|
1472
|
-
* Only injects formatting instructions in JSON fallback mode.
|
|
1473
|
-
* In native tools mode, structured output is handled by the provider.
|
|
1474
|
-
*/
|
|
1475
|
-
injectResponseFormatInstructions(systemPrompt, responseFormat, useNativeTools) {
|
|
1476
|
-
if (!responseFormat) {
|
|
1477
|
-
return systemPrompt;
|
|
1478
|
-
}
|
|
1479
|
-
if (useNativeTools) {
|
|
1480
|
-
return systemPrompt;
|
|
1481
|
-
}
|
|
1482
|
-
let enhanced = systemPrompt || "";
|
|
1483
|
-
if (responseFormat.type === "json") {
|
|
1484
|
-
const jsonPrompt = `
|
|
1485
|
-
|
|
1486
|
-
IMPORTANT: You MUST respond with valid JSON only. Do not include any text before or after the JSON.
|
|
1487
|
-
- Your response must be a valid JSON object
|
|
1488
|
-
- Do not wrap the JSON in markdown code blocks
|
|
1489
|
-
- Do not include explanations or comments
|
|
1490
|
-
- Ensure all JSON is properly formatted and parseable`;
|
|
1491
|
-
enhanced = enhanced ? `${enhanced}${jsonPrompt}` : jsonPrompt.trim();
|
|
1492
|
-
if (responseFormat.schema) {
|
|
1493
|
-
const schemaInfo = `
|
|
1494
|
-
- Follow this JSON schema structure: ${JSON.stringify(responseFormat.schema)}`;
|
|
1495
|
-
enhanced += schemaInfo;
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
return enhanced || void 0;
|
|
1499
|
-
}
|
|
1500
|
-
/**
|
|
1501
|
-
* Inject tool definitions into system prompt
|
|
1502
|
-
*
|
|
1503
|
-
* WORKAROUND: MCP sampling currently doesn't support native tools parameter.
|
|
1504
|
-
* This method injects tool descriptions and usage instructions into the system prompt.
|
|
1505
|
-
*
|
|
1506
|
-
* TODO: Remove this workaround when MCP protocol adds native support for:
|
|
1507
|
-
* - tools parameter in createMessage
|
|
1508
|
-
* - Tool calling and function execution
|
|
1509
|
-
* - Structured tool responses
|
|
1510
|
-
*/
|
|
1511
|
-
injectToolInstructions(systemPrompt, tools, useNativeTools) {
|
|
1512
|
-
if (!tools || tools.length === 0) {
|
|
1513
|
-
return systemPrompt;
|
|
1514
|
-
}
|
|
1515
|
-
if (useNativeTools) {
|
|
1516
|
-
this.server.sendLoggingMessage({
|
|
1517
|
-
level: "info",
|
|
1518
|
-
data: `Using native tools mode - skipping XML tool injection`
|
|
1519
|
-
});
|
|
1520
|
-
return systemPrompt;
|
|
1521
|
-
}
|
|
1522
|
-
this.server.sendLoggingMessage({
|
|
1523
|
-
level: "info",
|
|
1524
|
-
data: `Injecting ${tools.length} tools into system prompt (fallback mode)`
|
|
1525
|
-
});
|
|
1526
|
-
let enhanced = systemPrompt || "";
|
|
1527
|
-
const toolsPrompt = `
|
|
1528
|
-
|
|
1529
|
-
<available_tools>
|
|
1530
|
-
You have access to the following tools. To use a tool, respond with this XML format:
|
|
1531
|
-
<use_tool tool="tool_name">
|
|
1532
|
-
{"param1": "value1", "param2": "value2"}
|
|
1533
|
-
</use_tool>
|
|
1534
|
-
|
|
1535
|
-
Follow the JSON schema definition for each tool's parameters.
|
|
1536
|
-
You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
|
|
1537
|
-
|
|
1538
|
-
<tools>`;
|
|
1539
|
-
const toolDescriptions = tools.map((tool2) => {
|
|
1540
|
-
if (tool2.type === "function") {
|
|
1541
|
-
const toolAny = tool2;
|
|
1542
|
-
const description = toolAny.description || "No description provided";
|
|
1543
|
-
const schema = toolAny.inputSchema || toolAny.parameters;
|
|
1544
|
-
const schemaStr = schema ? `
|
|
1545
|
-
<schema>
|
|
1546
|
-
${JSON.stringify(schema, null, 2)}
|
|
1547
|
-
</schema>` : "";
|
|
1548
|
-
return `
|
|
1549
|
-
<tool name="${tool2.name}">
|
|
1550
|
-
<description>
|
|
1551
|
-
${description}
|
|
1552
|
-
</description>${schemaStr}
|
|
1553
|
-
</tool>`;
|
|
1554
|
-
} else if (tool2.type === "provider-defined") {
|
|
1555
|
-
return `
|
|
1556
|
-
<tool name="${tool2.name}">
|
|
1557
|
-
<description>${tool2.id || "No description provided"}</description>
|
|
1558
|
-
</tool>`;
|
|
1559
|
-
}
|
|
1560
|
-
return "";
|
|
1561
|
-
}).filter(Boolean).join("");
|
|
1562
|
-
const toolsEnd = `
|
|
1563
|
-
</tools>
|
|
1564
|
-
</available_tools>`;
|
|
1565
|
-
enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}${toolsEnd}` : `${toolsPrompt}${toolDescriptions}${toolsEnd}`.trim();
|
|
1566
|
-
return enhanced || void 0;
|
|
1567
|
-
}
|
|
1568
|
-
/**
|
|
1569
|
-
* Extract tool calls from LLM response text
|
|
1570
|
-
*
|
|
1571
|
-
* Parses XML-style tool call tags from the response:
|
|
1572
|
-
* <use_tool tool="tool_name">{"arg": "value"}</use_tool>
|
|
1573
|
-
*/
|
|
1574
|
-
extractToolCalls(responseText, tools) {
|
|
1575
|
-
if (!tools || tools.length === 0) {
|
|
1576
|
-
return {
|
|
1577
|
-
text: responseText,
|
|
1578
|
-
toolCalls: []
|
|
1579
|
-
};
|
|
1580
|
-
}
|
|
1581
|
-
const toolCalls = [];
|
|
1582
|
-
const toolCallRegex = /<use_tool\s+tool="([^"]+)">([\s\S]*?)<\/use_tool>/g;
|
|
1583
|
-
let match;
|
|
1584
|
-
let lastIndex = 0;
|
|
1585
|
-
const textParts = [];
|
|
1586
|
-
let callIndex = 0;
|
|
1587
|
-
while ((match = toolCallRegex.exec(responseText)) !== null) {
|
|
1588
|
-
textParts.push(responseText.slice(lastIndex, match.index));
|
|
1589
|
-
const toolName = match[1];
|
|
1590
|
-
const argsText = match[2].trim?.();
|
|
1591
|
-
toolCalls.push({
|
|
1592
|
-
type: "tool-call",
|
|
1593
|
-
toolCallId: `call_${Date.now()}_${callIndex++}`,
|
|
1594
|
-
toolName,
|
|
1595
|
-
input: argsText
|
|
1596
|
-
});
|
|
1597
|
-
lastIndex = match.index + match[0].length;
|
|
1598
|
-
}
|
|
1599
|
-
textParts.push(responseText.slice(lastIndex));
|
|
1600
|
-
const text = textParts.join("").trim();
|
|
1601
|
-
return {
|
|
1602
|
-
text,
|
|
1603
|
-
toolCalls
|
|
1604
|
-
};
|
|
1605
|
-
}
|
|
1606
|
-
};
|
|
1607
|
-
|
|
1608
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/provider.js
|
|
1609
|
-
var MCPSamplingProvider = class {
|
|
1610
|
-
config;
|
|
1611
|
-
constructor(config) {
|
|
1612
|
-
this.config = config;
|
|
1613
|
-
}
|
|
1614
|
-
/**
|
|
1615
|
-
* Create a language model instance for a specific MCP tool/agent
|
|
1616
|
-
*
|
|
1617
|
-
* @param options - Optional configuration overrides
|
|
1618
|
-
* @returns A LanguageModelV2 instance
|
|
1619
|
-
*/
|
|
1620
|
-
languageModel(options) {
|
|
1621
|
-
return new MCPSamplingLanguageModel({
|
|
1622
|
-
server: this.config.server,
|
|
1623
|
-
modelPreferences: options?.modelPreferences,
|
|
1624
|
-
maxTokens: this.config.maxTokens
|
|
1625
|
-
});
|
|
1626
|
-
}
|
|
1627
|
-
/**
|
|
1628
|
-
* Shorthand for creating a language model
|
|
1629
|
-
*/
|
|
1630
|
-
call(options) {
|
|
1631
|
-
return this.languageModel(options);
|
|
1632
|
-
}
|
|
1633
|
-
};
|
|
1634
|
-
|
|
1635
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/client-sampling.js
|
|
1636
|
-
var import_types2 = require("@modelcontextprotocol/sdk/types.js");
|
|
1637
|
-
|
|
1638
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/ai/base-ai-executor.js
|
|
1639
|
-
var import_api2 = require("@opentelemetry/api");
|
|
1640
|
-
var import_ai = require("ai");
|
|
1641
|
-
var BaseAIExecutor = class {
|
|
1642
|
-
config;
|
|
1643
|
-
tracer;
|
|
1644
|
-
logger;
|
|
1645
|
-
constructor(config, server) {
|
|
1646
|
-
this.config = {
|
|
1647
|
-
maxSteps: 50,
|
|
1648
|
-
tracingEnabled: true,
|
|
1649
|
-
...config
|
|
1650
|
-
};
|
|
1651
|
-
this.tracer = import_api2.trace.getTracer(`mcpc.ai.${config.name}`);
|
|
1652
|
-
this.logger = createLogger(`mcpc.ai.${config.name}`, server);
|
|
1653
|
-
}
|
|
1654
|
-
execute(args) {
|
|
1655
|
-
if (this.config.tracingEnabled) {
|
|
1656
|
-
return this.executeWithTracing(args);
|
|
1657
|
-
}
|
|
1658
|
-
return this.executeCore(args);
|
|
1659
|
-
}
|
|
1660
|
-
executeWithTracing(args) {
|
|
1661
|
-
return this.tracer.startActiveSpan(`mcpc.ai.${this.config.name}`, async (span) => {
|
|
1662
|
-
try {
|
|
1663
|
-
span.setAttributes({
|
|
1664
|
-
"mcpc.executor": this.config.name,
|
|
1665
|
-
"mcpc.type": this.getExecutorType()
|
|
1666
|
-
});
|
|
1667
|
-
const result = await this.executeCore(args, span);
|
|
1668
|
-
span.setAttributes({
|
|
1669
|
-
"mcpc.error": !!result.isError
|
|
1670
|
-
});
|
|
1671
|
-
return result;
|
|
1672
|
-
} catch (error) {
|
|
1673
|
-
span.recordException(error);
|
|
1674
|
-
throw error;
|
|
1675
|
-
} finally {
|
|
1676
|
-
span.end();
|
|
1677
|
-
}
|
|
1678
|
-
});
|
|
1679
|
-
}
|
|
1680
|
-
async executeCore(args, span) {
|
|
1681
|
-
try {
|
|
1682
|
-
const result = (0, import_ai.streamText)({
|
|
1683
|
-
model: this.getModel(),
|
|
1684
|
-
system: this.buildSystemPrompt(args),
|
|
1685
|
-
messages: [
|
|
1686
|
-
{
|
|
1687
|
-
role: "user",
|
|
1688
|
-
content: args.prompt
|
|
1689
|
-
}
|
|
1690
|
-
],
|
|
1691
|
-
tools: this.buildTools(),
|
|
1692
|
-
stopWhen: (0, import_ai.stepCountIs)(this.config.maxSteps),
|
|
1693
|
-
experimental_telemetry: this.config.tracingEnabled ? {
|
|
1694
|
-
isEnabled: true,
|
|
1695
|
-
functionId: `mcpc.${this.config.name}`,
|
|
1696
|
-
tracer: this.tracer
|
|
1697
|
-
} : void 0,
|
|
1698
|
-
onStepFinish: (step) => {
|
|
1699
|
-
if (span) {
|
|
1700
|
-
span.addEvent("step", {
|
|
1701
|
-
tools: step.toolCalls?.length ?? 0,
|
|
1702
|
-
reason: step.finishReason ?? ""
|
|
1703
|
-
});
|
|
1704
|
-
}
|
|
1705
|
-
}
|
|
1706
|
-
});
|
|
1707
|
-
return {
|
|
1708
|
-
content: [
|
|
1709
|
-
{
|
|
1710
|
-
type: "text",
|
|
1711
|
-
text: await result.text || `Completed in ${(await result.steps)?.length ?? "unknown"} step(s).`
|
|
1712
|
-
}
|
|
1713
|
-
],
|
|
1714
|
-
isError: false
|
|
1715
|
-
};
|
|
1716
|
-
} catch (error) {
|
|
1717
|
-
this.logger.error({
|
|
1718
|
-
message: "Execution error",
|
|
1719
|
-
error
|
|
1720
|
-
});
|
|
1721
|
-
return {
|
|
1722
|
-
content: [
|
|
1723
|
-
{
|
|
1724
|
-
type: "text",
|
|
1725
|
-
text: `Error: ${error instanceof Error ? error.message : String(error)}`
|
|
1726
|
-
}
|
|
1727
|
-
],
|
|
1728
|
-
isError: true
|
|
1729
|
-
};
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
buildSystemPrompt(args) {
|
|
1733
|
-
return CompiledPrompts.aiLoopSystem({
|
|
1734
|
-
toolName: this.config.name,
|
|
1735
|
-
description: this.config.description,
|
|
1736
|
-
rules: this.getRules(),
|
|
1737
|
-
context: this.formatContext(args.context)
|
|
1738
|
-
});
|
|
1739
|
-
}
|
|
1740
|
-
getRules() {
|
|
1741
|
-
return `1. Use tools to complete the user's request
|
|
1742
|
-
2. Review results after each tool call
|
|
1743
|
-
3. Adapt your approach based on outcomes
|
|
1744
|
-
4. Continue until task is complete
|
|
1745
|
-
5. When complete, provide a summary WITHOUT calling more tools`;
|
|
1746
|
-
}
|
|
1747
|
-
formatContext(context2) {
|
|
1748
|
-
if (!context2 || Object.keys(context2).length === 0) {
|
|
1749
|
-
return "";
|
|
1750
|
-
}
|
|
1751
|
-
return `
|
|
1752
|
-
|
|
1753
|
-
<context>
|
|
1754
|
-
${JSON.stringify(context2, null, 2)}
|
|
1755
|
-
</context>`;
|
|
1756
|
-
}
|
|
1757
|
-
convertToAISDKTool(name, toolDetail, execute) {
|
|
1758
|
-
const cleanedSchema = toolDetail.inputSchema ? cleanToolSchema(toolDetail.inputSchema) : {
|
|
1759
|
-
type: "object"
|
|
1760
|
-
};
|
|
1761
|
-
return (0, import_ai.tool)({
|
|
1762
|
-
description: toolDetail.description || `Tool: ${name}`,
|
|
1763
|
-
inputSchema: (0, import_ai.jsonSchema)(cleanedSchema),
|
|
1764
|
-
execute
|
|
1765
|
-
});
|
|
1766
|
-
}
|
|
1767
|
-
};
|
|
1768
|
-
|
|
1769
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-sampling-executor.js
|
|
1770
|
-
var AISamplingExecutor = class extends BaseAIExecutor {
|
|
1771
|
-
server;
|
|
1772
|
-
tools;
|
|
1773
|
-
providerOptions;
|
|
1774
|
-
maxTokens;
|
|
1775
|
-
model = null;
|
|
1776
|
-
constructor(config) {
|
|
1777
|
-
super(config, "callTool" in config.server ? config.server : void 0);
|
|
1778
|
-
this.server = config.server;
|
|
1779
|
-
this.tools = config.tools;
|
|
1780
|
-
this.providerOptions = config.providerOptions;
|
|
1781
|
-
this.maxTokens = config.maxTokens;
|
|
1782
|
-
}
|
|
1783
|
-
initProvider() {
|
|
1784
|
-
if (!this.model) {
|
|
1785
|
-
const provider = new MCPSamplingProvider({
|
|
1786
|
-
server: this.server,
|
|
1787
|
-
maxTokens: this.maxTokens
|
|
1788
|
-
});
|
|
1789
|
-
this.model = provider.languageModel(this.providerOptions);
|
|
1790
|
-
}
|
|
1791
|
-
return this.model;
|
|
1792
|
-
}
|
|
1793
|
-
getModel() {
|
|
1794
|
-
if (!this.model) throw new Error("Model not initialized");
|
|
1795
|
-
return this.model;
|
|
1796
|
-
}
|
|
1797
|
-
getExecutorType() {
|
|
1798
|
-
return "mcp";
|
|
1799
|
-
}
|
|
1800
|
-
buildTools() {
|
|
1801
|
-
const aiTools = {};
|
|
1802
|
-
for (const [name, detail] of this.tools) {
|
|
1803
|
-
aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
|
|
1804
|
-
const result = await this.callTool(name, input);
|
|
1805
|
-
return this.formatResult(result);
|
|
1806
|
-
});
|
|
1807
|
-
}
|
|
1808
|
-
return aiTools;
|
|
1809
|
-
}
|
|
1810
|
-
async callTool(name, input) {
|
|
1811
|
-
if ("callTool" in this.server) {
|
|
1812
|
-
return await this.server.callTool(name, input);
|
|
1813
|
-
}
|
|
1814
|
-
const detail = this.tools.find(([n]) => n === name)?.[1];
|
|
1815
|
-
if (detail?.execute) return await detail.execute(input);
|
|
1816
|
-
throw new Error(`Cannot call tool "${name}"`);
|
|
1817
|
-
}
|
|
1818
|
-
formatResult(result) {
|
|
1819
|
-
const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
|
|
1820
|
-
return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
|
|
1821
|
-
}
|
|
1822
|
-
execute(args) {
|
|
1823
|
-
this.initProvider();
|
|
1824
|
-
return super.execute(args);
|
|
1825
|
-
}
|
|
1826
|
-
};
|
|
1827
|
-
|
|
1828
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-sampling-registrar.js
|
|
1829
|
-
function registerAISamplingTool(server, params) {
|
|
1830
|
-
const { name, description, allToolNames, depGroups, toolNameToDetailList, providerOptions, maxSteps = 50, tracingEnabled = false, maxTokens } = params;
|
|
1831
|
-
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
1832
|
-
const executor = new AISamplingExecutor({
|
|
1833
|
-
name,
|
|
1834
|
-
description,
|
|
1835
|
-
server,
|
|
1836
|
-
tools: toolNameToDetailList,
|
|
1837
|
-
providerOptions,
|
|
1838
|
-
maxSteps,
|
|
1839
|
-
tracingEnabled,
|
|
1840
|
-
maxTokens
|
|
1841
|
-
});
|
|
1842
|
-
const toolDescription = CompiledPrompts.samplingToolDescription({
|
|
1843
|
-
toolName: name,
|
|
1844
|
-
description,
|
|
1845
|
-
toolList: allToolNames.map((n) => `- ${n}`).join("\n")
|
|
1846
|
-
});
|
|
1847
|
-
const argsDef = createArgsDef.forSampling();
|
|
1848
|
-
const schema = allToolNames.length > 0 ? argsDef : {
|
|
1849
|
-
type: "object",
|
|
1850
|
-
properties: {}
|
|
1851
|
-
};
|
|
1852
|
-
server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
|
|
1853
|
-
const validationResult = validateSchema(args, schema);
|
|
1854
|
-
if (!validationResult.valid) {
|
|
1855
|
-
return {
|
|
1856
|
-
content: [
|
|
1857
|
-
{
|
|
1858
|
-
type: "text",
|
|
1859
|
-
text: CompiledPrompts.errorResponse({
|
|
1860
|
-
errorMessage: validationResult.error || "Validation failed"
|
|
1861
|
-
})
|
|
1862
|
-
}
|
|
1863
|
-
],
|
|
1864
|
-
isError: true
|
|
1865
|
-
};
|
|
1866
|
-
}
|
|
1867
|
-
const prompt = typeof args.prompt === "string" ? args.prompt : JSON.stringify(args);
|
|
1868
|
-
return executor.execute({
|
|
1869
|
-
prompt,
|
|
1870
|
-
context: args.context
|
|
1871
|
-
});
|
|
1872
|
-
});
|
|
1873
|
-
}
|
|
1874
|
-
|
|
1875
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/mode-ai-sampling-plugin.js
|
|
1876
|
-
var createAISamplingModePlugin = () => ({
|
|
1877
|
-
name: "mode-ai-sampling",
|
|
1878
|
-
version: "1.0.0",
|
|
1879
|
-
apply: "ai_sampling",
|
|
1880
|
-
registerAgentTool: (context2) => {
|
|
1881
|
-
const opts = context2.options;
|
|
1882
|
-
registerAISamplingTool(context2.server, {
|
|
1883
|
-
description: context2.description,
|
|
1884
|
-
name: context2.name,
|
|
1885
|
-
allToolNames: context2.allToolNames,
|
|
1886
|
-
depGroups: context2.depGroups,
|
|
1887
|
-
toolNameToDetailList: context2.toolNameToDetailList,
|
|
1888
|
-
providerOptions: opts.providerOptions,
|
|
1889
|
-
maxSteps: opts.maxSteps,
|
|
1890
|
-
tracingEnabled: opts.tracingEnabled,
|
|
1891
|
-
maxTokens: opts.maxTokens
|
|
1892
|
-
});
|
|
1893
|
-
}
|
|
1894
|
-
});
|
|
1895
|
-
var mode_ai_sampling_plugin_default = createAISamplingModePlugin();
|
|
1896
|
-
|
|
1897
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-acp-executor.js
|
|
1898
|
-
var import_acp_ai_provider = require("@mcpc-tech/acp-ai-provider");
|
|
1899
|
-
var AIACPExecutor = class extends BaseAIExecutor {
|
|
1900
|
-
acpSettings;
|
|
1901
|
-
tools;
|
|
1902
|
-
provider = null;
|
|
1903
|
-
model = null;
|
|
1904
|
-
constructor(config) {
|
|
1905
|
-
super(config);
|
|
1906
|
-
this.acpSettings = config.acpSettings;
|
|
1907
|
-
this.tools = config.tools;
|
|
1908
|
-
}
|
|
1909
|
-
initProvider() {
|
|
1910
|
-
if (!this.model) {
|
|
1911
|
-
this.provider = (0, import_acp_ai_provider.createACPProvider)(this.acpSettings);
|
|
1912
|
-
this.model = this.provider.languageModel();
|
|
1913
|
-
}
|
|
1914
|
-
return this.model;
|
|
1915
|
-
}
|
|
1916
|
-
getModel() {
|
|
1917
|
-
if (!this.model) throw new Error("Model not initialized");
|
|
1918
|
-
return this.model;
|
|
1919
|
-
}
|
|
1920
|
-
getExecutorType() {
|
|
1921
|
-
return "acp";
|
|
1922
|
-
}
|
|
1923
|
-
buildTools() {
|
|
1924
|
-
const aiTools = {};
|
|
1925
|
-
for (const [name, detail] of this.tools) {
|
|
1926
|
-
if (!detail.execute) continue;
|
|
1927
|
-
aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
|
|
1928
|
-
const result = await detail.execute(input);
|
|
1929
|
-
return this.formatResult(result);
|
|
1930
|
-
});
|
|
1931
|
-
}
|
|
1932
|
-
return (0, import_acp_ai_provider.acpTools)(aiTools);
|
|
1933
|
-
}
|
|
1934
|
-
formatResult(result) {
|
|
1935
|
-
const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
|
|
1936
|
-
return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
|
|
1937
|
-
}
|
|
1938
|
-
execute(args) {
|
|
1939
|
-
this.initProvider();
|
|
1940
|
-
return super.execute(args);
|
|
1941
|
-
}
|
|
1942
|
-
cleanup() {
|
|
1943
|
-
if (this.provider && typeof this.provider.cleanup === "function") {
|
|
1944
|
-
this.provider.cleanup();
|
|
1945
|
-
}
|
|
1946
|
-
this.model = null;
|
|
1947
|
-
this.provider = null;
|
|
1948
|
-
}
|
|
1949
|
-
};
|
|
1950
|
-
|
|
1951
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-acp-registrar.js
|
|
1952
|
-
function registerAIACPTool(server, params) {
|
|
1953
|
-
const { name, description, allToolNames, depGroups, toolNameToDetailList, acpSettings, maxSteps = 50, tracingEnabled = false } = params;
|
|
1954
|
-
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
1955
|
-
const executor = new AIACPExecutor({
|
|
1956
|
-
name,
|
|
1957
|
-
description,
|
|
1958
|
-
acpSettings,
|
|
1959
|
-
tools: toolNameToDetailList,
|
|
1960
|
-
maxSteps,
|
|
1961
|
-
tracingEnabled
|
|
1962
|
-
});
|
|
1963
|
-
const toolDescription = CompiledPrompts.samplingToolDescription({
|
|
1964
|
-
toolName: name,
|
|
1965
|
-
description,
|
|
1966
|
-
toolList: allToolNames.length > 0 ? allToolNames.map((n) => `- ${n}`).join("\n") : "Agent has its own tools"
|
|
1967
|
-
});
|
|
1968
|
-
const argsDef = createArgsDef.forSampling();
|
|
1969
|
-
const schema = allToolNames.length > 0 ? argsDef : {
|
|
1970
|
-
type: "object",
|
|
1971
|
-
properties: {}
|
|
1972
|
-
};
|
|
1973
|
-
server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
|
|
1974
|
-
const validationResult = validateSchema(args, schema);
|
|
1975
|
-
if (!validationResult.valid) {
|
|
1976
|
-
return {
|
|
1977
|
-
content: [
|
|
1978
|
-
{
|
|
1979
|
-
type: "text",
|
|
1980
|
-
text: CompiledPrompts.errorResponse({
|
|
1981
|
-
errorMessage: validationResult.error || "Validation failed"
|
|
1982
|
-
})
|
|
1983
|
-
}
|
|
1984
|
-
],
|
|
1985
|
-
isError: true
|
|
1986
|
-
};
|
|
1987
|
-
}
|
|
1988
|
-
const prompt = typeof args.prompt === "string" ? args.prompt : JSON.stringify(args);
|
|
1989
|
-
return executor.execute({
|
|
1990
|
-
prompt,
|
|
1991
|
-
context: args.context
|
|
1992
|
-
});
|
|
1993
|
-
});
|
|
1994
|
-
return executor;
|
|
1995
|
-
}
|
|
1996
|
-
|
|
1997
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/mode-ai-acp-plugin.js
|
|
1998
|
-
var createAIACPModePlugin = () => ({
|
|
1999
|
-
name: "mode-ai-acp",
|
|
2000
|
-
version: "1.0.0",
|
|
2001
|
-
apply: "ai_acp",
|
|
2002
|
-
registerAgentTool: (context2) => {
|
|
2003
|
-
const opts = context2.options;
|
|
2004
|
-
if (!opts.acpSettings) {
|
|
2005
|
-
throw new Error("ai_acp mode requires acpSettings in options");
|
|
2006
|
-
}
|
|
2007
|
-
registerAIACPTool(context2.server, {
|
|
2008
|
-
description: context2.description,
|
|
2009
|
-
name: context2.name,
|
|
2010
|
-
allToolNames: context2.allToolNames,
|
|
2011
|
-
depGroups: context2.depGroups,
|
|
2012
|
-
toolNameToDetailList: context2.toolNameToDetailList,
|
|
2013
|
-
acpSettings: opts.acpSettings,
|
|
2014
|
-
maxSteps: opts.maxSteps,
|
|
2015
|
-
tracingEnabled: opts.tracingEnabled
|
|
2016
|
-
});
|
|
2017
|
-
}
|
|
2018
|
-
});
|
|
2019
|
-
var mode_ai_acp_plugin_default = createAIACPModePlugin();
|
|
2020
|
-
|
|
2021
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/common/schema.js
|
|
2022
|
-
var import_json_schema_traverse = __toESM(require("json-schema-traverse"), 1);
|
|
2023
|
-
|
|
2024
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/common/env.js
|
|
2025
|
-
var import_node_process4 = __toESM(require("node:process"), 1);
|
|
2026
|
-
var isSCF = () => Boolean(import_node_process4.default.env.SCF_RUNTIME || import_node_process4.default.env.PROD_SCF);
|
|
2027
|
-
if (isSCF()) {
|
|
2028
|
-
console.log({
|
|
2029
|
-
isSCF: isSCF(),
|
|
2030
|
-
SCF_RUNTIME: import_node_process4.default.env.SCF_RUNTIME
|
|
2031
|
-
});
|
|
2032
|
-
}
|
|
2033
|
-
|
|
2034
|
-
// __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/set-up-mcp-compose.js
|
|
2035
|
-
var markdownAgentLoader = null;
|
|
2036
|
-
function setMarkdownAgentLoader(loader) {
|
|
2037
|
-
markdownAgentLoader = loader;
|
|
2038
|
-
}
|
|
2039
|
-
function isMarkdownFile(path) {
|
|
2040
|
-
return path.endsWith(".md") || path.endsWith(".markdown");
|
|
2041
|
-
}
|
|
2042
|
-
|
|
2043
45
|
// __mcpc__plugin-markdown-loader_latest/node_modules/@mcpc/plugin-markdown-loader/src/markdown-loader.js
|
|
2044
46
|
var import_promises = require("node:fs/promises");
|
|
2045
47
|
|
|
@@ -3981,10 +1983,13 @@ function parse(content, options = {}) {
|
|
|
3981
1983
|
|
|
3982
1984
|
// __mcpc__plugin-markdown-loader_latest/node_modules/@mcpc/plugin-markdown-loader/src/markdown-loader.js
|
|
3983
1985
|
var import_node_path = require("node:path");
|
|
3984
|
-
var
|
|
1986
|
+
var import_node_process = __toESM(require("node:process"), 1);
|
|
1987
|
+
function isMarkdownFile(path) {
|
|
1988
|
+
return path.endsWith(".md") || path.endsWith(".markdown");
|
|
1989
|
+
}
|
|
3985
1990
|
function replaceEnvVars(str2) {
|
|
3986
1991
|
return str2.replace(/\$([A-Za-z_][A-Za-z0-9_]*)(?!\s*\()/g, (match, varName) => {
|
|
3987
|
-
const value =
|
|
1992
|
+
const value = import_node_process.default.env[varName];
|
|
3988
1993
|
if (value !== void 0) {
|
|
3989
1994
|
return value;
|
|
3990
1995
|
}
|
|
@@ -4113,8 +2118,9 @@ function markdownLoaderPlugin() {
|
|
|
4113
2118
|
version: "1.0.0",
|
|
4114
2119
|
enforce: "pre",
|
|
4115
2120
|
// Run before other plugins
|
|
4116
|
-
configureServer: () => {
|
|
4117
|
-
|
|
2121
|
+
configureServer: (server) => {
|
|
2122
|
+
server.registerFileLoader(".md", loadMarkdownAgentFile);
|
|
2123
|
+
server.registerFileLoader(".markdown", loadMarkdownAgentFile);
|
|
4118
2124
|
}
|
|
4119
2125
|
};
|
|
4120
2126
|
}
|
|
@@ -4130,6 +2136,5 @@ var mod_default = defaultPlugin;
|
|
|
4130
2136
|
loadMarkdownAgentFile,
|
|
4131
2137
|
markdownAgentToComposeDefinition,
|
|
4132
2138
|
markdownLoaderPlugin,
|
|
4133
|
-
parseMarkdownAgent
|
|
4134
|
-
setMarkdownAgentLoader
|
|
2139
|
+
parseMarkdownAgent
|
|
4135
2140
|
});
|