@@ -16,231 +16,283 @@ import {
16
16
assetCategoryVendorParam ,
17
17
} from '@repo/mcp-common/src/schemas/cf1-integrations'
18
18
19
+ import type { zReturnedAssetResult } from '@repo/mcp-common/src/schemas/cf1-integrations'
19
20
import type { ToolDefinition } from '@repo/mcp-common/src/types/tools'
20
21
import type { CASBMCP } from '../index'
21
22
22
- const PAGE_SIZE = 3
23
-
24
23
const integrationIdParam = z . string ( ) . describe ( 'The UUID of the integration to analyze' )
25
24
const assetSearchTerm = z . string ( ) . describe ( 'The search keyword for assets' )
26
25
const assetIdParam = z . string ( ) . describe ( 'The UUID of the asset to analyze' )
27
26
const assetCategoryIdParam = z . string ( ) . describe ( 'The UUID of the asset category to analyze' )
28
27
28
+ const paginationParams = z
29
+ . object ( {
30
+ page : z . number ( ) . optional ( ) . describe ( 'Page number for pagination' ) ,
31
+ pageSize : z . number ( ) . optional ( ) . describe ( 'Number of items per page' ) ,
32
+ } )
33
+ . optional ( )
34
+
35
+ const assetLite = ( { fields : _ , integration, ...asset } : zReturnedAssetResult ) => ( {
36
+ ...asset ,
37
+ integration : {
38
+ id : integration . id ,
39
+ name : integration . name ,
40
+ } ,
41
+ } )
42
+
29
43
const toolDefinitions : Array < ToolDefinition < any > > = [
30
44
{
31
45
name : 'integration_by_id' ,
32
46
description : 'Analyze Cloudflare One Integration by ID' ,
33
- params : { integrationIdParam } ,
47
+ params : { integrationIdParam, paginationParams } ,
34
48
handler : async ( {
35
49
integrationIdParam,
36
50
accountId,
37
51
apiToken,
52
+ paginationParams = { } ,
38
53
} : {
39
54
integrationIdParam : string
40
55
accountId : string
41
56
apiToken : string
57
+ paginationParams ?: { page ?: number ; pageSize ?: number }
42
58
} ) => {
43
59
const { integration } = await handleIntegrationById ( {
44
60
integrationIdParam,
45
61
accountId,
46
62
apiToken,
63
+ ...paginationParams ,
47
64
} )
48
65
return { integration }
49
66
} ,
50
67
} ,
51
68
{
52
69
name : 'integrations_list' ,
53
70
description : 'List all Cloudflare One Integrations in a given account' ,
54
- params : { } ,
55
- handler : async ( { accountId, apiToken } : { accountId : string ; apiToken : string } ) => {
56
- const { integrations } = await handleIntegrations ( { accountId, apiToken } )
57
- return { integrations }
71
+ params : { paginationParams } ,
72
+ handler : async ( {
73
+ accountId,
74
+ apiToken,
75
+ paginationParams = { } ,
76
+ } : {
77
+ accountId : string
78
+ apiToken : string
79
+ paginationParams ?: { page ?: number ; pageSize ?: number }
80
+ } ) => {
81
+ const { integrations, result_info } = await handleIntegrations ( {
82
+ accountId,
83
+ apiToken,
84
+ ...paginationParams ,
85
+ } )
86
+ return { integrations, result_info }
58
87
} ,
59
88
} ,
60
89
{
61
90
name : 'assets_search' ,
62
91
description : 'Search Assets by keyword' ,
63
- params : { assetSearchTerm } ,
92
+ params : { assetSearchTerm, paginationParams } ,
64
93
handler : async ( {
65
94
assetSearchTerm,
66
95
accountId,
67
96
apiToken,
97
+ paginationParams = { } ,
68
98
} : {
69
99
assetSearchTerm : string
70
100
accountId : string
71
101
apiToken : string
102
+ paginationParams ?: { page ?: number ; pageSize ?: number }
72
103
} ) => {
73
- const { assets } = await handleAssetsSearch ( {
104
+ const { assets, result_info } = await handleAssetsSearch ( {
74
105
accountId,
75
106
apiToken,
76
107
searchTerm : assetSearchTerm ,
77
- pageSize : PAGE_SIZE ,
108
+ ... paginationParams ,
78
109
} )
79
- return { assets }
110
+ return { assets : assets . map ( assetLite ) , result_info }
80
111
} ,
81
112
} ,
82
113
{
83
114
name : 'asset_by_id' ,
84
115
description : 'Search Assets by ID' ,
85
- params : { assetIdParam } ,
116
+ params : { assetIdParam, paginationParams } ,
86
117
handler : async ( {
87
118
assetIdParam,
88
119
accountId,
89
120
apiToken,
121
+ paginationParams = { } ,
90
122
} : {
91
123
assetIdParam : string
92
124
accountId : string
93
125
apiToken : string
126
+ paginationParams ?: { page ?: number ; pageSize ?: number }
94
127
} ) => {
95
128
const { asset } = await handleAssetById ( {
96
129
accountId,
97
130
apiToken,
98
131
assetId : assetIdParam ,
132
+ ...paginationParams ,
99
133
} )
100
134
return { asset }
101
135
} ,
102
136
} ,
103
137
{
104
138
name : 'assets_by_integration_id' ,
105
139
description : 'Search Assets by Integration ID' ,
106
- params : { integrationIdParam } ,
140
+ params : { integrationIdParam, paginationParams } ,
107
141
handler : async ( {
108
142
integrationIdParam,
109
143
accountId,
110
144
apiToken,
145
+ paginationParams = { } ,
111
146
} : {
112
147
integrationIdParam : string
113
148
accountId : string
114
149
apiToken : string
150
+ paginationParams ?: { page ?: number ; pageSize ?: number }
115
151
} ) => {
116
- const { assets } = await handleAssetsByIntegrationId ( {
152
+ const { assets, result_info } = await handleAssetsByIntegrationId ( {
117
153
accountId,
118
154
apiToken,
119
155
integrationId : integrationIdParam ,
120
- pageSize : PAGE_SIZE ,
156
+ ... paginationParams ,
121
157
} )
122
- return { assets }
158
+ return { assets : assets . map ( assetLite ) , result_info }
123
159
} ,
124
160
} ,
125
161
{
126
162
name : 'assets_by_category_id' ,
127
163
description : 'Search Assets by Asset Category ID' ,
128
- params : { assetCategoryIdParam } ,
164
+ params : { assetCategoryIdParam, paginationParams } ,
129
165
handler : async ( {
130
166
assetCategoryIdParam,
131
167
accountId,
132
168
apiToken,
169
+ paginationParams = { } ,
133
170
} : {
134
171
assetCategoryIdParam : string
135
172
accountId : string
136
173
apiToken : string
174
+ paginationParams ?: { page ?: number ; pageSize ?: number }
137
175
} ) => {
138
- const { assets } = await handleAssetsByAssetCategoryId ( {
176
+ const { assets, result_info } = await handleAssetsByAssetCategoryId ( {
139
177
accountId,
140
178
apiToken,
141
179
categoryId : assetCategoryIdParam ,
142
- pageSize : PAGE_SIZE ,
180
+ ... paginationParams ,
143
181
} )
144
- return { assets }
182
+ return { assets : assets . map ( assetLite ) , result_info }
145
183
} ,
146
184
} ,
147
185
{
148
186
name : 'assets_list' ,
149
187
description : 'Paginated list of Assets' ,
150
- params : { } ,
151
- handler : async ( { accountId, apiToken } : { accountId : string ; apiToken : string } ) => {
152
- const { assets } = await handleAssets ( {
188
+ params : { paginationParams } ,
189
+ handler : async ( {
190
+ accountId,
191
+ apiToken,
192
+ paginationParams = { } ,
193
+ } : {
194
+ accountId : string
195
+ apiToken : string
196
+ paginationParams ?: { page ?: number ; pageSize ?: number }
197
+ } ) => {
198
+ const { assets, result_info } = await handleAssets ( {
153
199
accountId,
154
200
apiToken,
155
- pageSize : PAGE_SIZE ,
201
+ ... paginationParams ,
156
202
} )
157
- return { assets }
203
+ return { assets : assets . map ( assetLite ) , result_info }
158
204
} ,
159
205
} ,
160
206
{
161
207
name : 'asset_categories_list' ,
162
208
description : 'List Asset Categories' ,
163
- params : { } ,
164
- handler : async ( { accountId, apiToken } : { accountId : string ; apiToken : string } ) => {
165
- const { categories } = await handleAssetCategories ( {
209
+ params : { paginationParams } ,
210
+ handler : async ( {
211
+ accountId,
212
+ apiToken,
213
+ paginationParams = { } ,
214
+ } : {
215
+ accountId : string
216
+ apiToken : string
217
+ paginationParams ?: { page ?: number ; pageSize ?: number }
218
+ } ) =>
219
+ await handleAssetCategories ( {
166
220
accountId,
167
221
apiToken,
168
- } )
169
- return { categories }
170
- } ,
222
+ ...paginationParams ,
223
+ } ) ,
171
224
} ,
172
225
{
173
226
name : 'asset_categories_by_vendor' ,
174
227
description : 'List asset categories by vendor' ,
175
- params : { assetCategoryVendorParam } ,
228
+ params : { assetCategoryVendorParam, paginationParams } ,
176
229
handler : async ( {
177
230
assetCategoryVendorParam,
178
231
accountId,
179
232
apiToken,
233
+ paginationParams = { } ,
180
234
} : {
181
235
assetCategoryVendorParam : string
182
236
accountId : string
183
237
apiToken : string
184
- } ) => {
185
- const { categories } = await handleAssetCategories ( {
238
+ paginationParams ?: { page ?: number ; pageSize ?: number }
239
+ } ) =>
240
+ await handleAssetCategories ( {
186
241
accountId,
187
242
apiToken,
188
243
vendor : assetCategoryVendorParam ,
189
- } )
190
- return { categories }
191
- } ,
244
+ ...paginationParams ,
245
+ } ) ,
192
246
} ,
193
247
{
194
248
name : 'asset_categories_by_type' ,
195
249
description : 'Search Asset Categories by type' ,
196
- params : { assetCategoryTypeParam } ,
250
+ params : { assetCategoryTypeParam, paginationParams } ,
197
251
handler : async ( {
198
252
assetCategoryTypeParam,
199
253
accountId,
200
254
apiToken,
255
+ paginationParams = { } ,
201
256
} : {
202
257
assetCategoryTypeParam ?: string
203
258
accountId : string
204
259
apiToken : string
205
- } ) => {
206
- const { categories } = await handleAssetCategories ( {
260
+ paginationParams ?: { page ?: number ; pageSize ?: number }
261
+ } ) =>
262
+ await handleAssetCategories ( {
207
263
accountId,
208
264
apiToken,
209
265
type : assetCategoryTypeParam ,
210
- } )
211
- return { categories }
212
- } ,
266
+ ...paginationParams ,
267
+ } ) ,
213
268
} ,
214
269
{
215
270
name : 'asset_categories_by_vendor_and_type' ,
216
271
description : 'Search Asset Categories by vendor and type' ,
217
- params : { assetCategoryTypeParam, assetCategoryVendorParam } ,
272
+ params : { assetCategoryTypeParam, assetCategoryVendorParam, paginationParams } ,
218
273
handler : async ( {
219
274
assetCategoryTypeParam,
220
275
assetCategoryVendorParam,
221
276
accountId,
222
277
apiToken,
278
+ paginationParams = { } ,
223
279
} : {
224
280
assetCategoryTypeParam ?: string
225
281
assetCategoryVendorParam : string
226
282
accountId : string
227
283
apiToken : string
228
- } ) => {
229
- const { categories } = await handleAssetCategories ( {
284
+ paginationParams ?: { page ?: number ; pageSize ?: number }
285
+ } ) =>
286
+ await handleAssetCategories ( {
230
287
accountId,
231
288
apiToken,
232
289
type : assetCategoryTypeParam ,
233
290
vendor : assetCategoryVendorParam ,
234
- } )
235
- return { categories }
236
- } ,
291
+ ...paginationParams ,
292
+ } ) ,
237
293
} ,
238
294
]
239
295
240
- /**
241
- * Registers the logs analysis tool with the MCP server
242
- * @param agent The MCP server instance
243
- */
244
296
export function registerIntegrationsTools ( agent : CASBMCP ) {
245
297
toolDefinitions . forEach ( ( { name, description, params, handler } ) => {
246
298
agent . server . tool ( name , description , params , withAccountCheck ( agent , handler ) )
0 commit comments