@mcpc-tech/cli 0.1.23 → 0.1.25

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.
Files changed (3) hide show
  1. package/bin/mcpc.cjs +819 -60
  2. package/bin/mcpc.mjs +819 -60
  3. package/package.json +4 -1
package/bin/mcpc.cjs CHANGED
@@ -5161,17 +5161,17 @@ var Client = class extends Protocol {
5161
5161
  this._cachedToolOutputValidators.clear();
5162
5162
  this._cachedKnownTaskTools.clear();
5163
5163
  this._cachedRequiredTaskTools.clear();
5164
- for (const tool of tools) {
5165
- if (tool.outputSchema) {
5166
- const toolValidator = this._jsonSchemaValidator.getValidator(tool.outputSchema);
5167
- this._cachedToolOutputValidators.set(tool.name, toolValidator);
5164
+ for (const tool2 of tools) {
5165
+ if (tool2.outputSchema) {
5166
+ const toolValidator = this._jsonSchemaValidator.getValidator(tool2.outputSchema);
5167
+ this._cachedToolOutputValidators.set(tool2.name, toolValidator);
5168
5168
  }
5169
- const taskSupport = tool.execution?.taskSupport;
5169
+ const taskSupport = tool2.execution?.taskSupport;
5170
5170
  if (taskSupport === "required" || taskSupport === "optional") {
5171
- this._cachedKnownTaskTools.add(tool.name);
5171
+ this._cachedKnownTaskTools.add(tool2.name);
5172
5172
  }
5173
5173
  if (taskSupport === "required") {
5174
- this._cachedRequiredTaskTools.add(tool.name);
5174
+ this._cachedRequiredTaskTools.add(tool2.name);
5175
5175
  }
5176
5176
  }
5177
5177
  }
@@ -7468,14 +7468,14 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
7468
7468
  acquiredKeys.push(defKey);
7469
7469
  allClients[serverId] = client;
7470
7470
  const { tools } = await client.listTools();
7471
- tools.forEach((tool) => {
7472
- const toolNameWithScope = `${name}.${tool.name}`;
7473
- const internalToolName = tool.name;
7471
+ tools.forEach((tool2) => {
7472
+ const toolNameWithScope = `${name}.${tool2.name}`;
7473
+ const internalToolName = tool2.name;
7474
7474
  const rawToolId = `${serverId}_${internalToolName}`;
7475
7475
  const toolId = sanitizePropertyKey(rawToolId);
7476
7476
  if (filterIn && !filterIn({
7477
7477
  action: internalToolName,
7478
- tool,
7478
+ tool: tool2,
7479
7479
  mcpName: name,
7480
7480
  toolNameWithScope,
7481
7481
  internalToolName,
@@ -7490,7 +7490,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
7490
7490
  timeout: def.toolCallTimeout
7491
7491
  });
7492
7492
  allTools[toolId] = {
7493
- ...tool,
7493
+ ...tool2,
7494
7494
  execute,
7495
7495
  _originalName: toolNameWithScope
7496
7496
  };
@@ -7553,13 +7553,13 @@ var createConfigPlugin = () => ({
7553
7553
  name: "built-in-config",
7554
7554
  version: "1.0.0",
7555
7555
  enforce: "pre",
7556
- transformTool: (tool, context2) => {
7556
+ transformTool: (tool2, context2) => {
7557
7557
  const server = context2.server;
7558
7558
  const config = server.findToolConfig?.(context2.toolName);
7559
7559
  if (config?.description) {
7560
- tool.description = config.description;
7560
+ tool2.description = config.description;
7561
7561
  }
7562
- return tool;
7562
+ return tool2;
7563
7563
  }
7564
7564
  });
7565
7565
  var config_plugin_default = createConfigPlugin();
@@ -7569,10 +7569,10 @@ var createToolNameMappingPlugin = () => ({
7569
7569
  name: "built-in-tool-name-mapping",
7570
7570
  version: "1.0.0",
7571
7571
  enforce: "pre",
7572
- transformTool: (tool, context2) => {
7572
+ transformTool: (tool2, context2) => {
7573
7573
  const server = context2.server;
7574
7574
  const toolName = context2.toolName;
7575
- const originalName = tool._originalName || toolName;
7575
+ const originalName = tool2._originalName || toolName;
7576
7576
  const dotNotation = originalName.replace(/_/g, ".");
7577
7577
  const underscoreNotation = originalName.replace(/\./g, "_");
7578
7578
  if (dotNotation !== originalName && server.toolNameMapping) {
@@ -7584,7 +7584,7 @@ var createToolNameMappingPlugin = () => ({
7584
7584
  if (originalName !== toolName && server.toolNameMapping) {
7585
7585
  server.toolNameMapping.set(originalName, toolName);
7586
7586
  }
7587
- return tool;
7587
+ return tool2;
7588
7588
  }
7589
7589
  });
7590
7590
  var tool_name_mapping_plugin_default = createToolNameMappingPlugin();
@@ -8077,13 +8077,13 @@ var PromptUtils = {
8077
8077
  * Generate tool list for descriptions
8078
8078
  */
8079
8079
  generateToolList: (tools) => {
8080
- return tools.filter((tool) => !tool.hide).map((tool) => `<tool name="${tool.name}"${tool.description ? ` description="${tool.description}"` : ""}/>`).join("\n");
8080
+ return tools.filter((tool2) => !tool2.hide).map((tool2) => `<tool name="${tool2.name}"${tool2.description ? ` description="${tool2.description}"` : ""}/>`).join("\n");
8081
8081
  },
8082
8082
  /**
8083
8083
  * Generate hidden tool list for descriptions
8084
8084
  */
8085
8085
  generateHiddenToolList: (tools) => {
8086
- return tools.filter((tool) => tool.hide).map((tool) => `<tool name="${tool.name}" hide/>`).join("\n");
8086
+ return tools.filter((tool2) => tool2.hide).map((tool2) => `<tool name="${tool2.name}" hide/>`).join("\n");
8087
8087
  },
8088
8088
  /**
8089
8089
  * Format workflow steps for display
@@ -9868,12 +9868,12 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
9868
9868
  }
9869
9869
  buildDepGroups() {
9870
9870
  const depGroups = {};
9871
- this.toolNameToDetailList.forEach(([toolName, tool]) => {
9872
- if (tool?.inputSchema) {
9871
+ this.toolNameToDetailList.forEach(([toolName, tool2]) => {
9872
+ if (tool2?.inputSchema) {
9873
9873
  depGroups[toolName] = {
9874
9874
  type: "object",
9875
- description: tool.description || `Tool: ${toolName}`,
9876
- ...tool.inputSchema
9875
+ description: tool2.description || `Tool: ${toolName}`,
9876
+ ...tool2.inputSchema
9877
9877
  };
9878
9878
  } else {
9879
9879
  const toolSchema = this.server.getHiddenToolSchema(toolName);
@@ -9930,10 +9930,10 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
9930
9930
  }
9931
9931
  buildSystemPrompt(userRequest, agenticSchema, context2) {
9932
9932
  const toolList = this.allToolNames.map((name) => {
9933
- const tool = this.toolNameToDetailList.find(([toolName]) => toolName === name);
9933
+ const tool2 = this.toolNameToDetailList.find(([toolName]) => toolName === name);
9934
9934
  const toolSchema = this.server.getHiddenToolSchema(name);
9935
- if (tool && tool[1]) {
9936
- return `- ${name}: ${tool[1].description || `Tool: ${name}`}`;
9935
+ if (tool2 && tool2[1]) {
9936
+ return `- ${name}: ${tool2[1].description || `Tool: ${name}`}`;
9937
9937
  } else if (toolSchema) {
9938
9938
  return `- ${name}: ${toolSchema.description}`;
9939
9939
  }
@@ -9960,7 +9960,7 @@ ${JSON.stringify(context2, null, 2)}`;
9960
9960
  ## Current Task
9961
9961
  You will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
9962
9962
 
9963
- When you need to use a tool, specify the tool name in 'action' and provide tool-specific parameters as additional properties.`;
9963
+ When you need to use a tool, specify the tool name in 'useTool' and provide tool-specific parameters as additional properties.`;
9964
9964
  return this.formatPromptForMode({
9965
9965
  prompt: basePrompt + taskPrompt,
9966
9966
  schema: agenticSchema
@@ -10140,6 +10140,763 @@ var createWorkflowSamplingModePlugin = () => ({
10140
10140
  });
10141
10141
  var mode_workflow_sampling_plugin_default = createWorkflowSamplingModePlugin();
10142
10142
 
10143
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/utils.js
10144
+ function convertAISDKToMCPMessages(prompt) {
10145
+ const messages = [];
10146
+ for (const msg of prompt) {
10147
+ if (msg.role === "system") continue;
10148
+ const role = msg.role === "assistant" ? "assistant" : "user";
10149
+ const textParts = msg.content.filter((c) => c.type === "text");
10150
+ const toolCalls = msg.content.filter((c) => c.type === "tool-call");
10151
+ const toolResults = msg.content.filter((c) => c.type === "tool-result");
10152
+ const parts = [];
10153
+ if (textParts.length > 0) {
10154
+ parts.push(textParts.map((c) => c.text).join("\n"));
10155
+ }
10156
+ if (toolCalls.length > 0) {
10157
+ const calls = toolCalls.map((c) => {
10158
+ const call = c;
10159
+ const toolArgs = call.args ?? call.input ?? {};
10160
+ return `<use_tool tool="${call.toolName}">
10161
+ ${JSON.stringify(toolArgs)}
10162
+ </use_tool>`;
10163
+ });
10164
+ parts.push(calls.join("\n"));
10165
+ }
10166
+ if (toolResults.length > 0) {
10167
+ const results = toolResults.map((c) => {
10168
+ const result = c;
10169
+ const resultValue = result.result ?? result.output ?? "undefined";
10170
+ const output = JSON.stringify(resultValue);
10171
+ return `Tool "${result.toolName}" result:
10172
+ ${output}`;
10173
+ });
10174
+ parts.push(results.join("\n\n"));
10175
+ }
10176
+ const text = parts.join("\n\n");
10177
+ if (text) {
10178
+ messages.push({
10179
+ role,
10180
+ content: {
10181
+ type: "text",
10182
+ text
10183
+ }
10184
+ });
10185
+ }
10186
+ }
10187
+ return messages;
10188
+ }
10189
+ function convertMCPStopReasonToAISDK(stopReason) {
10190
+ if (stopReason === "endTurn" || stopReason === "stopSequence") {
10191
+ return "stop";
10192
+ }
10193
+ if (stopReason === "maxTokens") return "length";
10194
+ return stopReason ?? "unknown";
10195
+ }
10196
+
10197
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/language-model.js
10198
+ var MCPSamplingLanguageModel = class {
10199
+ specificationVersion = "v2";
10200
+ provider;
10201
+ modelId;
10202
+ supportedUrls = {};
10203
+ server;
10204
+ modelPreferences;
10205
+ constructor(config) {
10206
+ this.server = config.server;
10207
+ this.modelId = "";
10208
+ this.provider = "mcp-client";
10209
+ this.modelPreferences = config.modelPreferences;
10210
+ }
10211
+ /**
10212
+ * Generate a response using MCP's createMessage capability
10213
+ */
10214
+ async doGenerate(options) {
10215
+ const messages = this.convertMessages(options.prompt);
10216
+ let systemPrompt;
10217
+ for (const msg of options.prompt) {
10218
+ if (msg.role === "system") {
10219
+ systemPrompt = msg.content;
10220
+ break;
10221
+ }
10222
+ }
10223
+ const useNativeTools = this.supportsSamplingTools();
10224
+ systemPrompt = this.injectResponseFormatInstructions(systemPrompt, options.responseFormat, useNativeTools);
10225
+ systemPrompt = this.injectToolInstructions(systemPrompt, options.tools, useNativeTools);
10226
+ const createMessageParams = {
10227
+ systemPrompt,
10228
+ messages,
10229
+ maxTokens: options.maxOutputTokens ?? 55e3,
10230
+ modelPreferences: this.modelPreferences
10231
+ };
10232
+ if (useNativeTools && options.tools && options.tools.length > 0) {
10233
+ createMessageParams.tools = this.convertAISDKToolsToMCP(options.tools);
10234
+ createMessageParams.toolChoice = {
10235
+ mode: "auto"
10236
+ };
10237
+ }
10238
+ const result = await this.server.createMessage(createMessageParams);
10239
+ const content = [];
10240
+ if (useNativeTools) {
10241
+ const contentArray = Array.isArray(result.content) ? result.content : [
10242
+ result.content
10243
+ ];
10244
+ for (const block of contentArray) {
10245
+ if (block.type === "text" && "text" in block) {
10246
+ content.push({
10247
+ type: "text",
10248
+ text: block.text
10249
+ });
10250
+ } else if (block.type === "tool_use" && "id" in block && "name" in block) {
10251
+ const toolInput = block.input || {};
10252
+ content.push({
10253
+ type: "tool-call",
10254
+ toolCallId: block.id,
10255
+ toolName: block.name,
10256
+ input: JSON.stringify(toolInput)
10257
+ });
10258
+ }
10259
+ }
10260
+ } else {
10261
+ if (result.content.type === "text" && result.content.text) {
10262
+ const { text, toolCalls } = this.extractToolCalls(result.content.text, options.tools);
10263
+ if (text.trim()) {
10264
+ const textContent = {
10265
+ type: "text",
10266
+ text
10267
+ };
10268
+ content.push(textContent);
10269
+ }
10270
+ content.push(...toolCalls);
10271
+ }
10272
+ }
10273
+ const finishReason = this.mapStopReason(result.stopReason);
10274
+ return {
10275
+ content,
10276
+ finishReason,
10277
+ usage: {
10278
+ inputTokens: void 0,
10279
+ outputTokens: void 0,
10280
+ totalTokens: 0
10281
+ },
10282
+ request: {
10283
+ body: JSON.stringify({
10284
+ systemPrompt,
10285
+ messages
10286
+ })
10287
+ },
10288
+ response: {
10289
+ modelId: result.model
10290
+ },
10291
+ warnings: []
10292
+ };
10293
+ }
10294
+ /**
10295
+ * Stream a response using MCP's createMessage capability
10296
+ *
10297
+ * Since MCP doesn't support native streaming, we generate the full response
10298
+ * and emit it as stream events following AI SDK's protocol.
10299
+ */
10300
+ async doStream(options) {
10301
+ const result = await this.doGenerate(options);
10302
+ const stream = new ReadableStream({
10303
+ start(controller) {
10304
+ if (result.response?.modelId) {
10305
+ controller.enqueue({
10306
+ type: "response-metadata",
10307
+ modelId: result.response.modelId,
10308
+ ...result.response.headers && {
10309
+ headers: result.response.headers
10310
+ }
10311
+ });
10312
+ }
10313
+ let textIndex = 0;
10314
+ for (const part of result.content) {
10315
+ if (part.type === "text") {
10316
+ const id = `text-${++textIndex}`;
10317
+ controller.enqueue({
10318
+ type: "text-start",
10319
+ id
10320
+ });
10321
+ controller.enqueue({
10322
+ type: "text-delta",
10323
+ id,
10324
+ delta: part.text
10325
+ });
10326
+ controller.enqueue({
10327
+ type: "text-end",
10328
+ id
10329
+ });
10330
+ } else if (part.type === "tool-call") {
10331
+ controller.enqueue({
10332
+ type: "tool-call",
10333
+ toolCallId: part.toolCallId,
10334
+ toolName: part.toolName,
10335
+ input: part.input
10336
+ });
10337
+ }
10338
+ }
10339
+ controller.enqueue({
10340
+ type: "finish",
10341
+ finishReason: result.finishReason,
10342
+ usage: result.usage
10343
+ });
10344
+ controller.close();
10345
+ }
10346
+ });
10347
+ return {
10348
+ stream,
10349
+ request: result.request,
10350
+ warnings: result.warnings
10351
+ };
10352
+ }
10353
+ /**
10354
+ * Convert AI SDK messages to MCP sampling format
10355
+ */
10356
+ convertMessages(prompt) {
10357
+ return convertAISDKToMCPMessages(prompt);
10358
+ }
10359
+ /**
10360
+ * Map MCP stop reason to AI SDK finish reason
10361
+ */
10362
+ mapStopReason(stopReason) {
10363
+ return convertMCPStopReasonToAISDK(stopReason);
10364
+ }
10365
+ /**
10366
+ * Check if client supports native tool use in sampling
10367
+ */
10368
+ supportsSamplingTools() {
10369
+ const capabilities = this.server.getClientCapabilities();
10370
+ return !!capabilities?.sampling?.tools;
10371
+ }
10372
+ /**
10373
+ * Convert AI SDK tools to MCP Tool format
10374
+ */
10375
+ convertAISDKToolsToMCP(tools) {
10376
+ if (!tools || tools.length === 0) return [];
10377
+ return tools.filter((tool2) => tool2.type === "function").map((tool2) => {
10378
+ const toolAny = tool2;
10379
+ return {
10380
+ name: tool2.name,
10381
+ description: toolAny.description || `Tool: ${tool2.name}`,
10382
+ inputSchema: {
10383
+ type: "object",
10384
+ ...toolAny.inputSchema || toolAny.parameters
10385
+ }
10386
+ };
10387
+ });
10388
+ }
10389
+ /**
10390
+ * Inject response format instructions into system prompt
10391
+ *
10392
+ * Only injects formatting instructions in JSON fallback mode.
10393
+ * In native tools mode, structured output is handled by the provider.
10394
+ */
10395
+ injectResponseFormatInstructions(systemPrompt, responseFormat, useNativeTools) {
10396
+ if (!responseFormat) {
10397
+ return systemPrompt;
10398
+ }
10399
+ if (useNativeTools) {
10400
+ return systemPrompt;
10401
+ }
10402
+ let enhanced = systemPrompt || "";
10403
+ if (responseFormat.type === "json") {
10404
+ const jsonPrompt = `
10405
+
10406
+ IMPORTANT: You MUST respond with valid JSON only. Do not include any text before or after the JSON.
10407
+ - Your response must be a valid JSON object
10408
+ - Do not wrap the JSON in markdown code blocks
10409
+ - Do not include explanations or comments
10410
+ - Ensure all JSON is properly formatted and parseable`;
10411
+ enhanced = enhanced ? `${enhanced}${jsonPrompt}` : jsonPrompt.trim();
10412
+ if (responseFormat.schema) {
10413
+ const schemaInfo = `
10414
+ - Follow this JSON schema structure: ${JSON.stringify(responseFormat.schema)}`;
10415
+ enhanced += schemaInfo;
10416
+ }
10417
+ }
10418
+ return enhanced || void 0;
10419
+ }
10420
+ /**
10421
+ * Inject tool definitions into system prompt
10422
+ *
10423
+ * WORKAROUND: MCP sampling currently doesn't support native tools parameter.
10424
+ * This method injects tool descriptions and usage instructions into the system prompt.
10425
+ *
10426
+ * TODO: Remove this workaround when MCP protocol adds native support for:
10427
+ * - tools parameter in createMessage
10428
+ * - Tool calling and function execution
10429
+ * - Structured tool responses
10430
+ */
10431
+ injectToolInstructions(systemPrompt, tools, useNativeTools) {
10432
+ if (!tools || tools.length === 0) {
10433
+ return systemPrompt;
10434
+ }
10435
+ if (useNativeTools) {
10436
+ return systemPrompt;
10437
+ }
10438
+ let enhanced = systemPrompt || "";
10439
+ const toolsPrompt = `
10440
+
10441
+ AVAILABLE TOOLS:
10442
+ You have access to the following tools. To use a tool, respond with this XML format:
10443
+ <use_tool tool="tool_name">
10444
+ {"param1": "value1", "param2": "value2"}
10445
+ </use_tool>
10446
+
10447
+ Follow the JSON schema definition for each tool's parameters.
10448
+ You can use multiple tools in one response. You can include text before tool calls, but do NOT include text after tool calls - wait for the tool results first.
10449
+
10450
+ Tools:`;
10451
+ const toolDescriptions = tools.map((tool2) => {
10452
+ if (tool2.type === "function") {
10453
+ const toolAny = tool2;
10454
+ const description = toolAny.description || "No description provided";
10455
+ const schema = toolAny.inputSchema || toolAny.parameters;
10456
+ const params = schema ? `
10457
+ JSON Schema: ${JSON.stringify(schema, null, 2)}` : "";
10458
+ return `
10459
+ - ${tool2.name}: ${description}${params}`;
10460
+ } else if (tool2.type === "provider-defined") {
10461
+ return `
10462
+ - ${tool2.name}: ${tool2.id || "No description provided"}`;
10463
+ }
10464
+ return "";
10465
+ }).filter(Boolean).join("");
10466
+ enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}` : `${toolsPrompt}${toolDescriptions}`.trim();
10467
+ return enhanced || void 0;
10468
+ }
10469
+ /**
10470
+ * Extract tool calls from LLM response text
10471
+ *
10472
+ * Parses XML-style tool call tags from the response:
10473
+ * <use_tool tool="tool_name">{"arg": "value"}</use_tool>
10474
+ */
10475
+ extractToolCalls(responseText, tools) {
10476
+ if (!tools || tools.length === 0) {
10477
+ return {
10478
+ text: responseText,
10479
+ toolCalls: []
10480
+ };
10481
+ }
10482
+ const toolCalls = [];
10483
+ const toolCallRegex = /<use_tool\s+tool="([^"]+)">([\s\S]*?)<\/use_tool>/g;
10484
+ let match;
10485
+ let lastIndex = 0;
10486
+ const textParts = [];
10487
+ let callIndex = 0;
10488
+ while ((match = toolCallRegex.exec(responseText)) !== null) {
10489
+ textParts.push(responseText.slice(lastIndex, match.index));
10490
+ const toolName = match[1];
10491
+ const argsText = match[2].trim?.();
10492
+ toolCalls.push({
10493
+ type: "tool-call",
10494
+ toolCallId: `call_${Date.now()}_${callIndex++}`,
10495
+ toolName,
10496
+ input: argsText
10497
+ });
10498
+ lastIndex = match.index + match[0].length;
10499
+ }
10500
+ textParts.push(responseText.slice(lastIndex));
10501
+ const text = textParts.join("").trim();
10502
+ return {
10503
+ text,
10504
+ toolCalls
10505
+ };
10506
+ }
10507
+ };
10508
+
10509
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/provider.js
10510
+ var MCPSamplingProvider = class {
10511
+ config;
10512
+ constructor(config) {
10513
+ this.config = config;
10514
+ }
10515
+ /**
10516
+ * Create a language model instance for a specific MCP tool/agent
10517
+ *
10518
+ * @param options - Optional configuration overrides
10519
+ * @returns A LanguageModelV2 instance
10520
+ */
10521
+ languageModel(options) {
10522
+ return new MCPSamplingLanguageModel({
10523
+ server: this.config.server,
10524
+ modelPreferences: options?.modelPreferences
10525
+ });
10526
+ }
10527
+ /**
10528
+ * Shorthand for creating a language model
10529
+ */
10530
+ call(options) {
10531
+ return this.languageModel(options);
10532
+ }
10533
+ };
10534
+
10535
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/base-ai-executor.js
10536
+ var import_api2 = require("@opentelemetry/api");
10537
+ var import_ai = require("ai");
10538
+ var BaseAIExecutor = class {
10539
+ config;
10540
+ tracer;
10541
+ logger;
10542
+ constructor(config, server) {
10543
+ this.config = {
10544
+ maxSteps: 50,
10545
+ tracingEnabled: true,
10546
+ ...config
10547
+ };
10548
+ this.tracer = import_api2.trace.getTracer(`mcpc.ai.${config.name}`);
10549
+ this.logger = createLogger(`mcpc.ai.${config.name}`, server);
10550
+ }
10551
+ execute(args) {
10552
+ if (this.config.tracingEnabled) {
10553
+ return this.executeWithTracing(args);
10554
+ }
10555
+ return this.executeCore(args);
10556
+ }
10557
+ executeWithTracing(args) {
10558
+ return this.tracer.startActiveSpan(`mcpc.ai.${this.config.name}`, async (span) => {
10559
+ try {
10560
+ span.setAttributes({
10561
+ "mcpc.executor": this.config.name,
10562
+ "mcpc.type": this.getExecutorType()
10563
+ });
10564
+ const result = await this.executeCore(args, span);
10565
+ span.setAttributes({
10566
+ "mcpc.error": !!result.isError
10567
+ });
10568
+ return result;
10569
+ } catch (error) {
10570
+ span.recordException(error);
10571
+ throw error;
10572
+ } finally {
10573
+ span.end();
10574
+ }
10575
+ });
10576
+ }
10577
+ async executeCore(args, span) {
10578
+ try {
10579
+ const result = (0, import_ai.streamText)({
10580
+ model: this.getModel(),
10581
+ system: this.buildSystemPrompt(args),
10582
+ messages: [
10583
+ {
10584
+ role: "user",
10585
+ content: args.userRequest
10586
+ }
10587
+ ],
10588
+ tools: this.buildTools(),
10589
+ stopWhen: (0, import_ai.stepCountIs)(this.config.maxSteps),
10590
+ experimental_telemetry: this.config.tracingEnabled ? {
10591
+ isEnabled: true,
10592
+ functionId: `mcpc.${this.config.name}`,
10593
+ tracer: this.tracer
10594
+ } : void 0,
10595
+ onStepFinish: (step) => {
10596
+ if (span) {
10597
+ span.addEvent("step", {
10598
+ tools: step.toolCalls?.length ?? 0,
10599
+ reason: step.finishReason ?? ""
10600
+ });
10601
+ }
10602
+ }
10603
+ });
10604
+ return {
10605
+ content: [
10606
+ {
10607
+ type: "text",
10608
+ text: await result.text || `Completed in ${(await result.steps)?.length ?? "unknown"} step(s).`
10609
+ }
10610
+ ],
10611
+ isError: false
10612
+ };
10613
+ } catch (error) {
10614
+ this.logger.error({
10615
+ message: "Execution error",
10616
+ error
10617
+ });
10618
+ return {
10619
+ content: [
10620
+ {
10621
+ type: "text",
10622
+ text: `Error: ${error instanceof Error ? error.message : String(error)}`
10623
+ }
10624
+ ],
10625
+ isError: true
10626
+ };
10627
+ }
10628
+ }
10629
+ buildSystemPrompt(args) {
10630
+ return `Agent \`${this.config.name}\` that completes tasks by calling tools.
10631
+
10632
+ <manual>
10633
+ ${this.config.description}
10634
+ </manual>
10635
+
10636
+ <rules>
10637
+ ${this.getRules()}
10638
+ </rules>
10639
+
10640
+ <tools>
10641
+ ${this.getToolListDescription()}
10642
+ </tools>${args.context ? this.formatContext(args.context) : ""}`;
10643
+ }
10644
+ getRules() {
10645
+ return `1. Use tools to complete the user's request
10646
+ 2. Review results after each tool call
10647
+ 3. Adapt your approach based on outcomes
10648
+ 4. Continue until task is complete
10649
+ 5. When complete, provide a summary WITHOUT calling more tools`;
10650
+ }
10651
+ getToolListDescription() {
10652
+ return "Tools will be provided by AI SDK";
10653
+ }
10654
+ formatContext(context2) {
10655
+ return `
10656
+
10657
+ <context>
10658
+ ${JSON.stringify(context2, null, 2)}
10659
+ </context>`;
10660
+ }
10661
+ convertToAISDKTool(name, toolDetail, execute) {
10662
+ return (0, import_ai.tool)({
10663
+ description: toolDetail.description || `Tool: ${name}`,
10664
+ inputSchema: (0, import_ai.jsonSchema)(toolDetail.inputSchema || {
10665
+ type: "object"
10666
+ }),
10667
+ execute
10668
+ });
10669
+ }
10670
+ };
10671
+
10672
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-sampling-executor.js
10673
+ var AISamplingExecutor = class extends BaseAIExecutor {
10674
+ server;
10675
+ tools;
10676
+ providerOptions;
10677
+ model = null;
10678
+ constructor(config) {
10679
+ super(config, "callTool" in config.server ? config.server : void 0);
10680
+ this.server = config.server;
10681
+ this.tools = config.tools;
10682
+ this.providerOptions = config.providerOptions;
10683
+ }
10684
+ initProvider() {
10685
+ if (!this.model) {
10686
+ const provider = new MCPSamplingProvider({
10687
+ server: this.server
10688
+ });
10689
+ this.model = provider.languageModel(this.providerOptions);
10690
+ }
10691
+ return this.model;
10692
+ }
10693
+ getModel() {
10694
+ if (!this.model) throw new Error("Model not initialized");
10695
+ return this.model;
10696
+ }
10697
+ getExecutorType() {
10698
+ return "mcp";
10699
+ }
10700
+ getToolListDescription() {
10701
+ return this.tools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
10702
+ }
10703
+ buildTools() {
10704
+ const aiTools = {};
10705
+ for (const [name, detail] of this.tools) {
10706
+ aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
10707
+ const result = await this.callTool(name, input);
10708
+ return this.formatResult(result);
10709
+ });
10710
+ }
10711
+ return aiTools;
10712
+ }
10713
+ async callTool(name, input) {
10714
+ if ("callTool" in this.server) {
10715
+ return await this.server.callTool(name, input);
10716
+ }
10717
+ const detail = this.tools.find(([n]) => n === name)?.[1];
10718
+ if (detail?.execute) return await detail.execute(input);
10719
+ throw new Error(`Cannot call tool "${name}"`);
10720
+ }
10721
+ formatResult(result) {
10722
+ const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
10723
+ return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
10724
+ }
10725
+ execute(args) {
10726
+ this.initProvider();
10727
+ return super.execute(args);
10728
+ }
10729
+ };
10730
+
10731
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-sampling-registrar.js
10732
+ function registerAISamplingTool(server, params) {
10733
+ const { name, description, allToolNames, depGroups, toolNameToDetailList, providerOptions, maxSteps = 50, tracingEnabled = false } = params;
10734
+ const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
10735
+ const executor = new AISamplingExecutor({
10736
+ name,
10737
+ description,
10738
+ server,
10739
+ tools: toolNameToDetailList,
10740
+ providerOptions,
10741
+ maxSteps,
10742
+ tracingEnabled
10743
+ });
10744
+ const toolDescription = CompiledPrompts.samplingToolDescription({
10745
+ toolName: name,
10746
+ description,
10747
+ toolList: allToolNames.map((n) => `- ${n}`).join("\n")
10748
+ });
10749
+ const argsDef = createArgsDef.forSampling();
10750
+ const schema = allToolNames.length > 0 ? argsDef : {
10751
+ type: "object",
10752
+ properties: {}
10753
+ };
10754
+ server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
10755
+ const userRequest = typeof args.userRequest === "string" ? args.userRequest : JSON.stringify(args);
10756
+ return executor.execute({
10757
+ userRequest,
10758
+ context: args.context
10759
+ });
10760
+ });
10761
+ }
10762
+
10763
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/mode-ai-sampling-plugin.js
10764
+ var createAISamplingModePlugin = () => ({
10765
+ name: "mode-ai-sampling",
10766
+ version: "1.0.0",
10767
+ apply: "ai_sampling",
10768
+ registerAgentTool: (context2) => {
10769
+ const opts = context2.options;
10770
+ registerAISamplingTool(context2.server, {
10771
+ description: context2.description,
10772
+ name: context2.name,
10773
+ allToolNames: context2.allToolNames,
10774
+ depGroups: context2.depGroups,
10775
+ toolNameToDetailList: context2.toolNameToDetailList,
10776
+ providerOptions: opts.providerOptions,
10777
+ maxSteps: opts.maxSteps,
10778
+ tracingEnabled: opts.tracingEnabled
10779
+ });
10780
+ }
10781
+ });
10782
+ var mode_ai_sampling_plugin_default = createAISamplingModePlugin();
10783
+
10784
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-acp-executor.js
10785
+ var import_acp_ai_provider = require("@mcpc-tech/acp-ai-provider");
10786
+ var AIACPExecutor = class extends BaseAIExecutor {
10787
+ acpSettings;
10788
+ clientTools;
10789
+ provider = null;
10790
+ model = null;
10791
+ constructor(config) {
10792
+ super(config);
10793
+ this.acpSettings = config.acpSettings;
10794
+ this.clientTools = config.clientTools ?? [];
10795
+ }
10796
+ initProvider() {
10797
+ if (!this.model) {
10798
+ this.provider = (0, import_acp_ai_provider.createACPProvider)(this.acpSettings);
10799
+ this.model = this.provider.languageModel();
10800
+ }
10801
+ return this.model;
10802
+ }
10803
+ getModel() {
10804
+ if (!this.model) throw new Error("Model not initialized");
10805
+ return this.model;
10806
+ }
10807
+ getExecutorType() {
10808
+ return "acp";
10809
+ }
10810
+ getToolListDescription() {
10811
+ if (this.clientTools.length === 0) {
10812
+ return "Tools will be provided by AI SDK";
10813
+ }
10814
+ return this.clientTools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
10815
+ }
10816
+ buildTools() {
10817
+ const aiTools = {};
10818
+ for (const [name, detail] of this.clientTools) {
10819
+ if (!detail.execute) continue;
10820
+ aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
10821
+ const result = await detail.execute(input);
10822
+ return this.formatResult(result);
10823
+ });
10824
+ }
10825
+ return aiTools;
10826
+ }
10827
+ formatResult(result) {
10828
+ const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
10829
+ return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
10830
+ }
10831
+ execute(args) {
10832
+ this.initProvider();
10833
+ return super.execute(args);
10834
+ }
10835
+ cleanup() {
10836
+ if (this.provider && typeof this.provider.cleanup === "function") {
10837
+ this.provider.cleanup();
10838
+ }
10839
+ this.model = null;
10840
+ this.provider = null;
10841
+ }
10842
+ };
10843
+
10844
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/executors/ai/ai-acp-registrar.js
10845
+ function registerAIACPTool(server, params) {
10846
+ const { name, description, allToolNames, depGroups, acpSettings, clientTools = [], maxSteps = 50, tracingEnabled = false } = params;
10847
+ const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
10848
+ const executor = new AIACPExecutor({
10849
+ name,
10850
+ description,
10851
+ acpSettings,
10852
+ clientTools,
10853
+ maxSteps,
10854
+ tracingEnabled
10855
+ });
10856
+ const toolDescription = CompiledPrompts.samplingToolDescription({
10857
+ toolName: name,
10858
+ description,
10859
+ toolList: allToolNames.length > 0 ? allToolNames.map((n) => `- ${n}`).join("\n") : "Agent has its own tools"
10860
+ });
10861
+ const argsDef = createArgsDef.forSampling();
10862
+ const schema = allToolNames.length > 0 ? argsDef : {
10863
+ type: "object",
10864
+ properties: {}
10865
+ };
10866
+ server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
10867
+ const userRequest = typeof args.userRequest === "string" ? args.userRequest : JSON.stringify(args);
10868
+ return executor.execute({
10869
+ userRequest,
10870
+ context: args.context
10871
+ });
10872
+ });
10873
+ return executor;
10874
+ }
10875
+
10876
+ // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/mode-ai-acp-plugin.js
10877
+ var createAIACPModePlugin = () => ({
10878
+ name: "mode-ai-acp",
10879
+ version: "1.0.0",
10880
+ apply: "ai_acp",
10881
+ registerAgentTool: (context2) => {
10882
+ const opts = context2.options;
10883
+ if (!opts.acpSettings) {
10884
+ throw new Error("ai_acp mode requires acpSettings in options");
10885
+ }
10886
+ registerAIACPTool(context2.server, {
10887
+ description: context2.description,
10888
+ name: context2.name,
10889
+ allToolNames: context2.allToolNames,
10890
+ depGroups: context2.depGroups,
10891
+ acpSettings: opts.acpSettings,
10892
+ clientTools: opts.clientTools,
10893
+ maxSteps: opts.maxSteps,
10894
+ tracingEnabled: opts.tracingEnabled
10895
+ });
10896
+ }
10897
+ });
10898
+ var mode_ai_acp_plugin_default = createAIACPModePlugin();
10899
+
10143
10900
  // __mcpc__cli_latest/node_modules/@jsr/mcpc__core/src/plugins/built-in/index.js
10144
10901
  function getBuiltInPlugins() {
10145
10902
  return [
@@ -10149,6 +10906,8 @@ function getBuiltInPlugins() {
10149
10906
  mode_workflow_plugin_default,
10150
10907
  mode_agentic_sampling_plugin_default,
10151
10908
  mode_workflow_sampling_plugin_default,
10909
+ mode_ai_sampling_plugin_default,
10910
+ mode_ai_acp_plugin_default,
10152
10911
  logging_plugin_default
10153
10912
  ];
10154
10913
  }
@@ -10437,13 +11196,13 @@ var PluginManager = class {
10437
11196
  /**
10438
11197
  * Apply transformTool hooks to a tool during composition
10439
11198
  */
10440
- async applyTransformToolHooks(tool, context2) {
11199
+ async applyTransformToolHooks(tool2, context2) {
10441
11200
  const transformPlugins = this.plugins.filter((p2) => p2.transformTool && shouldApplyPlugin(p2, context2.mode));
10442
11201
  if (transformPlugins.length === 0) {
10443
- return tool;
11202
+ return tool2;
10444
11203
  }
10445
11204
  const sortedPlugins = sortPluginsByOrder(transformPlugins);
10446
- let currentTool = tool;
11205
+ let currentTool = tool2;
10447
11206
  for (const plugin of sortedPlugins) {
10448
11207
  if (plugin.transformTool) {
10449
11208
  try {
@@ -10691,12 +11450,12 @@ var ToolManager = class {
10691
11450
  * Get tool schema if it's hidden (for internal access)
10692
11451
  */
10693
11452
  getHiddenToolSchema(name) {
10694
- const tool = this.toolRegistry.get(name);
11453
+ const tool2 = this.toolRegistry.get(name);
10695
11454
  const config = this.toolConfigs.get(name);
10696
- if (tool && config?.visibility?.hidden && tool.schema) {
11455
+ if (tool2 && config?.visibility?.hidden && tool2.schema) {
10697
11456
  return {
10698
- description: tool.description,
10699
- schema: tool.schema
11457
+ description: tool2.description,
11458
+ schema: tool2.schema
10700
11459
  };
10701
11460
  }
10702
11461
  return void 0;
@@ -10725,18 +11484,18 @@ var ToolManager = class {
10725
11484
  */
10726
11485
  getRegisteredToolsAsComposed() {
10727
11486
  const composedTools = {};
10728
- for (const [name, tool] of this.toolRegistry.entries()) {
11487
+ for (const [name, tool2] of this.toolRegistry.entries()) {
10729
11488
  if (this.toolConfigs.get(name)?.visibility?.public === true) {
10730
11489
  continue;
10731
11490
  }
10732
11491
  composedTools[name] = {
10733
11492
  name,
10734
- description: tool.description,
10735
- inputSchema: jsonSchema(tool.schema || {
11493
+ description: tool2.description,
11494
+ inputSchema: jsonSchema(tool2.schema || {
10736
11495
  type: "object",
10737
11496
  properties: {}
10738
11497
  }),
10739
- execute: tool.callback
11498
+ execute: tool2.callback
10740
11499
  };
10741
11500
  }
10742
11501
  return composedTools;
@@ -10806,18 +11565,18 @@ async function processToolsWithPlugins(server, _externalTools, mode) {
10806
11565
  function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicToolNames, server) {
10807
11566
  const depGroups = {};
10808
11567
  const toolManager = server.toolManager;
10809
- toolNameToDetailList.forEach(([toolName, tool]) => {
11568
+ toolNameToDetailList.forEach(([toolName, tool2]) => {
10810
11569
  const resolvedName = toolManager.resolveToolName(toolName);
10811
11570
  if (hiddenToolNames.includes(resolvedName ?? "") || publicToolNames.includes(resolvedName ?? "")) {
10812
11571
  return;
10813
11572
  }
10814
- if (!tool) {
11573
+ if (!tool2) {
10815
11574
  const allToolNames = [
10816
11575
  ...toolNameToDetailList.map(([n]) => n)
10817
11576
  ];
10818
11577
  throw new Error(`Action ${toolName} not found, available action list: ${allToolNames.join(", ")}`);
10819
11578
  }
10820
- const baseSchema = tool.inputSchema.jsonSchema ?? tool.inputSchema ?? {
11579
+ const baseSchema = tool2.inputSchema.jsonSchema ?? tool2.inputSchema ?? {
10821
11580
  type: "object",
10822
11581
  properties: {},
10823
11582
  required: []
@@ -10828,7 +11587,7 @@ function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicTool
10828
11587
  const sanitizedKey = sanitizePropertyKey(toolName);
10829
11588
  depGroups[sanitizedKey] = {
10830
11589
  type: "object",
10831
- description: tool.description,
11590
+ description: tool2.description,
10832
11591
  properties: updatedProperties,
10833
11592
  required: [
10834
11593
  ...baseRequired
@@ -11104,9 +11863,9 @@ var ComposableMCPServer = class extends Server {
11104
11863
  const requestedToolNames = /* @__PURE__ */ new Set();
11105
11864
  const availableToolNames = /* @__PURE__ */ new Set();
11106
11865
  const allPlaceholderUsages = [];
11107
- tagToResults.tool.forEach((tool) => {
11108
- if (tool.attribs.name) {
11109
- const originalName = tool.attribs.name;
11866
+ tagToResults.tool.forEach((tool2) => {
11867
+ if (tool2.attribs.name) {
11868
+ const originalName = tool2.attribs.name;
11110
11869
  const toolName = sanitizePropertyKey(originalName);
11111
11870
  if (toolName.endsWith(`_${ALL_TOOLS_PLACEHOLDER2}`) || toolName === ALL_TOOLS_PLACEHOLDER2) {
11112
11871
  allPlaceholderUsages.push(originalName);
@@ -11132,24 +11891,24 @@ var ComposableMCPServer = class extends Server {
11132
11891
  }
11133
11892
  return true;
11134
11893
  }
11135
- return tagToResults.tool.find((tool) => {
11136
- const selectAll = tool.attribs.name === `${mcpName}.${ALL_TOOLS_PLACEHOLDER2}` || tool.attribs.name === `${mcpName}`;
11894
+ return tagToResults.tool.find((tool2) => {
11895
+ const selectAll = tool2.attribs.name === `${mcpName}.${ALL_TOOLS_PLACEHOLDER2}` || tool2.attribs.name === `${mcpName}`;
11137
11896
  if (selectAll) {
11138
11897
  return true;
11139
11898
  }
11140
- return tool.attribs.name === toolNameWithScope || tool.attribs.name === toolId;
11899
+ return tool2.attribs.name === toolNameWithScope || tool2.attribs.name === toolId;
11141
11900
  });
11142
11901
  });
11143
- Object.entries(tools).forEach(([toolId, tool]) => {
11144
- this.toolManager.registerTool(toolId, tool.description || "", tool.inputSchema, tool.execute);
11902
+ Object.entries(tools).forEach(([toolId, tool2]) => {
11903
+ this.toolManager.registerTool(toolId, tool2.description || "", tool2.inputSchema, tool2.execute);
11145
11904
  });
11146
11905
  const registeredTools = this.toolManager.getRegisteredToolsAsComposed();
11147
11906
  const allTools = {
11148
11907
  ...tools
11149
11908
  };
11150
- Object.entries(registeredTools).forEach(([toolName, tool]) => {
11909
+ Object.entries(registeredTools).forEach(([toolName, tool2]) => {
11151
11910
  if (!allTools[toolName]) {
11152
- allTools[toolName] = tool;
11911
+ allTools[toolName] = tool2;
11153
11912
  }
11154
11913
  availableToolNames.add(toolName);
11155
11914
  });
@@ -11193,11 +11952,11 @@ var ComposableMCPServer = class extends Server {
11193
11952
  const hiddenToolNames = this.getHiddenToolNames();
11194
11953
  const contextToolNames = toolNameToDetailList.map(([name2]) => name2).filter((n) => !hiddenToolNames.includes(n));
11195
11954
  publicToolNames.forEach((toolId) => {
11196
- const tool = allTools[toolId];
11197
- if (!tool) {
11955
+ const tool2 = allTools[toolId];
11956
+ if (!tool2) {
11198
11957
  throw new Error(`Public tool ${toolId} not found in registry, available: ${Object.keys(allTools).join(", ")}`);
11199
11958
  }
11200
- this.tool(toolId, tool.description || "", jsonSchema(tool.inputSchema), tool.execute, {
11959
+ this.tool(toolId, tool2.description || "", jsonSchema(tool2.inputSchema), tool2.execute, {
11201
11960
  internal: false
11202
11961
  });
11203
11962
  });
@@ -11545,9 +12304,9 @@ function createLargeResultPlugin(options = {}) {
11545
12304
  configuredServers.set(server, true);
11546
12305
  }
11547
12306
  },
11548
- transformTool: (tool, context2) => {
11549
- const originalExecute = tool.execute;
11550
- tool.execute = async (args) => {
12307
+ transformTool: (tool2, context2) => {
12308
+ const originalExecute = tool2.execute;
12309
+ tool2.execute = async (args) => {
11551
12310
  try {
11552
12311
  const result = await originalExecute(args);
11553
12312
  const resultText = JSON.stringify(result);
@@ -11589,7 +12348,7 @@ ${preview}
11589
12348
  throw error;
11590
12349
  }
11591
12350
  };
11592
- return tool;
12351
+ return tool2;
11593
12352
  },
11594
12353
  dispose: () => {
11595
12354
  configuredServers.clear();