@mcpc-tech/core 0.3.11 → 0.3.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs CHANGED
@@ -7071,10 +7071,10 @@ var stringbool = (...args) => _stringbool({
7071
7071
  String: ZodString
7072
7072
  }, ...args);
7073
7073
  function json(params) {
7074
- const jsonSchema2 = lazy(() => {
7075
- return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema2), record(string2(), jsonSchema2)]);
7074
+ const jsonSchema3 = lazy(() => {
7075
+ return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema3), record(string2(), jsonSchema3)]);
7076
7076
  });
7077
- return jsonSchema2;
7077
+ return jsonSchema3;
7078
7078
  }
7079
7079
  function preprocess(fn, schema) {
7080
7080
  return pipe(transform(fn), schema);
@@ -14891,17 +14891,17 @@ var Client = class extends Protocol {
14891
14891
  this._cachedToolOutputValidators.clear();
14892
14892
  this._cachedKnownTaskTools.clear();
14893
14893
  this._cachedRequiredTaskTools.clear();
14894
- for (const tool of tools) {
14895
- if (tool.outputSchema) {
14896
- const toolValidator = this._jsonSchemaValidator.getValidator(tool.outputSchema);
14897
- this._cachedToolOutputValidators.set(tool.name, toolValidator);
14894
+ for (const tool2 of tools) {
14895
+ if (tool2.outputSchema) {
14896
+ const toolValidator = this._jsonSchemaValidator.getValidator(tool2.outputSchema);
14897
+ this._cachedToolOutputValidators.set(tool2.name, toolValidator);
14898
14898
  }
14899
- const taskSupport = tool.execution?.taskSupport;
14899
+ const taskSupport = tool2.execution?.taskSupport;
14900
14900
  if (taskSupport === "required" || taskSupport === "optional") {
14901
- this._cachedKnownTaskTools.add(tool.name);
14901
+ this._cachedKnownTaskTools.add(tool2.name);
14902
14902
  }
14903
14903
  if (taskSupport === "required") {
14904
- this._cachedRequiredTaskTools.add(tool.name);
14904
+ this._cachedRequiredTaskTools.add(tool2.name);
14905
14905
  }
14906
14906
  }
14907
14907
  }
@@ -17260,14 +17260,14 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
17260
17260
  acquiredKeys.push(defKey);
17261
17261
  allClients[serverId] = client;
17262
17262
  const { tools } = await client.listTools();
17263
- tools.forEach((tool) => {
17264
- const toolNameWithScope = `${name}.${tool.name}`;
17265
- const internalToolName = tool.name;
17263
+ tools.forEach((tool2) => {
17264
+ const toolNameWithScope = `${name}.${tool2.name}`;
17265
+ const internalToolName = tool2.name;
17266
17266
  const rawToolId = `${serverId}_${internalToolName}`;
17267
17267
  const toolId = sanitizePropertyKey(rawToolId);
17268
17268
  if (filterIn && !filterIn({
17269
17269
  action: internalToolName,
17270
- tool,
17270
+ tool: tool2,
17271
17271
  mcpName: name,
17272
17272
  toolNameWithScope,
17273
17273
  internalToolName,
@@ -17282,7 +17282,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
17282
17282
  timeout: def.toolCallTimeout
17283
17283
  });
17284
17284
  allTools[toolId] = {
17285
- ...tool,
17285
+ ...tool2,
17286
17286
  execute,
17287
17287
  _originalName: toolNameWithScope
17288
17288
  };
@@ -17345,13 +17345,13 @@ var createConfigPlugin = () => ({
17345
17345
  name: "built-in-config",
17346
17346
  version: "1.0.0",
17347
17347
  enforce: "pre",
17348
- transformTool: (tool, context2) => {
17348
+ transformTool: (tool2, context2) => {
17349
17349
  const server = context2.server;
17350
17350
  const config2 = server.findToolConfig?.(context2.toolName);
17351
17351
  if (config2?.description) {
17352
- tool.description = config2.description;
17352
+ tool2.description = config2.description;
17353
17353
  }
17354
- return tool;
17354
+ return tool2;
17355
17355
  }
17356
17356
  });
17357
17357
  var config_plugin_default = createConfigPlugin();
@@ -17361,10 +17361,10 @@ var createToolNameMappingPlugin = () => ({
17361
17361
  name: "built-in-tool-name-mapping",
17362
17362
  version: "1.0.0",
17363
17363
  enforce: "pre",
17364
- transformTool: (tool, context2) => {
17364
+ transformTool: (tool2, context2) => {
17365
17365
  const server = context2.server;
17366
17366
  const toolName = context2.toolName;
17367
- const originalName = tool._originalName || toolName;
17367
+ const originalName = tool2._originalName || toolName;
17368
17368
  const dotNotation = originalName.replace(/_/g, ".");
17369
17369
  const underscoreNotation = originalName.replace(/\./g, "_");
17370
17370
  if (dotNotation !== originalName && server.toolNameMapping) {
@@ -17376,7 +17376,7 @@ var createToolNameMappingPlugin = () => ({
17376
17376
  if (originalName !== toolName && server.toolNameMapping) {
17377
17377
  server.toolNameMapping.set(originalName, toolName);
17378
17378
  }
17379
- return tool;
17379
+ return tool2;
17380
17380
  }
17381
17381
  });
17382
17382
  var tool_name_mapping_plugin_default = createToolNameMappingPlugin();
@@ -17869,13 +17869,13 @@ var PromptUtils = {
17869
17869
  * Generate tool list for descriptions
17870
17870
  */
17871
17871
  generateToolList: (tools) => {
17872
- return tools.filter((tool) => !tool.hide).map((tool) => `<tool name="${tool.name}"${tool.description ? ` description="${tool.description}"` : ""}/>`).join("\n");
17872
+ return tools.filter((tool2) => !tool2.hide).map((tool2) => `<tool name="${tool2.name}"${tool2.description ? ` description="${tool2.description}"` : ""}/>`).join("\n");
17873
17873
  },
17874
17874
  /**
17875
17875
  * Generate hidden tool list for descriptions
17876
17876
  */
17877
17877
  generateHiddenToolList: (tools) => {
17878
- return tools.filter((tool) => tool.hide).map((tool) => `<tool name="${tool.name}" hide/>`).join("\n");
17878
+ return tools.filter((tool2) => tool2.hide).map((tool2) => `<tool name="${tool2.name}" hide/>`).join("\n");
17879
17879
  },
17880
17880
  /**
17881
17881
  * Format workflow steps for display
@@ -19660,12 +19660,12 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
19660
19660
  }
19661
19661
  buildDepGroups() {
19662
19662
  const depGroups = {};
19663
- this.toolNameToDetailList.forEach(([toolName, tool]) => {
19664
- if (tool?.inputSchema) {
19663
+ this.toolNameToDetailList.forEach(([toolName, tool2]) => {
19664
+ if (tool2?.inputSchema) {
19665
19665
  depGroups[toolName] = {
19666
19666
  type: "object",
19667
- description: tool.description || `Tool: ${toolName}`,
19668
- ...tool.inputSchema
19667
+ description: tool2.description || `Tool: ${toolName}`,
19668
+ ...tool2.inputSchema
19669
19669
  };
19670
19670
  } else {
19671
19671
  const toolSchema = this.server.getHiddenToolSchema(toolName);
@@ -19722,10 +19722,10 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
19722
19722
  }
19723
19723
  buildSystemPrompt(userRequest, agenticSchema, context2) {
19724
19724
  const toolList = this.allToolNames.map((name) => {
19725
- const tool = this.toolNameToDetailList.find(([toolName]) => toolName === name);
19725
+ const tool2 = this.toolNameToDetailList.find(([toolName]) => toolName === name);
19726
19726
  const toolSchema = this.server.getHiddenToolSchema(name);
19727
- if (tool && tool[1]) {
19728
- return `- ${name}: ${tool[1].description || `Tool: ${name}`}`;
19727
+ if (tool2 && tool2[1]) {
19728
+ return `- ${name}: ${tool2[1].description || `Tool: ${name}`}`;
19729
19729
  } else if (toolSchema) {
19730
19730
  return `- ${name}: ${toolSchema.description}`;
19731
19731
  }
@@ -19752,7 +19752,7 @@ ${JSON.stringify(context2, null, 2)}`;
19752
19752
  ## Current Task
19753
19753
  You will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
19754
19754
 
19755
- When you need to use a tool, specify the tool name in 'action' and provide tool-specific parameters as additional properties.`;
19755
+ When you need to use a tool, specify the tool name in 'useTool' and provide tool-specific parameters as additional properties.`;
19756
19756
  return this.formatPromptForMode({
19757
19757
  prompt: basePrompt + taskPrompt,
19758
19758
  schema: agenticSchema
@@ -19932,6 +19932,763 @@ var createWorkflowSamplingModePlugin = () => ({
19932
19932
  });
19933
19933
  var mode_workflow_sampling_plugin_default = createWorkflowSamplingModePlugin();
19934
19934
 
19935
+ // __mcpc__core_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/utils.js
19936
+ function convertAISDKToMCPMessages(prompt) {
19937
+ const messages = [];
19938
+ for (const msg of prompt) {
19939
+ if (msg.role === "system") continue;
19940
+ const role = msg.role === "assistant" ? "assistant" : "user";
19941
+ const textParts = msg.content.filter((c) => c.type === "text");
19942
+ const toolCalls = msg.content.filter((c) => c.type === "tool-call");
19943
+ const toolResults = msg.content.filter((c) => c.type === "tool-result");
19944
+ const parts = [];
19945
+ if (textParts.length > 0) {
19946
+ parts.push(textParts.map((c) => c.text).join("\n"));
19947
+ }
19948
+ if (toolCalls.length > 0) {
19949
+ const calls = toolCalls.map((c) => {
19950
+ const call = c;
19951
+ const toolArgs = call.args ?? call.input ?? {};
19952
+ return `<use_tool tool="${call.toolName}">
19953
+ ${JSON.stringify(toolArgs)}
19954
+ </use_tool>`;
19955
+ });
19956
+ parts.push(calls.join("\n"));
19957
+ }
19958
+ if (toolResults.length > 0) {
19959
+ const results = toolResults.map((c) => {
19960
+ const result = c;
19961
+ const resultValue = result.result ?? result.output ?? "undefined";
19962
+ const output = JSON.stringify(resultValue);
19963
+ return `Tool "${result.toolName}" result:
19964
+ ${output}`;
19965
+ });
19966
+ parts.push(results.join("\n\n"));
19967
+ }
19968
+ const text = parts.join("\n\n");
19969
+ if (text) {
19970
+ messages.push({
19971
+ role,
19972
+ content: {
19973
+ type: "text",
19974
+ text
19975
+ }
19976
+ });
19977
+ }
19978
+ }
19979
+ return messages;
19980
+ }
19981
+ function convertMCPStopReasonToAISDK(stopReason) {
19982
+ if (stopReason === "endTurn" || stopReason === "stopSequence") {
19983
+ return "stop";
19984
+ }
19985
+ if (stopReason === "maxTokens") return "length";
19986
+ return stopReason ?? "unknown";
19987
+ }
19988
+
19989
+ // __mcpc__core_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/language-model.js
19990
+ var MCPSamplingLanguageModel = class {
19991
+ specificationVersion = "v2";
19992
+ provider;
19993
+ modelId;
19994
+ supportedUrls = {};
19995
+ server;
19996
+ modelPreferences;
19997
+ constructor(config2) {
19998
+ this.server = config2.server;
19999
+ this.modelId = "";
20000
+ this.provider = "mcp-client";
20001
+ this.modelPreferences = config2.modelPreferences;
20002
+ }
20003
+ /**
20004
+ * Generate a response using MCP's createMessage capability
20005
+ */
20006
+ async doGenerate(options) {
20007
+ const messages = this.convertMessages(options.prompt);
20008
+ let systemPrompt;
20009
+ for (const msg of options.prompt) {
20010
+ if (msg.role === "system") {
20011
+ systemPrompt = msg.content;
20012
+ break;
20013
+ }
20014
+ }
20015
+ const useNativeTools = this.supportsSamplingTools();
20016
+ systemPrompt = this.injectResponseFormatInstructions(systemPrompt, options.responseFormat, useNativeTools);
20017
+ systemPrompt = this.injectToolInstructions(systemPrompt, options.tools, useNativeTools);
20018
+ const createMessageParams = {
20019
+ systemPrompt,
20020
+ messages,
20021
+ maxTokens: options.maxOutputTokens ?? 55e3,
20022
+ modelPreferences: this.modelPreferences
20023
+ };
20024
+ if (useNativeTools && options.tools && options.tools.length > 0) {
20025
+ createMessageParams.tools = this.convertAISDKToolsToMCP(options.tools);
20026
+ createMessageParams.toolChoice = {
20027
+ mode: "auto"
20028
+ };
20029
+ }
20030
+ const result = await this.server.createMessage(createMessageParams);
20031
+ const content = [];
20032
+ if (useNativeTools) {
20033
+ const contentArray = Array.isArray(result.content) ? result.content : [
20034
+ result.content
20035
+ ];
20036
+ for (const block of contentArray) {
20037
+ if (block.type === "text" && "text" in block) {
20038
+ content.push({
20039
+ type: "text",
20040
+ text: block.text
20041
+ });
20042
+ } else if (block.type === "tool_use" && "id" in block && "name" in block) {
20043
+ const toolInput = block.input || {};
20044
+ content.push({
20045
+ type: "tool-call",
20046
+ toolCallId: block.id,
20047
+ toolName: block.name,
20048
+ input: JSON.stringify(toolInput)
20049
+ });
20050
+ }
20051
+ }
20052
+ } else {
20053
+ if (result.content.type === "text" && result.content.text) {
20054
+ const { text, toolCalls } = this.extractToolCalls(result.content.text, options.tools);
20055
+ if (text.trim()) {
20056
+ const textContent = {
20057
+ type: "text",
20058
+ text
20059
+ };
20060
+ content.push(textContent);
20061
+ }
20062
+ content.push(...toolCalls);
20063
+ }
20064
+ }
20065
+ const finishReason = this.mapStopReason(result.stopReason);
20066
+ return {
20067
+ content,
20068
+ finishReason,
20069
+ usage: {
20070
+ inputTokens: void 0,
20071
+ outputTokens: void 0,
20072
+ totalTokens: 0
20073
+ },
20074
+ request: {
20075
+ body: JSON.stringify({
20076
+ systemPrompt,
20077
+ messages
20078
+ })
20079
+ },
20080
+ response: {
20081
+ modelId: result.model
20082
+ },
20083
+ warnings: []
20084
+ };
20085
+ }
20086
+ /**
20087
+ * Stream a response using MCP's createMessage capability
20088
+ *
20089
+ * Since MCP doesn't support native streaming, we generate the full response
20090
+ * and emit it as stream events following AI SDK's protocol.
20091
+ */
20092
+ async doStream(options) {
20093
+ const result = await this.doGenerate(options);
20094
+ const stream = new ReadableStream({
20095
+ start(controller) {
20096
+ if (result.response?.modelId) {
20097
+ controller.enqueue({
20098
+ type: "response-metadata",
20099
+ modelId: result.response.modelId,
20100
+ ...result.response.headers && {
20101
+ headers: result.response.headers
20102
+ }
20103
+ });
20104
+ }
20105
+ let textIndex = 0;
20106
+ for (const part of result.content) {
20107
+ if (part.type === "text") {
20108
+ const id = `text-${++textIndex}`;
20109
+ controller.enqueue({
20110
+ type: "text-start",
20111
+ id
20112
+ });
20113
+ controller.enqueue({
20114
+ type: "text-delta",
20115
+ id,
20116
+ delta: part.text
20117
+ });
20118
+ controller.enqueue({
20119
+ type: "text-end",
20120
+ id
20121
+ });
20122
+ } else if (part.type === "tool-call") {
20123
+ controller.enqueue({
20124
+ type: "tool-call",
20125
+ toolCallId: part.toolCallId,
20126
+ toolName: part.toolName,
20127
+ input: part.input
20128
+ });
20129
+ }
20130
+ }
20131
+ controller.enqueue({
20132
+ type: "finish",
20133
+ finishReason: result.finishReason,
20134
+ usage: result.usage
20135
+ });
20136
+ controller.close();
20137
+ }
20138
+ });
20139
+ return {
20140
+ stream,
20141
+ request: result.request,
20142
+ warnings: result.warnings
20143
+ };
20144
+ }
20145
+ /**
20146
+ * Convert AI SDK messages to MCP sampling format
20147
+ */
20148
+ convertMessages(prompt) {
20149
+ return convertAISDKToMCPMessages(prompt);
20150
+ }
20151
+ /**
20152
+ * Map MCP stop reason to AI SDK finish reason
20153
+ */
20154
+ mapStopReason(stopReason) {
20155
+ return convertMCPStopReasonToAISDK(stopReason);
20156
+ }
20157
+ /**
20158
+ * Check if client supports native tool use in sampling
20159
+ */
20160
+ supportsSamplingTools() {
20161
+ const capabilities = this.server.getClientCapabilities();
20162
+ return !!capabilities?.sampling?.tools;
20163
+ }
20164
+ /**
20165
+ * Convert AI SDK tools to MCP Tool format
20166
+ */
20167
+ convertAISDKToolsToMCP(tools) {
20168
+ if (!tools || tools.length === 0) return [];
20169
+ return tools.filter((tool2) => tool2.type === "function").map((tool2) => {
20170
+ const toolAny = tool2;
20171
+ return {
20172
+ name: tool2.name,
20173
+ description: toolAny.description || `Tool: ${tool2.name}`,
20174
+ inputSchema: {
20175
+ type: "object",
20176
+ ...toolAny.inputSchema || toolAny.parameters
20177
+ }
20178
+ };
20179
+ });
20180
+ }
20181
+ /**
20182
+ * Inject response format instructions into system prompt
20183
+ *
20184
+ * Only injects formatting instructions in JSON fallback mode.
20185
+ * In native tools mode, structured output is handled by the provider.
20186
+ */
20187
+ injectResponseFormatInstructions(systemPrompt, responseFormat, useNativeTools) {
20188
+ if (!responseFormat) {
20189
+ return systemPrompt;
20190
+ }
20191
+ if (useNativeTools) {
20192
+ return systemPrompt;
20193
+ }
20194
+ let enhanced = systemPrompt || "";
20195
+ if (responseFormat.type === "json") {
20196
+ const jsonPrompt = `
20197
+
20198
+ IMPORTANT: You MUST respond with valid JSON only. Do not include any text before or after the JSON.
20199
+ - Your response must be a valid JSON object
20200
+ - Do not wrap the JSON in markdown code blocks
20201
+ - Do not include explanations or comments
20202
+ - Ensure all JSON is properly formatted and parseable`;
20203
+ enhanced = enhanced ? `${enhanced}${jsonPrompt}` : jsonPrompt.trim();
20204
+ if (responseFormat.schema) {
20205
+ const schemaInfo = `
20206
+ - Follow this JSON schema structure: ${JSON.stringify(responseFormat.schema)}`;
20207
+ enhanced += schemaInfo;
20208
+ }
20209
+ }
20210
+ return enhanced || void 0;
20211
+ }
20212
+ /**
20213
+ * Inject tool definitions into system prompt
20214
+ *
20215
+ * WORKAROUND: MCP sampling currently doesn't support native tools parameter.
20216
+ * This method injects tool descriptions and usage instructions into the system prompt.
20217
+ *
20218
+ * TODO: Remove this workaround when MCP protocol adds native support for:
20219
+ * - tools parameter in createMessage
20220
+ * - Tool calling and function execution
20221
+ * - Structured tool responses
20222
+ */
20223
+ injectToolInstructions(systemPrompt, tools, useNativeTools) {
20224
+ if (!tools || tools.length === 0) {
20225
+ return systemPrompt;
20226
+ }
20227
+ if (useNativeTools) {
20228
+ return systemPrompt;
20229
+ }
20230
+ let enhanced = systemPrompt || "";
20231
+ const toolsPrompt = `
20232
+
20233
+ AVAILABLE TOOLS:
20234
+ You have access to the following tools. To use a tool, respond with this XML format:
20235
+ <use_tool tool="tool_name">
20236
+ {"param1": "value1", "param2": "value2"}
20237
+ </use_tool>
20238
+
20239
+ Follow the JSON schema definition for each tool's parameters.
20240
+ 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.
20241
+
20242
+ Tools:`;
20243
+ const toolDescriptions = tools.map((tool2) => {
20244
+ if (tool2.type === "function") {
20245
+ const toolAny = tool2;
20246
+ const description = toolAny.description || "No description provided";
20247
+ const schema = toolAny.inputSchema || toolAny.parameters;
20248
+ const params = schema ? `
20249
+ JSON Schema: ${JSON.stringify(schema, null, 2)}` : "";
20250
+ return `
20251
+ - ${tool2.name}: ${description}${params}`;
20252
+ } else if (tool2.type === "provider-defined") {
20253
+ return `
20254
+ - ${tool2.name}: ${tool2.id || "No description provided"}`;
20255
+ }
20256
+ return "";
20257
+ }).filter(Boolean).join("");
20258
+ enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}` : `${toolsPrompt}${toolDescriptions}`.trim();
20259
+ return enhanced || void 0;
20260
+ }
20261
+ /**
20262
+ * Extract tool calls from LLM response text
20263
+ *
20264
+ * Parses XML-style tool call tags from the response:
20265
+ * <use_tool tool="tool_name">{"arg": "value"}</use_tool>
20266
+ */
20267
+ extractToolCalls(responseText, tools) {
20268
+ if (!tools || tools.length === 0) {
20269
+ return {
20270
+ text: responseText,
20271
+ toolCalls: []
20272
+ };
20273
+ }
20274
+ const toolCalls = [];
20275
+ const toolCallRegex = /<use_tool\s+tool="([^"]+)">([\s\S]*?)<\/use_tool>/g;
20276
+ let match;
20277
+ let lastIndex = 0;
20278
+ const textParts = [];
20279
+ let callIndex = 0;
20280
+ while ((match = toolCallRegex.exec(responseText)) !== null) {
20281
+ textParts.push(responseText.slice(lastIndex, match.index));
20282
+ const toolName = match[1];
20283
+ const argsText = match[2].trim?.();
20284
+ toolCalls.push({
20285
+ type: "tool-call",
20286
+ toolCallId: `call_${Date.now()}_${callIndex++}`,
20287
+ toolName,
20288
+ input: argsText
20289
+ });
20290
+ lastIndex = match.index + match[0].length;
20291
+ }
20292
+ textParts.push(responseText.slice(lastIndex));
20293
+ const text = textParts.join("").trim();
20294
+ return {
20295
+ text,
20296
+ toolCalls
20297
+ };
20298
+ }
20299
+ };
20300
+
20301
+ // __mcpc__core_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/provider.js
20302
+ var MCPSamplingProvider = class {
20303
+ config;
20304
+ constructor(config2) {
20305
+ this.config = config2;
20306
+ }
20307
+ /**
20308
+ * Create a language model instance for a specific MCP tool/agent
20309
+ *
20310
+ * @param options - Optional configuration overrides
20311
+ * @returns A LanguageModelV2 instance
20312
+ */
20313
+ languageModel(options) {
20314
+ return new MCPSamplingLanguageModel({
20315
+ server: this.config.server,
20316
+ modelPreferences: options?.modelPreferences
20317
+ });
20318
+ }
20319
+ /**
20320
+ * Shorthand for creating a language model
20321
+ */
20322
+ call(options) {
20323
+ return this.languageModel(options);
20324
+ }
20325
+ };
20326
+
20327
+ // __mcpc__core_latest/node_modules/@mcpc/core/src/executors/ai/base-ai-executor.js
20328
+ var import_api2 = require("@opentelemetry/api");
20329
+ var import_ai = require("ai");
20330
+ var BaseAIExecutor = class {
20331
+ config;
20332
+ tracer;
20333
+ logger;
20334
+ constructor(config2, server) {
20335
+ this.config = {
20336
+ maxSteps: 50,
20337
+ tracingEnabled: true,
20338
+ ...config2
20339
+ };
20340
+ this.tracer = import_api2.trace.getTracer(`mcpc.ai.${config2.name}`);
20341
+ this.logger = createLogger(`mcpc.ai.${config2.name}`, server);
20342
+ }
20343
+ execute(args) {
20344
+ if (this.config.tracingEnabled) {
20345
+ return this.executeWithTracing(args);
20346
+ }
20347
+ return this.executeCore(args);
20348
+ }
20349
+ executeWithTracing(args) {
20350
+ return this.tracer.startActiveSpan(`mcpc.ai.${this.config.name}`, async (span) => {
20351
+ try {
20352
+ span.setAttributes({
20353
+ "mcpc.executor": this.config.name,
20354
+ "mcpc.type": this.getExecutorType()
20355
+ });
20356
+ const result = await this.executeCore(args, span);
20357
+ span.setAttributes({
20358
+ "mcpc.error": !!result.isError
20359
+ });
20360
+ return result;
20361
+ } catch (error2) {
20362
+ span.recordException(error2);
20363
+ throw error2;
20364
+ } finally {
20365
+ span.end();
20366
+ }
20367
+ });
20368
+ }
20369
+ async executeCore(args, span) {
20370
+ try {
20371
+ const result = (0, import_ai.streamText)({
20372
+ model: this.getModel(),
20373
+ system: this.buildSystemPrompt(args),
20374
+ messages: [
20375
+ {
20376
+ role: "user",
20377
+ content: args.userRequest
20378
+ }
20379
+ ],
20380
+ tools: this.buildTools(),
20381
+ stopWhen: (0, import_ai.stepCountIs)(this.config.maxSteps),
20382
+ experimental_telemetry: this.config.tracingEnabled ? {
20383
+ isEnabled: true,
20384
+ functionId: `mcpc.${this.config.name}`,
20385
+ tracer: this.tracer
20386
+ } : void 0,
20387
+ onStepFinish: (step) => {
20388
+ if (span) {
20389
+ span.addEvent("step", {
20390
+ tools: step.toolCalls?.length ?? 0,
20391
+ reason: step.finishReason ?? ""
20392
+ });
20393
+ }
20394
+ }
20395
+ });
20396
+ return {
20397
+ content: [
20398
+ {
20399
+ type: "text",
20400
+ text: await result.text || `Completed in ${(await result.steps)?.length ?? "unknown"} step(s).`
20401
+ }
20402
+ ],
20403
+ isError: false
20404
+ };
20405
+ } catch (error2) {
20406
+ this.logger.error({
20407
+ message: "Execution error",
20408
+ error: error2
20409
+ });
20410
+ return {
20411
+ content: [
20412
+ {
20413
+ type: "text",
20414
+ text: `Error: ${error2 instanceof Error ? error2.message : String(error2)}`
20415
+ }
20416
+ ],
20417
+ isError: true
20418
+ };
20419
+ }
20420
+ }
20421
+ buildSystemPrompt(args) {
20422
+ return `Agent \`${this.config.name}\` that completes tasks by calling tools.
20423
+
20424
+ <manual>
20425
+ ${this.config.description}
20426
+ </manual>
20427
+
20428
+ <rules>
20429
+ ${this.getRules()}
20430
+ </rules>
20431
+
20432
+ <tools>
20433
+ ${this.getToolListDescription()}
20434
+ </tools>${args.context ? this.formatContext(args.context) : ""}`;
20435
+ }
20436
+ getRules() {
20437
+ return `1. Use tools to complete the user's request
20438
+ 2. Review results after each tool call
20439
+ 3. Adapt your approach based on outcomes
20440
+ 4. Continue until task is complete
20441
+ 5. When complete, provide a summary WITHOUT calling more tools`;
20442
+ }
20443
+ getToolListDescription() {
20444
+ return "Tools will be provided by AI SDK";
20445
+ }
20446
+ formatContext(context2) {
20447
+ return `
20448
+
20449
+ <context>
20450
+ ${JSON.stringify(context2, null, 2)}
20451
+ </context>`;
20452
+ }
20453
+ convertToAISDKTool(name, toolDetail, execute) {
20454
+ return (0, import_ai.tool)({
20455
+ description: toolDetail.description || `Tool: ${name}`,
20456
+ inputSchema: (0, import_ai.jsonSchema)(toolDetail.inputSchema || {
20457
+ type: "object"
20458
+ }),
20459
+ execute
20460
+ });
20461
+ }
20462
+ };
20463
+
20464
+ // __mcpc__core_latest/node_modules/@mcpc/core/src/executors/ai/ai-sampling-executor.js
20465
+ var AISamplingExecutor = class extends BaseAIExecutor {
20466
+ server;
20467
+ tools;
20468
+ providerOptions;
20469
+ model = null;
20470
+ constructor(config2) {
20471
+ super(config2, "callTool" in config2.server ? config2.server : void 0);
20472
+ this.server = config2.server;
20473
+ this.tools = config2.tools;
20474
+ this.providerOptions = config2.providerOptions;
20475
+ }
20476
+ initProvider() {
20477
+ if (!this.model) {
20478
+ const provider = new MCPSamplingProvider({
20479
+ server: this.server
20480
+ });
20481
+ this.model = provider.languageModel(this.providerOptions);
20482
+ }
20483
+ return this.model;
20484
+ }
20485
+ getModel() {
20486
+ if (!this.model) throw new Error("Model not initialized");
20487
+ return this.model;
20488
+ }
20489
+ getExecutorType() {
20490
+ return "mcp";
20491
+ }
20492
+ getToolListDescription() {
20493
+ return this.tools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
20494
+ }
20495
+ buildTools() {
20496
+ const aiTools = {};
20497
+ for (const [name, detail] of this.tools) {
20498
+ aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
20499
+ const result = await this.callTool(name, input);
20500
+ return this.formatResult(result);
20501
+ });
20502
+ }
20503
+ return aiTools;
20504
+ }
20505
+ async callTool(name, input) {
20506
+ if ("callTool" in this.server) {
20507
+ return await this.server.callTool(name, input);
20508
+ }
20509
+ const detail = this.tools.find(([n]) => n === name)?.[1];
20510
+ if (detail?.execute) return await detail.execute(input);
20511
+ throw new Error(`Cannot call tool "${name}"`);
20512
+ }
20513
+ formatResult(result) {
20514
+ const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
20515
+ return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
20516
+ }
20517
+ execute(args) {
20518
+ this.initProvider();
20519
+ return super.execute(args);
20520
+ }
20521
+ };
20522
+
20523
+ // __mcpc__core_latest/node_modules/@mcpc/core/src/executors/ai/ai-sampling-registrar.js
20524
+ function registerAISamplingTool(server, params) {
20525
+ const { name, description, allToolNames, depGroups, toolNameToDetailList, providerOptions, maxSteps = 50, tracingEnabled = false } = params;
20526
+ const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
20527
+ const executor = new AISamplingExecutor({
20528
+ name,
20529
+ description,
20530
+ server,
20531
+ tools: toolNameToDetailList,
20532
+ providerOptions,
20533
+ maxSteps,
20534
+ tracingEnabled
20535
+ });
20536
+ const toolDescription = CompiledPrompts.samplingToolDescription({
20537
+ toolName: name,
20538
+ description,
20539
+ toolList: allToolNames.map((n) => `- ${n}`).join("\n")
20540
+ });
20541
+ const argsDef = createArgsDef.forSampling();
20542
+ const schema = allToolNames.length > 0 ? argsDef : {
20543
+ type: "object",
20544
+ properties: {}
20545
+ };
20546
+ server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
20547
+ const userRequest = typeof args.userRequest === "string" ? args.userRequest : JSON.stringify(args);
20548
+ return executor.execute({
20549
+ userRequest,
20550
+ context: args.context
20551
+ });
20552
+ });
20553
+ }
20554
+
20555
+ // __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-ai-sampling-plugin.js
20556
+ var createAISamplingModePlugin = () => ({
20557
+ name: "mode-ai-sampling",
20558
+ version: "1.0.0",
20559
+ apply: "ai_sampling",
20560
+ registerAgentTool: (context2) => {
20561
+ const opts = context2.options;
20562
+ registerAISamplingTool(context2.server, {
20563
+ description: context2.description,
20564
+ name: context2.name,
20565
+ allToolNames: context2.allToolNames,
20566
+ depGroups: context2.depGroups,
20567
+ toolNameToDetailList: context2.toolNameToDetailList,
20568
+ providerOptions: opts.providerOptions,
20569
+ maxSteps: opts.maxSteps,
20570
+ tracingEnabled: opts.tracingEnabled
20571
+ });
20572
+ }
20573
+ });
20574
+ var mode_ai_sampling_plugin_default = createAISamplingModePlugin();
20575
+
20576
+ // __mcpc__core_latest/node_modules/@mcpc/core/src/executors/ai/ai-acp-executor.js
20577
+ var import_acp_ai_provider = require("@mcpc-tech/acp-ai-provider");
20578
+ var AIACPExecutor = class extends BaseAIExecutor {
20579
+ acpSettings;
20580
+ clientTools;
20581
+ provider = null;
20582
+ model = null;
20583
+ constructor(config2) {
20584
+ super(config2);
20585
+ this.acpSettings = config2.acpSettings;
20586
+ this.clientTools = config2.clientTools ?? [];
20587
+ }
20588
+ initProvider() {
20589
+ if (!this.model) {
20590
+ this.provider = (0, import_acp_ai_provider.createACPProvider)(this.acpSettings);
20591
+ this.model = this.provider.languageModel();
20592
+ }
20593
+ return this.model;
20594
+ }
20595
+ getModel() {
20596
+ if (!this.model) throw new Error("Model not initialized");
20597
+ return this.model;
20598
+ }
20599
+ getExecutorType() {
20600
+ return "acp";
20601
+ }
20602
+ getToolListDescription() {
20603
+ if (this.clientTools.length === 0) {
20604
+ return "Tools will be provided by AI SDK";
20605
+ }
20606
+ return this.clientTools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
20607
+ }
20608
+ buildTools() {
20609
+ const aiTools = {};
20610
+ for (const [name, detail] of this.clientTools) {
20611
+ if (!detail.execute) continue;
20612
+ aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
20613
+ const result = await detail.execute(input);
20614
+ return this.formatResult(result);
20615
+ });
20616
+ }
20617
+ return aiTools;
20618
+ }
20619
+ formatResult(result) {
20620
+ const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
20621
+ return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
20622
+ }
20623
+ execute(args) {
20624
+ this.initProvider();
20625
+ return super.execute(args);
20626
+ }
20627
+ cleanup() {
20628
+ if (this.provider && typeof this.provider.cleanup === "function") {
20629
+ this.provider.cleanup();
20630
+ }
20631
+ this.model = null;
20632
+ this.provider = null;
20633
+ }
20634
+ };
20635
+
20636
+ // __mcpc__core_latest/node_modules/@mcpc/core/src/executors/ai/ai-acp-registrar.js
20637
+ function registerAIACPTool(server, params) {
20638
+ const { name, description, allToolNames, depGroups, acpSettings, clientTools = [], maxSteps = 50, tracingEnabled = false } = params;
20639
+ const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
20640
+ const executor = new AIACPExecutor({
20641
+ name,
20642
+ description,
20643
+ acpSettings,
20644
+ clientTools,
20645
+ maxSteps,
20646
+ tracingEnabled
20647
+ });
20648
+ const toolDescription = CompiledPrompts.samplingToolDescription({
20649
+ toolName: name,
20650
+ description,
20651
+ toolList: allToolNames.length > 0 ? allToolNames.map((n) => `- ${n}`).join("\n") : "Agent has its own tools"
20652
+ });
20653
+ const argsDef = createArgsDef.forSampling();
20654
+ const schema = allToolNames.length > 0 ? argsDef : {
20655
+ type: "object",
20656
+ properties: {}
20657
+ };
20658
+ server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
20659
+ const userRequest = typeof args.userRequest === "string" ? args.userRequest : JSON.stringify(args);
20660
+ return executor.execute({
20661
+ userRequest,
20662
+ context: args.context
20663
+ });
20664
+ });
20665
+ return executor;
20666
+ }
20667
+
20668
+ // __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-ai-acp-plugin.js
20669
+ var createAIACPModePlugin = () => ({
20670
+ name: "mode-ai-acp",
20671
+ version: "1.0.0",
20672
+ apply: "ai_acp",
20673
+ registerAgentTool: (context2) => {
20674
+ const opts = context2.options;
20675
+ if (!opts.acpSettings) {
20676
+ throw new Error("ai_acp mode requires acpSettings in options");
20677
+ }
20678
+ registerAIACPTool(context2.server, {
20679
+ description: context2.description,
20680
+ name: context2.name,
20681
+ allToolNames: context2.allToolNames,
20682
+ depGroups: context2.depGroups,
20683
+ acpSettings: opts.acpSettings,
20684
+ clientTools: opts.clientTools,
20685
+ maxSteps: opts.maxSteps,
20686
+ tracingEnabled: opts.tracingEnabled
20687
+ });
20688
+ }
20689
+ });
20690
+ var mode_ai_acp_plugin_default = createAIACPModePlugin();
20691
+
19935
20692
  // __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/index.js
19936
20693
  function getBuiltInPlugins() {
19937
20694
  return [
@@ -19941,6 +20698,8 @@ function getBuiltInPlugins() {
19941
20698
  mode_workflow_plugin_default,
19942
20699
  mode_agentic_sampling_plugin_default,
19943
20700
  mode_workflow_sampling_plugin_default,
20701
+ mode_ai_sampling_plugin_default,
20702
+ mode_ai_acp_plugin_default,
19944
20703
  logging_plugin_default
19945
20704
  ];
19946
20705
  }
@@ -20229,13 +20988,13 @@ var PluginManager = class {
20229
20988
  /**
20230
20989
  * Apply transformTool hooks to a tool during composition
20231
20990
  */
20232
- async applyTransformToolHooks(tool, context2) {
20991
+ async applyTransformToolHooks(tool2, context2) {
20233
20992
  const transformPlugins = this.plugins.filter((p2) => p2.transformTool && shouldApplyPlugin(p2, context2.mode));
20234
20993
  if (transformPlugins.length === 0) {
20235
- return tool;
20994
+ return tool2;
20236
20995
  }
20237
20996
  const sortedPlugins = sortPluginsByOrder(transformPlugins);
20238
- let currentTool = tool;
20997
+ let currentTool = tool2;
20239
20998
  for (const plugin of sortedPlugins) {
20240
20999
  if (plugin.transformTool) {
20241
21000
  try {
@@ -20483,12 +21242,12 @@ var ToolManager = class {
20483
21242
  * Get tool schema if it's hidden (for internal access)
20484
21243
  */
20485
21244
  getHiddenToolSchema(name) {
20486
- const tool = this.toolRegistry.get(name);
21245
+ const tool2 = this.toolRegistry.get(name);
20487
21246
  const config2 = this.toolConfigs.get(name);
20488
- if (tool && config2?.visibility?.hidden && tool.schema) {
21247
+ if (tool2 && config2?.visibility?.hidden && tool2.schema) {
20489
21248
  return {
20490
- description: tool.description,
20491
- schema: tool.schema
21249
+ description: tool2.description,
21250
+ schema: tool2.schema
20492
21251
  };
20493
21252
  }
20494
21253
  return void 0;
@@ -20517,18 +21276,18 @@ var ToolManager = class {
20517
21276
  */
20518
21277
  getRegisteredToolsAsComposed() {
20519
21278
  const composedTools = {};
20520
- for (const [name, tool] of this.toolRegistry.entries()) {
21279
+ for (const [name, tool2] of this.toolRegistry.entries()) {
20521
21280
  if (this.toolConfigs.get(name)?.visibility?.public === true) {
20522
21281
  continue;
20523
21282
  }
20524
21283
  composedTools[name] = {
20525
21284
  name,
20526
- description: tool.description,
20527
- inputSchema: jsonSchema(tool.schema || {
21285
+ description: tool2.description,
21286
+ inputSchema: jsonSchema(tool2.schema || {
20528
21287
  type: "object",
20529
21288
  properties: {}
20530
21289
  }),
20531
- execute: tool.callback
21290
+ execute: tool2.callback
20532
21291
  };
20533
21292
  }
20534
21293
  return composedTools;
@@ -20598,18 +21357,18 @@ async function processToolsWithPlugins(server, _externalTools, mode) {
20598
21357
  function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicToolNames, server) {
20599
21358
  const depGroups = {};
20600
21359
  const toolManager = server.toolManager;
20601
- toolNameToDetailList.forEach(([toolName, tool]) => {
21360
+ toolNameToDetailList.forEach(([toolName, tool2]) => {
20602
21361
  const resolvedName = toolManager.resolveToolName(toolName);
20603
21362
  if (hiddenToolNames.includes(resolvedName ?? "") || publicToolNames.includes(resolvedName ?? "")) {
20604
21363
  return;
20605
21364
  }
20606
- if (!tool) {
21365
+ if (!tool2) {
20607
21366
  const allToolNames = [
20608
21367
  ...toolNameToDetailList.map(([n]) => n)
20609
21368
  ];
20610
21369
  throw new Error(`Action ${toolName} not found, available action list: ${allToolNames.join(", ")}`);
20611
21370
  }
20612
- const baseSchema = tool.inputSchema.jsonSchema ?? tool.inputSchema ?? {
21371
+ const baseSchema = tool2.inputSchema.jsonSchema ?? tool2.inputSchema ?? {
20613
21372
  type: "object",
20614
21373
  properties: {},
20615
21374
  required: []
@@ -20620,7 +21379,7 @@ function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicTool
20620
21379
  const sanitizedKey = sanitizePropertyKey(toolName);
20621
21380
  depGroups[sanitizedKey] = {
20622
21381
  type: "object",
20623
- description: tool.description,
21382
+ description: tool2.description,
20624
21383
  properties: updatedProperties,
20625
21384
  required: [
20626
21385
  ...baseRequired
@@ -20896,9 +21655,9 @@ var ComposableMCPServer = class extends Server {
20896
21655
  const requestedToolNames = /* @__PURE__ */ new Set();
20897
21656
  const availableToolNames = /* @__PURE__ */ new Set();
20898
21657
  const allPlaceholderUsages = [];
20899
- tagToResults.tool.forEach((tool) => {
20900
- if (tool.attribs.name) {
20901
- const originalName = tool.attribs.name;
21658
+ tagToResults.tool.forEach((tool2) => {
21659
+ if (tool2.attribs.name) {
21660
+ const originalName = tool2.attribs.name;
20902
21661
  const toolName = sanitizePropertyKey(originalName);
20903
21662
  if (toolName.endsWith(`_${ALL_TOOLS_PLACEHOLDER2}`) || toolName === ALL_TOOLS_PLACEHOLDER2) {
20904
21663
  allPlaceholderUsages.push(originalName);
@@ -20924,24 +21683,24 @@ var ComposableMCPServer = class extends Server {
20924
21683
  }
20925
21684
  return true;
20926
21685
  }
20927
- return tagToResults.tool.find((tool) => {
20928
- const selectAll = tool.attribs.name === `${mcpName}.${ALL_TOOLS_PLACEHOLDER2}` || tool.attribs.name === `${mcpName}`;
21686
+ return tagToResults.tool.find((tool2) => {
21687
+ const selectAll = tool2.attribs.name === `${mcpName}.${ALL_TOOLS_PLACEHOLDER2}` || tool2.attribs.name === `${mcpName}`;
20929
21688
  if (selectAll) {
20930
21689
  return true;
20931
21690
  }
20932
- return tool.attribs.name === toolNameWithScope || tool.attribs.name === toolId;
21691
+ return tool2.attribs.name === toolNameWithScope || tool2.attribs.name === toolId;
20933
21692
  });
20934
21693
  });
20935
- Object.entries(tools).forEach(([toolId, tool]) => {
20936
- this.toolManager.registerTool(toolId, tool.description || "", tool.inputSchema, tool.execute);
21694
+ Object.entries(tools).forEach(([toolId, tool2]) => {
21695
+ this.toolManager.registerTool(toolId, tool2.description || "", tool2.inputSchema, tool2.execute);
20937
21696
  });
20938
21697
  const registeredTools = this.toolManager.getRegisteredToolsAsComposed();
20939
21698
  const allTools = {
20940
21699
  ...tools
20941
21700
  };
20942
- Object.entries(registeredTools).forEach(([toolName, tool]) => {
21701
+ Object.entries(registeredTools).forEach(([toolName, tool2]) => {
20943
21702
  if (!allTools[toolName]) {
20944
- allTools[toolName] = tool;
21703
+ allTools[toolName] = tool2;
20945
21704
  }
20946
21705
  availableToolNames.add(toolName);
20947
21706
  });
@@ -20985,11 +21744,11 @@ var ComposableMCPServer = class extends Server {
20985
21744
  const hiddenToolNames = this.getHiddenToolNames();
20986
21745
  const contextToolNames = toolNameToDetailList.map(([name2]) => name2).filter((n) => !hiddenToolNames.includes(n));
20987
21746
  publicToolNames.forEach((toolId) => {
20988
- const tool = allTools[toolId];
20989
- if (!tool) {
21747
+ const tool2 = allTools[toolId];
21748
+ if (!tool2) {
20990
21749
  throw new Error(`Public tool ${toolId} not found in registry, available: ${Object.keys(allTools).join(", ")}`);
20991
21750
  }
20992
- this.tool(toolId, tool.description || "", jsonSchema(tool.inputSchema), tool.execute, {
21751
+ this.tool(toolId, tool2.description || "", jsonSchema(tool2.inputSchema), tool2.execute, {
20993
21752
  internal: false
20994
21753
  });
20995
21754
  });
@@ -21054,13 +21813,13 @@ if (isSCF()) {
21054
21813
 
21055
21814
  // __mcpc__core_latest/node_modules/@mcpc/core/src/ai-sdk-adapter.js
21056
21815
  function convertToAISDKTools(server, helpers) {
21057
- const { tool, jsonSchema: jsonSchema2 } = helpers;
21816
+ const { tool: tool2, jsonSchema: jsonSchema3 } = helpers;
21058
21817
  const mcpcTools = server.getPublicTools();
21059
21818
  return Object.fromEntries(mcpcTools.map((mcpcTool) => [
21060
21819
  mcpcTool.name,
21061
- tool({
21820
+ tool2({
21062
21821
  description: mcpcTool.description || "No description",
21063
- inputSchema: jsonSchema2(mcpcTool.inputSchema),
21822
+ inputSchema: jsonSchema3(mcpcTool.inputSchema),
21064
21823
  execute: async (input) => {
21065
21824
  return await server.callTool(mcpcTool.name, input);
21066
21825
  }