@mcpc-tech/core 0.3.3 → 0.3.5

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.mjs CHANGED
@@ -510,7 +510,7 @@ function processToolTags({ description, tagToResults, $, tools, toolOverrides, t
510
510
  } else {
511
511
  const toolId = findToolId(toolName, tools, toolNameMapping);
512
512
  if (toolId) {
513
- $(toolEl).replaceWith(`<action action="${toolId}"/>`);
513
+ $(toolEl).replaceWith(`<tool name="${toolId}"/>`);
514
514
  } else {
515
515
  $(toolEl).remove();
516
516
  }
@@ -691,7 +691,7 @@ var SystemPrompts = {
691
691
  /**
692
692
  * Base system prompt for autonomous MCP execution
693
693
  */
694
- AUTONOMOUS_EXECUTION: `Agentic tool \`{toolName}\` that executes complex tasks by iteratively calling actions, gathering results, and deciding next steps until completion. Use this tool when the task matches the manual below.
694
+ AUTONOMOUS_EXECUTION: `Agentic tool \`{toolName}\` that executes complex tasks by iteratively selecting and calling tools, gathering results, and continuing until completion. Use this tool when the task matches the manual below.
695
695
 
696
696
  You must follow the <manual/>, obey the <execution_rules/>, and use the <call_format/>.
697
697
 
@@ -699,31 +699,39 @@ You must follow the <manual/>, obey the <execution_rules/>, and use the <call_fo
699
699
  {description}
700
700
  </manual>
701
701
 
702
+ <parameters>
703
+ \`useTool\` - Which tool to execute this iteration
704
+ \`hasDefinitions\` - Tool names whose schemas you already have
705
+ \`definitionsOf\` - Tool names whose schemas you need
706
+ </parameters>
707
+
702
708
  <execution_rules>
703
- 1. **Execute** one action per call
704
- 2. **Collect** feedback from each action result
705
- 3. **Decide** next step based on feedback:
706
- - **proceed**: More work needed
707
- - **complete**: Task finished (omit action field)
708
- - **retry**: Current action failed
709
- 4. **Provide** parameters matching the action name
710
- 5. **Continue** until task is complete
711
- 6. Note: You are an agent exposed as an MCP tool - **"action" is an internal parameter, NOT an external MCP tool you can call**
709
+ 1. **First call**: No tool definitions available\u2014you must request them via \`definitionsOf\`
710
+ 2. **When executing tools**: Must provide \`hasDefinitions\` with ALL tools you have schemas for (avoid duplicate requests and reduce tokens)
711
+ 3. **When requesting definitions**: Use \`definitionsOf\` to request tool schemas you need
712
+ 4. **Both together**: Execute tool AND request new definitions in one call for efficiency
713
+ 5. **Never request definitions you already have**
714
+ 6. **Select** one tool to execute per call using \`useTool\`
715
+ 7. **Provide** parameters matching the selected tool name
716
+ 8. Note: You are an agent exposed as an MCP tool - **\`useTool\` is an internal parameter for choosing which tool to execute, NOT an external MCP tool you can call**
712
717
  </execution_rules>
713
718
 
714
719
  <call_format>
720
+ Initial definition request:
715
721
  \`\`\`json
716
722
  {
717
- "action": "action_name",
718
- "decision": "proceed|retry",
719
- "action_name": { /* action parameters */ }
723
+ "hasDefinitions": [],
724
+ "definitionsOf": ["tool1", "tool2"]
720
725
  }
721
726
  \`\`\`
722
727
 
723
- When complete:
728
+ Execute tool + get new definitions:
724
729
  \`\`\`json
725
730
  {
726
- "decision": "complete"
731
+ "useTool": "tool1",
732
+ "tool1": { /* parameters */ },
733
+ "hasDefinitions": ["tool1", "tool2"],
734
+ "definitionsOf": ["tool3"]
727
735
  }
728
736
  \`\`\`
729
737
  </call_format>`,
@@ -1119,17 +1127,15 @@ var AgenticExecutor = class {
1119
1127
  allToolNames;
1120
1128
  toolNameToDetailList;
1121
1129
  server;
1122
- ACTION_KEY;
1123
- NEXT_ACTION_KEY;
1130
+ USE_TOOL_KEY;
1124
1131
  logger;
1125
1132
  tracingEnabled;
1126
- constructor(name, allToolNames, toolNameToDetailList, server, ACTION_KEY = "action", NEXT_ACTION_KEY = "nextAction") {
1133
+ constructor(name, allToolNames, toolNameToDetailList, server, USE_TOOL_KEY = "useTool") {
1127
1134
  this.name = name;
1128
1135
  this.allToolNames = allToolNames;
1129
1136
  this.toolNameToDetailList = toolNameToDetailList;
1130
1137
  this.server = server;
1131
- this.ACTION_KEY = ACTION_KEY;
1132
- this.NEXT_ACTION_KEY = NEXT_ACTION_KEY;
1138
+ this.USE_TOOL_KEY = USE_TOOL_KEY;
1133
1139
  this.tracingEnabled = false;
1134
1140
  this.logger = createLogger(`mcpc.agentic.${name}`, server);
1135
1141
  try {
@@ -1149,8 +1155,7 @@ var AgenticExecutor = class {
1149
1155
  async execute(args, schema, parentSpan) {
1150
1156
  const executeSpan = this.tracingEnabled ? startSpan("mcpc.agentic_execute", {
1151
1157
  agent: this.name,
1152
- action: String(args[this.ACTION_KEY] ?? "unknown"),
1153
- nextAction: String(args[this.NEXT_ACTION_KEY] ?? "none"),
1158
+ selectTool: String(args[this.USE_TOOL_KEY] ?? "unknown"),
1154
1159
  args: JSON.stringify(args)
1155
1160
  }, parentSpan ?? void 0) : null;
1156
1161
  try {
@@ -1165,7 +1170,7 @@ var AgenticExecutor = class {
1165
1170
  }
1166
1171
  this.logger.warning({
1167
1172
  message: "Validation failed",
1168
- action: args[this.ACTION_KEY],
1173
+ selectTool: args[this.USE_TOOL_KEY],
1169
1174
  error: validationResult.error
1170
1175
  });
1171
1176
  return {
@@ -1180,105 +1185,67 @@ var AgenticExecutor = class {
1180
1185
  isError: true
1181
1186
  };
1182
1187
  }
1183
- const actionName = args[this.ACTION_KEY];
1184
- if (executeSpan && actionName) {
1188
+ const useTool = args[this.USE_TOOL_KEY];
1189
+ const definitionsOf = args.definitionsOf || [];
1190
+ const hasDefinitions = args.hasDefinitions || [];
1191
+ if (executeSpan && useTool) {
1185
1192
  try {
1186
- const safeAction = String(actionName).replace(/\s+/g, "_");
1193
+ const safeTool = String(useTool).replace(/\s+/g, "_");
1187
1194
  if (typeof executeSpan.updateName === "function") {
1188
- executeSpan.updateName(`mcpc.agentic_execute.${safeAction}`);
1195
+ executeSpan.updateName(`mcpc.agentic_execute.${safeTool}`);
1189
1196
  }
1190
1197
  } catch {
1191
1198
  }
1192
1199
  }
1193
- const currentTool = this.toolNameToDetailList.find(([name, _detail]) => name === actionName)?.[1];
1200
+ const currentTool = this.toolNameToDetailList.find(([name, _detail]) => name === useTool)?.[1];
1194
1201
  if (currentTool) {
1195
- const nextAction = args[this.NEXT_ACTION_KEY];
1196
1202
  if (executeSpan) {
1197
1203
  executeSpan.setAttributes({
1198
1204
  toolType: "external",
1199
- actionName,
1200
- nextAction: nextAction || "none"
1205
+ selectedTool: useTool
1201
1206
  });
1202
1207
  }
1203
1208
  this.logger.debug({
1204
1209
  message: "Executing external tool",
1205
- action: actionName,
1206
- nextAction
1210
+ selectTool: useTool
1207
1211
  });
1208
1212
  const currentResult = await currentTool.execute({
1209
- ...args[actionName]
1213
+ ...args[useTool]
1210
1214
  });
1211
- if (args[nextAction]) {
1212
- currentResult?.content?.push({
1213
- type: "text",
1214
- text: CompiledPrompts.actionSuccess({
1215
- toolName: this.name,
1216
- nextAction,
1217
- currentAction: actionName
1218
- })
1219
- });
1220
- } else {
1221
- currentResult?.content?.push({
1222
- type: "text",
1223
- text: CompiledPrompts.planningPrompt({
1224
- currentAction: actionName,
1225
- toolName: this.name
1226
- })
1227
- });
1228
- }
1215
+ this.appendToolSchemas(currentResult, definitionsOf, hasDefinitions);
1229
1216
  if (executeSpan) {
1230
1217
  executeSpan.setAttributes({
1231
1218
  success: true,
1232
1219
  isError: !!currentResult.isError,
1233
1220
  resultContentLength: currentResult.content?.length || 0,
1234
- hasNextAction: !!args[nextAction],
1235
1221
  toolResult: JSON.stringify(currentResult)
1236
1222
  });
1237
1223
  endSpan(executeSpan);
1238
1224
  }
1239
1225
  return currentResult;
1240
1226
  }
1241
- if (this.allToolNames.includes(actionName)) {
1227
+ if (this.allToolNames.includes(useTool)) {
1242
1228
  if (executeSpan) {
1243
1229
  executeSpan.setAttributes({
1244
1230
  toolType: "internal",
1245
- actionName
1231
+ selectedTool: useTool
1246
1232
  });
1247
1233
  }
1248
1234
  this.logger.debug({
1249
1235
  message: "Executing internal tool",
1250
- action: actionName
1236
+ selectTool: useTool
1251
1237
  });
1252
1238
  try {
1253
- const result = await this.server.callTool(actionName, args[actionName]);
1254
- const nextAction = args[this.NEXT_ACTION_KEY];
1255
- const callToolResult = result ?? {
1239
+ const result2 = await this.server.callTool(useTool, args[useTool]);
1240
+ const callToolResult = result2 ?? {
1256
1241
  content: []
1257
1242
  };
1258
- if (nextAction && this.allToolNames.includes(nextAction)) {
1259
- callToolResult.content.push({
1260
- type: "text",
1261
- text: CompiledPrompts.actionSuccess({
1262
- toolName: this.name,
1263
- nextAction,
1264
- currentAction: actionName
1265
- })
1266
- });
1267
- } else {
1268
- callToolResult.content.push({
1269
- type: "text",
1270
- text: CompiledPrompts.planningPrompt({
1271
- currentAction: actionName,
1272
- toolName: this.name
1273
- })
1274
- });
1275
- }
1243
+ this.appendToolSchemas(callToolResult, definitionsOf, hasDefinitions);
1276
1244
  if (executeSpan) {
1277
1245
  executeSpan.setAttributes({
1278
1246
  success: true,
1279
1247
  isError: !!callToolResult.isError,
1280
1248
  resultContentLength: callToolResult.content?.length || 0,
1281
- hasNextAction: !!(nextAction && this.allToolNames.includes(nextAction)),
1282
1249
  toolResult: JSON.stringify(callToolResult)
1283
1250
  });
1284
1251
  endSpan(executeSpan);
@@ -1290,14 +1257,14 @@ var AgenticExecutor = class {
1290
1257
  }
1291
1258
  this.logger.error({
1292
1259
  message: "Error executing internal tool",
1293
- action: actionName,
1260
+ useTool,
1294
1261
  error: String(error)
1295
1262
  });
1296
1263
  return {
1297
1264
  content: [
1298
1265
  {
1299
1266
  type: "text",
1300
- text: `Error executing internal tool ${actionName}: ${error instanceof Error ? error.message : String(error)}`
1267
+ text: `Error executing internal tool ${useTool}: ${error instanceof Error ? error.message : String(error)}`
1301
1268
  }
1302
1269
  ],
1303
1270
  isError: true
@@ -1307,23 +1274,20 @@ var AgenticExecutor = class {
1307
1274
  if (executeSpan) {
1308
1275
  executeSpan.setAttributes({
1309
1276
  toolType: "not_found",
1310
- actionName: actionName || "unknown",
1277
+ useTool: useTool || "unknown",
1311
1278
  completion: true
1312
1279
  });
1313
1280
  endSpan(executeSpan);
1314
1281
  }
1315
1282
  this.logger.debug({
1316
1283
  message: "Tool not found, returning completion message",
1317
- action: actionName
1284
+ useTool
1318
1285
  });
1319
- return {
1320
- content: [
1321
- {
1322
- type: "text",
1323
- text: CompiledPrompts.completionMessage()
1324
- }
1325
- ]
1286
+ const result = {
1287
+ content: []
1326
1288
  };
1289
+ this.appendToolSchemas(result, definitionsOf, hasDefinitions);
1290
+ return result;
1327
1291
  } catch (error) {
1328
1292
  if (executeSpan) {
1329
1293
  endSpan(executeSpan, error);
@@ -1343,13 +1307,32 @@ var AgenticExecutor = class {
1343
1307
  };
1344
1308
  }
1345
1309
  }
1310
+ // Append tool schemas to result if requested
1311
+ appendToolSchemas(result, definitionsOf, hasDefinitions) {
1312
+ const schemasToProvide = definitionsOf.filter((toolName) => !hasDefinitions.includes(toolName));
1313
+ if (schemasToProvide.length === 0) {
1314
+ return;
1315
+ }
1316
+ const definitionTexts = [];
1317
+ for (const toolName of schemasToProvide) {
1318
+ const toolDetail = this.toolNameToDetailList.find(([name]) => name === toolName);
1319
+ if (toolDetail) {
1320
+ const [name, schema] = toolDetail;
1321
+ const schemaJson = JSON.stringify(schema, null, 2);
1322
+ definitionTexts.push(`<tool_definition name="${name}">
1323
+ ${schemaJson}
1324
+ </tool_definition>`);
1325
+ }
1326
+ }
1327
+ if (definitionTexts.length > 0) {
1328
+ result.content.push({
1329
+ type: "text",
1330
+ text: `${definitionTexts.join("\n\n")}`
1331
+ });
1332
+ }
1333
+ }
1346
1334
  // Validate arguments using JSON schema
1347
1335
  validate(args, schema) {
1348
- if (args.decision === "complete") {
1349
- return {
1350
- valid: true
1351
- };
1352
- }
1353
1336
  return validateSchema(args, schema);
1354
1337
  }
1355
1338
  };
@@ -1585,47 +1568,103 @@ Workflow step definitions - provide ONLY on initial call.
1585
1568
  ]
1586
1569
  };
1587
1570
  },
1588
- forAgentic: function(toolNameToDetailList, _sampling = false, ACTION_KEY = "action", NEXT_ACTION_KEY = "nextAction") {
1589
- const allOf = toolNameToDetailList.map(([toolName, _toolDetail]) => {
1590
- return {
1571
+ forAgentic: function(toolNameToDetailList, _sampling = false, USE_TOOL_KEY = "useTool") {
1572
+ const allOf = [
1573
+ // When hasDefinitions is empty, definitionsOf must be provided
1574
+ {
1591
1575
  if: {
1592
1576
  properties: {
1593
- [ACTION_KEY]: {
1594
- const: toolName
1577
+ hasDefinitions: {
1578
+ type: "array",
1579
+ maxItems: 0
1595
1580
  }
1596
1581
  },
1597
1582
  required: [
1598
- ACTION_KEY
1583
+ "hasDefinitions"
1599
1584
  ]
1600
1585
  },
1601
1586
  then: {
1602
1587
  required: [
1603
- toolName
1588
+ "definitionsOf"
1604
1589
  ]
1605
1590
  }
1606
- };
1607
- });
1608
- const actionDescription = `Specifies the action to be performed from the enum. **\u26A0\uFE0F When setting \`action: "example_action"\`, you MUST also provide \`"example_action": { ... }\`**`;
1591
+ },
1592
+ // When useTool is present, hasDefinitions must contain that tool
1593
+ ...toolNameToDetailList.map(([toolName, _toolDetail]) => {
1594
+ return {
1595
+ if: {
1596
+ properties: {
1597
+ [USE_TOOL_KEY]: {
1598
+ const: toolName
1599
+ }
1600
+ },
1601
+ required: [
1602
+ USE_TOOL_KEY
1603
+ ]
1604
+ },
1605
+ then: {
1606
+ properties: {
1607
+ hasDefinitions: {
1608
+ type: "array",
1609
+ contains: {
1610
+ const: toolName
1611
+ }
1612
+ }
1613
+ },
1614
+ required: [
1615
+ "hasDefinitions"
1616
+ ]
1617
+ }
1618
+ };
1619
+ }),
1620
+ // When a specific tool is selected, its parameters must be provided
1621
+ ...toolNameToDetailList.map(([toolName, _toolDetail]) => {
1622
+ return {
1623
+ if: {
1624
+ properties: {
1625
+ [USE_TOOL_KEY]: {
1626
+ const: toolName
1627
+ }
1628
+ },
1629
+ required: [
1630
+ USE_TOOL_KEY
1631
+ ]
1632
+ },
1633
+ then: {
1634
+ required: [
1635
+ toolName
1636
+ ]
1637
+ }
1638
+ };
1639
+ })
1640
+ ];
1641
+ const useToolDescription = `Specifies which tool to execute from the available options. **When setting \`useTool: "example_tool"\`, you MUST also provide \`"example_tool": { ...parameters }\` with that tool's parameters**`;
1642
+ const toolItems = allToolNames.length > 0 ? {
1643
+ type: "string",
1644
+ enum: allToolNames
1645
+ } : {
1646
+ type: "string"
1647
+ };
1609
1648
  const baseProperties = {
1610
- [ACTION_KEY]: {
1649
+ [USE_TOOL_KEY]: {
1611
1650
  type: "string",
1612
1651
  enum: allToolNames,
1613
- description: actionDescription
1652
+ description: useToolDescription
1614
1653
  },
1615
- [NEXT_ACTION_KEY]: {
1616
- type: "string",
1617
- enum: allToolNames,
1618
- description: "Optional: Specify the next action to execute. Only include this when you know additional actions are needed after the current one completes."
1654
+ hasDefinitions: {
1655
+ type: "array",
1656
+ items: toolItems,
1657
+ description: "Tool names whose schemas you already have. List all tools you have schemas for to avoid duplicate schema requests and reduce token usage."
1619
1658
  },
1620
- decision: this.decision(),
1621
- ...depGroups
1659
+ definitionsOf: {
1660
+ type: "array",
1661
+ items: toolItems,
1662
+ description: "Tool names whose schemas you need. Request tool schemas before calling them to understand their parameters."
1663
+ }
1622
1664
  };
1623
- const requiredFields = [
1624
- ACTION_KEY,
1625
- "decision"
1626
- ];
1665
+ const requiredFields = [];
1627
1666
  const schema = {
1628
- additionalProperties: false,
1667
+ additionalProperties: true,
1629
1668
  type: "object",
1630
1669
  properties: baseProperties,
1631
1670
  required: requiredFields
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpc-tech/core",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "homepage": "https://jsr.io/@mcpc/core",
5
5
  "type": "module",
6
6
  "dependencies": {
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Execution mode types
3
- */ export type ExecutionMode = "agentic" | "agentic_workflow" | "agentic_sampling" | "agentic_workflow_sampling" | "custom";
3
+ */ export type ExecutionMode = "agentic" | "agentic_workflow" | "agentic_sampling" | "agentic_workflow_sampling" | (string & Record<never, never>);
4
4
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sources":["../../../src/prompts/types.ts"],"names":[],"mappings":"AA4BA;;CAEC,GACD,YAAY,gBACR,YACA,qBACA,qBACA,8BACA"}
1
+ {"version":3,"file":"types.d.ts","sources":["../../../src/prompts/types.ts"],"names":[],"mappings":"AA4BA;;CAEC,GACD,YAAY,gBACR,YACA,qBACA,qBACA,+BACC,MAAM,GAAG,OAAO,KAAK,EAAE,KAAK"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sources":["../../src/types.ts"],"names":[],"mappings":"AAEA,YAAY,aAAa,OAAO,MAAM,EAAE,OAAO;AAE/C,YAAY,gBAAgB,MAAM,OAAO,EAAE,QAAQ,OAAO,KAAK,OAAO;AAEtE,iBAAiB;EACf,gBAAgB,MAAM;EACtB;;;GAGC,GACD,YAAY,OAAO;;AAgDrB;;;;;;;;CAQC,GACD,YAAY,WAAW,MAAM,cAAc,EAAE,MAAM,CAAC,CAAC;AACrD,YAAY,YACR,KACA,UACA,YACA,iBACA;AACJ,YAAY,UAAU,OAAO;AAE7B,YAAY,cACP,YAAY,EAAE,MAAM,CAAC,CAAC,EAAE,WAAW,YAAY,aAC/C,YAAY,EAAE,MAAM,CAAC,CAAC,EAAE,YAAY,WAAW"}
1
+ {"version":3,"file":"types.d.ts","sources":["../../src/types.ts"],"names":[],"mappings":"AAEA,YAAY,aAAa,OAAO,MAAM,EAAE,OAAO;AAE/C,YAAY,gBAAgB,MAAM,OAAO,EAAE,QAAQ,OAAO,KAAK,OAAO;AAEtE,iBAAiB;EACf,gBAAgB,MAAM;EACtB;;;GAGC,GACD,YAAY,OAAO;;AA+CrB;;;;;;;;CAQC,GACD,YAAY,WAAW,MAAM,cAAc,EAAE,MAAM,CAAC,CAAC;AACrD,YAAY,YACR,KACA,UACA,YACA,iBACA;AACJ,YAAY,UAAU,OAAO;AAE7B,YAAY,cACP,YAAY,EAAE,MAAM,CAAC,CAAC,EAAE,WAAW,YAAY,aAC/C,YAAY,EAAE,MAAM,CAAC,CAAC,EAAE,YAAY,WAAW"}