@mcpc-tech/cli 0.1.34 → 0.1.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/bin/mcpc.cjs +55 -72
  2. package/bin/mcpc.mjs +55 -72
  3. 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 externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
8888
- if (externalTool) {
8889
- const [, toolDetail] = externalTool;
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: "external",
8893
- selectedTool: tool2
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
- this.logger.debug({
8919
- message: "Executing external tool",
8920
- tool: tool2
8932
+ }
8933
+ const toolType = isExternalTool ? "external" : "internal";
8934
+ if (executeSpan) {
8935
+ executeSpan.setAttributes({
8936
+ toolType,
8937
+ selectedTool: tool2
8921
8938
  });
8922
- const result = await toolDetail.execute(toolArgs);
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: !!result.isError,
8927
- resultContentLength: result.content?.length || 0
8954
+ isError: !!callToolResult.isError,
8955
+ resultContentLength: callToolResult.content?.length || 0
8928
8956
  });
8929
8957
  endSpan(executeSpan);
8930
8958
  }
8931
- return result;
8932
- }
8933
- if (this.allToolNames.includes(tool2)) {
8959
+ return callToolResult;
8960
+ } catch (error) {
8934
8961
  if (executeSpan) {
8935
- executeSpan.setAttributes({
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
- if (executeSpan) {
8981
- executeSpan.setAttributes({
8982
- toolType: "not_found",
8983
- tool: tool2
8964
+ this.logger.error({
8965
+ message: `Error executing ${toolType} tool`,
8966
+ tool: tool2,
8967
+ error: String(error)
8984
8968
  });
8985
- endSpan(executeSpan);
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);
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 externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
8896
- if (externalTool) {
8897
- const [, toolDetail] = externalTool;
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: "external",
8901
- selectedTool: tool2
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
- this.logger.debug({
8927
- message: "Executing external tool",
8928
- tool: tool2
8940
+ }
8941
+ const toolType = isExternalTool ? "external" : "internal";
8942
+ if (executeSpan) {
8943
+ executeSpan.setAttributes({
8944
+ toolType,
8945
+ selectedTool: tool2
8929
8946
  });
8930
- const result = await toolDetail.execute(toolArgs);
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: !!result.isError,
8935
- resultContentLength: result.content?.length || 0
8962
+ isError: !!callToolResult.isError,
8963
+ resultContentLength: callToolResult.content?.length || 0
8936
8964
  });
8937
8965
  endSpan(executeSpan);
8938
8966
  }
8939
- return result;
8940
- }
8941
- if (this.allToolNames.includes(tool2)) {
8967
+ return callToolResult;
8968
+ } catch (error) {
8942
8969
  if (executeSpan) {
8943
- executeSpan.setAttributes({
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
- if (executeSpan) {
8989
- executeSpan.setAttributes({
8990
- toolType: "not_found",
8991
- tool: tool2
8972
+ this.logger.error({
8973
+ message: `Error executing ${toolType} tool`,
8974
+ tool: tool2,
8975
+ error: String(error)
8992
8976
  });
8993
- endSpan(executeSpan);
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpc-tech/cli",
3
- "version": "0.1.34",
3
+ "version": "0.1.35",
4
4
  "homepage": "https://jsr.io/@mcpc/cli",
5
5
  "dependencies": {
6
6
  "@hono/zod-openapi": "^0.19.2",