@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 +821 -62
- package/index.mjs +821 -62
- package/package.json +4 -1
- package/types/src/prompts/types.d.ts +1 -1
- package/types/src/prompts/types.d.ts.map +1 -1
- package/types/src/set-up-mcp-compose.d.ts +45 -0
- package/types/src/set-up-mcp-compose.d.ts.map +1 -1
package/index.mjs
CHANGED
|
@@ -7059,10 +7059,10 @@ var stringbool = (...args) => _stringbool({
|
|
|
7059
7059
|
String: ZodString
|
|
7060
7060
|
}, ...args);
|
|
7061
7061
|
function json(params) {
|
|
7062
|
-
const
|
|
7063
|
-
return union([string2(params), number2(), boolean2(), _null3(), array(
|
|
7062
|
+
const jsonSchema3 = lazy(() => {
|
|
7063
|
+
return union([string2(params), number2(), boolean2(), _null3(), array(jsonSchema3), record(string2(), jsonSchema3)]);
|
|
7064
7064
|
});
|
|
7065
|
-
return
|
|
7065
|
+
return jsonSchema3;
|
|
7066
7066
|
}
|
|
7067
7067
|
function preprocess(fn, schema) {
|
|
7068
7068
|
return pipe(transform(fn), schema);
|
|
@@ -14879,17 +14879,17 @@ var Client = class extends Protocol {
|
|
|
14879
14879
|
this._cachedToolOutputValidators.clear();
|
|
14880
14880
|
this._cachedKnownTaskTools.clear();
|
|
14881
14881
|
this._cachedRequiredTaskTools.clear();
|
|
14882
|
-
for (const
|
|
14883
|
-
if (
|
|
14884
|
-
const toolValidator = this._jsonSchemaValidator.getValidator(
|
|
14885
|
-
this._cachedToolOutputValidators.set(
|
|
14882
|
+
for (const tool2 of tools) {
|
|
14883
|
+
if (tool2.outputSchema) {
|
|
14884
|
+
const toolValidator = this._jsonSchemaValidator.getValidator(tool2.outputSchema);
|
|
14885
|
+
this._cachedToolOutputValidators.set(tool2.name, toolValidator);
|
|
14886
14886
|
}
|
|
14887
|
-
const taskSupport =
|
|
14887
|
+
const taskSupport = tool2.execution?.taskSupport;
|
|
14888
14888
|
if (taskSupport === "required" || taskSupport === "optional") {
|
|
14889
|
-
this._cachedKnownTaskTools.add(
|
|
14889
|
+
this._cachedKnownTaskTools.add(tool2.name);
|
|
14890
14890
|
}
|
|
14891
14891
|
if (taskSupport === "required") {
|
|
14892
|
-
this._cachedRequiredTaskTools.add(
|
|
14892
|
+
this._cachedRequiredTaskTools.add(tool2.name);
|
|
14893
14893
|
}
|
|
14894
14894
|
}
|
|
14895
14895
|
}
|
|
@@ -17248,14 +17248,14 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
17248
17248
|
acquiredKeys.push(defKey);
|
|
17249
17249
|
allClients[serverId] = client;
|
|
17250
17250
|
const { tools } = await client.listTools();
|
|
17251
|
-
tools.forEach((
|
|
17252
|
-
const toolNameWithScope = `${name}.${
|
|
17253
|
-
const internalToolName =
|
|
17251
|
+
tools.forEach((tool2) => {
|
|
17252
|
+
const toolNameWithScope = `${name}.${tool2.name}`;
|
|
17253
|
+
const internalToolName = tool2.name;
|
|
17254
17254
|
const rawToolId = `${serverId}_${internalToolName}`;
|
|
17255
17255
|
const toolId = sanitizePropertyKey(rawToolId);
|
|
17256
17256
|
if (filterIn && !filterIn({
|
|
17257
17257
|
action: internalToolName,
|
|
17258
|
-
tool,
|
|
17258
|
+
tool: tool2,
|
|
17259
17259
|
mcpName: name,
|
|
17260
17260
|
toolNameWithScope,
|
|
17261
17261
|
internalToolName,
|
|
@@ -17270,7 +17270,7 @@ async function composeMcpDepTools(mcpConfig, filterIn) {
|
|
|
17270
17270
|
timeout: def.toolCallTimeout
|
|
17271
17271
|
});
|
|
17272
17272
|
allTools[toolId] = {
|
|
17273
|
-
...
|
|
17273
|
+
...tool2,
|
|
17274
17274
|
execute,
|
|
17275
17275
|
_originalName: toolNameWithScope
|
|
17276
17276
|
};
|
|
@@ -17333,13 +17333,13 @@ var createConfigPlugin = () => ({
|
|
|
17333
17333
|
name: "built-in-config",
|
|
17334
17334
|
version: "1.0.0",
|
|
17335
17335
|
enforce: "pre",
|
|
17336
|
-
transformTool: (
|
|
17336
|
+
transformTool: (tool2, context2) => {
|
|
17337
17337
|
const server = context2.server;
|
|
17338
17338
|
const config2 = server.findToolConfig?.(context2.toolName);
|
|
17339
17339
|
if (config2?.description) {
|
|
17340
|
-
|
|
17340
|
+
tool2.description = config2.description;
|
|
17341
17341
|
}
|
|
17342
|
-
return
|
|
17342
|
+
return tool2;
|
|
17343
17343
|
}
|
|
17344
17344
|
});
|
|
17345
17345
|
var config_plugin_default = createConfigPlugin();
|
|
@@ -17349,10 +17349,10 @@ var createToolNameMappingPlugin = () => ({
|
|
|
17349
17349
|
name: "built-in-tool-name-mapping",
|
|
17350
17350
|
version: "1.0.0",
|
|
17351
17351
|
enforce: "pre",
|
|
17352
|
-
transformTool: (
|
|
17352
|
+
transformTool: (tool2, context2) => {
|
|
17353
17353
|
const server = context2.server;
|
|
17354
17354
|
const toolName = context2.toolName;
|
|
17355
|
-
const originalName =
|
|
17355
|
+
const originalName = tool2._originalName || toolName;
|
|
17356
17356
|
const dotNotation = originalName.replace(/_/g, ".");
|
|
17357
17357
|
const underscoreNotation = originalName.replace(/\./g, "_");
|
|
17358
17358
|
if (dotNotation !== originalName && server.toolNameMapping) {
|
|
@@ -17364,7 +17364,7 @@ var createToolNameMappingPlugin = () => ({
|
|
|
17364
17364
|
if (originalName !== toolName && server.toolNameMapping) {
|
|
17365
17365
|
server.toolNameMapping.set(originalName, toolName);
|
|
17366
17366
|
}
|
|
17367
|
-
return
|
|
17367
|
+
return tool2;
|
|
17368
17368
|
}
|
|
17369
17369
|
});
|
|
17370
17370
|
var tool_name_mapping_plugin_default = createToolNameMappingPlugin();
|
|
@@ -17857,13 +17857,13 @@ var PromptUtils = {
|
|
|
17857
17857
|
* Generate tool list for descriptions
|
|
17858
17858
|
*/
|
|
17859
17859
|
generateToolList: (tools) => {
|
|
17860
|
-
return tools.filter((
|
|
17860
|
+
return tools.filter((tool2) => !tool2.hide).map((tool2) => `<tool name="${tool2.name}"${tool2.description ? ` description="${tool2.description}"` : ""}/>`).join("\n");
|
|
17861
17861
|
},
|
|
17862
17862
|
/**
|
|
17863
17863
|
* Generate hidden tool list for descriptions
|
|
17864
17864
|
*/
|
|
17865
17865
|
generateHiddenToolList: (tools) => {
|
|
17866
|
-
return tools.filter((
|
|
17866
|
+
return tools.filter((tool2) => tool2.hide).map((tool2) => `<tool name="${tool2.name}" hide/>`).join("\n");
|
|
17867
17867
|
},
|
|
17868
17868
|
/**
|
|
17869
17869
|
* Format workflow steps for display
|
|
@@ -19648,12 +19648,12 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
19648
19648
|
}
|
|
19649
19649
|
buildDepGroups() {
|
|
19650
19650
|
const depGroups = {};
|
|
19651
|
-
this.toolNameToDetailList.forEach(([toolName,
|
|
19652
|
-
if (
|
|
19651
|
+
this.toolNameToDetailList.forEach(([toolName, tool2]) => {
|
|
19652
|
+
if (tool2?.inputSchema) {
|
|
19653
19653
|
depGroups[toolName] = {
|
|
19654
19654
|
type: "object",
|
|
19655
|
-
description:
|
|
19656
|
-
...
|
|
19655
|
+
description: tool2.description || `Tool: ${toolName}`,
|
|
19656
|
+
...tool2.inputSchema
|
|
19657
19657
|
};
|
|
19658
19658
|
} else {
|
|
19659
19659
|
const toolSchema = this.server.getHiddenToolSchema(toolName);
|
|
@@ -19710,10 +19710,10 @@ var SamplingExecutor = class extends BaseSamplingExecutor {
|
|
|
19710
19710
|
}
|
|
19711
19711
|
buildSystemPrompt(userRequest, agenticSchema, context2) {
|
|
19712
19712
|
const toolList = this.allToolNames.map((name) => {
|
|
19713
|
-
const
|
|
19713
|
+
const tool2 = this.toolNameToDetailList.find(([toolName]) => toolName === name);
|
|
19714
19714
|
const toolSchema = this.server.getHiddenToolSchema(name);
|
|
19715
|
-
if (
|
|
19716
|
-
return `- ${name}: ${
|
|
19715
|
+
if (tool2 && tool2[1]) {
|
|
19716
|
+
return `- ${name}: ${tool2[1].description || `Tool: ${name}`}`;
|
|
19717
19717
|
} else if (toolSchema) {
|
|
19718
19718
|
return `- ${name}: ${toolSchema.description}`;
|
|
19719
19719
|
}
|
|
@@ -19740,7 +19740,7 @@ ${JSON.stringify(context2, null, 2)}`;
|
|
|
19740
19740
|
## Current Task
|
|
19741
19741
|
You will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
|
|
19742
19742
|
|
|
19743
|
-
When you need to use a tool, specify the tool name in '
|
|
19743
|
+
When you need to use a tool, specify the tool name in 'useTool' and provide tool-specific parameters as additional properties.`;
|
|
19744
19744
|
return this.formatPromptForMode({
|
|
19745
19745
|
prompt: basePrompt + taskPrompt,
|
|
19746
19746
|
schema: agenticSchema
|
|
@@ -19920,6 +19920,763 @@ var createWorkflowSamplingModePlugin = () => ({
|
|
|
19920
19920
|
});
|
|
19921
19921
|
var mode_workflow_sampling_plugin_default = createWorkflowSamplingModePlugin();
|
|
19922
19922
|
|
|
19923
|
+
// __mcpc__core_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/utils.js
|
|
19924
|
+
function convertAISDKToMCPMessages(prompt) {
|
|
19925
|
+
const messages = [];
|
|
19926
|
+
for (const msg of prompt) {
|
|
19927
|
+
if (msg.role === "system") continue;
|
|
19928
|
+
const role = msg.role === "assistant" ? "assistant" : "user";
|
|
19929
|
+
const textParts = msg.content.filter((c) => c.type === "text");
|
|
19930
|
+
const toolCalls = msg.content.filter((c) => c.type === "tool-call");
|
|
19931
|
+
const toolResults = msg.content.filter((c) => c.type === "tool-result");
|
|
19932
|
+
const parts = [];
|
|
19933
|
+
if (textParts.length > 0) {
|
|
19934
|
+
parts.push(textParts.map((c) => c.text).join("\n"));
|
|
19935
|
+
}
|
|
19936
|
+
if (toolCalls.length > 0) {
|
|
19937
|
+
const calls = toolCalls.map((c) => {
|
|
19938
|
+
const call = c;
|
|
19939
|
+
const toolArgs = call.args ?? call.input ?? {};
|
|
19940
|
+
return `<use_tool tool="${call.toolName}">
|
|
19941
|
+
${JSON.stringify(toolArgs)}
|
|
19942
|
+
</use_tool>`;
|
|
19943
|
+
});
|
|
19944
|
+
parts.push(calls.join("\n"));
|
|
19945
|
+
}
|
|
19946
|
+
if (toolResults.length > 0) {
|
|
19947
|
+
const results = toolResults.map((c) => {
|
|
19948
|
+
const result = c;
|
|
19949
|
+
const resultValue = result.result ?? result.output ?? "undefined";
|
|
19950
|
+
const output = JSON.stringify(resultValue);
|
|
19951
|
+
return `Tool "${result.toolName}" result:
|
|
19952
|
+
${output}`;
|
|
19953
|
+
});
|
|
19954
|
+
parts.push(results.join("\n\n"));
|
|
19955
|
+
}
|
|
19956
|
+
const text = parts.join("\n\n");
|
|
19957
|
+
if (text) {
|
|
19958
|
+
messages.push({
|
|
19959
|
+
role,
|
|
19960
|
+
content: {
|
|
19961
|
+
type: "text",
|
|
19962
|
+
text
|
|
19963
|
+
}
|
|
19964
|
+
});
|
|
19965
|
+
}
|
|
19966
|
+
}
|
|
19967
|
+
return messages;
|
|
19968
|
+
}
|
|
19969
|
+
function convertMCPStopReasonToAISDK(stopReason) {
|
|
19970
|
+
if (stopReason === "endTurn" || stopReason === "stopSequence") {
|
|
19971
|
+
return "stop";
|
|
19972
|
+
}
|
|
19973
|
+
if (stopReason === "maxTokens") return "length";
|
|
19974
|
+
return stopReason ?? "unknown";
|
|
19975
|
+
}
|
|
19976
|
+
|
|
19977
|
+
// __mcpc__core_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/language-model.js
|
|
19978
|
+
var MCPSamplingLanguageModel = class {
|
|
19979
|
+
specificationVersion = "v2";
|
|
19980
|
+
provider;
|
|
19981
|
+
modelId;
|
|
19982
|
+
supportedUrls = {};
|
|
19983
|
+
server;
|
|
19984
|
+
modelPreferences;
|
|
19985
|
+
constructor(config2) {
|
|
19986
|
+
this.server = config2.server;
|
|
19987
|
+
this.modelId = "";
|
|
19988
|
+
this.provider = "mcp-client";
|
|
19989
|
+
this.modelPreferences = config2.modelPreferences;
|
|
19990
|
+
}
|
|
19991
|
+
/**
|
|
19992
|
+
* Generate a response using MCP's createMessage capability
|
|
19993
|
+
*/
|
|
19994
|
+
async doGenerate(options) {
|
|
19995
|
+
const messages = this.convertMessages(options.prompt);
|
|
19996
|
+
let systemPrompt;
|
|
19997
|
+
for (const msg of options.prompt) {
|
|
19998
|
+
if (msg.role === "system") {
|
|
19999
|
+
systemPrompt = msg.content;
|
|
20000
|
+
break;
|
|
20001
|
+
}
|
|
20002
|
+
}
|
|
20003
|
+
const useNativeTools = this.supportsSamplingTools();
|
|
20004
|
+
systemPrompt = this.injectResponseFormatInstructions(systemPrompt, options.responseFormat, useNativeTools);
|
|
20005
|
+
systemPrompt = this.injectToolInstructions(systemPrompt, options.tools, useNativeTools);
|
|
20006
|
+
const createMessageParams = {
|
|
20007
|
+
systemPrompt,
|
|
20008
|
+
messages,
|
|
20009
|
+
maxTokens: options.maxOutputTokens ?? 55e3,
|
|
20010
|
+
modelPreferences: this.modelPreferences
|
|
20011
|
+
};
|
|
20012
|
+
if (useNativeTools && options.tools && options.tools.length > 0) {
|
|
20013
|
+
createMessageParams.tools = this.convertAISDKToolsToMCP(options.tools);
|
|
20014
|
+
createMessageParams.toolChoice = {
|
|
20015
|
+
mode: "auto"
|
|
20016
|
+
};
|
|
20017
|
+
}
|
|
20018
|
+
const result = await this.server.createMessage(createMessageParams);
|
|
20019
|
+
const content = [];
|
|
20020
|
+
if (useNativeTools) {
|
|
20021
|
+
const contentArray = Array.isArray(result.content) ? result.content : [
|
|
20022
|
+
result.content
|
|
20023
|
+
];
|
|
20024
|
+
for (const block of contentArray) {
|
|
20025
|
+
if (block.type === "text" && "text" in block) {
|
|
20026
|
+
content.push({
|
|
20027
|
+
type: "text",
|
|
20028
|
+
text: block.text
|
|
20029
|
+
});
|
|
20030
|
+
} else if (block.type === "tool_use" && "id" in block && "name" in block) {
|
|
20031
|
+
const toolInput = block.input || {};
|
|
20032
|
+
content.push({
|
|
20033
|
+
type: "tool-call",
|
|
20034
|
+
toolCallId: block.id,
|
|
20035
|
+
toolName: block.name,
|
|
20036
|
+
input: JSON.stringify(toolInput)
|
|
20037
|
+
});
|
|
20038
|
+
}
|
|
20039
|
+
}
|
|
20040
|
+
} else {
|
|
20041
|
+
if (result.content.type === "text" && result.content.text) {
|
|
20042
|
+
const { text, toolCalls } = this.extractToolCalls(result.content.text, options.tools);
|
|
20043
|
+
if (text.trim()) {
|
|
20044
|
+
const textContent = {
|
|
20045
|
+
type: "text",
|
|
20046
|
+
text
|
|
20047
|
+
};
|
|
20048
|
+
content.push(textContent);
|
|
20049
|
+
}
|
|
20050
|
+
content.push(...toolCalls);
|
|
20051
|
+
}
|
|
20052
|
+
}
|
|
20053
|
+
const finishReason = this.mapStopReason(result.stopReason);
|
|
20054
|
+
return {
|
|
20055
|
+
content,
|
|
20056
|
+
finishReason,
|
|
20057
|
+
usage: {
|
|
20058
|
+
inputTokens: void 0,
|
|
20059
|
+
outputTokens: void 0,
|
|
20060
|
+
totalTokens: 0
|
|
20061
|
+
},
|
|
20062
|
+
request: {
|
|
20063
|
+
body: JSON.stringify({
|
|
20064
|
+
systemPrompt,
|
|
20065
|
+
messages
|
|
20066
|
+
})
|
|
20067
|
+
},
|
|
20068
|
+
response: {
|
|
20069
|
+
modelId: result.model
|
|
20070
|
+
},
|
|
20071
|
+
warnings: []
|
|
20072
|
+
};
|
|
20073
|
+
}
|
|
20074
|
+
/**
|
|
20075
|
+
* Stream a response using MCP's createMessage capability
|
|
20076
|
+
*
|
|
20077
|
+
* Since MCP doesn't support native streaming, we generate the full response
|
|
20078
|
+
* and emit it as stream events following AI SDK's protocol.
|
|
20079
|
+
*/
|
|
20080
|
+
async doStream(options) {
|
|
20081
|
+
const result = await this.doGenerate(options);
|
|
20082
|
+
const stream = new ReadableStream({
|
|
20083
|
+
start(controller) {
|
|
20084
|
+
if (result.response?.modelId) {
|
|
20085
|
+
controller.enqueue({
|
|
20086
|
+
type: "response-metadata",
|
|
20087
|
+
modelId: result.response.modelId,
|
|
20088
|
+
...result.response.headers && {
|
|
20089
|
+
headers: result.response.headers
|
|
20090
|
+
}
|
|
20091
|
+
});
|
|
20092
|
+
}
|
|
20093
|
+
let textIndex = 0;
|
|
20094
|
+
for (const part of result.content) {
|
|
20095
|
+
if (part.type === "text") {
|
|
20096
|
+
const id = `text-${++textIndex}`;
|
|
20097
|
+
controller.enqueue({
|
|
20098
|
+
type: "text-start",
|
|
20099
|
+
id
|
|
20100
|
+
});
|
|
20101
|
+
controller.enqueue({
|
|
20102
|
+
type: "text-delta",
|
|
20103
|
+
id,
|
|
20104
|
+
delta: part.text
|
|
20105
|
+
});
|
|
20106
|
+
controller.enqueue({
|
|
20107
|
+
type: "text-end",
|
|
20108
|
+
id
|
|
20109
|
+
});
|
|
20110
|
+
} else if (part.type === "tool-call") {
|
|
20111
|
+
controller.enqueue({
|
|
20112
|
+
type: "tool-call",
|
|
20113
|
+
toolCallId: part.toolCallId,
|
|
20114
|
+
toolName: part.toolName,
|
|
20115
|
+
input: part.input
|
|
20116
|
+
});
|
|
20117
|
+
}
|
|
20118
|
+
}
|
|
20119
|
+
controller.enqueue({
|
|
20120
|
+
type: "finish",
|
|
20121
|
+
finishReason: result.finishReason,
|
|
20122
|
+
usage: result.usage
|
|
20123
|
+
});
|
|
20124
|
+
controller.close();
|
|
20125
|
+
}
|
|
20126
|
+
});
|
|
20127
|
+
return {
|
|
20128
|
+
stream,
|
|
20129
|
+
request: result.request,
|
|
20130
|
+
warnings: result.warnings
|
|
20131
|
+
};
|
|
20132
|
+
}
|
|
20133
|
+
/**
|
|
20134
|
+
* Convert AI SDK messages to MCP sampling format
|
|
20135
|
+
*/
|
|
20136
|
+
convertMessages(prompt) {
|
|
20137
|
+
return convertAISDKToMCPMessages(prompt);
|
|
20138
|
+
}
|
|
20139
|
+
/**
|
|
20140
|
+
* Map MCP stop reason to AI SDK finish reason
|
|
20141
|
+
*/
|
|
20142
|
+
mapStopReason(stopReason) {
|
|
20143
|
+
return convertMCPStopReasonToAISDK(stopReason);
|
|
20144
|
+
}
|
|
20145
|
+
/**
|
|
20146
|
+
* Check if client supports native tool use in sampling
|
|
20147
|
+
*/
|
|
20148
|
+
supportsSamplingTools() {
|
|
20149
|
+
const capabilities = this.server.getClientCapabilities();
|
|
20150
|
+
return !!capabilities?.sampling?.tools;
|
|
20151
|
+
}
|
|
20152
|
+
/**
|
|
20153
|
+
* Convert AI SDK tools to MCP Tool format
|
|
20154
|
+
*/
|
|
20155
|
+
convertAISDKToolsToMCP(tools) {
|
|
20156
|
+
if (!tools || tools.length === 0) return [];
|
|
20157
|
+
return tools.filter((tool2) => tool2.type === "function").map((tool2) => {
|
|
20158
|
+
const toolAny = tool2;
|
|
20159
|
+
return {
|
|
20160
|
+
name: tool2.name,
|
|
20161
|
+
description: toolAny.description || `Tool: ${tool2.name}`,
|
|
20162
|
+
inputSchema: {
|
|
20163
|
+
type: "object",
|
|
20164
|
+
...toolAny.inputSchema || toolAny.parameters
|
|
20165
|
+
}
|
|
20166
|
+
};
|
|
20167
|
+
});
|
|
20168
|
+
}
|
|
20169
|
+
/**
|
|
20170
|
+
* Inject response format instructions into system prompt
|
|
20171
|
+
*
|
|
20172
|
+
* Only injects formatting instructions in JSON fallback mode.
|
|
20173
|
+
* In native tools mode, structured output is handled by the provider.
|
|
20174
|
+
*/
|
|
20175
|
+
injectResponseFormatInstructions(systemPrompt, responseFormat, useNativeTools) {
|
|
20176
|
+
if (!responseFormat) {
|
|
20177
|
+
return systemPrompt;
|
|
20178
|
+
}
|
|
20179
|
+
if (useNativeTools) {
|
|
20180
|
+
return systemPrompt;
|
|
20181
|
+
}
|
|
20182
|
+
let enhanced = systemPrompt || "";
|
|
20183
|
+
if (responseFormat.type === "json") {
|
|
20184
|
+
const jsonPrompt = `
|
|
20185
|
+
|
|
20186
|
+
IMPORTANT: You MUST respond with valid JSON only. Do not include any text before or after the JSON.
|
|
20187
|
+
- Your response must be a valid JSON object
|
|
20188
|
+
- Do not wrap the JSON in markdown code blocks
|
|
20189
|
+
- Do not include explanations or comments
|
|
20190
|
+
- Ensure all JSON is properly formatted and parseable`;
|
|
20191
|
+
enhanced = enhanced ? `${enhanced}${jsonPrompt}` : jsonPrompt.trim();
|
|
20192
|
+
if (responseFormat.schema) {
|
|
20193
|
+
const schemaInfo = `
|
|
20194
|
+
- Follow this JSON schema structure: ${JSON.stringify(responseFormat.schema)}`;
|
|
20195
|
+
enhanced += schemaInfo;
|
|
20196
|
+
}
|
|
20197
|
+
}
|
|
20198
|
+
return enhanced || void 0;
|
|
20199
|
+
}
|
|
20200
|
+
/**
|
|
20201
|
+
* Inject tool definitions into system prompt
|
|
20202
|
+
*
|
|
20203
|
+
* WORKAROUND: MCP sampling currently doesn't support native tools parameter.
|
|
20204
|
+
* This method injects tool descriptions and usage instructions into the system prompt.
|
|
20205
|
+
*
|
|
20206
|
+
* TODO: Remove this workaround when MCP protocol adds native support for:
|
|
20207
|
+
* - tools parameter in createMessage
|
|
20208
|
+
* - Tool calling and function execution
|
|
20209
|
+
* - Structured tool responses
|
|
20210
|
+
*/
|
|
20211
|
+
injectToolInstructions(systemPrompt, tools, useNativeTools) {
|
|
20212
|
+
if (!tools || tools.length === 0) {
|
|
20213
|
+
return systemPrompt;
|
|
20214
|
+
}
|
|
20215
|
+
if (useNativeTools) {
|
|
20216
|
+
return systemPrompt;
|
|
20217
|
+
}
|
|
20218
|
+
let enhanced = systemPrompt || "";
|
|
20219
|
+
const toolsPrompt = `
|
|
20220
|
+
|
|
20221
|
+
AVAILABLE TOOLS:
|
|
20222
|
+
You have access to the following tools. To use a tool, respond with this XML format:
|
|
20223
|
+
<use_tool tool="tool_name">
|
|
20224
|
+
{"param1": "value1", "param2": "value2"}
|
|
20225
|
+
</use_tool>
|
|
20226
|
+
|
|
20227
|
+
Follow the JSON schema definition for each tool's parameters.
|
|
20228
|
+
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.
|
|
20229
|
+
|
|
20230
|
+
Tools:`;
|
|
20231
|
+
const toolDescriptions = tools.map((tool2) => {
|
|
20232
|
+
if (tool2.type === "function") {
|
|
20233
|
+
const toolAny = tool2;
|
|
20234
|
+
const description = toolAny.description || "No description provided";
|
|
20235
|
+
const schema = toolAny.inputSchema || toolAny.parameters;
|
|
20236
|
+
const params = schema ? `
|
|
20237
|
+
JSON Schema: ${JSON.stringify(schema, null, 2)}` : "";
|
|
20238
|
+
return `
|
|
20239
|
+
- ${tool2.name}: ${description}${params}`;
|
|
20240
|
+
} else if (tool2.type === "provider-defined") {
|
|
20241
|
+
return `
|
|
20242
|
+
- ${tool2.name}: ${tool2.id || "No description provided"}`;
|
|
20243
|
+
}
|
|
20244
|
+
return "";
|
|
20245
|
+
}).filter(Boolean).join("");
|
|
20246
|
+
enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}` : `${toolsPrompt}${toolDescriptions}`.trim();
|
|
20247
|
+
return enhanced || void 0;
|
|
20248
|
+
}
|
|
20249
|
+
/**
|
|
20250
|
+
* Extract tool calls from LLM response text
|
|
20251
|
+
*
|
|
20252
|
+
* Parses XML-style tool call tags from the response:
|
|
20253
|
+
* <use_tool tool="tool_name">{"arg": "value"}</use_tool>
|
|
20254
|
+
*/
|
|
20255
|
+
extractToolCalls(responseText, tools) {
|
|
20256
|
+
if (!tools || tools.length === 0) {
|
|
20257
|
+
return {
|
|
20258
|
+
text: responseText,
|
|
20259
|
+
toolCalls: []
|
|
20260
|
+
};
|
|
20261
|
+
}
|
|
20262
|
+
const toolCalls = [];
|
|
20263
|
+
const toolCallRegex = /<use_tool\s+tool="([^"]+)">([\s\S]*?)<\/use_tool>/g;
|
|
20264
|
+
let match;
|
|
20265
|
+
let lastIndex = 0;
|
|
20266
|
+
const textParts = [];
|
|
20267
|
+
let callIndex = 0;
|
|
20268
|
+
while ((match = toolCallRegex.exec(responseText)) !== null) {
|
|
20269
|
+
textParts.push(responseText.slice(lastIndex, match.index));
|
|
20270
|
+
const toolName = match[1];
|
|
20271
|
+
const argsText = match[2].trim?.();
|
|
20272
|
+
toolCalls.push({
|
|
20273
|
+
type: "tool-call",
|
|
20274
|
+
toolCallId: `call_${Date.now()}_${callIndex++}`,
|
|
20275
|
+
toolName,
|
|
20276
|
+
input: argsText
|
|
20277
|
+
});
|
|
20278
|
+
lastIndex = match.index + match[0].length;
|
|
20279
|
+
}
|
|
20280
|
+
textParts.push(responseText.slice(lastIndex));
|
|
20281
|
+
const text = textParts.join("").trim();
|
|
20282
|
+
return {
|
|
20283
|
+
text,
|
|
20284
|
+
toolCalls
|
|
20285
|
+
};
|
|
20286
|
+
}
|
|
20287
|
+
};
|
|
20288
|
+
|
|
20289
|
+
// __mcpc__core_latest/node_modules/@jsr/mcpc__mcp-sampling-ai-provider/src/provider.js
|
|
20290
|
+
var MCPSamplingProvider = class {
|
|
20291
|
+
config;
|
|
20292
|
+
constructor(config2) {
|
|
20293
|
+
this.config = config2;
|
|
20294
|
+
}
|
|
20295
|
+
/**
|
|
20296
|
+
* Create a language model instance for a specific MCP tool/agent
|
|
20297
|
+
*
|
|
20298
|
+
* @param options - Optional configuration overrides
|
|
20299
|
+
* @returns A LanguageModelV2 instance
|
|
20300
|
+
*/
|
|
20301
|
+
languageModel(options) {
|
|
20302
|
+
return new MCPSamplingLanguageModel({
|
|
20303
|
+
server: this.config.server,
|
|
20304
|
+
modelPreferences: options?.modelPreferences
|
|
20305
|
+
});
|
|
20306
|
+
}
|
|
20307
|
+
/**
|
|
20308
|
+
* Shorthand for creating a language model
|
|
20309
|
+
*/
|
|
20310
|
+
call(options) {
|
|
20311
|
+
return this.languageModel(options);
|
|
20312
|
+
}
|
|
20313
|
+
};
|
|
20314
|
+
|
|
20315
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/ai/base-ai-executor.js
|
|
20316
|
+
import { trace as trace2 } from "@opentelemetry/api";
|
|
20317
|
+
import { jsonSchema as jsonSchema2, stepCountIs, streamText, tool } from "ai";
|
|
20318
|
+
var BaseAIExecutor = class {
|
|
20319
|
+
config;
|
|
20320
|
+
tracer;
|
|
20321
|
+
logger;
|
|
20322
|
+
constructor(config2, server) {
|
|
20323
|
+
this.config = {
|
|
20324
|
+
maxSteps: 50,
|
|
20325
|
+
tracingEnabled: true,
|
|
20326
|
+
...config2
|
|
20327
|
+
};
|
|
20328
|
+
this.tracer = trace2.getTracer(`mcpc.ai.${config2.name}`);
|
|
20329
|
+
this.logger = createLogger(`mcpc.ai.${config2.name}`, server);
|
|
20330
|
+
}
|
|
20331
|
+
execute(args) {
|
|
20332
|
+
if (this.config.tracingEnabled) {
|
|
20333
|
+
return this.executeWithTracing(args);
|
|
20334
|
+
}
|
|
20335
|
+
return this.executeCore(args);
|
|
20336
|
+
}
|
|
20337
|
+
executeWithTracing(args) {
|
|
20338
|
+
return this.tracer.startActiveSpan(`mcpc.ai.${this.config.name}`, async (span) => {
|
|
20339
|
+
try {
|
|
20340
|
+
span.setAttributes({
|
|
20341
|
+
"mcpc.executor": this.config.name,
|
|
20342
|
+
"mcpc.type": this.getExecutorType()
|
|
20343
|
+
});
|
|
20344
|
+
const result = await this.executeCore(args, span);
|
|
20345
|
+
span.setAttributes({
|
|
20346
|
+
"mcpc.error": !!result.isError
|
|
20347
|
+
});
|
|
20348
|
+
return result;
|
|
20349
|
+
} catch (error2) {
|
|
20350
|
+
span.recordException(error2);
|
|
20351
|
+
throw error2;
|
|
20352
|
+
} finally {
|
|
20353
|
+
span.end();
|
|
20354
|
+
}
|
|
20355
|
+
});
|
|
20356
|
+
}
|
|
20357
|
+
async executeCore(args, span) {
|
|
20358
|
+
try {
|
|
20359
|
+
const result = streamText({
|
|
20360
|
+
model: this.getModel(),
|
|
20361
|
+
system: this.buildSystemPrompt(args),
|
|
20362
|
+
messages: [
|
|
20363
|
+
{
|
|
20364
|
+
role: "user",
|
|
20365
|
+
content: args.userRequest
|
|
20366
|
+
}
|
|
20367
|
+
],
|
|
20368
|
+
tools: this.buildTools(),
|
|
20369
|
+
stopWhen: stepCountIs(this.config.maxSteps),
|
|
20370
|
+
experimental_telemetry: this.config.tracingEnabled ? {
|
|
20371
|
+
isEnabled: true,
|
|
20372
|
+
functionId: `mcpc.${this.config.name}`,
|
|
20373
|
+
tracer: this.tracer
|
|
20374
|
+
} : void 0,
|
|
20375
|
+
onStepFinish: (step) => {
|
|
20376
|
+
if (span) {
|
|
20377
|
+
span.addEvent("step", {
|
|
20378
|
+
tools: step.toolCalls?.length ?? 0,
|
|
20379
|
+
reason: step.finishReason ?? ""
|
|
20380
|
+
});
|
|
20381
|
+
}
|
|
20382
|
+
}
|
|
20383
|
+
});
|
|
20384
|
+
return {
|
|
20385
|
+
content: [
|
|
20386
|
+
{
|
|
20387
|
+
type: "text",
|
|
20388
|
+
text: await result.text || `Completed in ${(await result.steps)?.length ?? "unknown"} step(s).`
|
|
20389
|
+
}
|
|
20390
|
+
],
|
|
20391
|
+
isError: false
|
|
20392
|
+
};
|
|
20393
|
+
} catch (error2) {
|
|
20394
|
+
this.logger.error({
|
|
20395
|
+
message: "Execution error",
|
|
20396
|
+
error: error2
|
|
20397
|
+
});
|
|
20398
|
+
return {
|
|
20399
|
+
content: [
|
|
20400
|
+
{
|
|
20401
|
+
type: "text",
|
|
20402
|
+
text: `Error: ${error2 instanceof Error ? error2.message : String(error2)}`
|
|
20403
|
+
}
|
|
20404
|
+
],
|
|
20405
|
+
isError: true
|
|
20406
|
+
};
|
|
20407
|
+
}
|
|
20408
|
+
}
|
|
20409
|
+
buildSystemPrompt(args) {
|
|
20410
|
+
return `Agent \`${this.config.name}\` that completes tasks by calling tools.
|
|
20411
|
+
|
|
20412
|
+
<manual>
|
|
20413
|
+
${this.config.description}
|
|
20414
|
+
</manual>
|
|
20415
|
+
|
|
20416
|
+
<rules>
|
|
20417
|
+
${this.getRules()}
|
|
20418
|
+
</rules>
|
|
20419
|
+
|
|
20420
|
+
<tools>
|
|
20421
|
+
${this.getToolListDescription()}
|
|
20422
|
+
</tools>${args.context ? this.formatContext(args.context) : ""}`;
|
|
20423
|
+
}
|
|
20424
|
+
getRules() {
|
|
20425
|
+
return `1. Use tools to complete the user's request
|
|
20426
|
+
2. Review results after each tool call
|
|
20427
|
+
3. Adapt your approach based on outcomes
|
|
20428
|
+
4. Continue until task is complete
|
|
20429
|
+
5. When complete, provide a summary WITHOUT calling more tools`;
|
|
20430
|
+
}
|
|
20431
|
+
getToolListDescription() {
|
|
20432
|
+
return "Tools will be provided by AI SDK";
|
|
20433
|
+
}
|
|
20434
|
+
formatContext(context2) {
|
|
20435
|
+
return `
|
|
20436
|
+
|
|
20437
|
+
<context>
|
|
20438
|
+
${JSON.stringify(context2, null, 2)}
|
|
20439
|
+
</context>`;
|
|
20440
|
+
}
|
|
20441
|
+
convertToAISDKTool(name, toolDetail, execute) {
|
|
20442
|
+
return tool({
|
|
20443
|
+
description: toolDetail.description || `Tool: ${name}`,
|
|
20444
|
+
inputSchema: jsonSchema2(toolDetail.inputSchema || {
|
|
20445
|
+
type: "object"
|
|
20446
|
+
}),
|
|
20447
|
+
execute
|
|
20448
|
+
});
|
|
20449
|
+
}
|
|
20450
|
+
};
|
|
20451
|
+
|
|
20452
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/ai/ai-sampling-executor.js
|
|
20453
|
+
var AISamplingExecutor = class extends BaseAIExecutor {
|
|
20454
|
+
server;
|
|
20455
|
+
tools;
|
|
20456
|
+
providerOptions;
|
|
20457
|
+
model = null;
|
|
20458
|
+
constructor(config2) {
|
|
20459
|
+
super(config2, "callTool" in config2.server ? config2.server : void 0);
|
|
20460
|
+
this.server = config2.server;
|
|
20461
|
+
this.tools = config2.tools;
|
|
20462
|
+
this.providerOptions = config2.providerOptions;
|
|
20463
|
+
}
|
|
20464
|
+
initProvider() {
|
|
20465
|
+
if (!this.model) {
|
|
20466
|
+
const provider = new MCPSamplingProvider({
|
|
20467
|
+
server: this.server
|
|
20468
|
+
});
|
|
20469
|
+
this.model = provider.languageModel(this.providerOptions);
|
|
20470
|
+
}
|
|
20471
|
+
return this.model;
|
|
20472
|
+
}
|
|
20473
|
+
getModel() {
|
|
20474
|
+
if (!this.model) throw new Error("Model not initialized");
|
|
20475
|
+
return this.model;
|
|
20476
|
+
}
|
|
20477
|
+
getExecutorType() {
|
|
20478
|
+
return "mcp";
|
|
20479
|
+
}
|
|
20480
|
+
getToolListDescription() {
|
|
20481
|
+
return this.tools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
|
|
20482
|
+
}
|
|
20483
|
+
buildTools() {
|
|
20484
|
+
const aiTools = {};
|
|
20485
|
+
for (const [name, detail] of this.tools) {
|
|
20486
|
+
aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
|
|
20487
|
+
const result = await this.callTool(name, input);
|
|
20488
|
+
return this.formatResult(result);
|
|
20489
|
+
});
|
|
20490
|
+
}
|
|
20491
|
+
return aiTools;
|
|
20492
|
+
}
|
|
20493
|
+
async callTool(name, input) {
|
|
20494
|
+
if ("callTool" in this.server) {
|
|
20495
|
+
return await this.server.callTool(name, input);
|
|
20496
|
+
}
|
|
20497
|
+
const detail = this.tools.find(([n]) => n === name)?.[1];
|
|
20498
|
+
if (detail?.execute) return await detail.execute(input);
|
|
20499
|
+
throw new Error(`Cannot call tool "${name}"`);
|
|
20500
|
+
}
|
|
20501
|
+
formatResult(result) {
|
|
20502
|
+
const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
|
|
20503
|
+
return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
|
|
20504
|
+
}
|
|
20505
|
+
execute(args) {
|
|
20506
|
+
this.initProvider();
|
|
20507
|
+
return super.execute(args);
|
|
20508
|
+
}
|
|
20509
|
+
};
|
|
20510
|
+
|
|
20511
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/ai/ai-sampling-registrar.js
|
|
20512
|
+
function registerAISamplingTool(server, params) {
|
|
20513
|
+
const { name, description, allToolNames, depGroups, toolNameToDetailList, providerOptions, maxSteps = 50, tracingEnabled = false } = params;
|
|
20514
|
+
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
20515
|
+
const executor = new AISamplingExecutor({
|
|
20516
|
+
name,
|
|
20517
|
+
description,
|
|
20518
|
+
server,
|
|
20519
|
+
tools: toolNameToDetailList,
|
|
20520
|
+
providerOptions,
|
|
20521
|
+
maxSteps,
|
|
20522
|
+
tracingEnabled
|
|
20523
|
+
});
|
|
20524
|
+
const toolDescription = CompiledPrompts.samplingToolDescription({
|
|
20525
|
+
toolName: name,
|
|
20526
|
+
description,
|
|
20527
|
+
toolList: allToolNames.map((n) => `- ${n}`).join("\n")
|
|
20528
|
+
});
|
|
20529
|
+
const argsDef = createArgsDef.forSampling();
|
|
20530
|
+
const schema = allToolNames.length > 0 ? argsDef : {
|
|
20531
|
+
type: "object",
|
|
20532
|
+
properties: {}
|
|
20533
|
+
};
|
|
20534
|
+
server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
|
|
20535
|
+
const userRequest = typeof args.userRequest === "string" ? args.userRequest : JSON.stringify(args);
|
|
20536
|
+
return executor.execute({
|
|
20537
|
+
userRequest,
|
|
20538
|
+
context: args.context
|
|
20539
|
+
});
|
|
20540
|
+
});
|
|
20541
|
+
}
|
|
20542
|
+
|
|
20543
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-ai-sampling-plugin.js
|
|
20544
|
+
var createAISamplingModePlugin = () => ({
|
|
20545
|
+
name: "mode-ai-sampling",
|
|
20546
|
+
version: "1.0.0",
|
|
20547
|
+
apply: "ai_sampling",
|
|
20548
|
+
registerAgentTool: (context2) => {
|
|
20549
|
+
const opts = context2.options;
|
|
20550
|
+
registerAISamplingTool(context2.server, {
|
|
20551
|
+
description: context2.description,
|
|
20552
|
+
name: context2.name,
|
|
20553
|
+
allToolNames: context2.allToolNames,
|
|
20554
|
+
depGroups: context2.depGroups,
|
|
20555
|
+
toolNameToDetailList: context2.toolNameToDetailList,
|
|
20556
|
+
providerOptions: opts.providerOptions,
|
|
20557
|
+
maxSteps: opts.maxSteps,
|
|
20558
|
+
tracingEnabled: opts.tracingEnabled
|
|
20559
|
+
});
|
|
20560
|
+
}
|
|
20561
|
+
});
|
|
20562
|
+
var mode_ai_sampling_plugin_default = createAISamplingModePlugin();
|
|
20563
|
+
|
|
20564
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/ai/ai-acp-executor.js
|
|
20565
|
+
import { createACPProvider } from "@mcpc-tech/acp-ai-provider";
|
|
20566
|
+
var AIACPExecutor = class extends BaseAIExecutor {
|
|
20567
|
+
acpSettings;
|
|
20568
|
+
clientTools;
|
|
20569
|
+
provider = null;
|
|
20570
|
+
model = null;
|
|
20571
|
+
constructor(config2) {
|
|
20572
|
+
super(config2);
|
|
20573
|
+
this.acpSettings = config2.acpSettings;
|
|
20574
|
+
this.clientTools = config2.clientTools ?? [];
|
|
20575
|
+
}
|
|
20576
|
+
initProvider() {
|
|
20577
|
+
if (!this.model) {
|
|
20578
|
+
this.provider = createACPProvider(this.acpSettings);
|
|
20579
|
+
this.model = this.provider.languageModel();
|
|
20580
|
+
}
|
|
20581
|
+
return this.model;
|
|
20582
|
+
}
|
|
20583
|
+
getModel() {
|
|
20584
|
+
if (!this.model) throw new Error("Model not initialized");
|
|
20585
|
+
return this.model;
|
|
20586
|
+
}
|
|
20587
|
+
getExecutorType() {
|
|
20588
|
+
return "acp";
|
|
20589
|
+
}
|
|
20590
|
+
getToolListDescription() {
|
|
20591
|
+
if (this.clientTools.length === 0) {
|
|
20592
|
+
return "Tools will be provided by AI SDK";
|
|
20593
|
+
}
|
|
20594
|
+
return this.clientTools.map(([name, detail]) => `- ${name}: ${detail.description || "No description"}`).join("\n");
|
|
20595
|
+
}
|
|
20596
|
+
buildTools() {
|
|
20597
|
+
const aiTools = {};
|
|
20598
|
+
for (const [name, detail] of this.clientTools) {
|
|
20599
|
+
if (!detail.execute) continue;
|
|
20600
|
+
aiTools[name] = this.convertToAISDKTool(name, detail, async (input) => {
|
|
20601
|
+
const result = await detail.execute(input);
|
|
20602
|
+
return this.formatResult(result);
|
|
20603
|
+
});
|
|
20604
|
+
}
|
|
20605
|
+
return aiTools;
|
|
20606
|
+
}
|
|
20607
|
+
formatResult(result) {
|
|
20608
|
+
const texts = result.content?.filter((c) => c.type === "text").map((c) => c.text);
|
|
20609
|
+
return texts?.length ? texts.join("\n") : JSON.stringify(result.content);
|
|
20610
|
+
}
|
|
20611
|
+
execute(args) {
|
|
20612
|
+
this.initProvider();
|
|
20613
|
+
return super.execute(args);
|
|
20614
|
+
}
|
|
20615
|
+
cleanup() {
|
|
20616
|
+
if (this.provider && typeof this.provider.cleanup === "function") {
|
|
20617
|
+
this.provider.cleanup();
|
|
20618
|
+
}
|
|
20619
|
+
this.model = null;
|
|
20620
|
+
this.provider = null;
|
|
20621
|
+
}
|
|
20622
|
+
};
|
|
20623
|
+
|
|
20624
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/executors/ai/ai-acp-registrar.js
|
|
20625
|
+
function registerAIACPTool(server, params) {
|
|
20626
|
+
const { name, description, allToolNames, depGroups, acpSettings, clientTools = [], maxSteps = 50, tracingEnabled = false } = params;
|
|
20627
|
+
const createArgsDef = createArgsDefFactory(name, allToolNames, depGroups, void 0, void 0);
|
|
20628
|
+
const executor = new AIACPExecutor({
|
|
20629
|
+
name,
|
|
20630
|
+
description,
|
|
20631
|
+
acpSettings,
|
|
20632
|
+
clientTools,
|
|
20633
|
+
maxSteps,
|
|
20634
|
+
tracingEnabled
|
|
20635
|
+
});
|
|
20636
|
+
const toolDescription = CompiledPrompts.samplingToolDescription({
|
|
20637
|
+
toolName: name,
|
|
20638
|
+
description,
|
|
20639
|
+
toolList: allToolNames.length > 0 ? allToolNames.map((n) => `- ${n}`).join("\n") : "Agent has its own tools"
|
|
20640
|
+
});
|
|
20641
|
+
const argsDef = createArgsDef.forSampling();
|
|
20642
|
+
const schema = allToolNames.length > 0 ? argsDef : {
|
|
20643
|
+
type: "object",
|
|
20644
|
+
properties: {}
|
|
20645
|
+
};
|
|
20646
|
+
server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), (args) => {
|
|
20647
|
+
const userRequest = typeof args.userRequest === "string" ? args.userRequest : JSON.stringify(args);
|
|
20648
|
+
return executor.execute({
|
|
20649
|
+
userRequest,
|
|
20650
|
+
context: args.context
|
|
20651
|
+
});
|
|
20652
|
+
});
|
|
20653
|
+
return executor;
|
|
20654
|
+
}
|
|
20655
|
+
|
|
20656
|
+
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/mode-ai-acp-plugin.js
|
|
20657
|
+
var createAIACPModePlugin = () => ({
|
|
20658
|
+
name: "mode-ai-acp",
|
|
20659
|
+
version: "1.0.0",
|
|
20660
|
+
apply: "ai_acp",
|
|
20661
|
+
registerAgentTool: (context2) => {
|
|
20662
|
+
const opts = context2.options;
|
|
20663
|
+
if (!opts.acpSettings) {
|
|
20664
|
+
throw new Error("ai_acp mode requires acpSettings in options");
|
|
20665
|
+
}
|
|
20666
|
+
registerAIACPTool(context2.server, {
|
|
20667
|
+
description: context2.description,
|
|
20668
|
+
name: context2.name,
|
|
20669
|
+
allToolNames: context2.allToolNames,
|
|
20670
|
+
depGroups: context2.depGroups,
|
|
20671
|
+
acpSettings: opts.acpSettings,
|
|
20672
|
+
clientTools: opts.clientTools,
|
|
20673
|
+
maxSteps: opts.maxSteps,
|
|
20674
|
+
tracingEnabled: opts.tracingEnabled
|
|
20675
|
+
});
|
|
20676
|
+
}
|
|
20677
|
+
});
|
|
20678
|
+
var mode_ai_acp_plugin_default = createAIACPModePlugin();
|
|
20679
|
+
|
|
19923
20680
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/plugins/built-in/index.js
|
|
19924
20681
|
function getBuiltInPlugins() {
|
|
19925
20682
|
return [
|
|
@@ -19929,6 +20686,8 @@ function getBuiltInPlugins() {
|
|
|
19929
20686
|
mode_workflow_plugin_default,
|
|
19930
20687
|
mode_agentic_sampling_plugin_default,
|
|
19931
20688
|
mode_workflow_sampling_plugin_default,
|
|
20689
|
+
mode_ai_sampling_plugin_default,
|
|
20690
|
+
mode_ai_acp_plugin_default,
|
|
19932
20691
|
logging_plugin_default
|
|
19933
20692
|
];
|
|
19934
20693
|
}
|
|
@@ -20216,13 +20975,13 @@ var PluginManager = class {
|
|
|
20216
20975
|
/**
|
|
20217
20976
|
* Apply transformTool hooks to a tool during composition
|
|
20218
20977
|
*/
|
|
20219
|
-
async applyTransformToolHooks(
|
|
20978
|
+
async applyTransformToolHooks(tool2, context2) {
|
|
20220
20979
|
const transformPlugins = this.plugins.filter((p2) => p2.transformTool && shouldApplyPlugin(p2, context2.mode));
|
|
20221
20980
|
if (transformPlugins.length === 0) {
|
|
20222
|
-
return
|
|
20981
|
+
return tool2;
|
|
20223
20982
|
}
|
|
20224
20983
|
const sortedPlugins = sortPluginsByOrder(transformPlugins);
|
|
20225
|
-
let currentTool =
|
|
20984
|
+
let currentTool = tool2;
|
|
20226
20985
|
for (const plugin of sortedPlugins) {
|
|
20227
20986
|
if (plugin.transformTool) {
|
|
20228
20987
|
try {
|
|
@@ -20470,12 +21229,12 @@ var ToolManager = class {
|
|
|
20470
21229
|
* Get tool schema if it's hidden (for internal access)
|
|
20471
21230
|
*/
|
|
20472
21231
|
getHiddenToolSchema(name) {
|
|
20473
|
-
const
|
|
21232
|
+
const tool2 = this.toolRegistry.get(name);
|
|
20474
21233
|
const config2 = this.toolConfigs.get(name);
|
|
20475
|
-
if (
|
|
21234
|
+
if (tool2 && config2?.visibility?.hidden && tool2.schema) {
|
|
20476
21235
|
return {
|
|
20477
|
-
description:
|
|
20478
|
-
schema:
|
|
21236
|
+
description: tool2.description,
|
|
21237
|
+
schema: tool2.schema
|
|
20479
21238
|
};
|
|
20480
21239
|
}
|
|
20481
21240
|
return void 0;
|
|
@@ -20504,18 +21263,18 @@ var ToolManager = class {
|
|
|
20504
21263
|
*/
|
|
20505
21264
|
getRegisteredToolsAsComposed() {
|
|
20506
21265
|
const composedTools = {};
|
|
20507
|
-
for (const [name,
|
|
21266
|
+
for (const [name, tool2] of this.toolRegistry.entries()) {
|
|
20508
21267
|
if (this.toolConfigs.get(name)?.visibility?.public === true) {
|
|
20509
21268
|
continue;
|
|
20510
21269
|
}
|
|
20511
21270
|
composedTools[name] = {
|
|
20512
21271
|
name,
|
|
20513
|
-
description:
|
|
20514
|
-
inputSchema: jsonSchema(
|
|
21272
|
+
description: tool2.description,
|
|
21273
|
+
inputSchema: jsonSchema(tool2.schema || {
|
|
20515
21274
|
type: "object",
|
|
20516
21275
|
properties: {}
|
|
20517
21276
|
}),
|
|
20518
|
-
execute:
|
|
21277
|
+
execute: tool2.callback
|
|
20519
21278
|
};
|
|
20520
21279
|
}
|
|
20521
21280
|
return composedTools;
|
|
@@ -20585,18 +21344,18 @@ async function processToolsWithPlugins(server, _externalTools, mode) {
|
|
|
20585
21344
|
function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicToolNames, server) {
|
|
20586
21345
|
const depGroups = {};
|
|
20587
21346
|
const toolManager = server.toolManager;
|
|
20588
|
-
toolNameToDetailList.forEach(([toolName,
|
|
21347
|
+
toolNameToDetailList.forEach(([toolName, tool2]) => {
|
|
20589
21348
|
const resolvedName = toolManager.resolveToolName(toolName);
|
|
20590
21349
|
if (hiddenToolNames.includes(resolvedName ?? "") || publicToolNames.includes(resolvedName ?? "")) {
|
|
20591
21350
|
return;
|
|
20592
21351
|
}
|
|
20593
|
-
if (!
|
|
21352
|
+
if (!tool2) {
|
|
20594
21353
|
const allToolNames = [
|
|
20595
21354
|
...toolNameToDetailList.map(([n]) => n)
|
|
20596
21355
|
];
|
|
20597
21356
|
throw new Error(`Action ${toolName} not found, available action list: ${allToolNames.join(", ")}`);
|
|
20598
21357
|
}
|
|
20599
|
-
const baseSchema =
|
|
21358
|
+
const baseSchema = tool2.inputSchema.jsonSchema ?? tool2.inputSchema ?? {
|
|
20600
21359
|
type: "object",
|
|
20601
21360
|
properties: {},
|
|
20602
21361
|
required: []
|
|
@@ -20607,7 +21366,7 @@ function buildDependencyGroups(toolNameToDetailList, hiddenToolNames, publicTool
|
|
|
20607
21366
|
const sanitizedKey = sanitizePropertyKey(toolName);
|
|
20608
21367
|
depGroups[sanitizedKey] = {
|
|
20609
21368
|
type: "object",
|
|
20610
|
-
description:
|
|
21369
|
+
description: tool2.description,
|
|
20611
21370
|
properties: updatedProperties,
|
|
20612
21371
|
required: [
|
|
20613
21372
|
...baseRequired
|
|
@@ -20883,9 +21642,9 @@ var ComposableMCPServer = class extends Server {
|
|
|
20883
21642
|
const requestedToolNames = /* @__PURE__ */ new Set();
|
|
20884
21643
|
const availableToolNames = /* @__PURE__ */ new Set();
|
|
20885
21644
|
const allPlaceholderUsages = [];
|
|
20886
|
-
tagToResults.tool.forEach((
|
|
20887
|
-
if (
|
|
20888
|
-
const originalName =
|
|
21645
|
+
tagToResults.tool.forEach((tool2) => {
|
|
21646
|
+
if (tool2.attribs.name) {
|
|
21647
|
+
const originalName = tool2.attribs.name;
|
|
20889
21648
|
const toolName = sanitizePropertyKey(originalName);
|
|
20890
21649
|
if (toolName.endsWith(`_${ALL_TOOLS_PLACEHOLDER2}`) || toolName === ALL_TOOLS_PLACEHOLDER2) {
|
|
20891
21650
|
allPlaceholderUsages.push(originalName);
|
|
@@ -20911,24 +21670,24 @@ var ComposableMCPServer = class extends Server {
|
|
|
20911
21670
|
}
|
|
20912
21671
|
return true;
|
|
20913
21672
|
}
|
|
20914
|
-
return tagToResults.tool.find((
|
|
20915
|
-
const selectAll =
|
|
21673
|
+
return tagToResults.tool.find((tool2) => {
|
|
21674
|
+
const selectAll = tool2.attribs.name === `${mcpName}.${ALL_TOOLS_PLACEHOLDER2}` || tool2.attribs.name === `${mcpName}`;
|
|
20916
21675
|
if (selectAll) {
|
|
20917
21676
|
return true;
|
|
20918
21677
|
}
|
|
20919
|
-
return
|
|
21678
|
+
return tool2.attribs.name === toolNameWithScope || tool2.attribs.name === toolId;
|
|
20920
21679
|
});
|
|
20921
21680
|
});
|
|
20922
|
-
Object.entries(tools).forEach(([toolId,
|
|
20923
|
-
this.toolManager.registerTool(toolId,
|
|
21681
|
+
Object.entries(tools).forEach(([toolId, tool2]) => {
|
|
21682
|
+
this.toolManager.registerTool(toolId, tool2.description || "", tool2.inputSchema, tool2.execute);
|
|
20924
21683
|
});
|
|
20925
21684
|
const registeredTools = this.toolManager.getRegisteredToolsAsComposed();
|
|
20926
21685
|
const allTools = {
|
|
20927
21686
|
...tools
|
|
20928
21687
|
};
|
|
20929
|
-
Object.entries(registeredTools).forEach(([toolName,
|
|
21688
|
+
Object.entries(registeredTools).forEach(([toolName, tool2]) => {
|
|
20930
21689
|
if (!allTools[toolName]) {
|
|
20931
|
-
allTools[toolName] =
|
|
21690
|
+
allTools[toolName] = tool2;
|
|
20932
21691
|
}
|
|
20933
21692
|
availableToolNames.add(toolName);
|
|
20934
21693
|
});
|
|
@@ -20972,11 +21731,11 @@ var ComposableMCPServer = class extends Server {
|
|
|
20972
21731
|
const hiddenToolNames = this.getHiddenToolNames();
|
|
20973
21732
|
const contextToolNames = toolNameToDetailList.map(([name2]) => name2).filter((n) => !hiddenToolNames.includes(n));
|
|
20974
21733
|
publicToolNames.forEach((toolId) => {
|
|
20975
|
-
const
|
|
20976
|
-
if (!
|
|
21734
|
+
const tool2 = allTools[toolId];
|
|
21735
|
+
if (!tool2) {
|
|
20977
21736
|
throw new Error(`Public tool ${toolId} not found in registry, available: ${Object.keys(allTools).join(", ")}`);
|
|
20978
21737
|
}
|
|
20979
|
-
this.tool(toolId,
|
|
21738
|
+
this.tool(toolId, tool2.description || "", jsonSchema(tool2.inputSchema), tool2.execute, {
|
|
20980
21739
|
internal: false
|
|
20981
21740
|
});
|
|
20982
21741
|
});
|
|
@@ -21041,13 +21800,13 @@ if (isSCF()) {
|
|
|
21041
21800
|
|
|
21042
21801
|
// __mcpc__core_latest/node_modules/@mcpc/core/src/ai-sdk-adapter.js
|
|
21043
21802
|
function convertToAISDKTools(server, helpers) {
|
|
21044
|
-
const { tool, jsonSchema:
|
|
21803
|
+
const { tool: tool2, jsonSchema: jsonSchema3 } = helpers;
|
|
21045
21804
|
const mcpcTools = server.getPublicTools();
|
|
21046
21805
|
return Object.fromEntries(mcpcTools.map((mcpcTool) => [
|
|
21047
21806
|
mcpcTool.name,
|
|
21048
|
-
|
|
21807
|
+
tool2({
|
|
21049
21808
|
description: mcpcTool.description || "No description",
|
|
21050
|
-
inputSchema:
|
|
21809
|
+
inputSchema: jsonSchema3(mcpcTool.inputSchema),
|
|
21051
21810
|
execute: async (input) => {
|
|
21052
21811
|
return await server.callTool(mcpcTool.name, input);
|
|
21053
21812
|
}
|