@mcpc-tech/core 0.3.28 → 0.3.30

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 +73 -79
  2. package/index.mjs +73 -79
  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);
@@ -18923,7 +18906,7 @@ IMPORTANT: You MUST respond with valid JSON only. Do not include any text before
18923
18906
  let enhanced = systemPrompt || "";
18924
18907
  const toolsPrompt = `
18925
18908
 
18926
- AVAILABLE TOOLS:
18909
+ <available_tools>
18927
18910
  You have access to the following tools. To use a tool, respond with this XML format:
18928
18911
  <use_tool tool="tool_name">
18929
18912
  {"param1": "value1", "param2": "value2"}
@@ -18932,23 +18915,34 @@ You have access to the following tools. To use a tool, respond with this XML for
18932
18915
  Follow the JSON schema definition for each tool's parameters.
18933
18916
  You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
18934
18917
 
18935
- Tools:`;
18918
+ <tools>`;
18936
18919
  const toolDescriptions = tools.map((tool2) => {
18937
18920
  if (tool2.type === "function") {
18938
18921
  const toolAny = tool2;
18939
18922
  const description = toolAny.description || "No description provided";
18940
18923
  const schema = toolAny.inputSchema || toolAny.parameters;
18941
- const params = schema ? `
18942
- JSON Schema: ${JSON.stringify(schema, null, 2)}` : "";
18924
+ const schemaStr = schema ? `
18925
+ <schema>
18926
+ ${JSON.stringify(schema, null, 2)}
18927
+ </schema>` : "";
18943
18928
  return `
18944
- - ${tool2.name}: ${description}${params}`;
18929
+ <tool name="${tool2.name}">
18930
+ <description>
18931
+ ${description}
18932
+ </description>${schemaStr}
18933
+ </tool>`;
18945
18934
  } else if (tool2.type === "provider-defined") {
18946
18935
  return `
18947
- - ${tool2.name}: ${tool2.id || "No description provided"}`;
18936
+ <tool name="${tool2.name}">
18937
+ <description>${tool2.id || "No description provided"}</description>
18938
+ </tool>`;
18948
18939
  }
18949
18940
  return "";
18950
18941
  }).filter(Boolean).join("");
18951
- enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}` : `${toolsPrompt}${toolDescriptions}`.trim();
18942
+ const toolsEnd = `
18943
+ </tools>
18944
+ </available_tools>`;
18945
+ enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}${toolsEnd}` : `${toolsPrompt}${toolDescriptions}${toolsEnd}`.trim();
18952
18946
  return enhanced || void 0;
18953
18947
  }
18954
18948
  /**
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);
@@ -18909,7 +18892,7 @@ IMPORTANT: You MUST respond with valid JSON only. Do not include any text before
18909
18892
  let enhanced = systemPrompt || "";
18910
18893
  const toolsPrompt = `
18911
18894
 
18912
- AVAILABLE TOOLS:
18895
+ <available_tools>
18913
18896
  You have access to the following tools. To use a tool, respond with this XML format:
18914
18897
  <use_tool tool="tool_name">
18915
18898
  {"param1": "value1", "param2": "value2"}
@@ -18918,23 +18901,34 @@ You have access to the following tools. To use a tool, respond with this XML for
18918
18901
  Follow the JSON schema definition for each tool's parameters.
18919
18902
  You can use multiple tools in one response. DO NOT include text before or after tool calls - wait for the tool results first.
18920
18903
 
18921
- Tools:`;
18904
+ <tools>`;
18922
18905
  const toolDescriptions = tools.map((tool2) => {
18923
18906
  if (tool2.type === "function") {
18924
18907
  const toolAny = tool2;
18925
18908
  const description = toolAny.description || "No description provided";
18926
18909
  const schema = toolAny.inputSchema || toolAny.parameters;
18927
- const params = schema ? `
18928
- JSON Schema: ${JSON.stringify(schema, null, 2)}` : "";
18910
+ const schemaStr = schema ? `
18911
+ <schema>
18912
+ ${JSON.stringify(schema, null, 2)}
18913
+ </schema>` : "";
18929
18914
  return `
18930
- - ${tool2.name}: ${description}${params}`;
18915
+ <tool name="${tool2.name}">
18916
+ <description>
18917
+ ${description}
18918
+ </description>${schemaStr}
18919
+ </tool>`;
18931
18920
  } else if (tool2.type === "provider-defined") {
18932
18921
  return `
18933
- - ${tool2.name}: ${tool2.id || "No description provided"}`;
18922
+ <tool name="${tool2.name}">
18923
+ <description>${tool2.id || "No description provided"}</description>
18924
+ </tool>`;
18934
18925
  }
18935
18926
  return "";
18936
18927
  }).filter(Boolean).join("");
18937
- enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}` : `${toolsPrompt}${toolDescriptions}`.trim();
18928
+ const toolsEnd = `
18929
+ </tools>
18930
+ </available_tools>`;
18931
+ enhanced = enhanced ? `${enhanced}${toolsPrompt}${toolDescriptions}${toolsEnd}` : `${toolsPrompt}${toolDescriptions}${toolsEnd}`.trim();
18938
18932
  return enhanced || void 0;
18939
18933
  }
18940
18934
  /**
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.30",
4
4
  "homepage": "https://jsr.io/@mcpc/core",
5
5
  "dependencies": {
6
6
  "@ai-sdk/provider": "^2.0.0",