@mcpc-tech/core 0.3.8 → 0.3.9

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 (2) hide show
  1. package/index.mjs +119 -82
  2. package/package.json +2 -1
package/index.mjs CHANGED
@@ -249,27 +249,38 @@ function optionalObject(obj, condition) {
249
249
  function sanitizePropertyKey(name) {
250
250
  return name.replace(/[@.,/\\:;!?#$%^&*()[\]{}]/g, "_").substring(0, 64);
251
251
  }
252
- var createGoogleCompatibleJSONSchema = (schema) => {
253
- if (!GEMINI_PREFERRED_FORMAT) {
254
- return schema;
255
- }
256
- const { oneOf: _oneOf, allOf: _allOf, anyOf: _anyOf, ...cleanSchema } = schema;
257
- const removeAdditionalProperties = (obj) => {
252
+ var createModelCompatibleJSONSchema = (schema) => {
253
+ const validatorOnlyKeys = [
254
+ "errorMessage"
255
+ ];
256
+ const geminiRestrictedKeys = GEMINI_PREFERRED_FORMAT ? [
257
+ "additionalProperties"
258
+ ] : [];
259
+ const keysToRemove = /* @__PURE__ */ new Set([
260
+ ...validatorOnlyKeys,
261
+ ...geminiRestrictedKeys
262
+ ]);
263
+ let cleanSchema = schema;
264
+ if (GEMINI_PREFERRED_FORMAT) {
265
+ const { oneOf: _oneOf, allOf: _allOf, anyOf: _anyOf, ...rest2 } = schema;
266
+ cleanSchema = rest2;
267
+ }
268
+ const cleanRecursively = (obj) => {
258
269
  if (Array.isArray(obj)) {
259
- return obj.map(removeAdditionalProperties);
270
+ return obj.map(cleanRecursively);
260
271
  }
261
272
  if (obj && typeof obj === "object") {
262
273
  const result = {};
263
274
  for (const [key, value] of Object.entries(obj)) {
264
- if (key !== "additionalProperties") {
265
- result[key] = removeAdditionalProperties(value);
275
+ if (!keysToRemove.has(key)) {
276
+ result[key] = cleanRecursively(value);
266
277
  }
267
278
  }
268
279
  return result;
269
280
  }
270
281
  return obj;
271
282
  };
272
- return removeAdditionalProperties(cleanSchema);
283
+ return cleanRecursively(cleanSchema);
273
284
  };
274
285
 
275
286
  // __mcpc__core_latest/node_modules/@mcpc/core/src/utils/common/mcp.js
@@ -1009,19 +1020,32 @@ ${JSON.stringify(steps, null, 2)}`;
1009
1020
  // __mcpc__core_latest/node_modules/@mcpc/core/src/utils/schema-validator.js
1010
1021
  import { Ajv } from "ajv";
1011
1022
  import addFormats from "ajv-formats";
1023
+ import ajvErrors from "ajv-errors";
1012
1024
  import { AggregateAjvError } from "@segment/ajv-human-errors";
1013
1025
  var ajv = new Ajv({
1014
1026
  allErrors: true,
1015
1027
  verbose: true
1016
1028
  });
1017
1029
  addFormats.default(ajv);
1030
+ ajvErrors.default(ajv);
1018
1031
  function validateSchema(args, schema) {
1019
1032
  const validate = ajv.compile(schema);
1020
1033
  if (!validate(args)) {
1021
- const errors = new AggregateAjvError(validate.errors);
1034
+ const errors = validate.errors;
1035
+ const customErrors = errors.filter((err) => err.keyword === "errorMessage");
1036
+ if (customErrors.length > 0) {
1037
+ const messages = [
1038
+ ...new Set(customErrors.map((err) => err.message))
1039
+ ];
1040
+ return {
1041
+ valid: false,
1042
+ error: messages.join("; ")
1043
+ };
1044
+ }
1045
+ const aggregateError = new AggregateAjvError(errors);
1022
1046
  return {
1023
1047
  valid: false,
1024
- error: errors.message
1048
+ error: aggregateError.message
1025
1049
  };
1026
1050
  }
1027
1051
  return {
@@ -1172,11 +1196,17 @@ var AgenticExecutor = class {
1172
1196
  });
1173
1197
  endSpan(executeSpan);
1174
1198
  }
1175
- const result2 = {
1199
+ const result = {
1176
1200
  content: []
1177
1201
  };
1178
- this.appendToolSchemas(result2, definitionsOf, hasDefinitions);
1179
- return result2;
1202
+ this.appendToolSchemas(result, definitionsOf, hasDefinitions);
1203
+ if (result.content.length === 0 && definitionsOf.length > 0) {
1204
+ result.content.push({
1205
+ type: "text",
1206
+ text: `All requested tool schemas are already in hasDefinitions. You can now call a tool using "${this.USE_TOOL_KEY}".`
1207
+ });
1208
+ }
1209
+ return result;
1180
1210
  }
1181
1211
  if (executeSpan) {
1182
1212
  try {
@@ -1226,8 +1256,8 @@ var AgenticExecutor = class {
1226
1256
  selectTool: useTool
1227
1257
  });
1228
1258
  try {
1229
- const result2 = await this.server.callTool(useTool, args[useTool]);
1230
- const callToolResult = result2 ?? {
1259
+ const result = await this.server.callTool(useTool, args[useTool]);
1260
+ const callToolResult = result ?? {
1231
1261
  content: []
1232
1262
  };
1233
1263
  this.appendToolSchemas(callToolResult, definitionsOf, hasDefinitions);
@@ -1268,16 +1298,15 @@ var AgenticExecutor = class {
1268
1298
  });
1269
1299
  endSpan(executeSpan);
1270
1300
  }
1271
- this.logger.warning({
1272
- message: "Tool not found",
1273
- useTool,
1274
- availableTools: this.allToolNames
1275
- });
1276
- const result = {
1277
- content: []
1301
+ return {
1302
+ content: [
1303
+ {
1304
+ type: "text",
1305
+ text: `Tool "${useTool}" not found. Available tools: ${this.allToolNames.join(", ")}.`
1306
+ }
1307
+ ],
1308
+ isError: true
1278
1309
  };
1279
- this.appendToolSchemas(result, definitionsOf, hasDefinitions);
1280
- return result;
1281
1310
  } catch (error) {
1282
1311
  if (executeSpan) {
1283
1312
  endSpan(executeSpan, error);
@@ -1505,7 +1534,10 @@ Workflow step definitions - provide ONLY on initial call.
1505
1534
  decision: () => ({
1506
1535
  type: "string",
1507
1536
  enum: Object.values(DECISION_OPTIONS),
1508
- description: `**Step control: \`${DECISION_OPTIONS.PROCEED}\` = next step, \`${DECISION_OPTIONS.RETRY}\` = retry/repeat current, \`${DECISION_OPTIONS.COMPLETE}\` = finish workflow**`
1537
+ description: `**Step control: \`${DECISION_OPTIONS.PROCEED}\` = next step, \`${DECISION_OPTIONS.RETRY}\` = retry/repeat current, \`${DECISION_OPTIONS.COMPLETE}\` = finish workflow**`,
1538
+ errorMessage: {
1539
+ enum: `Invalid decision. Must be one of: ${Object.values(DECISION_OPTIONS).join(", ")}.`
1540
+ }
1509
1541
  }),
1510
1542
  action: () => ({
1511
1543
  type: "string",
@@ -1513,7 +1545,10 @@ Workflow step definitions - provide ONLY on initial call.
1513
1545
  enum: allToolNames,
1514
1546
  required: [
1515
1547
  "action"
1516
- ]
1548
+ ],
1549
+ errorMessage: {
1550
+ enum: `Invalid action. Must be one of: ${allToolNames.join(", ")}.`
1551
+ }
1517
1552
  }),
1518
1553
  forTool: function() {
1519
1554
  return this.common({});
@@ -1555,58 +1590,17 @@ Workflow step definitions - provide ONLY on initial call.
1555
1590
  required: [
1556
1591
  "userRequest",
1557
1592
  "context"
1558
- ]
1593
+ ],
1594
+ errorMessage: {
1595
+ required: {
1596
+ userRequest: "Missing required field 'userRequest'. Please provide a clear task description.",
1597
+ context: "Missing required field 'context'. Please provide relevant context (e.g., current working directory)."
1598
+ }
1599
+ }
1559
1600
  };
1560
1601
  },
1561
1602
  forAgentic: function(toolNameToDetailList, _sampling = false, USE_TOOL_KEY = "useTool") {
1562
1603
  const allOf = [
1563
- // When hasDefinitions is empty, definitionsOf must be provided
1564
- {
1565
- if: {
1566
- properties: {
1567
- hasDefinitions: {
1568
- type: "array",
1569
- maxItems: 0
1570
- }
1571
- },
1572
- required: [
1573
- "hasDefinitions"
1574
- ]
1575
- },
1576
- then: {
1577
- required: [
1578
- "definitionsOf"
1579
- ]
1580
- }
1581
- },
1582
- // When useTool is present, hasDefinitions must contain that tool
1583
- ...toolNameToDetailList.map(([toolName, _toolDetail]) => {
1584
- return {
1585
- if: {
1586
- properties: {
1587
- [USE_TOOL_KEY]: {
1588
- const: toolName
1589
- }
1590
- },
1591
- required: [
1592
- USE_TOOL_KEY
1593
- ]
1594
- },
1595
- then: {
1596
- properties: {
1597
- hasDefinitions: {
1598
- type: "array",
1599
- contains: {
1600
- const: toolName
1601
- }
1602
- }
1603
- },
1604
- required: [
1605
- "hasDefinitions"
1606
- ]
1607
- }
1608
- };
1609
- }),
1610
1604
  // When a specific tool is selected, its parameters must be provided
1611
1605
  ...toolNameToDetailList.map(([toolName, _toolDetail]) => {
1612
1606
  return {
@@ -1623,7 +1617,12 @@ Workflow step definitions - provide ONLY on initial call.
1623
1617
  then: {
1624
1618
  required: [
1625
1619
  toolName
1626
- ]
1620
+ ],
1621
+ errorMessage: {
1622
+ required: {
1623
+ [toolName]: `Tool "${toolName}" is selected but its parameters are missing. Please provide "${toolName}": { ...parameters }.`
1624
+ }
1625
+ }
1627
1626
  }
1628
1627
  };
1629
1628
  })
@@ -1639,7 +1638,10 @@ Workflow step definitions - provide ONLY on initial call.
1639
1638
  [USE_TOOL_KEY]: {
1640
1639
  type: "string",
1641
1640
  enum: allToolNames,
1642
- description: useToolDescription
1641
+ description: useToolDescription,
1642
+ errorMessage: {
1643
+ enum: `Invalid tool name. Available tools: ${allToolNames.join(", ")}.`
1644
+ }
1643
1645
  },
1644
1646
  hasDefinitions: {
1645
1647
  type: "array",
@@ -1662,6 +1664,41 @@ Workflow step definitions - provide ONLY on initial call.
1662
1664
  if (allOf.length > 0) {
1663
1665
  schema.allOf = allOf;
1664
1666
  }
1667
+ if (allToolNames.length > 0) {
1668
+ const thenClause = {
1669
+ required: [
1670
+ USE_TOOL_KEY
1671
+ ],
1672
+ errorMessage: {
1673
+ required: {
1674
+ [USE_TOOL_KEY]: `No tool selected. Please specify "${USE_TOOL_KEY}" to select one of: ${allToolNames.join(", ")}. Or use "definitionsOf" with tool names to get their schemas first.`
1675
+ }
1676
+ }
1677
+ };
1678
+ Object.assign(schema, {
1679
+ if: {
1680
+ // definitionsOf is not provided OR is empty array
1681
+ anyOf: [
1682
+ {
1683
+ not: {
1684
+ required: [
1685
+ "definitionsOf"
1686
+ ]
1687
+ }
1688
+ },
1689
+ {
1690
+ properties: {
1691
+ definitionsOf: {
1692
+ type: "array",
1693
+ maxItems: 0
1694
+ }
1695
+ }
1696
+ }
1697
+ ]
1698
+ },
1699
+ then: thenClause
1700
+ });
1701
+ }
1665
1702
  return schema;
1666
1703
  },
1667
1704
  forNextState: function(state) {
@@ -1719,7 +1756,7 @@ function registerAgenticTool(server, { description, name, allToolNames, depGroup
1719
1756
  type: "object",
1720
1757
  properties: {}
1721
1758
  };
1722
- server.tool(name, description, jsonSchema(createGoogleCompatibleJSONSchema(schema)), async (args) => {
1759
+ server.tool(name, description, jsonSchema(createModelCompatibleJSONSchema(schema)), async (args) => {
1723
1760
  return await agenticExecutor.execute(args, schema);
1724
1761
  });
1725
1762
  }
@@ -2234,7 +2271,7 @@ function registerAgenticWorkflowTool(server, { description, name, allToolNames,
2234
2271
  });
2235
2272
  const argsDef = createArgsDef.forTool();
2236
2273
  const toolDescription = createArgsDef.forToolDescription(baseDescription, workflowState);
2237
- server.tool(name, toolDescription, jsonSchema(createGoogleCompatibleJSONSchema(argsDef)), async (args) => {
2274
+ server.tool(name, toolDescription, jsonSchema(createModelCompatibleJSONSchema(argsDef)), async (args) => {
2238
2275
  try {
2239
2276
  return await workflowExecutor.execute(args, workflowState);
2240
2277
  } catch (error) {
@@ -2756,7 +2793,7 @@ function registerAgenticSamplingTool(server, { description, name, allToolNames,
2756
2793
  type: "object",
2757
2794
  properties: {}
2758
2795
  };
2759
- server.tool(name, description, jsonSchema(createGoogleCompatibleJSONSchema(schema)), async (args) => {
2796
+ server.tool(name, description, jsonSchema(createModelCompatibleJSONSchema(schema)), async (args) => {
2760
2797
  return await samplingExecutor.executeSampling(args, schema);
2761
2798
  });
2762
2799
  }
@@ -2870,7 +2907,7 @@ function registerWorkflowSamplingTool(server, { description, name, allToolNames,
2870
2907
  type: "object",
2871
2908
  properties: {}
2872
2909
  };
2873
- server.tool(name, baseDescription, jsonSchema(createGoogleCompatibleJSONSchema(schema)), async (args) => {
2910
+ server.tool(name, baseDescription, jsonSchema(createModelCompatibleJSONSchema(schema)), async (args) => {
2874
2911
  try {
2875
2912
  return await workflowSamplingExecutor.executeWorkflowSampling(args, schema, workflowState);
2876
2913
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpc-tech/core",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "homepage": "https://jsr.io/@mcpc/core",
5
5
  "type": "module",
6
6
  "dependencies": {
@@ -14,6 +14,7 @@
14
14
  "@opentelemetry/semantic-conventions": "^1.29.0",
15
15
  "@segment/ajv-human-errors": "^2.15.0",
16
16
  "ajv": "^8.17.1",
17
+ "ajv-errors": "^3.0.0",
17
18
  "ajv-formats": "^3.0.1",
18
19
  "cheerio": "^1.0.0",
19
20
  "json-schema-traverse": "^1.0.0",