@mcpc-tech/plugin-markdown-loader 0.0.7 → 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 CHANGED
@@ -38,2043 +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 complex tasks by iteratively selecting and calling tools.
437
-
438
- You must follow the <manual/>, obey the <rules/>, and use the <format/>.
439
-
440
- <manual>
441
- {description}
442
- </manual>
443
-
444
- <parameters>
445
- \`tool\` - Which tool to execute: "man" to get schemas, or a tool name to execute
446
- \`args\` - For "man": { tools: ["tool1", "tool2"] }. For other tools: tool parameters that strictly adhere to the tool's JSON schema.
447
- </parameters>
448
-
449
- <rules>
450
- 1. **First call**: Use \`man\` to get tool schemas you need
451
- 2. **Execute tools**: Use tool name in \`tool\` and parameters in \`args\`
452
- 3. **Parallel calls**: If your client supports it, call \`man\` and execute tools simultaneously
453
- 4. Note: You are an agent exposed as an MCP tool
454
- </rules>
455
-
456
- <format>
457
- Get tool schemas:
458
- \`\`\`json
459
- {
460
- "tool": "man",
461
- "args": { "tools": ["tool1", "tool2"] }
462
- }
463
- \`\`\`
464
-
465
- Execute a tool:
466
- \`\`\`json
467
- {
468
- "tool": "tool_name",
469
- "args": { /* tool parameters */ }
470
- }
471
- \`\`\`
472
- </format>`,
473
- /**
474
- * Compact system prompt for autonomous MCP execution (when manual is provided)
475
- *
476
- * Uses simplified description with progressive disclosure:
477
- * - Short description shown by default
478
- * - Use `man` command with args `{ manual: true }` to get full manual
479
- */
480
- AUTONOMOUS_EXECUTION_COMPACT: `Agentic tool \`{toolName}\`: {description}
481
-
482
- Use \`man\` command with args \`{ tools: [], manual: true }\` to get the full manual, or \`{ tools: ["tool1"] }\` to get tool schemas.
483
-
484
- <format>
485
- Get full manual: \`{ "tool": "man", "args": { "tools": [], "manual": true } }\`
486
- Get tool schemas: \`{ "tool": "man", "args": { "tools": ["tool1", "tool2"] } }\`
487
- Get both: \`{ "tool": "man", "args": { "tools": ["tool1"], "manual": true } }\`
488
- Execute a tool: \`{ "tool": "tool_name", "args": { /* parameters */ } }\`
489
- </format>`,
490
- /**
491
- * Tool description for sampling tools (shown in MCP tools list)
492
- * Explains how to use prompt and context parameters
493
- */
494
- SAMPLING_TOOL_DESCRIPTION: `Subagent tool \`{toolName}\` that executes complex tasks.
495
-
496
- You must follow the <manual/>, obey the <rules/>, and use the <format/>.
497
-
498
- <manual>
499
- {description}
500
- </manual>
501
-
502
- <format>
503
- \`prompt\` - The task to be completed (e.g., "organize my desktop files")
504
- \`context\` - Execution context object (e.g., { cwd: "/path/to/dir" })
505
- </format>
506
-
507
- <rules>
508
- 1. Always provide both \`prompt\` and \`context\` parameters
509
- 2. \`prompt\` must be a clear, actionable description
510
- 3. \`context\` must include relevant environment info (e.g., working directory)
511
- </rules>`,
512
- /**
513
- * System prompt for AI sampling loop (ai_sampling/ai_acp modes)
514
- * Used inside the execution loop when AI calls native tools.
515
- * Note: Tool schemas are passed via AI SDK native tool calling, not in prompt.
516
- */
517
- AI_LOOP_SYSTEM: `Agent \`{toolName}\` that completes tasks by calling tools.
518
-
519
- <manual>
520
- {description}
521
- </manual>
522
-
523
- <rules>
524
- {rules}
525
- </rules>{context}`
526
- };
527
- var ResponseTemplates = {
528
- /**
529
- * Success response for action execution
530
- */
531
- ACTION_SUCCESS: `Action \`{currentAction}\` completed.
532
-
533
- Next: Execute \`{nextAction}\` by calling \`{toolName}\` again.`,
534
- /**
535
- * Planning prompt when no next action is specified
536
- */
537
- PLANNING_PROMPT: `Action \`{currentAction}\` completed. Determine next step:
538
-
539
- 1. Analyze results from \`{currentAction}\`
540
- 2. Decide: Continue with another action or Complete?
541
- 3. Call \`{toolName}\` with chosen action or \`decision: "complete"\``,
542
- /**
543
- * Error response templates
544
- */
545
- ERROR_RESPONSE: `Validation failed: {errorMessage}
546
-
547
- Adjust parameters and retry.`,
548
- /**
549
- * Completion message
550
- */
551
- COMPLETION_MESSAGE: `Task completed.`,
552
- /**
553
- * Security validation messages
554
- */
555
- SECURITY_VALIDATION: {
556
- PASSED: `Security check passed: {operation} on {path}`,
557
- FAILED: `Security check failed: {operation} on {path}`
558
- },
559
- /**
560
- * Audit log messages
561
- */
562
- AUDIT_LOG: `[{timestamp}] {level}: {action} on {resource}{userInfo}`
563
- };
564
- var CompiledPrompts = {
565
- autonomousExecution: p(SystemPrompts.AUTONOMOUS_EXECUTION),
566
- autonomousExecutionCompact: p(SystemPrompts.AUTONOMOUS_EXECUTION_COMPACT),
567
- samplingToolDescription: p(SystemPrompts.SAMPLING_TOOL_DESCRIPTION),
568
- aiLoopSystem: p(SystemPrompts.AI_LOOP_SYSTEM),
569
- actionSuccess: p(ResponseTemplates.ACTION_SUCCESS),
570
- planningPrompt: p(ResponseTemplates.PLANNING_PROMPT),
571
- errorResponse: p(ResponseTemplates.ERROR_RESPONSE),
572
- securityPassed: p(ResponseTemplates.SECURITY_VALIDATION.PASSED),
573
- securityFailed: p(ResponseTemplates.SECURITY_VALIDATION.FAILED),
574
- auditLog: p(ResponseTemplates.AUDIT_LOG),
575
- completionMessage: () => ResponseTemplates.COMPLETION_MESSAGE
576
- };
577
-
578
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/factories/args-def-factory.js
579
- function createArgsDefFactory(_name, _allToolNames, _depGroups, _predefinedSteps, _ensureStepActions) {
580
- return {
581
- forSampling: function() {
582
- return {
583
- type: "object",
584
- description: "Provide prompt for autonomous tool execution",
585
- properties: {
586
- prompt: {
587
- type: "string",
588
- description: "The task to be completed autonomously by the agentic system using available tools"
589
- },
590
- context: {
591
- type: "object",
592
- description: "Execution context, e.g., { cwd: '/path/to/dir' }. Any relevant fields allowed.",
593
- additionalProperties: true
594
- }
595
- },
596
- required: [
597
- "prompt",
598
- "context"
599
- ],
600
- errorMessage: {
601
- required: {
602
- prompt: "Missing required field 'prompt'. Please provide a clear task description.",
603
- context: "Missing required field 'context'. Please provide relevant context (e.g., { cwd: '...' })."
604
- }
605
- }
606
- };
607
- },
608
- /**
609
- * Agentic schema - simplified Unix-style interface
610
- *
611
- * Only two fields:
612
- * - `tool`: which tool to execute (enum includes "man" + all tool names)
613
- * - `args`: object with parameters. For "man": { tools: ["a", "b"] }. For others: tool parameters.
614
- */
615
- forAgentic: function(allToolNames) {
616
- const toolEnum = [
617
- "man",
618
- ...allToolNames
619
- ];
620
- return {
621
- type: "object",
622
- properties: {
623
- tool: {
624
- type: "string",
625
- enum: toolEnum,
626
- description: 'Which tool to execute. Use "man" to get tool schemas, or a tool name to execute.',
627
- errorMessage: {
628
- enum: `Invalid tool. Available: ${toolEnum.join(", ")}`
629
- }
630
- },
631
- args: {
632
- type: "object",
633
- description: `For "man": { tools: ["tool1", "tool2"], manual?: true }. For other tools: tool parameters that strictly adhere to the tool's JSON schema.`
634
- }
635
- },
636
- required: [
637
- "tool"
638
- ],
639
- additionalProperties: false
640
- };
641
- },
642
- /**
643
- * Schema for "man" command args validation
644
- * Expected format: { tools: ["tool1", "tool2"], manual?: true }
645
- *
646
- * - Always require `tools`
647
- * - Allow empty tools only when `manual: true`
648
- */
649
- forMan: function(allToolNames) {
650
- return {
651
- type: "object",
652
- properties: {
653
- tools: {
654
- type: "array",
655
- items: {
656
- type: "string",
657
- enum: allToolNames,
658
- errorMessage: {
659
- enum: `Invalid tool name. Available: ${allToolNames.join(", ")}`
660
- }
661
- }
662
- },
663
- manual: {
664
- type: "boolean",
665
- description: "Set to true to get the full manual for this agent (progressive disclosure)."
666
- }
667
- },
668
- required: [
669
- "tools"
670
- ],
671
- additionalProperties: false,
672
- anyOf: [
673
- // manual-only (tools can be empty)
674
- {
675
- properties: {
676
- manual: {
677
- enum: [
678
- true
679
- ]
680
- },
681
- tools: {
682
- minItems: 0
683
- }
684
- },
685
- required: [
686
- "tools",
687
- "manual"
688
- ]
689
- },
690
- // tool schemas (require at least one tool)
691
- {
692
- properties: {
693
- tools: {
694
- minItems: 1,
695
- errorMessage: {
696
- minItems: "At least one tool name is required"
697
- }
698
- }
699
- },
700
- required: [
701
- "tools"
702
- ]
703
- }
704
- ],
705
- errorMessage: {
706
- required: {
707
- tools: 'Missing "tools" field. Expected: { tools: ["tool1", "tool2"] }'
708
- }
709
- }
710
- };
711
- }
712
- };
713
- }
714
-
715
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/schema-validator.js
716
- var import_ajv = require("ajv");
717
- var import_ajv_formats = __toESM(require("ajv-formats"), 1);
718
- var import_ajv_errors = __toESM(require("ajv-errors"), 1);
719
- var import_ajv_human_errors = require("@segment/ajv-human-errors");
720
- var ajv = new import_ajv.Ajv({
721
- allErrors: true,
722
- verbose: true,
723
- strict: false
724
- });
725
- import_ajv_formats.default.default(ajv);
726
- import_ajv_errors.default.default(ajv);
727
- function validateSchema(data, schema) {
728
- const validate = ajv.compile(schema);
729
- if (!validate(data)) {
730
- const errors = validate.errors;
731
- const customErrors = errors.filter((err) => err.keyword === "errorMessage");
732
- if (customErrors.length > 0) {
733
- const messages = [
734
- ...new Set(customErrors.map((err) => err.message))
735
- ];
736
- return {
737
- valid: false,
738
- error: messages.join("; ")
739
- };
740
- }
741
- const aggregateError = new import_ajv_human_errors.AggregateAjvError(errors);
742
- return {
743
- valid: false,
744
- error: aggregateError.message
745
- };
746
- }
747
- return {
748
- valid: true
749
- };
750
- }
751
-
752
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/tracing.js
753
- var import_api = require("@opentelemetry/api");
754
- var import_sdk_trace_node = require("@opentelemetry/sdk-trace-node");
755
- var import_sdk_trace_base = require("@opentelemetry/sdk-trace-base");
756
- var import_exporter_trace_otlp_http = require("@opentelemetry/exporter-trace-otlp-http");
757
- var import_resources = require("@opentelemetry/resources");
758
- var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
759
- var tracerProvider = null;
760
- var tracer = null;
761
- var isInitialized = false;
762
- function initializeTracing(config = {}) {
763
- if (isInitialized) {
764
- return;
765
- }
766
- const { enabled = true, serviceName = "mcpc-sampling", serviceVersion = "0.2.0", exportTo = "console", otlpEndpoint = "http://localhost:4318/v1/traces", otlpHeaders = {} } = config;
767
- if (!enabled) {
768
- isInitialized = true;
769
- return;
770
- }
771
- const resource = import_resources.Resource.default().merge(new import_resources.Resource({
772
- [import_semantic_conventions.ATTR_SERVICE_NAME]: serviceName,
773
- [import_semantic_conventions.ATTR_SERVICE_VERSION]: serviceVersion
774
- }));
775
- tracerProvider = new import_sdk_trace_node.NodeTracerProvider({
776
- resource
777
- });
778
- if (exportTo === "console") {
779
- tracerProvider.addSpanProcessor(new import_sdk_trace_base.SimpleSpanProcessor(new import_sdk_trace_base.ConsoleSpanExporter()));
780
- } else if (exportTo === "otlp") {
781
- const otlpExporter = new import_exporter_trace_otlp_http.OTLPTraceExporter({
782
- url: otlpEndpoint,
783
- headers: otlpHeaders
784
- });
785
- tracerProvider.addSpanProcessor(new import_sdk_trace_base.BatchSpanProcessor(otlpExporter));
786
- }
787
- tracerProvider.register();
788
- tracer = import_api.trace.getTracer(serviceName, serviceVersion);
789
- isInitialized = true;
790
- }
791
- function getTracer() {
792
- if (!isInitialized) {
793
- initializeTracing();
794
- }
795
- return tracer;
796
- }
797
- function startSpan(name, attributes, parent) {
798
- const tracer2 = getTracer();
799
- const ctx = parent ? import_api.trace.setSpan(import_api.context.active(), parent) : void 0;
800
- return tracer2.startSpan(name, {
801
- attributes
802
- }, ctx);
803
- }
804
- function endSpan(span, error) {
805
- if (error) {
806
- span.setStatus({
807
- code: import_api.SpanStatusCode.ERROR,
808
- message: error.message
809
- });
810
- span.recordException(error);
811
- } else {
812
- span.setStatus({
813
- code: import_api.SpanStatusCode.OK
814
- });
815
- }
816
- span.end();
817
- }
818
-
819
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/agentic/agentic-executor.js
820
- var import_node_process3 = __toESM(require("node:process"), 1);
821
- var AgenticExecutor = class {
822
- name;
823
- allToolNames;
824
- toolNameToDetailList;
825
- server;
826
- manual;
827
- logger;
828
- tracingEnabled;
829
- toolSchemaMap;
830
- constructor(name, allToolNames, toolNameToDetailList, server, manual) {
831
- this.name = name;
832
- this.allToolNames = allToolNames;
833
- this.toolNameToDetailList = toolNameToDetailList;
834
- this.server = server;
835
- this.manual = manual;
836
- this.tracingEnabled = false;
837
- this.logger = createLogger(`mcpc.agentic.${name}`, server);
838
- this.toolSchemaMap = new Map(toolNameToDetailList);
839
- try {
840
- this.tracingEnabled = import_node_process3.default.env.MCPC_TRACING_ENABLED === "true";
841
- if (this.tracingEnabled) {
842
- initializeTracing({
843
- enabled: true,
844
- serviceName: `mcpc-agentic-${name}`,
845
- exportTo: import_node_process3.default.env.MCPC_TRACING_EXPORT ?? "otlp",
846
- otlpEndpoint: import_node_process3.default.env.MCPC_TRACING_OTLP_ENDPOINT ?? "http://localhost:4318/v1/traces"
847
- });
848
- }
849
- } catch {
850
- this.tracingEnabled = false;
851
- }
852
- }
853
- async execute(args, schema, parentSpan) {
854
- const executeSpan = this.tracingEnabled ? startSpan("mcpc.agentic_execute", {
855
- agent: this.name,
856
- tool: String(args.tool ?? "unknown"),
857
- args: JSON.stringify(args)
858
- }, parentSpan ?? void 0) : null;
859
- try {
860
- const validationResult = this.validate(args, schema);
861
- if (!validationResult.valid) {
862
- if (executeSpan) {
863
- executeSpan.setAttributes({
864
- validationError: true,
865
- errorMessage: validationResult.error || "Validation failed"
866
- });
867
- endSpan(executeSpan);
868
- }
869
- this.logger.warning({
870
- message: "Validation failed",
871
- tool: args.tool,
872
- error: validationResult.error
873
- });
874
- return {
875
- content: [
876
- {
877
- type: "text",
878
- text: CompiledPrompts.errorResponse({
879
- errorMessage: validationResult.error || "Validation failed"
880
- })
881
- }
882
- ],
883
- isError: true
884
- };
885
- }
886
- const tool2 = args.tool;
887
- if (tool2 === "man") {
888
- const createArgsDef = createArgsDefFactory(this.name, this.allToolNames, {});
889
- const manSchema = createArgsDef.forMan(this.allToolNames);
890
- const manValidation = validateSchema(args.args ?? {}, manSchema);
891
- if (!manValidation.valid) {
892
- return {
893
- content: [
894
- {
895
- type: "text",
896
- text: `Invalid args for "man": ${manValidation.error}`
897
- }
898
- ],
899
- isError: true
900
- };
901
- }
902
- const argsObj = args.args;
903
- const tools = argsObj.tools ?? [];
904
- const wantManual = argsObj.manual === true;
905
- const wantTools = tools.length > 0;
906
- if (wantTools && wantManual) {
907
- const toolSchemas = this.handleManCommand(tools, null);
908
- const manualResult = this.handleManualRequest(null);
909
- if (executeSpan) {
910
- executeSpan.setAttributes({
911
- toolType: "man",
912
- requestType: "tools+manual"
913
- });
914
- endSpan(executeSpan);
915
- }
916
- return {
917
- content: [
918
- ...toolSchemas.content,
919
- {
920
- type: "text",
921
- text: "\n---\n"
922
- },
923
- ...manualResult.content
924
- ]
925
- };
926
- }
927
- if (wantManual) {
928
- return this.handleManualRequest(executeSpan);
929
- }
930
- return this.handleManCommand(tools, executeSpan);
931
- }
932
- const toolArgs = args.args || {};
933
- return await this.executeTool(tool2, toolArgs, executeSpan);
934
- } catch (error) {
935
- if (executeSpan) {
936
- endSpan(executeSpan, error);
937
- }
938
- this.logger.error({
939
- message: "Unexpected error in execute",
940
- error: String(error)
941
- });
942
- return {
943
- content: [
944
- {
945
- type: "text",
946
- text: `Unexpected error: ${error instanceof Error ? error.message : String(error)}`
947
- }
948
- ],
949
- isError: true
950
- };
951
- }
952
- }
953
- /**
954
- * Handle `man { manual: true }` - return full manual for progressive disclosure
955
- */
956
- handleManualRequest(executeSpan) {
957
- if (executeSpan) {
958
- executeSpan.setAttributes({
959
- toolType: "man",
960
- requestType: "manual"
961
- });
962
- }
963
- if (!this.manual) {
964
- if (executeSpan) {
965
- endSpan(executeSpan);
966
- }
967
- return {
968
- content: [
969
- {
970
- type: "text",
971
- text: "No manual available for this agent."
972
- }
973
- ]
974
- };
975
- }
976
- if (executeSpan) {
977
- executeSpan.setAttributes({
978
- success: true
979
- });
980
- endSpan(executeSpan);
981
- }
982
- return {
983
- content: [
984
- {
985
- type: "text",
986
- text: this.manual
987
- }
988
- ]
989
- };
990
- }
991
- /**
992
- * Handle `man` command - return schemas for requested tools
993
- * @param requestedTools - Array of tool names (already validated via JSON Schema)
994
- */
995
- handleManCommand(requestedTools, executeSpan) {
996
- if (executeSpan) {
997
- executeSpan.setAttributes({
998
- toolType: "man",
999
- requestedTools: requestedTools.join(",")
1000
- });
1001
- }
1002
- const schemas = requestedTools.map((toolName) => {
1003
- const toolDetail = this.toolSchemaMap.get(toolName);
1004
- if (toolDetail) {
1005
- const cleanedSchema = cleanToolSchema(toolDetail);
1006
- return `<tool_definition name="${toolName}">
1007
- ${JSON.stringify(cleanedSchema, null, 2)}
1008
- </tool_definition>`;
1009
- }
1010
- return null;
1011
- }).filter(Boolean);
1012
- if (executeSpan) {
1013
- executeSpan.setAttributes({
1014
- schemasReturned: schemas.length,
1015
- success: true
1016
- });
1017
- endSpan(executeSpan);
1018
- }
1019
- return {
1020
- content: [
1021
- {
1022
- type: "text",
1023
- text: schemas.length > 0 ? schemas.join("\n\n") : "No schemas found for requested tools."
1024
- }
1025
- ]
1026
- };
1027
- }
1028
- /**
1029
- * Execute a tool with runtime validation
1030
- */
1031
- async executeTool(tool2, toolArgs, executeSpan) {
1032
- const isExternalTool = this.toolNameToDetailList.some(([name]) => name === tool2);
1033
- const isInternalTool = this.allToolNames.includes(tool2);
1034
- if (!isExternalTool && !isInternalTool) {
1035
- if (executeSpan) {
1036
- executeSpan.setAttributes({
1037
- toolType: "not_found",
1038
- tool: tool2
1039
- });
1040
- endSpan(executeSpan);
1041
- }
1042
- return {
1043
- content: [
1044
- {
1045
- type: "text",
1046
- text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
1047
- }
1048
- ],
1049
- isError: true
1050
- };
1051
- }
1052
- if (isExternalTool) {
1053
- const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
1054
- const [, toolDetail] = externalTool;
1055
- if (toolDetail.inputSchema) {
1056
- const rawSchema = extractJsonSchema(toolDetail.inputSchema);
1057
- const validation = validateSchema(toolArgs, rawSchema);
1058
- if (!validation.valid) {
1059
- if (executeSpan) {
1060
- executeSpan.setAttributes({
1061
- validationError: true,
1062
- errorMessage: validation.error
1063
- });
1064
- endSpan(executeSpan);
1065
- }
1066
- return {
1067
- content: [
1068
- {
1069
- type: "text",
1070
- text: `Parameter validation failed for "${tool2}": ${validation.error}`
1071
- }
1072
- ],
1073
- isError: true
1074
- };
1075
- }
1076
- }
1077
- }
1078
- const toolType = isExternalTool ? "external" : "internal";
1079
- if (executeSpan) {
1080
- executeSpan.setAttributes({
1081
- toolType,
1082
- selectedTool: tool2
1083
- });
1084
- }
1085
- this.logger.debug({
1086
- message: `Executing ${toolType} tool`,
1087
- tool: tool2
1088
- });
1089
- try {
1090
- const result = await this.server.callTool(tool2, toolArgs, {
1091
- agentName: this.name
1092
- });
1093
- const callToolResult = result ?? {
1094
- content: []
1095
- };
1096
- if (executeSpan) {
1097
- executeSpan.setAttributes({
1098
- success: true,
1099
- isError: !!callToolResult.isError,
1100
- resultContentLength: callToolResult.content?.length || 0
1101
- });
1102
- endSpan(executeSpan);
1103
- }
1104
- return callToolResult;
1105
- } catch (error) {
1106
- if (executeSpan) {
1107
- endSpan(executeSpan, error);
1108
- }
1109
- this.logger.error({
1110
- message: `Error executing ${toolType} tool`,
1111
- tool: tool2,
1112
- error: String(error)
1113
- });
1114
- return {
1115
- content: [
1116
- {
1117
- type: "text",
1118
- text: `Error executing tool "${tool2}": ${error instanceof Error ? error.message : String(error)}`
1119
- }
1120
- ],
1121
- isError: true
1122
- };
1123
- }
1124
- }
1125
- validate(args, schema) {
1126
- return validateSchema(args, schema);
1127
- }
1128
- };
1129
-
1130
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/agentic/agentic-tool-registrar.js
1131
- function registerAgenticTool(server, { description, name, allToolNames, depGroups, toolNameToDetailList, manual }) {
1132
- const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
1133
- const agenticExecutor = new AgenticExecutor(name, allToolNames, toolNameToDetailList, server, manual);
1134
- description = manual ? CompiledPrompts.autonomousExecutionCompact({
1135
- toolName: name,
1136
- description
1137
- }) : CompiledPrompts.autonomousExecution({
1138
- toolName: name,
1139
- description
1140
- });
1141
- const agenticArgsDef = createArgsDef.forAgentic(allToolNames);
1142
- const schema = agenticArgsDef;
1143
- server.tool(name, description, jsonSchema(createModelCompatibleJSONSchema(schema)), async (args) => {
1144
- return await agenticExecutor.execute(args, schema);
1145
- });
1146
- }
1147
-
1148
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/mode-agentic-plugin.js
1149
- var createAgenticModePlugin = () => ({
1150
- name: "mode-agentic",
1151
- version: "2.0.0",
1152
- // Only apply to agentic mode
1153
- apply: "agentic",
1154
- // Register the agent tool
1155
- registerAgentTool: (context2) => {
1156
- registerAgenticTool(context2.server, {
1157
- description: context2.description,
1158
- name: context2.name,
1159
- allToolNames: context2.allToolNames,
1160
- depGroups: context2.depGroups,
1161
- toolNameToDetailList: context2.toolNameToDetailList,
1162
- manual: context2.manual
1163
- });
1164
- }
1165
- });
1166
- var mode_agentic_plugin_default = createAgenticModePlugin();
1167
-
1168
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/utils.js
1169
- function convertAISDKToMCPMessages(prompt) {
1170
- const messages = [];
1171
- for (const msg of prompt) {
1172
- if (msg.role === "system") continue;
1173
- const role = msg.role === "assistant" ? "assistant" : "user";
1174
- const textParts = msg.content.filter((c) => c.type === "text");
1175
- const toolCalls = msg.content.filter((c) => c.type === "tool-call");
1176
- const toolResults = msg.content.filter((c) => c.type === "tool-result");
1177
- const parts = [];
1178
- if (textParts.length > 0) {
1179
- parts.push(textParts.map((c) => c.text).join("\n"));
1180
- }
1181
- if (toolCalls.length > 0) {
1182
- const calls = toolCalls.map((c) => {
1183
- const call = c;
1184
- const toolArgs = call.args ?? call.input ?? {};
1185
- return `<use_tool tool="${call.toolName}">
1186
- ${JSON.stringify(toolArgs)}
1187
- </use_tool>`;
1188
- });
1189
- parts.push(calls.join("\n"));
1190
- }
1191
- if (toolResults.length > 0) {
1192
- const results = toolResults.map((c) => {
1193
- const result = c;
1194
- const resultValue = result.result ?? result.output ?? "undefined";
1195
- const output = JSON.stringify(resultValue);
1196
- return `Tool "${result.toolName}" result:
1197
- ${output}`;
1198
- });
1199
- parts.push(results.join("\n\n"));
1200
- }
1201
- const text = parts.join("\n\n");
1202
- if (text) {
1203
- messages.push({
1204
- role,
1205
- content: {
1206
- type: "text",
1207
- text
1208
- }
1209
- });
1210
- }
1211
- }
1212
- return messages;
1213
- }
1214
- function convertMCPStopReasonToAISDK(stopReason) {
1215
- if (stopReason === "endTurn" || stopReason === "stopSequence") {
1216
- return "stop";
1217
- }
1218
- if (stopReason === "maxTokens") return "length";
1219
- return stopReason ?? "unknown";
1220
- }
1221
-
1222
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/language-model.js
1223
- var DEFAULT_MAX_TOKENS = 128e3;
1224
- var MCPSamplingLanguageModel = class {
1225
- specificationVersion = "v2";
1226
- provider;
1227
- modelId;
1228
- supportedUrls = {};
1229
- server;
1230
- modelPreferences;
1231
- maxTokens;
1232
- constructor(config) {
1233
- this.server = config.server;
1234
- this.modelId = "";
1235
- this.provider = "mcp-client";
1236
- this.modelPreferences = config.modelPreferences;
1237
- this.maxTokens = config.maxTokens ?? DEFAULT_MAX_TOKENS;
1238
- }
1239
- /**
1240
- * Generate a response using MCP's createMessage capability
1241
- */
1242
- async doGenerate(options) {
1243
- const useNativeTools = this.supportsSamplingTools();
1244
- this.server.sendLoggingMessage({
1245
- level: "info",
1246
- data: `Client supports native tools: ${useNativeTools}`
1247
- });
1248
- const messages = this.convertMessages(options.prompt, useNativeTools);
1249
- this.server.sendLoggingMessage({
1250
- level: "info",
1251
- data: `Converted messages for MCP: ${JSON.stringify(messages)}`
1252
- });
1253
- let systemPrompt;
1254
- for (const msg of options.prompt) {
1255
- if (msg.role === "system") {
1256
- systemPrompt = msg.content;
1257
- break;
1258
- }
1259
- }
1260
- this.server.sendLoggingMessage({
1261
- level: "info",
1262
- data: `Client supports native tools: ${useNativeTools}`
1263
- });
1264
- systemPrompt = this.injectResponseFormatInstructions(systemPrompt, options.responseFormat, useNativeTools);
1265
- systemPrompt = this.injectToolInstructions(systemPrompt, options.tools, useNativeTools);
1266
- const createMessageParams = {
1267
- systemPrompt,
1268
- messages,
1269
- maxTokens: options.maxOutputTokens ?? this.maxTokens,
1270
- modelPreferences: this.modelPreferences
1271
- };
1272
- if (useNativeTools && options.tools && options.tools.length > 0) {
1273
- createMessageParams.tools = this.convertAISDKToolsToMCP(options.tools);
1274
- createMessageParams.toolChoice = {
1275
- mode: "auto"
1276
- };
1277
- this.server.sendLoggingMessage({
1278
- level: "info",
1279
- data: `Converted ${options.tools.length} tools to MCP format: ${JSON.stringify(createMessageParams.tools?.map((t) => t.name))}`
1280
- });
1281
- } else if (options.tools && options.tools.length > 0) {
1282
- this.server.sendLoggingMessage({
1283
- level: "info",
1284
- data: `Tools provided but not using native mode - injecting into system prompt instead`
1285
- });
1286
- }
1287
- this.server.sendLoggingMessage({
1288
- level: "info",
1289
- data: `Calling createMessage with params: ${JSON.stringify({
1290
- hasSystemPrompt: !!systemPrompt,
1291
- hasTools: !!createMessageParams.tools,
1292
- toolCount: createMessageParams.tools?.length || 0,
1293
- createMessageParams
1294
- }, null, 2)}`
1295
- });
1296
- const result = await this.server.createMessage(createMessageParams);
1297
- this.server.sendLoggingMessage({
1298
- level: "info",
1299
- data: `createMessage result: ${JSON.stringify({
1300
- contentType: result.content.type,
1301
- stopReason: result.stopReason,
1302
- text: result.content
1303
- })}`
1304
- });
1305
- const content = [];
1306
- if (useNativeTools) {
1307
- const contentArray = Array.isArray(result.content) ? result.content : [
1308
- result.content
1309
- ];
1310
- for (const block of contentArray) {
1311
- if (block.type === "text" && "text" in block) {
1312
- content.push({
1313
- type: "text",
1314
- text: block.text
1315
- });
1316
- } else if (block.type === "tool_use" && "id" in block && "name" in block) {
1317
- const toolInput = block.input || {};
1318
- content.push({
1319
- type: "tool-call",
1320
- toolCallId: block.id,
1321
- toolName: block.name,
1322
- input: JSON.stringify(toolInput)
1323
- });
1324
- }
1325
- }
1326
- } else {
1327
- if (result.content.type === "text" && result.content.text) {
1328
- const { text, toolCalls } = this.extractToolCalls(result.content.text, options.tools);
1329
- if (text.trim()) {
1330
- const textContent = {
1331
- type: "text",
1332
- text
1333
- };
1334
- content.push(textContent);
1335
- }
1336
- content.push(...toolCalls);
1337
- }
1338
- }
1339
- const finishReason = this.mapStopReason(result.stopReason);
1340
- return {
1341
- content,
1342
- finishReason,
1343
- usage: {
1344
- inputTokens: void 0,
1345
- outputTokens: void 0,
1346
- totalTokens: 0
1347
- },
1348
- request: {
1349
- body: JSON.stringify({
1350
- systemPrompt,
1351
- messages
1352
- })
1353
- },
1354
- response: {
1355
- modelId: result.model
1356
- },
1357
- warnings: []
1358
- };
1359
- }
1360
- /**
1361
- * Stream a response using MCP's createMessage capability
1362
- *
1363
- * Since MCP doesn't support native streaming, we generate the full response
1364
- * and emit it as stream events following AI SDK's protocol.
1365
- */
1366
- async doStream(options) {
1367
- const result = await this.doGenerate(options);
1368
- const stream = new ReadableStream({
1369
- start(controller) {
1370
- if (result.response?.modelId) {
1371
- controller.enqueue({
1372
- type: "response-metadata",
1373
- modelId: result.response.modelId,
1374
- ...result.response.headers && {
1375
- headers: result.response.headers
1376
- }
1377
- });
1378
- }
1379
- let textIndex = 0;
1380
- for (const part of result.content) {
1381
- if (part.type === "text") {
1382
- const id = `text-${++textIndex}`;
1383
- controller.enqueue({
1384
- type: "text-start",
1385
- id
1386
- });
1387
- controller.enqueue({
1388
- type: "text-delta",
1389
- id,
1390
- delta: part.text
1391
- });
1392
- controller.enqueue({
1393
- type: "text-end",
1394
- id
1395
- });
1396
- } else if (part.type === "tool-call") {
1397
- controller.enqueue({
1398
- type: "tool-call",
1399
- toolCallId: part.toolCallId,
1400
- toolName: part.toolName,
1401
- input: part.input
1402
- });
1403
- }
1404
- }
1405
- controller.enqueue({
1406
- type: "finish",
1407
- finishReason: result.finishReason,
1408
- usage: result.usage
1409
- });
1410
- controller.close();
1411
- }
1412
- });
1413
- return {
1414
- stream,
1415
- request: result.request,
1416
- warnings: result.warnings
1417
- };
1418
- }
1419
- /**
1420
- * Convert AI SDK messages to MCP sampling format
1421
- */
1422
- convertMessages(prompt, useNativeTools) {
1423
- if (!useNativeTools) {
1424
- return convertAISDKToMCPMessages(prompt);
1425
- }
1426
- const messages = [];
1427
- for (const msg of prompt) {
1428
- if (msg.role === "system") continue;
1429
- const role = msg.role === "assistant" ? "assistant" : "user";
1430
- const contentBlocks = [];
1431
- for (const part of msg.content) {
1432
- if (part.type === "text") {
1433
- contentBlocks.push({
1434
- type: "text",
1435
- text: part.text
1436
- });
1437
- } else if (part.type === "tool-call") {
1438
- const call = part;
1439
- contentBlocks.push({
1440
- type: "tool_use",
1441
- id: call.toolCallId,
1442
- name: call.toolName,
1443
- input: call.args ?? call.input ?? {}
1444
- });
1445
- } else if (part.type === "tool-result") {
1446
- const result = part;
1447
- contentBlocks.push({
1448
- type: "tool_result",
1449
- toolUseId: result.toolCallId,
1450
- // TODO: Handle different result types properly
1451
- content: [
1452
- {
1453
- type: "text",
1454
- text: result.output.type === "text" ? result.output.value?.toString() : JSON.stringify(result.output)
1455
- }
1456
- ]
1457
- });
1458
- }
1459
- }
1460
- if (contentBlocks.length > 0) {
1461
- messages.push({
1462
- role,
1463
- content: contentBlocks
1464
- });
1465
- }
1466
- }
1467
- return messages;
1468
- }
1469
- /**
1470
- * Map MCP stop reason to AI SDK finish reason
1471
- */
1472
- mapStopReason(stopReason) {
1473
- return convertMCPStopReasonToAISDK(stopReason);
1474
- }
1475
- /**
1476
- * Check if client supports native tool use in sampling
1477
- */
1478
- supportsSamplingTools() {
1479
- const capabilities = this.server.getClientCapabilities();
1480
- const supportsTools = !!capabilities?.sampling?.tools;
1481
- this.server.sendLoggingMessage({
1482
- level: "info",
1483
- data: `Client capabilities check: sampling=${!!capabilities?.sampling}, tools=${supportsTools}`
1484
- });
1485
- return supportsTools;
1486
- }
1487
- /**
1488
- * Convert AI SDK tools to MCP Tool format
1489
- */
1490
- convertAISDKToolsToMCP(tools) {
1491
- if (!tools || tools.length === 0) return [];
1492
- return tools.filter((tool2) => tool2.type === "function").map((tool2) => {
1493
- const toolAny = tool2;
1494
- return {
1495
- name: tool2.name,
1496
- description: toolAny.description || `Tool: ${tool2.name}`,
1497
- inputSchema: {
1498
- type: "object",
1499
- ...toolAny.inputSchema || toolAny.parameters
1500
- }
1501
- };
1502
- });
1503
- }
1504
- /**
1505
- * Inject response format instructions into system prompt
1506
- *
1507
- * Only injects formatting instructions in JSON fallback mode.
1508
- * In native tools mode, structured output is handled by the provider.
1509
- */
1510
- injectResponseFormatInstructions(systemPrompt, responseFormat, useNativeTools) {
1511
- if (!responseFormat) {
1512
- return systemPrompt;
1513
- }
1514
- if (useNativeTools) {
1515
- return systemPrompt;
1516
- }
1517
- let enhanced = systemPrompt || "";
1518
- if (responseFormat.type === "json") {
1519
- const jsonPrompt = `
1520
-
1521
- IMPORTANT: You MUST respond with valid JSON only. Do not include any text before or after the JSON.
1522
- - Your response must be a valid JSON object
1523
- - Do not wrap the JSON in markdown code blocks
1524
- - Do not include explanations or comments
1525
- - Ensure all JSON is properly formatted and parseable`;
1526
- enhanced = enhanced ? `${enhanced}${jsonPrompt}` : jsonPrompt.trim();
1527
- if (responseFormat.schema) {
1528
- const schemaInfo = `
1529
- - Follow this JSON schema structure: ${JSON.stringify(responseFormat.schema)}`;
1530
- enhanced += schemaInfo;
1531
- }
1532
- }
1533
- return enhanced || void 0;
1534
- }
1535
- /**
1536
- * Inject tool definitions into system prompt
1537
- *
1538
- * WORKAROUND: MCP sampling currently doesn't support native tools parameter.
1539
- * This method injects tool descriptions and usage instructions into the system prompt.
1540
- *
1541
- * TODO: Remove this workaround when MCP protocol adds native support for:
1542
- * - tools parameter in createMessage
1543
- * - Tool calling and function execution
1544
- * - Structured tool responses
1545
- */
1546
- injectToolInstructions(systemPrompt, tools, useNativeTools) {
1547
- if (!tools || tools.length === 0) {
1548
- return systemPrompt;
1549
- }
1550
- if (useNativeTools) {
1551
- this.server.sendLoggingMessage({
1552
- level: "info",
1553
- data: `Using native tools mode - skipping XML tool injection`
1554
- });
1555
- return systemPrompt;
1556
- }
1557
- this.server.sendLoggingMessage({
1558
- level: "info",
1559
- data: `Injecting ${tools.length} tools into system prompt (fallback mode)`
1560
- });
1561
- let enhanced = systemPrompt || "";
1562
- const toolsPrompt = `
1563
-
1564
- <available_tools>
1565
- You have access to the following tools. To use a tool, respond with this XML format:
1566
- <use_tool tool="tool_name">
1567
- {"param1": "value1", "param2": "value2"}
1568
- </use_tool>
1569
-
1570
- Follow the JSON schema definition for each tool's parameters.
1571
- You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
1572
-
1573
- <tools>`;
1574
- const toolDescriptions = tools.map((tool2) => {
1575
- if (tool2.type === "function") {
1576
- const toolAny = tool2;
1577
- const description = toolAny.description || "No description provided";
1578
- const schema = toolAny.inputSchema || toolAny.parameters;
1579
- const schemaStr = schema ? `
1580
- <schema>
1581
- ${JSON.stringify(schema, null, 2)}
1582
- </schema>` : "";
1583
- return `
1584
- <tool name="${tool2.name}">
1585
- <description>
1586
- ${description}
1587
- </description>${schemaStr}
1588
- </tool>`;
1589
- } else if (tool2.type === "provider-defined") {
1590
- return `
1591
- <tool name="${tool2.name}">
1592
- <description>${tool2.id || "No description provided"}</description>
1593
- </tool>`;
1594
- }
1595
- return "";
1596
- }).filter(Boolean).join("");
1597
- const toolsEnd = `
1598
- </tools>
1599
- </available_tools>`;
1600
- enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}${toolsEnd}` : `${toolsPrompt}${toolDescriptions}${toolsEnd}`.trim();
1601
- return enhanced || void 0;
1602
- }
1603
- /**
1604
- * Extract tool calls from LLM response text
1605
- *
1606
- * Parses XML-style tool call tags from the response:
1607
- * <use_tool tool="tool_name">{"arg": "value"}</use_tool>
1608
- */
1609
- extractToolCalls(responseText, tools) {
1610
- if (!tools || tools.length === 0) {
1611
- return {
1612
- text: responseText,
1613
- toolCalls: []
1614
- };
1615
- }
1616
- const toolCalls = [];
1617
- const toolCallRegex = /<use_tool\s+tool="([^"]+)">([\s\S]*?)<\/use_tool>/g;
1618
- let match;
1619
- let lastIndex = 0;
1620
- const textParts = [];
1621
- let callIndex = 0;
1622
- while ((match = toolCallRegex.exec(responseText)) !== null) {
1623
- textParts.push(responseText.slice(lastIndex, match.index));
1624
- const toolName = match[1];
1625
- const argsText = match[2].trim?.();
1626
- toolCalls.push({
1627
- type: "tool-call",
1628
- toolCallId: `call_${Date.now()}_${callIndex++}`,
1629
- toolName,
1630
- input: argsText
1631
- });
1632
- lastIndex = match.index + match[0].length;
1633
- }
1634
- textParts.push(responseText.slice(lastIndex));
1635
- const text = textParts.join("").trim();
1636
- return {
1637
- text,
1638
- toolCalls
1639
- };
1640
- }
1641
- };
1642
-
1643
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/provider.js
1644
- var MCPSamplingProvider = class {
1645
- config;
1646
- constructor(config) {
1647
- this.config = config;
1648
- }
1649
- /**
1650
- * Create a language model instance for a specific MCP tool/agent
1651
- *
1652
- * @param options - Optional configuration overrides
1653
- * @returns A LanguageModelV2 instance
1654
- */
1655
- languageModel(options) {
1656
- return new MCPSamplingLanguageModel({
1657
- server: this.config.server,
1658
- modelPreferences: options?.modelPreferences,
1659
- maxTokens: this.config.maxTokens
1660
- });
1661
- }
1662
- /**
1663
- * Shorthand for creating a language model
1664
- */
1665
- call(options) {
1666
- return this.languageModel(options);
1667
- }
1668
- };
1669
-
1670
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/client-sampling.js
1671
- var import_types2 = require("@modelcontextprotocol/sdk/types.js");
1672
-
1673
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/ai/base-ai-executor.js
1674
- var import_api2 = require("@opentelemetry/api");
1675
- var import_ai = require("ai");
1676
- var BaseAIExecutor = class {
1677
- config;
1678
- tracer;
1679
- logger;
1680
- constructor(config, server) {
1681
- this.config = {
1682
- maxSteps: 50,
1683
- tracingEnabled: true,
1684
- ...config
1685
- };
1686
- this.tracer = import_api2.trace.getTracer(`mcpc.ai.${config.name}`);
1687
- this.logger = createLogger(`mcpc.ai.${config.name}`, server);
1688
- }
1689
- execute(args) {
1690
- if (this.config.tracingEnabled) {
1691
- return this.executeWithTracing(args);
1692
- }
1693
- return this.executeCore(args);
1694
- }
1695
- executeWithTracing(args) {
1696
- return this.tracer.startActiveSpan(`mcpc.ai.${this.config.name}`, async (span) => {
1697
- try {
1698
- span.setAttributes({
1699
- "mcpc.executor": this.config.name,
1700
- "mcpc.type": this.getExecutorType()
1701
- });
1702
- const result = await this.executeCore(args, span);
1703
- span.setAttributes({
1704
- "mcpc.error": !!result.isError
1705
- });
1706
- return result;
1707
- } catch (error) {
1708
- span.recordException(error);
1709
- throw error;
1710
- } finally {
1711
- span.end();
1712
- }
1713
- });
1714
- }
1715
- async executeCore(args, span) {
1716
- try {
1717
- const result = (0, import_ai.streamText)({
1718
- model: this.getModel(),
1719
- system: this.buildSystemPrompt(args),
1720
- messages: [
1721
- {
1722
- role: "user",
1723
- content: args.prompt
1724
- }
1725
- ],
1726
- tools: this.buildTools(),
1727
- stopWhen: (0, import_ai.stepCountIs)(this.config.maxSteps),
1728
- experimental_telemetry: this.config.tracingEnabled ? {
1729
- isEnabled: true,
1730
- functionId: `mcpc.${this.config.name}`,
1731
- tracer: this.tracer
1732
- } : void 0,
1733
- onStepFinish: (step) => {
1734
- if (span) {
1735
- span.addEvent("step", {
1736
- tools: step.toolCalls?.length ?? 0,
1737
- reason: step.finishReason ?? ""
1738
- });
1739
- }
1740
- }
1741
- });
1742
- return {
1743
- content: [
1744
- {
1745
- type: "text",
1746
- text: await result.text || `Completed in ${(await result.steps)?.length ?? "unknown"} step(s).`
1747
- }
1748
- ],
1749
- isError: false
1750
- };
1751
- } catch (error) {
1752
- this.logger.error({
1753
- message: "Execution error",
1754
- error
1755
- });
1756
- return {
1757
- content: [
1758
- {
1759
- type: "text",
1760
- text: `Error: ${error instanceof Error ? error.message : String(error)}`
1761
- }
1762
- ],
1763
- isError: true
1764
- };
1765
- }
1766
- }
1767
- buildSystemPrompt(args) {
1768
- return CompiledPrompts.aiLoopSystem({
1769
- toolName: this.config.name,
1770
- description: this.config.description,
1771
- rules: this.getRules(),
1772
- context: this.formatContext(args.context)
1773
- });
1774
- }
1775
- getRules() {
1776
- return `1. Use tools to complete the user's request
1777
- 2. Review results after each tool call
1778
- 3. Adapt your approach based on outcomes
1779
- 4. Continue until task is complete
1780
- 5. When complete, provide a summary WITHOUT calling more tools`;
1781
- }
1782
- formatContext(context2) {
1783
- if (!context2 || Object.keys(context2).length === 0) {
1784
- return "";
1785
- }
1786
- return `
1787
-
1788
- <context>
1789
- ${JSON.stringify(context2, null, 2)}
1790
- </context>`;
1791
- }
1792
- convertToAISDKTool(name, toolDetail, execute) {
1793
- const cleanedSchema = toolDetail.inputSchema ? cleanToolSchema(toolDetail.inputSchema) : {
1794
- type: "object"
1795
- };
1796
- return (0, import_ai.tool)({
1797
- description: toolDetail.description || `Tool: ${name}`,
1798
- inputSchema: (0, import_ai.jsonSchema)(cleanedSchema),
1799
- execute
1800
- });
1801
- }
1802
- };
1803
-
1804
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-sampling-executor.js
1805
- var AISamplingExecutor = class extends BaseAIExecutor {
1806
- server;
1807
- tools;
1808
- providerOptions;
1809
- maxTokens;
1810
- model = null;
1811
- constructor(config) {
1812
- super(config, "callTool" in config.server ? config.server : void 0);
1813
- this.server = config.server;
1814
- this.tools = config.tools;
1815
- this.providerOptions = config.providerOptions;
1816
- this.maxTokens = config.maxTokens;
1817
- }
1818
- initProvider() {
1819
- if (!this.model) {
1820
- const provider = new MCPSamplingProvider({
1821
- server: this.server,
1822
- maxTokens: this.maxTokens
1823
- });
1824
- this.model = provider.languageModel(this.providerOptions);
1825
- }
1826
- return this.model;
1827
- }
1828
- getModel() {
1829
- if (!this.model) throw new Error("Model not initialized");
1830
- return this.model;
1831
- }
1832
- getExecutorType() {
1833
- return "mcp";
1834
- }
1835
- buildTools() {
1836
- const aiTools = {};
1837
- for (const [name, detail] of this.tools) {
1838
- aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
1839
- const result = await this.callTool(name, input);
1840
- return this.formatResult(result);
1841
- });
1842
- }
1843
- return aiTools;
1844
- }
1845
- async callTool(name, input) {
1846
- if ("callTool" in this.server) {
1847
- return await this.server.callTool(name, input);
1848
- }
1849
- const detail = this.tools.find(([n]) => n === name)?.[1];
1850
- if (detail?.execute) return await detail.execute(input);
1851
- throw new Error(`Cannot call tool "${name}"`);
1852
- }
1853
- formatResult(result) {
1854
- const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
1855
- return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
1856
- }
1857
- execute(args) {
1858
- this.initProvider();
1859
- return super.execute(args);
1860
- }
1861
- };
1862
-
1863
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-sampling-registrar.js
1864
- function registerAISamplingTool(server, params) {
1865
- const { name, description, allToolNames, depGroups, toolNameToDetailList, providerOptions, maxSteps = 50, tracingEnabled = false, maxTokens } = params;
1866
- const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
1867
- const executor = new AISamplingExecutor({
1868
- name,
1869
- description,
1870
- server,
1871
- tools: toolNameToDetailList,
1872
- providerOptions,
1873
- maxSteps,
1874
- tracingEnabled,
1875
- maxTokens
1876
- });
1877
- const toolDescription = CompiledPrompts.samplingToolDescription({
1878
- toolName: name,
1879
- description,
1880
- toolList: allToolNames.map((n) => `- ${n}`).join("\n")
1881
- });
1882
- const argsDef = createArgsDef.forSampling();
1883
- const schema = allToolNames.length > 0 ? argsDef : {
1884
- type: "object",
1885
- properties: {}
1886
- };
1887
- server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
1888
- const validationResult = validateSchema(args, schema);
1889
- if (!validationResult.valid) {
1890
- return {
1891
- content: [
1892
- {
1893
- type: "text",
1894
- text: CompiledPrompts.errorResponse({
1895
- errorMessage: validationResult.error || "Validation failed"
1896
- })
1897
- }
1898
- ],
1899
- isError: true
1900
- };
1901
- }
1902
- const prompt = typeof args.prompt === "string" ? args.prompt : JSON.stringify(args);
1903
- return executor.execute({
1904
- prompt,
1905
- context: args.context
1906
- });
1907
- });
1908
- }
1909
-
1910
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/mode-ai-sampling-plugin.js
1911
- var createAISamplingModePlugin = () => ({
1912
- name: "mode-ai-sampling",
1913
- version: "1.0.0",
1914
- apply: "ai_sampling",
1915
- registerAgentTool: (context2) => {
1916
- const opts = context2.options;
1917
- registerAISamplingTool(context2.server, {
1918
- description: context2.description,
1919
- name: context2.name,
1920
- allToolNames: context2.allToolNames,
1921
- depGroups: context2.depGroups,
1922
- toolNameToDetailList: context2.toolNameToDetailList,
1923
- providerOptions: opts.providerOptions,
1924
- maxSteps: opts.maxSteps,
1925
- tracingEnabled: opts.tracingEnabled,
1926
- maxTokens: opts.maxTokens
1927
- });
1928
- }
1929
- });
1930
- var mode_ai_sampling_plugin_default = createAISamplingModePlugin();
1931
-
1932
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-acp-executor.js
1933
- var import_acp_ai_provider = require("@mcpc-tech/acp-ai-provider");
1934
- var AIACPExecutor = class extends BaseAIExecutor {
1935
- acpSettings;
1936
- tools;
1937
- provider = null;
1938
- model = null;
1939
- constructor(config) {
1940
- super(config);
1941
- this.acpSettings = config.acpSettings;
1942
- this.tools = config.tools;
1943
- }
1944
- initProvider() {
1945
- if (!this.model) {
1946
- this.provider = (0, import_acp_ai_provider.createACPProvider)(this.acpSettings);
1947
- this.model = this.provider.languageModel();
1948
- }
1949
- return this.model;
1950
- }
1951
- getModel() {
1952
- if (!this.model) throw new Error("Model not initialized");
1953
- return this.model;
1954
- }
1955
- getExecutorType() {
1956
- return "acp";
1957
- }
1958
- buildTools() {
1959
- const aiTools = {};
1960
- for (const [name, detail] of this.tools) {
1961
- if (!detail.execute) continue;
1962
- aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
1963
- const result = await detail.execute(input);
1964
- return this.formatResult(result);
1965
- });
1966
- }
1967
- return (0, import_acp_ai_provider.acpTools)(aiTools);
1968
- }
1969
- formatResult(result) {
1970
- const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
1971
- return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
1972
- }
1973
- execute(args) {
1974
- this.initProvider();
1975
- return super.execute(args);
1976
- }
1977
- cleanup() {
1978
- if (this.provider && typeof this.provider.cleanup === "function") {
1979
- this.provider.cleanup();
1980
- }
1981
- this.model = null;
1982
- this.provider = null;
1983
- }
1984
- };
1985
-
1986
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-acp-registrar.js
1987
- function registerAIACPTool(server, params) {
1988
- const { name, description, allToolNames, depGroups, toolNameToDetailList, acpSettings, maxSteps = 50, tracingEnabled = false } = params;
1989
- const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
1990
- const executor = new AIACPExecutor({
1991
- name,
1992
- description,
1993
- acpSettings,
1994
- tools: toolNameToDetailList,
1995
- maxSteps,
1996
- tracingEnabled
1997
- });
1998
- const toolDescription = CompiledPrompts.samplingToolDescription({
1999
- toolName: name,
2000
- description,
2001
- toolList: allToolNames.length > 0 ? allToolNames.map((n) => `- ${n}`).join("\n") : "Agent has its own tools"
2002
- });
2003
- const argsDef = createArgsDef.forSampling();
2004
- const schema = allToolNames.length > 0 ? argsDef : {
2005
- type: "object",
2006
- properties: {}
2007
- };
2008
- server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
2009
- const validationResult = validateSchema(args, schema);
2010
- if (!validationResult.valid) {
2011
- return {
2012
- content: [
2013
- {
2014
- type: "text",
2015
- text: CompiledPrompts.errorResponse({
2016
- errorMessage: validationResult.error || "Validation failed"
2017
- })
2018
- }
2019
- ],
2020
- isError: true
2021
- };
2022
- }
2023
- const prompt = typeof args.prompt === "string" ? args.prompt : JSON.stringify(args);
2024
- return executor.execute({
2025
- prompt,
2026
- context: args.context
2027
- });
2028
- });
2029
- return executor;
2030
- }
2031
-
2032
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/mode-ai-acp-plugin.js
2033
- var createAIACPModePlugin = () => ({
2034
- name: "mode-ai-acp",
2035
- version: "1.0.0",
2036
- apply: "ai_acp",
2037
- registerAgentTool: (context2) => {
2038
- const opts = context2.options;
2039
- if (!opts.acpSettings) {
2040
- throw new Error("ai_acp mode requires acpSettings in options");
2041
- }
2042
- registerAIACPTool(context2.server, {
2043
- description: context2.description,
2044
- name: context2.name,
2045
- allToolNames: context2.allToolNames,
2046
- depGroups: context2.depGroups,
2047
- toolNameToDetailList: context2.toolNameToDetailList,
2048
- acpSettings: opts.acpSettings,
2049
- maxSteps: opts.maxSteps,
2050
- tracingEnabled: opts.tracingEnabled
2051
- });
2052
- }
2053
- });
2054
- var mode_ai_acp_plugin_default = createAIACPModePlugin();
2055
-
2056
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/common/schema.js
2057
- var import_json_schema_traverse = __toESM(require("json-schema-traverse"), 1);
2058
-
2059
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/utils/common/env.js
2060
- var import_node_process4 = __toESM(require("node:process"), 1);
2061
- var isSCF = () => Boolean(import_node_process4.default.env.SCF_RUNTIME || import_node_process4.default.env.PROD_SCF);
2062
- if (isSCF()) {
2063
- console.log({
2064
- isSCF: isSCF(),
2065
- SCF_RUNTIME: import_node_process4.default.env.SCF_RUNTIME
2066
- });
2067
- }
2068
-
2069
- // __mcpc__plugin-markdown-loader_latest/node_modules/@jsr/mcpc__core/src/set-up-mcp-compose.js
2070
- var markdownAgentLoader = null;
2071
- function setMarkdownAgentLoader(loader) {
2072
- markdownAgentLoader = loader;
2073
- }
2074
- function isMarkdownFile(path) {
2075
- return path.endsWith(".md") || path.endsWith(".markdown");
2076
- }
2077
-
2078
45
  // __mcpc__plugin-markdown-loader_latest/node_modules/@mcpc/plugin-markdown-loader/src/markdown-loader.js
2079
46
  var import_promises = require("node:fs/promises");
2080
47
 
@@ -4016,10 +1983,13 @@ function parse(content, options = {}) {
4016
1983
 
4017
1984
  // __mcpc__plugin-markdown-loader_latest/node_modules/@mcpc/plugin-markdown-loader/src/markdown-loader.js
4018
1985
  var import_node_path = require("node:path");
4019
- var import_node_process5 = __toESM(require("node:process"), 1);
1986
+ var import_node_process = __toESM(require("node:process"), 1);
1987
+ function isMarkdownFile(path) {
1988
+ return path.endsWith(".md") || path.endsWith(".markdown");
1989
+ }
4020
1990
  function replaceEnvVars(str2) {
4021
1991
  return str2.replace(/\$([A-Za-z_][A-Za-z0-9_]*)(?!\s*\()/g, (match, varName) => {
4022
- const value = import_node_process5.default.env[varName];
1992
+ const value = import_node_process.default.env[varName];
4023
1993
  if (value !== void 0) {
4024
1994
  return value;
4025
1995
  }
@@ -4148,8 +2118,9 @@ function markdownLoaderPlugin() {
4148
2118
  version: "1.0.0",
4149
2119
  enforce: "pre",
4150
2120
  // Run before other plugins
4151
- configureServer: () => {
4152
- setMarkdownAgentLoader(loadMarkdownAgentFile);
2121
+ configureServer: (server) => {
2122
+ server.registerFileLoader(".md", loadMarkdownAgentFile);
2123
+ server.registerFileLoader(".markdown", loadMarkdownAgentFile);
4153
2124
  }
4154
2125
  };
4155
2126
  }
@@ -4165,6 +2136,5 @@ var mod_default = defaultPlugin;
4165
2136
  loadMarkdownAgentFile,
4166
2137
  markdownAgentToComposeDefinition,
4167
2138
  markdownLoaderPlugin,
4168
- parseMarkdownAgent,
4169
- setMarkdownAgentLoader
2139
+ parseMarkdownAgent
4170
2140
  });