@gavdi/cap-mcp 0.9.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/LICENSE.md ADDED
@@ -0,0 +1,191 @@
1
+ # Apache License 2.0
2
+
3
+ Copyright (c) 2025 CAP-MCP Plugin Contributors
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ ---
18
+
19
+ ## Full License Text
20
+
21
+ ```
22
+ Apache License
23
+ Version 2.0, January 2004
24
+ http://www.apache.org/licenses/
25
+
26
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
27
+
28
+ 1. Definitions.
29
+
30
+ "License" shall mean the terms and conditions for use, reproduction,
31
+ and distribution as defined by Sections 1 through 9 of this document.
32
+
33
+ "Licensor" shall mean the copyright owner or entity granting the License.
34
+
35
+ "Legal Entity" shall mean the union of the acting entity and all
36
+ other entities that control, are controlled by, or are under common
37
+ control with that entity. For the purposes of this definition,
38
+ "control" means (i) the power, direct or indirect, to cause the
39
+ direction or management of such entity, whether by contract or
40
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
41
+ outstanding shares, or (iii) beneficial ownership of such entity.
42
+
43
+ "You" (or "Your") shall mean an individual or Legal Entity
44
+ exercising permissions granted by this License.
45
+
46
+ "Source" form shall mean the preferred form for making modifications,
47
+ including but not limited to software source code, documentation
48
+ source, and configuration files.
49
+
50
+ "Object" form shall mean any form resulting from mechanical
51
+ transformation or translation of a Source form, including but
52
+ not limited to compiled object code, generated documentation,
53
+ and conversions to other media types.
54
+
55
+ "Work" shall mean the work of authorship, whether in Source or
56
+ Object form, made available under the License, as indicated by a
57
+ copyright notice that is included in or attached to the work
58
+ (which shall not include communications that are clearly marked or
59
+ otherwise designated in writing by the copyright owner as "Not a Work").
60
+
61
+ "Derivative Works" shall mean any work, whether in Source or Object
62
+ form, that is based upon (or derived from) the Work and for which the
63
+ editorial revisions, annotations, elaborations, or other modifications
64
+ represent, as a whole, an original work of authorship. For the purposes
65
+ of this License, Derivative Works shall not include works that remain
66
+ separable from, or merely link (or bind by name) to the interfaces of,
67
+ the Work and derivative works thereof.
68
+
69
+ "Contribution" shall mean any work of authorship, including
70
+ the original version of the Work and any modifications or additions
71
+ to that Work or Derivative Works thereof, that is intentionally
72
+ submitted to Licensor for inclusion in the Work by the copyright owner
73
+ or by an individual or Legal Entity authorized to submit on behalf of
74
+ the copyright owner. For the purposes of this definition, "submitted"
75
+ means any form of electronic, verbal, or written communication sent
76
+ to the Licensor or its representatives, including but not limited to
77
+ communication on electronic mailing lists, source code control
78
+ systems, and issue tracking systems that are managed by, or on behalf
79
+ of, the Licensor for the purpose of discussing and improving the Work,
80
+ but excluding communication that is conspicuously marked or otherwise
81
+ designated in writing by the copyright owner as "Not a Contribution."
82
+
83
+ "Contributor" shall mean Licensor and any individual or Legal Entity
84
+ on behalf of whom a Contribution has been received by Licensor and
85
+ subsequently incorporated within the Work.
86
+
87
+ 2. Grant of Copyright License. Subject to the terms and conditions of
88
+ this License, each Contributor hereby grants to You a perpetual,
89
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
90
+ copyright license to use, reproduce, modify, display, perform,
91
+ sublicense, and distribute the Work and such Derivative Works in
92
+ Source or Object form.
93
+
94
+ 3. Grant of Patent License. Subject to the terms and conditions of
95
+ this License, each Contributor hereby grants to You a perpetual,
96
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
97
+ (except as stated in this section) patent license to make, have made,
98
+ use, offer to sell, sell, import, and otherwise transfer the Work,
99
+ where such license applies only to those patent claims licensable
100
+ by such Contributor that are necessarily infringed by their
101
+ Contribution(s) alone or by combination of their Contribution(s)
102
+ with the Work to which such Contribution(s) was submitted. If You
103
+ institute patent litigation against any entity (including a
104
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
105
+ or a Contribution incorporated within the Work constitutes direct
106
+ or contributory patent infringement, then any patent licenses
107
+ granted to You under this License for that Work shall terminate
108
+ as of the date such litigation is filed.
109
+
110
+ 4. Redistribution. You may reproduce and distribute copies of the
111
+ Work or Derivative Works thereof in any medium, with or without
112
+ modifications, and in Source or Object form, provided that You
113
+ meet the following conditions:
114
+
115
+ (a) You must give any other recipients of the Work or
116
+ Derivative Works a copy of this License; and
117
+
118
+ (b) You must cause any modified files to carry prominent notices
119
+ stating that You changed the files; and
120
+
121
+ (c) You must retain, in the Source form of any Derivative Works
122
+ that You distribute, all copyright, trademark, patent,
123
+ attribution and other notices from the Source form of the Work,
124
+ excluding those notices that do not pertain to any part of
125
+ the Derivative Works; and
126
+
127
+ (d) If the Work includes a "NOTICE" text file as part of its
128
+ distribution, then any Derivative Works that You distribute must
129
+ include a readable copy of the attribution notices contained
130
+ within such NOTICE file, excluding those notices that do not
131
+ pertain to any part of the Derivative Works, in at least one
132
+ of the following places: within a NOTICE text file distributed
133
+ as part of the Derivative Works; within the Source form or
134
+ documentation, if provided along with the Derivative Works; or,
135
+ within a display generated by the Derivative Works, if and
136
+ wherever such third-party notices normally appear. The contents
137
+ of the NOTICE file are for informational purposes only and
138
+ do not modify the License. You may add Your own attribution
139
+ notices within Derivative Works that You distribute, alongside
140
+ or as an addendum to the NOTICE text from the Work, provided
141
+ that such additional attribution notices cannot be construed
142
+ as modifying the License.
143
+
144
+ You may add Your own copyright notice or additional permissions.
145
+
146
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
147
+ any Contribution intentionally submitted for inclusion in the Work
148
+ by You to the Licensor shall be under the terms and conditions of
149
+ this License, without any additional terms or conditions.
150
+ Notwithstanding the above, nothing herein shall supersede or modify
151
+ the terms of any separate license agreement you may have executed
152
+ with Licensor regarding such Contributions.
153
+
154
+ 6. Trademarks. This License does not grant permission to use the trade
155
+ names, trademarks, service marks, or product names of the Licensor,
156
+ except as required for reasonable and customary use in describing the
157
+ origin of the Work and reproducing the content of the NOTICE file.
158
+
159
+ 7. Disclaimer of Warranty. Unless required by applicable law or
160
+ agreed to in writing, Licensor provides the Work (and each
161
+ Contributor provides its Contributions) on an "AS IS" BASIS,
162
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
163
+ implied, including, without limitation, any warranties or conditions
164
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
165
+ PARTICULAR PURPOSE. You are solely responsible for determining the
166
+ appropriateness of using or redistributing the Work and assume any
167
+ risks associated with Your exercise of permissions under this License.
168
+
169
+ 8. Limitation of Liability. In no event and under no legal theory,
170
+ whether in tort (including negligence), contract, or otherwise,
171
+ unless required by applicable law (such as deliberate and grossly
172
+ negligent acts) or agreed to in writing, shall any Contributor be
173
+ liable to You for damages, including any direct, indirect, special,
174
+ incidental, or consequential damages of any character arising as a
175
+ result of this License or out of the use or inability to use the
176
+ Work (including but not limited to damages for loss of goodwill,
177
+ work stoppage, computer failure or malfunction, or any and all
178
+ other commercial damages or losses), even if such Contributor
179
+ has been advised of the possibility of such damages.
180
+
181
+ 9. Accepting Warranty or Support. You may choose to offer, and to
182
+ charge a fee for, warranty, support, indemnity or other liability
183
+ obligations and/or rights consistent with this License. However, in
184
+ accepting such obligations, You may act only on Your own behalf and on
185
+ Your sole responsibility, not on behalf of any other Contributor, and
186
+ only if You agree to indemnify, defend, and hold each Contributor
187
+ harmless for any liability incurred by, or claims asserted against,
188
+ such Contributor by reason of your accepting any such warranty or support.
189
+
190
+ END OF TERMS AND CONDITIONS
191
+ ```
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ # CAP MCP Plugin - AI With Ease
2
+
3
+ > This implementation is based on the Model Context Protocol (MCP) put forward by Anthropic.
4
+ > For more information on MCP, please have a look at their [official documentation.](https://modelcontextprotocol.io/introduction)
5
+
6
+ > 🔧 **In active development - 1.0 release scheduled for Summer 2025**
7
+
8
+ # CAP-MCP Plugin
9
+
10
+ A CAP (Cloud Application Programming) plugin that automatically generates Model Context Protocol (MCP) servers from your CAP services using simple annotations.
11
+ Transform your CAP OData services into AI-accessible resources, tools, and prompts with minimal configuration.
12
+
13
+ ## 🚀 The Power of MCP for CAP Applications
14
+
15
+ The Model Context Protocol bridges the gap between your enterprise data and AI agents.
16
+ By integrating MCP with your CAP applications, you unlock:
17
+
18
+ - **AI-Native Data Access**: Your CAP services become directly accessible to AI agents like Claude, enabling natural language queries against your business data
19
+ - **Enterprise Integration**: Seamlessly connect AI tools to your SAP systems, databases, and business logic
20
+ - **Intelligent Automation**: Enable AI agents to perform complex business operations by combining multiple CAP service calls
21
+ - **Developer Productivity**: Allow AI assistants to help developers understand, query, and work with your CAP data models
22
+ - **Business Intelligence**: Transform your structured business data into AI-queryable resources for insights and analysis
23
+
24
+ ## ⚠️ Development Status
25
+
26
+ **This plugin is currently in active development (v0.9.0) and is not ready for production use.**
27
+ APIs and annotations may change in future releases. Use in development and testing environments only.
28
+
29
+ Version 1.0 of the plugin is planned to release shortly after auth integration is complete.
30
+
31
+ ### 👾 Known Bugs
32
+
33
+ > ❗Currently there is a bug in the `@modelcontextprotocol/sdk` package that breaks the RFC template strings. The issue has been reported.
34
+ > Until this issue is fixed, the resource reads for dynamic queries are only possible if all query options are provided.
35
+
36
+ ## 📦 Installation
37
+
38
+ ```bash
39
+ npm install @gavdi/cap-mcp
40
+ ```
41
+
42
+ The plugin follows CAP's standard plugin architecture and will automatically integrate with your CAP application.
43
+
44
+ ## 🎯 Features
45
+
46
+ This plugin transforms your annotated CAP services into a fully functional MCP server that can be consumed by any MCP-compatible AI client.
47
+
48
+ - **📊 Resources**: Expose CAP entities as MCP resources with OData v4 query capabilities
49
+ - **🔧 Tools**: Convert CAP functions and actions into executable MCP tools
50
+ - **💡 Prompts**: Define reusable prompt templates for AI interactions
51
+ - **🔄 Auto-generation**: Automatically creates MCP server endpoints based on annotations
52
+ - **⚙️ Flexible Configuration**: Support for custom parameter sets and descriptions
53
+
54
+ ## 📝 Usage
55
+
56
+ ### Resource Annotations
57
+
58
+ Transform CAP entities into AI-queryable resources:
59
+
60
+ ```cds
61
+ service CatalogService {
62
+
63
+ @readonly
64
+ @mcp: {
65
+ name : 'books',
66
+ description: 'Book data list',
67
+ resource : [
68
+ 'filter',
69
+ 'orderby',
70
+ 'select',
71
+ 'skip',
72
+ 'top'
73
+ ]
74
+ }
75
+ entity Books as projection on my.Books;
76
+
77
+ // Enable all OData query options
78
+ @mcp: {
79
+ name : 'authors',
80
+ description: 'Author data list',
81
+ resource : true
82
+ }
83
+ entity Authors as projection on my.Authors;
84
+
85
+ // Or maybe you just want it as a static top 100 list of data?
86
+ @mcp: {
87
+ name : 'genres',
88
+ description: 'Book genre list',
89
+ resource : []
90
+ }
91
+ entity Genres as projection on my.Genres;
92
+ }
93
+ ```
94
+
95
+ **Generated MCP Resource Capabilities:**
96
+ - **OData v4 Query Support**: `$filter`, `$orderby`, `$top`, `$skip`, `$select`
97
+ - **Natural Language Queries**: "Find books by Stephen King with stock > 20"
98
+ - **Dynamic Filtering**: Complex filter expressions using OData syntax
99
+ - **Flexible Selection**: Choose specific fields and sort orders
100
+
101
+ ### Tool Annotations
102
+
103
+ Convert CAP functions and actions into executable AI tools:
104
+
105
+ ```cds
106
+ // Service-level function
107
+ @mcp: {
108
+ name : 'get-author',
109
+ description: 'Gets the desired author',
110
+ tool : true
111
+ }
112
+ function getAuthor(input: String) returns String;
113
+
114
+ // Entity-level action
115
+ extend projection Books with actions {
116
+ @mcp: {
117
+ name : 'get-stock',
118
+ description: 'Retrieves stock from a given book',
119
+ tool : true
120
+ }
121
+ function getStock() returns Integer;
122
+ }
123
+ ```
124
+
125
+ ### Prompt Templates
126
+
127
+ Define reusable AI prompt templates:
128
+
129
+ ```cds
130
+ annotate CatalogService with @mcp.prompts: [{
131
+ name : 'give-me-book-abstract',
132
+ title : 'Book Abstract',
133
+ description: 'Gives an abstract of a book based on the title',
134
+ template : 'Search the internet and give me an abstract of the book {{book-id}}',
135
+ role : 'user',
136
+ inputs : [{
137
+ key : 'book-id',
138
+ type: 'String'
139
+ }]
140
+ }];
141
+ ```
142
+
143
+ ## 🔧 Configuration
144
+
145
+ The plugin automatically:
146
+ - Scans your CAP service definitions for `@mcp` annotations
147
+ - Generates appropriate MCP resources, tools, and prompts
148
+ - Creates ResourceTemplates with proper OData v4 query parameter support
149
+
150
+ ## 🌟 Example AI Interactions
151
+
152
+ Once configured, AI agents can interact with your CAP data naturally; Let's take an example from the standard CAP Bookshop:
153
+
154
+ - **"Show me the top 5 books with highest stock"** → Queries Books resource with `$orderby=stock desc&$top=5`
155
+ - **"Find authors whose names contain 'Smith'"** → Uses `$filter=contains(name,'Smith')` on Authors resource
156
+ - **"Get the current stock for book ID 123"** → Calls the `get-stock` tool for the specified book
157
+ - **"Give me a book recommendation"** → Executes the `book-recommendation` tool
158
+
159
+ While this shows how this example CDS annotation works, the possibilities are endless and only you and your data sets the boundaries.
160
+
161
+ ## 📋 Business Case Example: Workflow Approval Management
162
+
163
+ ### The Setup
164
+ Your CAP service includes a workflow management system with MCP integration:
165
+
166
+ ```cds
167
+ service WorkflowService {
168
+
169
+ @mcp: {
170
+ name : 'get-my-pending-approval',
171
+ description: 'Fetches workflows awaiting approval by the specified user',
172
+ tool : true
173
+ }
174
+ function getPendingApproval(userId: String) returns array of Workflows;
175
+ }
176
+ ```
177
+
178
+ ### The Interaction Flow
179
+
180
+ **1. User Query**
181
+ ```
182
+ User: "Hey <Agent>, do I have any workflows pending approval?"
183
+ ```
184
+
185
+ **2. AI Agent Processing**
186
+ - Agent recognizes this as a request for pending approval information
187
+ - Identifies the `get-my-pending-approval` tool as the appropriate method
188
+ - Determines the user's ID from context (session, authentication, etc.)
189
+
190
+ **3. MCP Tool Execution**
191
+ ```javascript
192
+ // Agent calls the MCP tool
193
+ {
194
+ "tool": "get-my-pending-approval",
195
+ "arguments": {
196
+ "userId": "john.doe@company.com"
197
+ }
198
+ }
199
+ ```
200
+
201
+ **4. CAP Service Processing**
202
+ - Your CAP service receives the tool call
203
+ - Executes `getPendingApproval("john.doe@company.com")`
204
+ - Queries your workflow database/system
205
+ - Returns structured workflow data
206
+
207
+ **5. AI Response**
208
+ ```
209
+ Agent: "You have 3 workflows pending your approval:
210
+
211
+ • **Purchase Order #PO-2024-001**
212
+ Submitted by: Sarah Johnson
213
+ Amount: $12,500
214
+ Submitted: 2 days ago
215
+
216
+ • **Budget Request - Marketing Q2**
217
+ Submitted by: Mike Chen
218
+ Amount: $45,000
219
+ Submitted: 1 day ago
220
+
221
+ • **New Employee Onboarding - Jane Smith**
222
+ Submitted by: HR Department
223
+ Start Date: Next Monday
224
+ Submitted: 4 hours ago
225
+
226
+ Would you like me to help you review any of these in detail?"
227
+ ```
228
+
229
+ ### Business Value
230
+ - **Instant Access**: No need to log into workflow systems or navigate complex UIs
231
+ - **Contextual Intelligence**: AI can prioritize based on urgency, amounts, or business rules
232
+ - **Natural Interaction**: Users can ask follow-up questions in plain language
233
+ - **Integration Ready**: Works with existing CAP-based workflow systems
234
+ - **Mobile Friendly**: Access approvals from any MCP-compatible AI client
235
+
236
+ ## 🧰 Testing Locally
237
+
238
+ If you want to test the MCP implementation you have made on your CAP application locally, you have 2 options available (that does not involve direct integration with AI Agent).
239
+
240
+ ### Option #1 - MCP Inspector
241
+
242
+ You can inspect the MCP implementation by utilizing the official `@modelcontextprotocol/inspector`.
243
+
244
+ This inspector can be started up through either the included `npm run inspect` command, or by running `npx @modelcontextprotocol/inspector`.
245
+
246
+ For plugin implementation implementation in your own project it is recommended to add the above command to your own script collection.
247
+
248
+ For more information on the inspector, please [see the official documentation](https://github.com/modelcontextprotocol/inspector).
249
+
250
+ ### Option #2 - Bruno Collection
251
+
252
+ This repository comes with a Bruno collection available that includes some example queries you can use to verify your MCP implementation. These can be found in the `bruno` directory.
253
+
254
+ ## 🤝 Contributing
255
+
256
+ Contributions are welcome! This is an open-source project aimed at bridging CAP applications with the AI ecosystem.
257
+
258
+ - **Issues**: Report bugs and request features
259
+ - **Pull Requests**: Submit improvements and fixes
260
+ - **Documentation**: Help improve examples and guides
261
+ - **Testing**: Share your use cases and edge cases
262
+
263
+ ## 📄 License
264
+
265
+ This project is licensed under the Apache-2.0 License - see the [LICENSE.md](LICENSE.md) file for details.
266
+
267
+ ## 🔗 Resources
268
+
269
+ - [Model Context Protocol Specification](https://modelcontextprotocol.io)
270
+ - [SAP CAP Documentation](https://cap.cloud.sap)
271
+ - [OData v4 Specification](https://odata.org)
272
+
273
+ ---
274
+ (c) Copyright by Gavdi Labs 2025 - All Rights Reserved
275
+
276
+ **Transform your CAP applications into AI-ready systems with the power of the Model Context Protocol.**
package/cds-plugin.js ADDED
@@ -0,0 +1,17 @@
1
+ const cds = global.cds || require("@sap/cds");
2
+ const McpPlugin = require("./lib/mcp").default;
3
+
4
+ const plugin = new McpPlugin();
5
+
6
+ // Plugin hooks event registration
7
+ cds.on("bootstrap", async (app) => {
8
+ await plugin?.onBootstrap(app);
9
+ });
10
+
11
+ cds.on("loaded", async (model) => {
12
+ await plugin?.onLoaded(model);
13
+ });
14
+
15
+ cds.on("shutdown", async () => {
16
+ await plugin?.onShutdown();
17
+ });
package/index.cds ADDED
@@ -0,0 +1 @@
1
+ namespace gavdi.mcp;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_ALL_RESOURCE_OPTIONS = exports.MCP_ANNOTATION_PROPS = exports.MCP_ANNOTATION_KEY = void 0;
4
+ exports.MCP_ANNOTATION_KEY = "@mcp";
5
+ exports.MCP_ANNOTATION_PROPS = {
6
+ // Standard annotations - required for all
7
+ MCP_NAME: "@mcp.name",
8
+ MCP_DESCRIPTION: "@mcp.description",
9
+ // Resource annotations for MCP
10
+ MCP_RESOURCE: "@mcp.resource",
11
+ // Tool annotations for MCP
12
+ MCP_TOOL: "@mcp.tool",
13
+ // Prompt annotations for MCP
14
+ MCP_PROMPT: "@mcp.prompts",
15
+ };
16
+ exports.DEFAULT_ALL_RESOURCE_OPTIONS = new Set([
17
+ "filter",
18
+ "orderby",
19
+ "top",
20
+ "skip",
21
+ "select",
22
+ ]);
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseDefinitions = parseDefinitions;
4
+ const logger_1 = require("../logger");
5
+ const structures_1 = require("./structures");
6
+ const utils_1 = require("./utils");
7
+ const constants_1 = require("./constants");
8
+ function parseDefinitions(model) {
9
+ if (!model.definitions) {
10
+ logger_1.LOGGER.error("Invalid model loaded", model);
11
+ throw new Error("Cannot parse model without valid definitions");
12
+ }
13
+ const result = new Map();
14
+ for (const [key, value] of Object.entries(model.definitions)) {
15
+ const parsedAnnotations = parseAnnotations(value);
16
+ const { serviceName, target } = (0, utils_1.splitDefinitionName)(key);
17
+ parseBoundOperations(serviceName, target, value, result); // Mutates result map with bound operations
18
+ if (!parsedAnnotations || !(0, utils_1.containsRequiredAnnotations)(parsedAnnotations)) {
19
+ continue; // This check must occur here, since we do want the bound operations even if the parent is not annotated
20
+ }
21
+ const verifiedAnnotations = parsedAnnotations;
22
+ switch (value.kind) {
23
+ case "entity":
24
+ const resourceAnnotation = constructResourceAnnotation(serviceName, target, verifiedAnnotations, value);
25
+ if (!resourceAnnotation)
26
+ continue;
27
+ result.set(resourceAnnotation.target, resourceAnnotation);
28
+ continue;
29
+ case "function":
30
+ const functionAnnotation = constructToolAnnotation(serviceName, target, verifiedAnnotations);
31
+ if (!functionAnnotation)
32
+ continue;
33
+ result.set(functionAnnotation.target, functionAnnotation);
34
+ continue;
35
+ case "action":
36
+ const actionAnnotation = constructToolAnnotation(serviceName, target, verifiedAnnotations);
37
+ if (!actionAnnotation)
38
+ continue;
39
+ result.set(actionAnnotation.target, actionAnnotation);
40
+ continue;
41
+ case "service":
42
+ const promptsAnnotation = constructPromptAnnotation(serviceName, verifiedAnnotations);
43
+ if (!promptsAnnotation)
44
+ continue;
45
+ result.set(promptsAnnotation.target, promptsAnnotation);
46
+ continue;
47
+ default:
48
+ continue;
49
+ }
50
+ }
51
+ return result;
52
+ }
53
+ function parseAnnotations(definition) {
54
+ if (!(0, utils_1.containsMcpAnnotation)(definition))
55
+ return undefined;
56
+ const annotations = {
57
+ definition: definition,
58
+ };
59
+ for (const [k, v] of Object.entries(definition)) {
60
+ if (!k.includes(constants_1.MCP_ANNOTATION_KEY))
61
+ continue;
62
+ logger_1.LOGGER.debug("Parsing: ", k, v);
63
+ switch (k) {
64
+ case constants_1.MCP_ANNOTATION_PROPS.MCP_NAME:
65
+ annotations.name = v;
66
+ continue;
67
+ case constants_1.MCP_ANNOTATION_PROPS.MCP_DESCRIPTION:
68
+ annotations.description = v;
69
+ continue;
70
+ case constants_1.MCP_ANNOTATION_PROPS.MCP_RESOURCE:
71
+ annotations.resource = v;
72
+ continue;
73
+ case constants_1.MCP_ANNOTATION_PROPS.MCP_TOOL:
74
+ annotations.tool = v;
75
+ continue;
76
+ case constants_1.MCP_ANNOTATION_PROPS.MCP_PROMPT:
77
+ annotations.prompts = v;
78
+ continue;
79
+ default:
80
+ continue;
81
+ }
82
+ }
83
+ return annotations;
84
+ }
85
+ function constructResourceAnnotation(serviceName, target, annotations, definition) {
86
+ if (!(0, utils_1.isValidResourceAnnotation)(annotations))
87
+ return undefined;
88
+ const functionalities = (0, utils_1.determineResourceOptions)(annotations);
89
+ const { properties, resourceKeys } = (0, utils_1.parseResourceElements)(definition);
90
+ return new structures_1.McpResourceAnnotation(annotations.name, annotations.description, target, serviceName, functionalities, properties, resourceKeys);
91
+ }
92
+ function constructToolAnnotation(serviceName, target, annotations, entityKey, keyParams) {
93
+ if (!(0, utils_1.isValidToolAnnotation)(annotations))
94
+ return undefined;
95
+ const { parameters, operationKind } = (0, utils_1.parseOperationElements)(annotations);
96
+ return new structures_1.McpToolAnnotation(annotations.name, annotations.description, target, serviceName, parameters, entityKey, operationKind, keyParams);
97
+ }
98
+ function constructPromptAnnotation(serviceName, annotations) {
99
+ if (!(0, utils_1.isValidPromptsAnnotation)(annotations))
100
+ return undefined;
101
+ return new structures_1.McpPromptAnnotation(annotations.name, annotations.description, serviceName, annotations.prompts);
102
+ }
103
+ /**
104
+ * Parses the bound operations found on the entity definition if any.
105
+ * This function mutates the passed result reference object.
106
+ */
107
+ function parseBoundOperations(serviceName, entityKey, definition, resultRef) {
108
+ if (definition.kind !== "entity")
109
+ return;
110
+ const boundOperations = definition
111
+ .actions; // Necessary due to missing type reference
112
+ if (!boundOperations)
113
+ return;
114
+ const keyParams = (0, utils_1.parseEntityKeys)(definition);
115
+ for (const [k, v] of Object.entries(boundOperations)) {
116
+ if (v.kind !== "function" && v.kind !== "action")
117
+ continue;
118
+ const parsedAnnotations = parseAnnotations(v);
119
+ if (!parsedAnnotations || !(0, utils_1.containsRequiredAnnotations)(parsedAnnotations)) {
120
+ continue;
121
+ }
122
+ const verifiedAnnotations = parsedAnnotations;
123
+ const toolAnnotation = constructToolAnnotation(serviceName, k, verifiedAnnotations, entityKey, keyParams);
124
+ if (!toolAnnotation)
125
+ continue;
126
+ resultRef.set(k, toolAnnotation);
127
+ }
128
+ }