@mcpc-tech/cli 0.1.34 → 0.1.36
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 +73 -79
- package/bin/mcpc.mjs +73 -79
- package/package.json +1 -1
package/bin/mcpc.cjs
CHANGED
|
@@ -8884,15 +8884,29 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8884
8884
|
* Execute a tool with runtime validation
|
|
8885
8885
|
*/
|
|
8886
8886
|
async executeTool(tool2, toolArgs, executeSpan) {
|
|
8887
|
-
const
|
|
8888
|
-
|
|
8889
|
-
|
|
8887
|
+
const isExternalTool = this.toolNameToDetailList.some(([name]) => name === tool2);
|
|
8888
|
+
const isInternalTool = this.allToolNames.includes(tool2);
|
|
8889
|
+
if (!isExternalTool && !isInternalTool) {
|
|
8890
8890
|
if (executeSpan) {
|
|
8891
8891
|
executeSpan.setAttributes({
|
|
8892
|
-
toolType: "
|
|
8893
|
-
|
|
8892
|
+
toolType: "not_found",
|
|
8893
|
+
tool: tool2
|
|
8894
8894
|
});
|
|
8895
|
+
endSpan(executeSpan);
|
|
8895
8896
|
}
|
|
8897
|
+
return {
|
|
8898
|
+
content: [
|
|
8899
|
+
{
|
|
8900
|
+
type: "text",
|
|
8901
|
+
text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
|
|
8902
|
+
}
|
|
8903
|
+
],
|
|
8904
|
+
isError: true
|
|
8905
|
+
};
|
|
8906
|
+
}
|
|
8907
|
+
if (isExternalTool) {
|
|
8908
|
+
const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
|
|
8909
|
+
const [, toolDetail] = externalTool;
|
|
8896
8910
|
if (toolDetail.inputSchema) {
|
|
8897
8911
|
const rawSchema = extractJsonSchema(toolDetail.inputSchema);
|
|
8898
8912
|
const validation = validateSchema(toolArgs, rawSchema);
|
|
@@ -8915,84 +8929,53 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8915
8929
|
};
|
|
8916
8930
|
}
|
|
8917
8931
|
}
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8932
|
+
}
|
|
8933
|
+
const toolType = isExternalTool ? "external" : "internal";
|
|
8934
|
+
if (executeSpan) {
|
|
8935
|
+
executeSpan.setAttributes({
|
|
8936
|
+
toolType,
|
|
8937
|
+
selectedTool: tool2
|
|
8921
8938
|
});
|
|
8922
|
-
|
|
8939
|
+
}
|
|
8940
|
+
this.logger.debug({
|
|
8941
|
+
message: `Executing ${toolType} tool`,
|
|
8942
|
+
tool: tool2
|
|
8943
|
+
});
|
|
8944
|
+
try {
|
|
8945
|
+
const result = await this.server.callTool(tool2, toolArgs, {
|
|
8946
|
+
agentName: this.name
|
|
8947
|
+
});
|
|
8948
|
+
const callToolResult = result ?? {
|
|
8949
|
+
content: []
|
|
8950
|
+
};
|
|
8923
8951
|
if (executeSpan) {
|
|
8924
8952
|
executeSpan.setAttributes({
|
|
8925
8953
|
success: true,
|
|
8926
|
-
isError: !!
|
|
8927
|
-
resultContentLength:
|
|
8954
|
+
isError: !!callToolResult.isError,
|
|
8955
|
+
resultContentLength: callToolResult.content?.length || 0
|
|
8928
8956
|
});
|
|
8929
8957
|
endSpan(executeSpan);
|
|
8930
8958
|
}
|
|
8931
|
-
return
|
|
8932
|
-
}
|
|
8933
|
-
if (this.allToolNames.includes(tool2)) {
|
|
8959
|
+
return callToolResult;
|
|
8960
|
+
} catch (error) {
|
|
8934
8961
|
if (executeSpan) {
|
|
8935
|
-
executeSpan
|
|
8936
|
-
toolType: "internal",
|
|
8937
|
-
selectedTool: tool2
|
|
8938
|
-
});
|
|
8939
|
-
}
|
|
8940
|
-
this.logger.debug({
|
|
8941
|
-
message: "Executing internal tool",
|
|
8942
|
-
tool: tool2
|
|
8943
|
-
});
|
|
8944
|
-
try {
|
|
8945
|
-
const result = await this.server.callTool(tool2, toolArgs, {
|
|
8946
|
-
agentName: this.name
|
|
8947
|
-
});
|
|
8948
|
-
const callToolResult = result ?? {
|
|
8949
|
-
content: []
|
|
8950
|
-
};
|
|
8951
|
-
if (executeSpan) {
|
|
8952
|
-
executeSpan.setAttributes({
|
|
8953
|
-
success: true,
|
|
8954
|
-
isError: !!callToolResult.isError,
|
|
8955
|
-
resultContentLength: callToolResult.content?.length || 0
|
|
8956
|
-
});
|
|
8957
|
-
endSpan(executeSpan);
|
|
8958
|
-
}
|
|
8959
|
-
return callToolResult;
|
|
8960
|
-
} catch (error) {
|
|
8961
|
-
if (executeSpan) {
|
|
8962
|
-
endSpan(executeSpan, error);
|
|
8963
|
-
}
|
|
8964
|
-
this.logger.error({
|
|
8965
|
-
message: "Error executing internal tool",
|
|
8966
|
-
tool: tool2,
|
|
8967
|
-
error: String(error)
|
|
8968
|
-
});
|
|
8969
|
-
return {
|
|
8970
|
-
content: [
|
|
8971
|
-
{
|
|
8972
|
-
type: "text",
|
|
8973
|
-
text: `Error executing tool "${tool2}": ${error instanceof Error ? error.message : String(error)}`
|
|
8974
|
-
}
|
|
8975
|
-
],
|
|
8976
|
-
isError: true
|
|
8977
|
-
};
|
|
8962
|
+
endSpan(executeSpan, error);
|
|
8978
8963
|
}
|
|
8979
|
-
|
|
8980
|
-
|
|
8981
|
-
|
|
8982
|
-
|
|
8983
|
-
tool: tool2
|
|
8964
|
+
this.logger.error({
|
|
8965
|
+
message: `Error executing ${toolType} tool`,
|
|
8966
|
+
tool: tool2,
|
|
8967
|
+
error: String(error)
|
|
8984
8968
|
});
|
|
8985
|
-
|
|
8969
|
+
return {
|
|
8970
|
+
content: [
|
|
8971
|
+
{
|
|
8972
|
+
type: "text",
|
|
8973
|
+
text: `Error executing tool "${tool2}": ${error instanceof Error ? error.message : String(error)}`
|
|
8974
|
+
}
|
|
8975
|
+
],
|
|
8976
|
+
isError: true
|
|
8977
|
+
};
|
|
8986
8978
|
}
|
|
8987
|
-
return {
|
|
8988
|
-
content: [
|
|
8989
|
-
{
|
|
8990
|
-
type: "text",
|
|
8991
|
-
text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
|
|
8992
|
-
}
|
|
8993
|
-
],
|
|
8994
|
-
isError: true
|
|
8995
|
-
};
|
|
8996
8979
|
}
|
|
8997
8980
|
validate(args, schema) {
|
|
8998
8981
|
return validateSchema(args, schema);
|
|
@@ -9433,7 +9416,7 @@ IMPORTANT: You MUST respond with valid JSON only. Do not include any text before
|
|
|
9433
9416
|
let enhanced = systemPrompt || "";
|
|
9434
9417
|
const toolsPrompt = `
|
|
9435
9418
|
|
|
9436
|
-
|
|
9419
|
+
<available_tools>
|
|
9437
9420
|
You have access to the following tools. To use a tool, respond with this XML format:
|
|
9438
9421
|
<use_tool tool="tool_name">
|
|
9439
9422
|
{"param1": "value1", "param2": "value2"}
|
|
@@ -9442,23 +9425,34 @@ You have access to the following tools. To use a tool, respond with this XML for
|
|
|
9442
9425
|
Follow the JSON schema definition for each tool's parameters.
|
|
9443
9426
|
You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
|
|
9444
9427
|
|
|
9445
|
-
|
|
9428
|
+
<tools>`;
|
|
9446
9429
|
const toolDescriptions = tools.map((tool2) => {
|
|
9447
9430
|
if (tool2.type === "function") {
|
|
9448
9431
|
const toolAny = tool2;
|
|
9449
9432
|
const description = toolAny.description || "No description provided";
|
|
9450
9433
|
const schema = toolAny.inputSchema || toolAny.parameters;
|
|
9451
|
-
const
|
|
9452
|
-
|
|
9434
|
+
const schemaStr = schema ? `
|
|
9435
|
+
<schema>
|
|
9436
|
+
${JSON.stringify(schema, null, 2)}
|
|
9437
|
+
</schema>` : "";
|
|
9453
9438
|
return `
|
|
9454
|
-
|
|
9439
|
+
<tool name="${tool2.name}">
|
|
9440
|
+
<description>
|
|
9441
|
+
${description}
|
|
9442
|
+
</description>${schemaStr}
|
|
9443
|
+
</tool>`;
|
|
9455
9444
|
} else if (tool2.type === "provider-defined") {
|
|
9456
9445
|
return `
|
|
9457
|
-
|
|
9446
|
+
<tool name="${tool2.name}">
|
|
9447
|
+
<description>${tool2.id || "No description provided"}</description>
|
|
9448
|
+
</tool>`;
|
|
9458
9449
|
}
|
|
9459
9450
|
return "";
|
|
9460
9451
|
}).filter(Boolean).join("");
|
|
9461
|
-
|
|
9452
|
+
const toolsEnd = `
|
|
9453
|
+
</tools>
|
|
9454
|
+
</available_tools>`;
|
|
9455
|
+
enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}${toolsEnd}` : `${toolsPrompt}${toolDescriptions}${toolsEnd}`.trim();
|
|
9462
9456
|
return enhanced || void 0;
|
|
9463
9457
|
}
|
|
9464
9458
|
/**
|
package/bin/mcpc.mjs
CHANGED
|
@@ -8892,15 +8892,29 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8892
8892
|
* Execute a tool with runtime validation
|
|
8893
8893
|
*/
|
|
8894
8894
|
async executeTool(tool2, toolArgs, executeSpan) {
|
|
8895
|
-
const
|
|
8896
|
-
|
|
8897
|
-
|
|
8895
|
+
const isExternalTool = this.toolNameToDetailList.some(([name]) => name === tool2);
|
|
8896
|
+
const isInternalTool = this.allToolNames.includes(tool2);
|
|
8897
|
+
if (!isExternalTool && !isInternalTool) {
|
|
8898
8898
|
if (executeSpan) {
|
|
8899
8899
|
executeSpan.setAttributes({
|
|
8900
|
-
toolType: "
|
|
8901
|
-
|
|
8900
|
+
toolType: "not_found",
|
|
8901
|
+
tool: tool2
|
|
8902
8902
|
});
|
|
8903
|
+
endSpan(executeSpan);
|
|
8903
8904
|
}
|
|
8905
|
+
return {
|
|
8906
|
+
content: [
|
|
8907
|
+
{
|
|
8908
|
+
type: "text",
|
|
8909
|
+
text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
|
|
8910
|
+
}
|
|
8911
|
+
],
|
|
8912
|
+
isError: true
|
|
8913
|
+
};
|
|
8914
|
+
}
|
|
8915
|
+
if (isExternalTool) {
|
|
8916
|
+
const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
|
|
8917
|
+
const [, toolDetail] = externalTool;
|
|
8904
8918
|
if (toolDetail.inputSchema) {
|
|
8905
8919
|
const rawSchema = extractJsonSchema(toolDetail.inputSchema);
|
|
8906
8920
|
const validation = validateSchema(toolArgs, rawSchema);
|
|
@@ -8923,84 +8937,53 @@ ${JSON.stringify(cleanedSchema, null, 2)}
|
|
|
8923
8937
|
};
|
|
8924
8938
|
}
|
|
8925
8939
|
}
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8940
|
+
}
|
|
8941
|
+
const toolType = isExternalTool ? "external" : "internal";
|
|
8942
|
+
if (executeSpan) {
|
|
8943
|
+
executeSpan.setAttributes({
|
|
8944
|
+
toolType,
|
|
8945
|
+
selectedTool: tool2
|
|
8929
8946
|
});
|
|
8930
|
-
|
|
8947
|
+
}
|
|
8948
|
+
this.logger.debug({
|
|
8949
|
+
message: `Executing ${toolType} tool`,
|
|
8950
|
+
tool: tool2
|
|
8951
|
+
});
|
|
8952
|
+
try {
|
|
8953
|
+
const result = await this.server.callTool(tool2, toolArgs, {
|
|
8954
|
+
agentName: this.name
|
|
8955
|
+
});
|
|
8956
|
+
const callToolResult = result ?? {
|
|
8957
|
+
content: []
|
|
8958
|
+
};
|
|
8931
8959
|
if (executeSpan) {
|
|
8932
8960
|
executeSpan.setAttributes({
|
|
8933
8961
|
success: true,
|
|
8934
|
-
isError: !!
|
|
8935
|
-
resultContentLength:
|
|
8962
|
+
isError: !!callToolResult.isError,
|
|
8963
|
+
resultContentLength: callToolResult.content?.length || 0
|
|
8936
8964
|
});
|
|
8937
8965
|
endSpan(executeSpan);
|
|
8938
8966
|
}
|
|
8939
|
-
return
|
|
8940
|
-
}
|
|
8941
|
-
if (this.allToolNames.includes(tool2)) {
|
|
8967
|
+
return callToolResult;
|
|
8968
|
+
} catch (error) {
|
|
8942
8969
|
if (executeSpan) {
|
|
8943
|
-
executeSpan
|
|
8944
|
-
toolType: "internal",
|
|
8945
|
-
selectedTool: tool2
|
|
8946
|
-
});
|
|
8947
|
-
}
|
|
8948
|
-
this.logger.debug({
|
|
8949
|
-
message: "Executing internal tool",
|
|
8950
|
-
tool: tool2
|
|
8951
|
-
});
|
|
8952
|
-
try {
|
|
8953
|
-
const result = await this.server.callTool(tool2, toolArgs, {
|
|
8954
|
-
agentName: this.name
|
|
8955
|
-
});
|
|
8956
|
-
const callToolResult = result ?? {
|
|
8957
|
-
content: []
|
|
8958
|
-
};
|
|
8959
|
-
if (executeSpan) {
|
|
8960
|
-
executeSpan.setAttributes({
|
|
8961
|
-
success: true,
|
|
8962
|
-
isError: !!callToolResult.isError,
|
|
8963
|
-
resultContentLength: callToolResult.content?.length || 0
|
|
8964
|
-
});
|
|
8965
|
-
endSpan(executeSpan);
|
|
8966
|
-
}
|
|
8967
|
-
return callToolResult;
|
|
8968
|
-
} catch (error) {
|
|
8969
|
-
if (executeSpan) {
|
|
8970
|
-
endSpan(executeSpan, error);
|
|
8971
|
-
}
|
|
8972
|
-
this.logger.error({
|
|
8973
|
-
message: "Error executing internal tool",
|
|
8974
|
-
tool: tool2,
|
|
8975
|
-
error: String(error)
|
|
8976
|
-
});
|
|
8977
|
-
return {
|
|
8978
|
-
content: [
|
|
8979
|
-
{
|
|
8980
|
-
type: "text",
|
|
8981
|
-
text: `Error executing tool "${tool2}": ${error instanceof Error ? error.message : String(error)}`
|
|
8982
|
-
}
|
|
8983
|
-
],
|
|
8984
|
-
isError: true
|
|
8985
|
-
};
|
|
8970
|
+
endSpan(executeSpan, error);
|
|
8986
8971
|
}
|
|
8987
|
-
|
|
8988
|
-
|
|
8989
|
-
|
|
8990
|
-
|
|
8991
|
-
tool: tool2
|
|
8972
|
+
this.logger.error({
|
|
8973
|
+
message: `Error executing ${toolType} tool`,
|
|
8974
|
+
tool: tool2,
|
|
8975
|
+
error: String(error)
|
|
8992
8976
|
});
|
|
8993
|
-
|
|
8977
|
+
return {
|
|
8978
|
+
content: [
|
|
8979
|
+
{
|
|
8980
|
+
type: "text",
|
|
8981
|
+
text: `Error executing tool "${tool2}": ${error instanceof Error ? error.message : String(error)}`
|
|
8982
|
+
}
|
|
8983
|
+
],
|
|
8984
|
+
isError: true
|
|
8985
|
+
};
|
|
8994
8986
|
}
|
|
8995
|
-
return {
|
|
8996
|
-
content: [
|
|
8997
|
-
{
|
|
8998
|
-
type: "text",
|
|
8999
|
-
text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
|
|
9000
|
-
}
|
|
9001
|
-
],
|
|
9002
|
-
isError: true
|
|
9003
|
-
};
|
|
9004
8987
|
}
|
|
9005
8988
|
validate(args, schema) {
|
|
9006
8989
|
return validateSchema(args, schema);
|
|
@@ -9441,7 +9424,7 @@ IMPORTANT: You MUST respond with valid JSON only. Do not include any text before
|
|
|
9441
9424
|
let enhanced = systemPrompt || "";
|
|
9442
9425
|
const toolsPrompt = `
|
|
9443
9426
|
|
|
9444
|
-
|
|
9427
|
+
<available_tools>
|
|
9445
9428
|
You have access to the following tools. To use a tool, respond with this XML format:
|
|
9446
9429
|
<use_tool tool="tool_name">
|
|
9447
9430
|
{"param1": "value1", "param2": "value2"}
|
|
@@ -9450,23 +9433,34 @@ You have access to the following tools. To use a tool, respond with this XML for
|
|
|
9450
9433
|
Follow the JSON schema definition for each tool's parameters.
|
|
9451
9434
|
You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
|
|
9452
9435
|
|
|
9453
|
-
|
|
9436
|
+
<tools>`;
|
|
9454
9437
|
const toolDescriptions = tools.map((tool2) => {
|
|
9455
9438
|
if (tool2.type === "function") {
|
|
9456
9439
|
const toolAny = tool2;
|
|
9457
9440
|
const description = toolAny.description || "No description provided";
|
|
9458
9441
|
const schema = toolAny.inputSchema || toolAny.parameters;
|
|
9459
|
-
const
|
|
9460
|
-
|
|
9442
|
+
const schemaStr = schema ? `
|
|
9443
|
+
<schema>
|
|
9444
|
+
${JSON.stringify(schema, null, 2)}
|
|
9445
|
+
</schema>` : "";
|
|
9461
9446
|
return `
|
|
9462
|
-
|
|
9447
|
+
<tool name="${tool2.name}">
|
|
9448
|
+
<description>
|
|
9449
|
+
${description}
|
|
9450
|
+
</description>${schemaStr}
|
|
9451
|
+
</tool>`;
|
|
9463
9452
|
} else if (tool2.type === "provider-defined") {
|
|
9464
9453
|
return `
|
|
9465
|
-
|
|
9454
|
+
<tool name="${tool2.name}">
|
|
9455
|
+
<description>${tool2.id || "No description provided"}</description>
|
|
9456
|
+
</tool>`;
|
|
9466
9457
|
}
|
|
9467
9458
|
return "";
|
|
9468
9459
|
}).filter(Boolean).join("");
|
|
9469
|
-
|
|
9460
|
+
const toolsEnd = `
|
|
9461
|
+
</tools>
|
|
9462
|
+
</available_tools>`;
|
|
9463
|
+
enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}${toolsEnd}` : `${toolsPrompt}${toolDescriptions}${toolsEnd}`.trim();
|
|
9470
9464
|
return enhanced || void 0;
|
|
9471
9465
|
}
|
|
9472
9466
|
/**
|