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