@@ -10,9 +10,12 @@ import {
10
10
handleIntegrationById ,
11
11
handleIntegrations ,
12
12
} from '@repo/mcp-common/src/api/cf1-integration'
13
+ import {
14
+ assetCategoryTypeParam ,
15
+ assetCategoryVendorParam ,
16
+ } from '@repo/mcp-common/src/schemas/cf1-integrations'
13
17
14
18
import type { MyMCP } from '../index'
15
- import { assetCategoryTypeParam , assetCategoryVendorParam } from '@repo/mcp-common/src/schemas/cf1-integrations'
16
19
17
20
const PAGE_SIZE = 3
18
21
@@ -24,12 +27,10 @@ const assetSearchTerm = z.string().describe('The search keyword for assets')
24
27
const assetIdParam = z . string ( ) . describe ( 'The UUID of the asset to analyze' )
25
28
const assetCategoryIdParam = z . string ( ) . describe ( 'The UUID of the asset category to analyze' )
26
29
27
-
28
-
29
-
30
-
31
30
// Define types for our tool handlers
32
- type ToolHandler < T extends Record < string , any > > = ( params : T & { accountId : string ; apiToken : string } ) => Promise < any >
31
+ type ToolHandler < T extends Record < string , any > > = (
32
+ params : T & { accountId : string ; apiToken : string }
33
+ ) => Promise < any >
33
34
34
35
interface ToolDefinition < T extends Record < string , any > > {
35
36
name : string
@@ -39,10 +40,7 @@ interface ToolDefinition<T extends Record<string, any>> {
39
40
}
40
41
41
42
// Helper function to handle common error cases and account ID checks
42
- const withAccountCheck = < T extends Record < string , any > > (
43
- agent : MyMCP ,
44
- handler : ToolHandler < T >
45
- ) => {
43
+ const withAccountCheck = < T extends Record < string , any > > ( agent : MyMCP , handler : ToolHandler < T > ) => {
46
44
return async ( params : T ) => {
47
45
const accountId = agent . getActiveAccountId ( )
48
46
if ( ! accountId ) {
@@ -81,12 +79,20 @@ const withAccountCheck = <T extends Record<string, any>>(
81
79
}
82
80
83
81
// Tool definitions with their handlers
84
- const toolDefinitions : ToolDefinition < any > [ ] = [
82
+ const toolDefinitions : Array < ToolDefinition < any > > = [
85
83
{
86
84
name : 'integration_by_id' ,
87
85
description : 'Analyze Cloudflare One Integration by ID' ,
88
86
params : { integrationIdParam } ,
89
- handler : async ( { integrationIdParam, accountId, apiToken } : { integrationIdParam : string ; accountId : string ; apiToken : string } ) => {
87
+ handler : async ( {
88
+ integrationIdParam,
89
+ accountId,
90
+ apiToken,
91
+ } : {
92
+ integrationIdParam : string
93
+ accountId : string
94
+ apiToken : string
95
+ } ) => {
90
96
const { integration } = await handleIntegrationById ( {
91
97
integrationIdParam,
92
98
accountId,
@@ -100,6 +106,7 @@ const toolDefinitions: ToolDefinition<any>[] = [
100
106
description : 'List all Cloudflare One Integrations in a given account' ,
101
107
params : { } ,
102
108
handler : async ( { accountId, apiToken } : { accountId : string ; apiToken : string } ) => {
109
+ console . log ( 'integrations_list' , accountId , apiToken )
103
110
const { integrations } = await handleIntegrations ( { accountId, apiToken } )
104
111
return { integrations }
105
112
} ,
@@ -108,7 +115,15 @@ const toolDefinitions: ToolDefinition<any>[] = [
108
115
name : 'assets_search' ,
109
116
description : 'Search Assets by keyword' ,
110
117
params : { assetSearchTerm } ,
111
- handler : async ( { assetSearchTerm, accountId, apiToken } : { assetSearchTerm : string ; accountId : string ; apiToken : string } ) => {
118
+ handler : async ( {
119
+ assetSearchTerm,
120
+ accountId,
121
+ apiToken,
122
+ } : {
123
+ assetSearchTerm : string
124
+ accountId : string
125
+ apiToken : string
126
+ } ) => {
112
127
const { assets } = await handleAssetsSearch ( {
113
128
accountId,
114
129
apiToken,
@@ -122,7 +137,15 @@ const toolDefinitions: ToolDefinition<any>[] = [
122
137
name : 'asset_by_id' ,
123
138
description : 'Search Assets by ID' ,
124
139
params : { assetIdParam } ,
125
- handler : async ( { assetIdParam, accountId, apiToken } : { assetIdParam : string ; accountId : string ; apiToken : string } ) => {
140
+ handler : async ( {
141
+ assetIdParam,
142
+ accountId,
143
+ apiToken,
144
+ } : {
145
+ assetIdParam : string
146
+ accountId : string
147
+ apiToken : string
148
+ } ) => {
126
149
const { asset } = await handleAssetById ( {
127
150
accountId,
128
151
apiToken,
@@ -135,7 +158,15 @@ const toolDefinitions: ToolDefinition<any>[] = [
135
158
name : 'assets_by_integration_id' ,
136
159
description : 'Search Assets by Integration ID' ,
137
160
params : { integrationIdParam } ,
138
- handler : async ( { integrationIdParam, accountId, apiToken } : { integrationIdParam : string ; accountId : string ; apiToken : string } ) => {
161
+ handler : async ( {
162
+ integrationIdParam,
163
+ accountId,
164
+ apiToken,
165
+ } : {
166
+ integrationIdParam : string
167
+ accountId : string
168
+ apiToken : string
169
+ } ) => {
139
170
const { assets } = await handleAssetsByIntegrationId ( {
140
171
accountId,
141
172
apiToken,
@@ -149,7 +180,15 @@ const toolDefinitions: ToolDefinition<any>[] = [
149
180
name : 'assets_by_category_id' ,
150
181
description : 'Search Assets by Asset Category ID' ,
151
182
params : { assetCategoryIdParam } ,
152
- handler : async ( { assetCategoryIdParam, accountId, apiToken } : { assetCategoryIdParam : string ; accountId : string ; apiToken : string } ) => {
183
+ handler : async ( {
184
+ assetCategoryIdParam,
185
+ accountId,
186
+ apiToken,
187
+ } : {
188
+ assetCategoryIdParam : string
189
+ accountId : string
190
+ apiToken : string
191
+ } ) => {
153
192
const { assets } = await handleAssetsByAssetCategoryId ( {
154
193
accountId,
155
194
apiToken,
@@ -188,7 +227,15 @@ const toolDefinitions: ToolDefinition<any>[] = [
188
227
name : 'asset_categories_by_vendor' ,
189
228
description : 'List asset categories by vendor' ,
190
229
params : { assetCategoryVendorParam } ,
191
- handler : async ( { assetCategoryVendorParam, accountId, apiToken } : { assetCategoryVendorParam : string ; accountId : string ; apiToken : string } ) => {
230
+ handler : async ( {
231
+ assetCategoryVendorParam,
232
+ accountId,
233
+ apiToken,
234
+ } : {
235
+ assetCategoryVendorParam : string
236
+ accountId : string
237
+ apiToken : string
238
+ } ) => {
192
239
const { categories } = await handleAssetCategories ( {
193
240
accountId,
194
241
apiToken,
@@ -201,7 +248,15 @@ const toolDefinitions: ToolDefinition<any>[] = [
201
248
name : 'asset_categories_by_type' ,
202
249
description : 'Search Asset Categories by type' ,
203
250
params : { assetCategoryTypeParam } ,
204
- handler : async ( { assetCategoryTypeParam, accountId, apiToken } : { assetCategoryTypeParam ?: string ; accountId : string ; apiToken : string } ) => {
251
+ handler : async ( {
252
+ assetCategoryTypeParam,
253
+ accountId,
254
+ apiToken,
255
+ } : {
256
+ assetCategoryTypeParam ?: string
257
+ accountId : string
258
+ apiToken : string
259
+ } ) => {
205
260
const { categories } = await handleAssetCategories ( {
206
261
accountId,
207
262
apiToken,
@@ -214,7 +269,17 @@ const toolDefinitions: ToolDefinition<any>[] = [
214
269
name : 'asset_categories_by_vendor_and_type' ,
215
270
description : 'Search Asset Categories by vendor and type' ,
216
271
params : { assetCategoryTypeParam, assetCategoryVendorParam } ,
217
- handler : async ( { assetCategoryTypeParam, assetCategoryVendorParam, accountId, apiToken } : { assetCategoryTypeParam ?: string ; assetCategoryVendorParam : string ; accountId : string ; apiToken : string } ) => {
272
+ handler : async ( {
273
+ assetCategoryTypeParam,
274
+ assetCategoryVendorParam,
275
+ accountId,
276
+ apiToken,
277
+ } : {
278
+ assetCategoryTypeParam ?: string
279
+ assetCategoryVendorParam : string
280
+ accountId : string
281
+ apiToken : string
282
+ } ) => {
218
283
const { categories } = await handleAssetCategories ( {
219
284
accountId,
220
285
apiToken,
0 commit comments