@mcpc-tech/core 0.3.28 → 0.3.29

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/index.cjs +55 -72
  2. package/index.mjs +55 -72
  3. package/package.json +1 -1
package/index.cjs CHANGED
@@ -18374,15 +18374,29 @@ ${JSON.stringify(cleanedSchema, null, 2)}
18374
18374
  * Execute a tool with runtime validation
18375
18375
  */
18376
18376
  async executeTool(tool2, toolArgs, executeSpan) {
18377
- const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
18378
- if (externalTool) {
18379
- const [, toolDetail] = externalTool;
18377
+ const isExternalTool = this.toolNameToDetailList.some(([name]) => name === tool2);
18378
+ const isInternalTool = this.allToolNames.includes(tool2);
18379
+ if (!isExternalTool && !isInternalTool) {
18380
18380
  if (executeSpan) {
18381
18381
  executeSpan.setAttributes({
18382
- toolType: "external",
18383
- selectedTool: tool2
18382
+ toolType: "not_found",
18383
+ tool: tool2
18384
18384
  });
18385
+ endSpan(executeSpan);
18385
18386
  }
18387
+ return {
18388
+ content: [
18389
+ {
18390
+ type: "text",
18391
+ text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
18392
+ }
18393
+ ],
18394
+ isError: true
18395
+ };
18396
+ }
18397
+ if (isExternalTool) {
18398
+ const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
18399
+ const [, toolDetail] = externalTool;
18386
18400
  if (toolDetail.inputSchema) {
18387
18401
  const rawSchema = extractJsonSchema(toolDetail.inputSchema);
18388
18402
  const validation = validateSchema(toolArgs, rawSchema);
@@ -18405,84 +18419,53 @@ ${JSON.stringify(cleanedSchema, null, 2)}
18405
18419
  };
18406
18420
  }
18407
18421
  }
18408
- this.logger.debug({
18409
- message: "Executing external tool",
18410
- tool: tool2
18422
+ }
18423
+ const toolType = isExternalTool ? "external" : "internal";
18424
+ if (executeSpan) {
18425
+ executeSpan.setAttributes({
18426
+ toolType,
18427
+ selectedTool: tool2
18411
18428
  });
18412
- const result = await toolDetail.execute(toolArgs);
18429
+ }
18430
+ this.logger.debug({
18431
+ message: `Executing ${toolType} tool`,
18432
+ tool: tool2
18433
+ });
18434
+ try {
18435
+ const result = await this.server.callTool(tool2, toolArgs, {
18436
+ agentName: this.name
18437
+ });
18438
+ const callToolResult = result ?? {
18439
+ content: []
18440
+ };
18413
18441
  if (executeSpan) {
18414
18442
  executeSpan.setAttributes({
18415
18443
  success: true,
18416
- isError: !!result.isError,
18417
- resultContentLength: result.content?.length || 0
18444
+ isError: !!callToolResult.isError,
18445
+ resultContentLength: callToolResult.content?.length || 0
18418
18446
  });
18419
18447
  endSpan(executeSpan);
18420
18448
  }
18421
- return result;
18422
- }
18423
- if (this.allToolNames.includes(tool2)) {
18449
+ return callToolResult;
18450
+ } catch (error2) {
18424
18451
  if (executeSpan) {
18425
- executeSpan.setAttributes({
18426
- toolType: "internal",
18427
- selectedTool: tool2
18428
- });
18429
- }
18430
- this.logger.debug({
18431
- message: "Executing internal tool",
18432
- tool: tool2
18433
- });
18434
- try {
18435
- const result = await this.server.callTool(tool2, toolArgs, {
18436
- agentName: this.name
18437
- });
18438
- const callToolResult = result ?? {
18439
- content: []
18440
- };
18441
- if (executeSpan) {
18442
- executeSpan.setAttributes({
18443
- success: true,
18444
- isError: !!callToolResult.isError,
18445
- resultContentLength: callToolResult.content?.length || 0
18446
- });
18447
- endSpan(executeSpan);
18448
- }
18449
- return callToolResult;
18450
- } catch (error2) {
18451
- if (executeSpan) {
18452
- endSpan(executeSpan, error2);
18453
- }
18454
- this.logger.error({
18455
- message: "Error executing internal tool",
18456
- tool: tool2,
18457
- error: String(error2)
18458
- });
18459
- return {
18460
- content: [
18461
- {
18462
- type: "text",
18463
- text: `Error executing tool "${tool2}": ${error2 instanceof Error ? error2.message : String(error2)}`
18464
- }
18465
- ],
18466
- isError: true
18467
- };
18452
+ endSpan(executeSpan, error2);
18468
18453
  }
18469
- }
18470
- if (executeSpan) {
18471
- executeSpan.setAttributes({
18472
- toolType: "not_found",
18473
- tool: tool2
18454
+ this.logger.error({
18455
+ message: `Error executing ${toolType} tool`,
18456
+ tool: tool2,
18457
+ error: String(error2)
18474
18458
  });
18475
- endSpan(executeSpan);
18459
+ return {
18460
+ content: [
18461
+ {
18462
+ type: "text",
18463
+ text: `Error executing tool "${tool2}": ${error2 instanceof Error ? error2.message : String(error2)}`
18464
+ }
18465
+ ],
18466
+ isError: true
18467
+ };
18476
18468
  }
18477
- return {
18478
- content: [
18479
- {
18480
- type: "text",
18481
- text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
18482
- }
18483
- ],
18484
- isError: true
18485
- };
18486
18469
  }
18487
18470
  validate(args, schema) {
18488
18471
  return validateSchema(args, schema);
package/index.mjs CHANGED
@@ -18360,15 +18360,29 @@ ${JSON.stringify(cleanedSchema, null, 2)}
18360
18360
  * Execute a tool with runtime validation
18361
18361
  */
18362
18362
  async executeTool(tool2, toolArgs, executeSpan) {
18363
- const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
18364
- if (externalTool) {
18365
- const [, toolDetail] = externalTool;
18363
+ const isExternalTool = this.toolNameToDetailList.some(([name]) => name === tool2);
18364
+ const isInternalTool = this.allToolNames.includes(tool2);
18365
+ if (!isExternalTool && !isInternalTool) {
18366
18366
  if (executeSpan) {
18367
18367
  executeSpan.setAttributes({
18368
- toolType: "external",
18369
- selectedTool: tool2
18368
+ toolType: "not_found",
18369
+ tool: tool2
18370
18370
  });
18371
+ endSpan(executeSpan);
18371
18372
  }
18373
+ return {
18374
+ content: [
18375
+ {
18376
+ type: "text",
18377
+ text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
18378
+ }
18379
+ ],
18380
+ isError: true
18381
+ };
18382
+ }
18383
+ if (isExternalTool) {
18384
+ const externalTool = this.toolNameToDetailList.find(([name]) => name === tool2);
18385
+ const [, toolDetail] = externalTool;
18372
18386
  if (toolDetail.inputSchema) {
18373
18387
  const rawSchema = extractJsonSchema(toolDetail.inputSchema);
18374
18388
  const validation = validateSchema(toolArgs, rawSchema);
@@ -18391,84 +18405,53 @@ ${JSON.stringify(cleanedSchema, null, 2)}
18391
18405
  };
18392
18406
  }
18393
18407
  }
18394
- this.logger.debug({
18395
- message: "Executing external tool",
18396
- tool: tool2
18408
+ }
18409
+ const toolType = isExternalTool ? "external" : "internal";
18410
+ if (executeSpan) {
18411
+ executeSpan.setAttributes({
18412
+ toolType,
18413
+ selectedTool: tool2
18397
18414
  });
18398
- const result = await toolDetail.execute(toolArgs);
18415
+ }
18416
+ this.logger.debug({
18417
+ message: `Executing ${toolType} tool`,
18418
+ tool: tool2
18419
+ });
18420
+ try {
18421
+ const result = await this.server.callTool(tool2, toolArgs, {
18422
+ agentName: this.name
18423
+ });
18424
+ const callToolResult = result ?? {
18425
+ content: []
18426
+ };
18399
18427
  if (executeSpan) {
18400
18428
  executeSpan.setAttributes({
18401
18429
  success: true,
18402
- isError: !!result.isError,
18403
- resultContentLength: result.content?.length || 0
18430
+ isError: !!callToolResult.isError,
18431
+ resultContentLength: callToolResult.content?.length || 0
18404
18432
  });
18405
18433
  endSpan(executeSpan);
18406
18434
  }
18407
- return result;
18408
- }
18409
- if (this.allToolNames.includes(tool2)) {
18435
+ return callToolResult;
18436
+ } catch (error2) {
18410
18437
  if (executeSpan) {
18411
- executeSpan.setAttributes({
18412
- toolType: "internal",
18413
- selectedTool: tool2
18414
- });
18415
- }
18416
- this.logger.debug({
18417
- message: "Executing internal tool",
18418
- tool: tool2
18419
- });
18420
- try {
18421
- const result = await this.server.callTool(tool2, toolArgs, {
18422
- agentName: this.name
18423
- });
18424
- const callToolResult = result ?? {
18425
- content: []
18426
- };
18427
- if (executeSpan) {
18428
- executeSpan.setAttributes({
18429
- success: true,
18430
- isError: !!callToolResult.isError,
18431
- resultContentLength: callToolResult.content?.length || 0
18432
- });
18433
- endSpan(executeSpan);
18434
- }
18435
- return callToolResult;
18436
- } catch (error2) {
18437
- if (executeSpan) {
18438
- endSpan(executeSpan, error2);
18439
- }
18440
- this.logger.error({
18441
- message: "Error executing internal tool",
18442
- tool: tool2,
18443
- error: String(error2)
18444
- });
18445
- return {
18446
- content: [
18447
- {
18448
- type: "text",
18449
- text: `Error executing tool "${tool2}": ${error2 instanceof Error ? error2.message : String(error2)}`
18450
- }
18451
- ],
18452
- isError: true
18453
- };
18438
+ endSpan(executeSpan, error2);
18454
18439
  }
18455
- }
18456
- if (executeSpan) {
18457
- executeSpan.setAttributes({
18458
- toolType: "not_found",
18459
- tool: tool2
18440
+ this.logger.error({
18441
+ message: `Error executing ${toolType} tool`,
18442
+ tool: tool2,
18443
+ error: String(error2)
18460
18444
  });
18461
- endSpan(executeSpan);
18445
+ return {
18446
+ content: [
18447
+ {
18448
+ type: "text",
18449
+ text: `Error executing tool "${tool2}": ${error2 instanceof Error ? error2.message : String(error2)}`
18450
+ }
18451
+ ],
18452
+ isError: true
18453
+ };
18462
18454
  }
18463
- return {
18464
- content: [
18465
- {
18466
- type: "text",
18467
- text: `Tool "${tool2}" not found. Available tools: ${this.allToolNames.join(", ")}`
18468
- }
18469
- ],
18470
- isError: true
18471
- };
18472
18455
  }
18473
18456
  validate(args, schema) {
18474
18457
  return validateSchema(args, schema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpc-tech/core",
3
- "version": "0.3.28",
3
+ "version": "0.3.29",
4
4
  "homepage": "https://jsr.io/@mcpc/core",
5
5
  "dependencies": {
6
6
  "@ai-sdk/provider": "^2.0.0",