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