@gavdi/cap-mcp 1.6.0 → 1.7.0

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/README.md CHANGED
@@ -294,6 +294,40 @@ extend projection Books with actions {
294
294
  }
295
295
  ```
296
296
 
297
+ #### Required vs Optional Parameters
298
+
299
+ Parameters follow standard CDS nullability rules. A parameter declared `not null` is **required** in the MCP tool schema; a parameter without `not null` is **optional** and may be omitted by the AI agent.
300
+
301
+ ```cds
302
+ @mcp: {
303
+ name : 'search-items',
304
+ description: 'Search for items by keyword with optional filters',
305
+ tool : true
306
+ }
307
+ function searchItems(
308
+ query : String not null, // required — must be provided
309
+ category : String, // optional — may be omitted
310
+ limit : Integer, // optional — may be omitted
311
+ format : String // optional — may be omitted
312
+ ) returns array of String;
313
+ ```
314
+
315
+ The generated JSON Schema will list only `not null` parameters in the `required` array:
316
+
317
+ ```json
318
+ {
319
+ "properties": {
320
+ "query": { "type": "string" },
321
+ "category": { "type": "string" },
322
+ "limit": { "type": "integer" },
323
+ "format": { "type": "string" }
324
+ },
325
+ "required": ["query"]
326
+ }
327
+ ```
328
+
329
+ > **Note:** This behaviour applies to unbound functions and actions. Entity wrapper tools (`query`, `get`, `create`, `update`) derive nullability from the entity element definitions.
330
+
297
331
  #### Tool Elicitation
298
332
 
299
333
  Request user confirmation or input before tool execution using the `elicit` property:
@@ -236,7 +236,8 @@ function parseOperationElements(annotations, model) {
236
236
  }
237
237
  continue;
238
238
  }
239
- parseParam(k, v);
239
+ const optionalSuffix = v.notNull ? undefined : "Optional";
240
+ parseParam(k, v, optionalSuffix);
240
241
  }
241
242
  }
242
243
  return {
package/lib/mcp/utils.js CHANGED
@@ -17,6 +17,10 @@ const cds = global.cds || require("@sap/cds"); // This is a work around for miss
17
17
  * @returns Zod schema instance for the given type
18
18
  */
19
19
  function determineMcpParameterType(cdsType, key, target) {
20
+ if (cdsType?.endsWith("Optional")) {
21
+ const baseType = cdsType.slice(0, -"Optional".length);
22
+ return determineMcpParameterType(baseType, key, target).optional();
23
+ }
20
24
  switch (cdsType) {
21
25
  case "String":
22
26
  return zod_1.z.string();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gavdi/cap-mcp",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "MCP Plugin for CAP",
5
5
  "keywords": [
6
6
  "MCP",