@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 +34 -0
- package/lib/annotations/utils.js +2 -1
- package/lib/mcp/utils.js +4 -0
- package/package.json +1 -1
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:
|
package/lib/annotations/utils.js
CHANGED
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();
|