@insforge/mcp 1.1.0 → 1.1.3-dev.2
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/dist/chunk-DR4IN3DB.js +1391 -0
- package/dist/http-server.js +191 -0
- package/dist/index.js +15 -1314
- package/package.json +6 -3
package/dist/index.js
CHANGED
|
@@ -1,1333 +1,34 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
registerInsforgeTools
|
|
4
|
+
} from "./chunk-DR4IN3DB.js";
|
|
2
5
|
|
|
3
|
-
// src/index.ts
|
|
6
|
+
// src/stdio/index.ts
|
|
4
7
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
5
8
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
-
import { z as z12 } from "zod";
|
|
7
|
-
import fetch2 from "node-fetch";
|
|
8
|
-
import FormData from "form-data";
|
|
9
9
|
import { program } from "commander";
|
|
10
|
-
import { promises as fs } from "fs";
|
|
11
|
-
|
|
12
|
-
// src/response-handler.ts
|
|
13
|
-
async function handleApiResponse(response) {
|
|
14
|
-
const responseData = await response.json();
|
|
15
|
-
if (!response.ok) {
|
|
16
|
-
const errorData = responseData;
|
|
17
|
-
let fullMessage = errorData.message || errorData.error || "Unknown error";
|
|
18
|
-
if (errorData.nextAction) {
|
|
19
|
-
fullMessage += `. ${errorData.nextAction}`;
|
|
20
|
-
}
|
|
21
|
-
throw new Error(fullMessage);
|
|
22
|
-
}
|
|
23
|
-
return responseData;
|
|
24
|
-
}
|
|
25
|
-
function formatSuccessMessage(operation, data) {
|
|
26
|
-
if (data && typeof data === "object" && "message" in data) {
|
|
27
|
-
return `${data.message}
|
|
28
|
-
${JSON.stringify(data, null, 2)}`;
|
|
29
|
-
}
|
|
30
|
-
return `${operation} completed successfully:
|
|
31
|
-
${JSON.stringify(data, null, 2)}`;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// src/usage-tracker.ts
|
|
35
|
-
import fetch from "node-fetch";
|
|
36
|
-
var UsageTracker = class {
|
|
37
|
-
apiBaseUrl;
|
|
38
|
-
apiKey;
|
|
39
|
-
constructor(apiBaseUrl, apiKey) {
|
|
40
|
-
this.apiBaseUrl = apiBaseUrl;
|
|
41
|
-
this.apiKey = apiKey;
|
|
42
|
-
}
|
|
43
|
-
async trackUsage(toolName, success = true) {
|
|
44
|
-
if (!this.apiKey) {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
try {
|
|
48
|
-
const payload = {
|
|
49
|
-
tool_name: toolName,
|
|
50
|
-
success,
|
|
51
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
52
|
-
};
|
|
53
|
-
await fetch(`${this.apiBaseUrl}/api/usage/mcp`, {
|
|
54
|
-
method: "POST",
|
|
55
|
-
headers: {
|
|
56
|
-
"Content-Type": "application/json",
|
|
57
|
-
"x-api-key": this.apiKey
|
|
58
|
-
},
|
|
59
|
-
body: JSON.stringify(payload)
|
|
60
|
-
});
|
|
61
|
-
} catch (error) {
|
|
62
|
-
console.error("Failed to track usage:", error);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// node_modules/@insforge/shared-schemas/dist/database.schema.js
|
|
68
|
-
import { z } from "zod";
|
|
69
|
-
var ColumnType;
|
|
70
|
-
(function(ColumnType2) {
|
|
71
|
-
ColumnType2["STRING"] = "string";
|
|
72
|
-
ColumnType2["DATE"] = "date";
|
|
73
|
-
ColumnType2["DATETIME"] = "datetime";
|
|
74
|
-
ColumnType2["INTEGER"] = "integer";
|
|
75
|
-
ColumnType2["FLOAT"] = "float";
|
|
76
|
-
ColumnType2["BOOLEAN"] = "boolean";
|
|
77
|
-
ColumnType2["UUID"] = "uuid";
|
|
78
|
-
ColumnType2["JSON"] = "json";
|
|
79
|
-
})(ColumnType || (ColumnType = {}));
|
|
80
|
-
var onUpdateActionSchema = z.enum(["CASCADE", "RESTRICT", "NO ACTION"]);
|
|
81
|
-
var onDeleteActionSchema = z.enum([
|
|
82
|
-
"CASCADE",
|
|
83
|
-
"SET NULL",
|
|
84
|
-
"SET DEFAULT",
|
|
85
|
-
"RESTRICT",
|
|
86
|
-
"NO ACTION"
|
|
87
|
-
]);
|
|
88
|
-
var columnTypeSchema = z.enum([
|
|
89
|
-
ColumnType.STRING,
|
|
90
|
-
ColumnType.DATE,
|
|
91
|
-
ColumnType.DATETIME,
|
|
92
|
-
ColumnType.INTEGER,
|
|
93
|
-
ColumnType.FLOAT,
|
|
94
|
-
ColumnType.BOOLEAN,
|
|
95
|
-
ColumnType.UUID,
|
|
96
|
-
ColumnType.JSON
|
|
97
|
-
]);
|
|
98
|
-
var foreignKeySchema = z.object({
|
|
99
|
-
referenceTable: z.string().min(1, "Target table cannot be empty"),
|
|
100
|
-
referenceColumn: z.string().min(1, "Target column cannot be empty"),
|
|
101
|
-
onDelete: onDeleteActionSchema,
|
|
102
|
-
onUpdate: onUpdateActionSchema
|
|
103
|
-
});
|
|
104
|
-
var columnSchema = z.object({
|
|
105
|
-
columnName: z.string().min(1, "Column name cannot be empty").max(64, "Column name must be less than 64 characters"),
|
|
106
|
-
type: z.union([columnTypeSchema, z.string()]),
|
|
107
|
-
defaultValue: z.string().optional(),
|
|
108
|
-
isPrimaryKey: z.boolean().optional(),
|
|
109
|
-
isNullable: z.boolean(),
|
|
110
|
-
isUnique: z.boolean(),
|
|
111
|
-
foreignKey: foreignKeySchema.optional()
|
|
112
|
-
});
|
|
113
|
-
var tableSchema = z.object({
|
|
114
|
-
tableName: z.string().min(1, "Table name cannot be empty").max(64, "Table name must be less than 64 characters"),
|
|
115
|
-
columns: z.array(columnSchema).min(1, "At least one column is required"),
|
|
116
|
-
recordCount: z.number().default(0),
|
|
117
|
-
createdAt: z.string().optional(),
|
|
118
|
-
updatedAt: z.string().optional()
|
|
119
|
-
});
|
|
120
|
-
|
|
121
|
-
// node_modules/@insforge/shared-schemas/dist/database-api.schema.js
|
|
122
|
-
import { z as z2 } from "zod";
|
|
123
|
-
var createTableRequestSchema = tableSchema.pick({
|
|
124
|
-
tableName: true,
|
|
125
|
-
columns: true
|
|
126
|
-
}).extend({
|
|
127
|
-
rlsEnabled: z2.boolean().default(true)
|
|
128
|
-
});
|
|
129
|
-
var createTableResponseSchema = tableSchema.pick({
|
|
130
|
-
tableName: true,
|
|
131
|
-
columns: true
|
|
132
|
-
}).extend({
|
|
133
|
-
message: z2.string(),
|
|
134
|
-
autoFields: z2.array(z2.string()),
|
|
135
|
-
nextActions: z2.string()
|
|
136
|
-
});
|
|
137
|
-
var updateTableSchemaRequestSchema = z2.object({
|
|
138
|
-
addColumns: z2.array(columnSchema.omit({
|
|
139
|
-
foreignKey: true
|
|
140
|
-
})).optional(),
|
|
141
|
-
dropColumns: z2.array(z2.string()).optional(),
|
|
142
|
-
updateColumns: z2.array(z2.object({
|
|
143
|
-
columnName: z2.string(),
|
|
144
|
-
defaultValue: z2.string().optional(),
|
|
145
|
-
newColumnName: z2.string().min(1, "New column name cannot be empty").max(64, "New column name must be less than 64 characters").optional()
|
|
146
|
-
})).optional(),
|
|
147
|
-
addForeignKeys: z2.array(z2.object({
|
|
148
|
-
columnName: z2.string().min(1, "Column name is required for adding foreign key"),
|
|
149
|
-
foreignKey: foreignKeySchema
|
|
150
|
-
})).optional(),
|
|
151
|
-
dropForeignKeys: z2.array(z2.string()).optional(),
|
|
152
|
-
renameTable: z2.object({
|
|
153
|
-
newTableName: z2.string().min(1, "New table name cannot be empty").max(64, "New table name must be less than 64 characters")
|
|
154
|
-
}).optional()
|
|
155
|
-
});
|
|
156
|
-
var updateTableSchemaResponse = z2.object({
|
|
157
|
-
message: z2.string(),
|
|
158
|
-
tableName: z2.string(),
|
|
159
|
-
operations: z2.array(z2.string())
|
|
160
|
-
});
|
|
161
|
-
var deleteTableResponse = z2.object({
|
|
162
|
-
message: z2.string(),
|
|
163
|
-
tableName: z2.string(),
|
|
164
|
-
nextActions: z2.string()
|
|
165
|
-
});
|
|
166
|
-
var rawSQLRequestSchema = z2.object({
|
|
167
|
-
query: z2.string().min(1, "Query is required"),
|
|
168
|
-
params: z2.array(z2.any()).optional()
|
|
169
|
-
});
|
|
170
|
-
var rawSQLResponseSchema = z2.object({
|
|
171
|
-
rows: z2.array(z2.any()),
|
|
172
|
-
rowCount: z2.number().nullable(),
|
|
173
|
-
fields: z2.array(z2.object({
|
|
174
|
-
name: z2.string(),
|
|
175
|
-
dataTypeID: z2.number()
|
|
176
|
-
})).optional()
|
|
177
|
-
});
|
|
178
|
-
var exportRequestSchema = z2.object({
|
|
179
|
-
tables: z2.array(z2.string()).optional(),
|
|
180
|
-
format: z2.enum(["sql", "json"]).default("sql"),
|
|
181
|
-
includeData: z2.boolean().default(true),
|
|
182
|
-
includeFunctions: z2.boolean().default(false),
|
|
183
|
-
includeSequences: z2.boolean().default(false),
|
|
184
|
-
includeViews: z2.boolean().default(false),
|
|
185
|
-
rowLimit: z2.number().int().positive().max(1e4).default(1e3)
|
|
186
|
-
});
|
|
187
|
-
var exportJsonDataSchema = z2.object({
|
|
188
|
-
timestamp: z2.string(),
|
|
189
|
-
tables: z2.record(z2.string(), z2.object({
|
|
190
|
-
schema: z2.array(z2.object({
|
|
191
|
-
columnName: z2.string(),
|
|
192
|
-
dataType: z2.string(),
|
|
193
|
-
characterMaximumLength: z2.number().nullable(),
|
|
194
|
-
isNullable: z2.string(),
|
|
195
|
-
columnDefault: z2.string().nullable()
|
|
196
|
-
})),
|
|
197
|
-
indexes: z2.array(z2.object({
|
|
198
|
-
indexname: z2.string(),
|
|
199
|
-
indexdef: z2.string(),
|
|
200
|
-
isUnique: z2.boolean().nullable(),
|
|
201
|
-
isPrimary: z2.boolean().nullable()
|
|
202
|
-
})),
|
|
203
|
-
foreignKeys: z2.array(z2.object({
|
|
204
|
-
constraintName: z2.string(),
|
|
205
|
-
columnName: z2.string(),
|
|
206
|
-
foreignTableName: z2.string(),
|
|
207
|
-
foreignColumnName: z2.string(),
|
|
208
|
-
deleteRule: z2.string().nullable(),
|
|
209
|
-
updateRule: z2.string().nullable()
|
|
210
|
-
})),
|
|
211
|
-
rlsEnabled: z2.boolean().optional(),
|
|
212
|
-
policies: z2.array(z2.object({
|
|
213
|
-
policyname: z2.string(),
|
|
214
|
-
cmd: z2.string(),
|
|
215
|
-
roles: z2.array(z2.string()),
|
|
216
|
-
qual: z2.string().nullable(),
|
|
217
|
-
withCheck: z2.string().nullable()
|
|
218
|
-
})),
|
|
219
|
-
triggers: z2.array(z2.object({
|
|
220
|
-
triggerName: z2.string(),
|
|
221
|
-
actionTiming: z2.string(),
|
|
222
|
-
eventManipulation: z2.string(),
|
|
223
|
-
actionOrientation: z2.string(),
|
|
224
|
-
actionCondition: z2.string().nullable(),
|
|
225
|
-
actionStatement: z2.string(),
|
|
226
|
-
newTable: z2.string().nullable(),
|
|
227
|
-
oldTable: z2.string().nullable()
|
|
228
|
-
})),
|
|
229
|
-
rows: z2.array(z2.any()).optional()
|
|
230
|
-
})),
|
|
231
|
-
functions: z2.array(z2.object({
|
|
232
|
-
functionName: z2.string(),
|
|
233
|
-
functionDef: z2.string(),
|
|
234
|
-
kind: z2.string()
|
|
235
|
-
})),
|
|
236
|
-
sequences: z2.array(z2.object({
|
|
237
|
-
sequenceName: z2.string(),
|
|
238
|
-
startValue: z2.string(),
|
|
239
|
-
increment: z2.string(),
|
|
240
|
-
minValue: z2.string().nullable(),
|
|
241
|
-
maxValue: z2.string().nullable(),
|
|
242
|
-
cycle: z2.string()
|
|
243
|
-
})),
|
|
244
|
-
views: z2.array(z2.object({
|
|
245
|
-
viewName: z2.string(),
|
|
246
|
-
definition: z2.string()
|
|
247
|
-
}))
|
|
248
|
-
});
|
|
249
|
-
var exportResponseSchema = z2.object({
|
|
250
|
-
format: z2.enum(["sql", "json"]),
|
|
251
|
-
data: z2.union([z2.string(), exportJsonDataSchema]),
|
|
252
|
-
timestamp: z2.string()
|
|
253
|
-
});
|
|
254
|
-
var importRequestSchema = z2.object({
|
|
255
|
-
truncate: z2.union([
|
|
256
|
-
z2.boolean(),
|
|
257
|
-
z2.string().transform((val) => {
|
|
258
|
-
if (val === "true")
|
|
259
|
-
return true;
|
|
260
|
-
if (val === "false")
|
|
261
|
-
return false;
|
|
262
|
-
throw new Error("Invalid boolean string");
|
|
263
|
-
})
|
|
264
|
-
]).default(false)
|
|
265
|
-
});
|
|
266
|
-
var importResponseSchema = z2.object({
|
|
267
|
-
success: z2.boolean(),
|
|
268
|
-
message: z2.string(),
|
|
269
|
-
filename: z2.string(),
|
|
270
|
-
tables: z2.array(z2.string()),
|
|
271
|
-
rowsImported: z2.number(),
|
|
272
|
-
fileSize: z2.number()
|
|
273
|
-
});
|
|
274
|
-
var bulkUpsertRequestSchema = z2.object({
|
|
275
|
-
table: z2.string().min(1, "Table name is required"),
|
|
276
|
-
upsertKey: z2.string().optional()
|
|
277
|
-
// Note: File handling is done at the API layer via multipart/form-data
|
|
278
|
-
});
|
|
279
|
-
var bulkUpsertResponseSchema = z2.object({
|
|
280
|
-
success: z2.boolean(),
|
|
281
|
-
message: z2.string(),
|
|
282
|
-
table: z2.string(),
|
|
283
|
-
rowsAffected: z2.number(),
|
|
284
|
-
totalRecords: z2.number(),
|
|
285
|
-
filename: z2.string()
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
// node_modules/@insforge/shared-schemas/dist/storage.schema.js
|
|
289
|
-
import { z as z3 } from "zod";
|
|
290
|
-
var storageFileSchema = z3.object({
|
|
291
|
-
key: z3.string(),
|
|
292
|
-
bucket: z3.string(),
|
|
293
|
-
size: z3.number(),
|
|
294
|
-
mimeType: z3.string().optional(),
|
|
295
|
-
uploadedAt: z3.string(),
|
|
296
|
-
url: z3.string()
|
|
297
|
-
});
|
|
298
|
-
var storageBucketSchema = z3.object({
|
|
299
|
-
name: z3.string(),
|
|
300
|
-
public: z3.boolean(),
|
|
301
|
-
createdAt: z3.string()
|
|
302
|
-
});
|
|
303
|
-
|
|
304
|
-
// node_modules/@insforge/shared-schemas/dist/storage-api.schema.js
|
|
305
|
-
import { z as z4 } from "zod";
|
|
306
|
-
var createBucketRequestSchema = z4.object({
|
|
307
|
-
bucketName: z4.string().min(1, "Bucket name cannot be empty"),
|
|
308
|
-
isPublic: z4.boolean().default(true)
|
|
309
|
-
});
|
|
310
|
-
var updateBucketRequestSchema = z4.object({
|
|
311
|
-
isPublic: z4.boolean()
|
|
312
|
-
});
|
|
313
|
-
var listObjectsResponseSchema = z4.object({
|
|
314
|
-
objects: z4.array(storageFileSchema),
|
|
315
|
-
pagination: z4.object({
|
|
316
|
-
offset: z4.number(),
|
|
317
|
-
limit: z4.number(),
|
|
318
|
-
total: z4.number()
|
|
319
|
-
})
|
|
320
|
-
});
|
|
321
|
-
var uploadStrategyRequestSchema = z4.object({
|
|
322
|
-
filename: z4.string().min(1, "Filename cannot be empty"),
|
|
323
|
-
contentType: z4.string().optional(),
|
|
324
|
-
size: z4.number().optional()
|
|
325
|
-
});
|
|
326
|
-
var uploadStrategyResponseSchema = z4.object({
|
|
327
|
-
method: z4.enum(["presigned", "direct"]),
|
|
328
|
-
uploadUrl: z4.string(),
|
|
329
|
-
fields: z4.record(z4.string()).optional(),
|
|
330
|
-
key: z4.string(),
|
|
331
|
-
confirmRequired: z4.boolean(),
|
|
332
|
-
confirmUrl: z4.string().optional(),
|
|
333
|
-
expiresAt: z4.date().optional()
|
|
334
|
-
});
|
|
335
|
-
var downloadStrategyRequestSchema = z4.object({
|
|
336
|
-
expiresIn: z4.number().optional().default(3600)
|
|
337
|
-
});
|
|
338
|
-
var downloadStrategyResponseSchema = z4.object({
|
|
339
|
-
method: z4.enum(["presigned", "direct"]),
|
|
340
|
-
url: z4.string(),
|
|
341
|
-
expiresAt: z4.date().optional(),
|
|
342
|
-
headers: z4.record(z4.string()).optional()
|
|
343
|
-
});
|
|
344
|
-
var confirmUploadRequestSchema = z4.object({
|
|
345
|
-
size: z4.number(),
|
|
346
|
-
contentType: z4.string().optional(),
|
|
347
|
-
etag: z4.string().optional()
|
|
348
|
-
});
|
|
349
|
-
|
|
350
|
-
// node_modules/@insforge/shared-schemas/dist/auth.schema.js
|
|
351
|
-
import { z as z5 } from "zod";
|
|
352
|
-
var userIdSchema = z5.string().uuid("Invalid user ID format");
|
|
353
|
-
var emailSchema = z5.string().email("Invalid email format").toLowerCase().trim();
|
|
354
|
-
var passwordSchema = z5.string().min(6, "Password must be at least 6 characters").max(32, "Password must be less than 32 characters");
|
|
355
|
-
var nameSchema = z5.string().min(1, "Name is required").max(100, "Name must be less than 100 characters").trim();
|
|
356
|
-
var roleSchema = z5.enum(["authenticated", "project_admin"]);
|
|
357
|
-
var userSchema = z5.object({
|
|
358
|
-
id: userIdSchema,
|
|
359
|
-
email: emailSchema,
|
|
360
|
-
name: nameSchema,
|
|
361
|
-
emailVerified: z5.boolean(),
|
|
362
|
-
identities: z5.array(z5.object({
|
|
363
|
-
provider: z5.string()
|
|
364
|
-
})).optional(),
|
|
365
|
-
providerType: z5.string().optional(),
|
|
366
|
-
createdAt: z5.string(),
|
|
367
|
-
// PostgreSQL timestamp
|
|
368
|
-
updatedAt: z5.string()
|
|
369
|
-
// PostgreSQL timestamp
|
|
370
|
-
});
|
|
371
|
-
var oAuthProvidersSchema = z5.enum(["google", "github"]);
|
|
372
|
-
var oAuthStateSchema = z5.object({
|
|
373
|
-
provider: oAuthProvidersSchema,
|
|
374
|
-
redirectUri: z5.string().url().optional()
|
|
375
|
-
});
|
|
376
|
-
var oAuthConfigSchema = z5.object({
|
|
377
|
-
provider: z5.string(),
|
|
378
|
-
clientId: z5.string().optional(),
|
|
379
|
-
scopes: z5.array(z5.string()).optional(),
|
|
380
|
-
redirectUri: z5.string().optional(),
|
|
381
|
-
useSharedKey: z5.boolean()
|
|
382
|
-
});
|
|
383
|
-
var tokenPayloadSchema = z5.object({
|
|
384
|
-
sub: userIdSchema,
|
|
385
|
-
// Subject (user ID)
|
|
386
|
-
email: emailSchema,
|
|
387
|
-
role: roleSchema,
|
|
388
|
-
iat: z5.number().optional(),
|
|
389
|
-
// Issued at
|
|
390
|
-
exp: z5.number().optional()
|
|
391
|
-
// Expiration
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
// node_modules/@insforge/shared-schemas/dist/auth-api.schema.js
|
|
395
|
-
import { z as z6 } from "zod";
|
|
396
|
-
var paginationSchema = z6.object({
|
|
397
|
-
limit: z6.string().optional(),
|
|
398
|
-
offset: z6.string().optional()
|
|
399
|
-
});
|
|
400
|
-
var createUserRequestSchema = z6.object({
|
|
401
|
-
email: emailSchema,
|
|
402
|
-
password: passwordSchema,
|
|
403
|
-
name: nameSchema.optional()
|
|
404
|
-
});
|
|
405
|
-
var createSessionRequestSchema = z6.object({
|
|
406
|
-
email: emailSchema,
|
|
407
|
-
password: passwordSchema
|
|
408
|
-
});
|
|
409
|
-
var exchangeAdminSessionRequestSchema = z6.object({
|
|
410
|
-
code: z6.string()
|
|
411
|
-
});
|
|
412
|
-
var listUsersRequestSchema = paginationSchema.extend({
|
|
413
|
-
search: z6.string().optional()
|
|
414
|
-
}).optional();
|
|
415
|
-
var deleteUsersRequestSchema = z6.object({
|
|
416
|
-
userIds: z6.array(userIdSchema).min(1, "At least one user ID is required")
|
|
417
|
-
});
|
|
418
|
-
var createUserResponseSchema = z6.object({
|
|
419
|
-
user: userSchema,
|
|
420
|
-
accessToken: z6.string()
|
|
421
|
-
});
|
|
422
|
-
var getCurrentSessionResponseSchema = z6.object({
|
|
423
|
-
user: z6.object({
|
|
424
|
-
id: userIdSchema,
|
|
425
|
-
email: emailSchema,
|
|
426
|
-
role: roleSchema
|
|
427
|
-
})
|
|
428
|
-
});
|
|
429
|
-
var listUsersResponseSchema = z6.object({
|
|
430
|
-
data: z6.array(userSchema),
|
|
431
|
-
pagination: z6.object({
|
|
432
|
-
offset: z6.number(),
|
|
433
|
-
limit: z6.number(),
|
|
434
|
-
total: z6.number()
|
|
435
|
-
})
|
|
436
|
-
});
|
|
437
|
-
var deleteUsersResponseSchema = z6.object({
|
|
438
|
-
message: z6.string(),
|
|
439
|
-
deletedCount: z6.number().int().nonnegative()
|
|
440
|
-
});
|
|
441
|
-
var getOauthUrlResponseSchema = z6.object({
|
|
442
|
-
authUrl: z6.string().url()
|
|
443
|
-
});
|
|
444
|
-
var createOAuthConfigRequestSchema = oAuthConfigSchema.extend({
|
|
445
|
-
clientSecret: z6.string().optional()
|
|
446
|
-
});
|
|
447
|
-
var updateOAuthConfigRequestSchema = oAuthConfigSchema.extend({
|
|
448
|
-
clientSecret: z6.string().optional()
|
|
449
|
-
}).omit({
|
|
450
|
-
provider: true
|
|
451
|
-
});
|
|
452
|
-
var listOAuthConfigsResponseSchema = z6.object({
|
|
453
|
-
data: z6.array(oAuthConfigSchema),
|
|
454
|
-
count: z6.number()
|
|
455
|
-
});
|
|
456
|
-
var authErrorResponseSchema = z6.object({
|
|
457
|
-
error: z6.string(),
|
|
458
|
-
message: z6.string(),
|
|
459
|
-
statusCode: z6.number().int(),
|
|
460
|
-
nextActions: z6.string().optional()
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
// node_modules/@insforge/shared-schemas/dist/metadata.schema.js
|
|
464
|
-
import { z as z7 } from "zod";
|
|
465
|
-
var authMetadataSchema = z7.object({
|
|
466
|
-
oauths: z7.array(oAuthConfigSchema)
|
|
467
|
-
});
|
|
468
|
-
var databaseMetadataSchema = z7.object({
|
|
469
|
-
tables: z7.array(tableSchema),
|
|
470
|
-
totalSize: z7.number()
|
|
471
|
-
});
|
|
472
|
-
var bucketMetadataSchema = storageBucketSchema.extend({
|
|
473
|
-
objectCount: z7.number().optional()
|
|
474
|
-
});
|
|
475
|
-
var storageMetadataSchema = z7.object({
|
|
476
|
-
buckets: z7.array(bucketMetadataSchema),
|
|
477
|
-
totalSize: z7.number()
|
|
478
|
-
});
|
|
479
|
-
var edgeFunctionMetadataSchema = z7.object({
|
|
480
|
-
slug: z7.string(),
|
|
481
|
-
name: z7.string(),
|
|
482
|
-
description: z7.string().nullable(),
|
|
483
|
-
status: z7.string()
|
|
484
|
-
});
|
|
485
|
-
var aiMetadataSchema = z7.object({
|
|
486
|
-
models: z7.array(z7.object({
|
|
487
|
-
inputModality: z7.array(z7.string()),
|
|
488
|
-
outputModality: z7.array(z7.string()),
|
|
489
|
-
modelId: z7.string()
|
|
490
|
-
}))
|
|
491
|
-
});
|
|
492
|
-
var appMetaDataSchema = z7.object({
|
|
493
|
-
auth: authMetadataSchema,
|
|
494
|
-
database: databaseMetadataSchema,
|
|
495
|
-
storage: storageMetadataSchema,
|
|
496
|
-
aiIntegration: aiMetadataSchema.optional(),
|
|
497
|
-
functions: z7.array(edgeFunctionMetadataSchema),
|
|
498
|
-
version: z7.string().optional()
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
// node_modules/@insforge/shared-schemas/dist/ai.schema.js
|
|
502
|
-
import { z as z8 } from "zod";
|
|
503
|
-
var modalitySchema = z8.enum(["text", "image"]);
|
|
504
|
-
var aiConfigurationSchema = z8.object({
|
|
505
|
-
id: z8.string().uuid(),
|
|
506
|
-
inputModality: z8.array(modalitySchema).min(1),
|
|
507
|
-
outputModality: z8.array(modalitySchema).min(1),
|
|
508
|
-
provider: z8.string(),
|
|
509
|
-
modelId: z8.string(),
|
|
510
|
-
systemPrompt: z8.string().optional()
|
|
511
|
-
});
|
|
512
|
-
var aiConfigurationWithUsageSchema = aiConfigurationSchema.extend({
|
|
513
|
-
usageStats: z8.object({
|
|
514
|
-
totalInputTokens: z8.number(),
|
|
515
|
-
totalOutputTokens: z8.number(),
|
|
516
|
-
totalTokens: z8.number(),
|
|
517
|
-
totalImageCount: z8.number(),
|
|
518
|
-
totalRequests: z8.number()
|
|
519
|
-
}).optional()
|
|
520
|
-
});
|
|
521
|
-
var aiUsageDataSchema = z8.object({
|
|
522
|
-
configId: z8.string().uuid(),
|
|
523
|
-
inputTokens: z8.number().int().optional(),
|
|
524
|
-
outputTokens: z8.number().int().optional(),
|
|
525
|
-
imageCount: z8.number().int().optional(),
|
|
526
|
-
imageResolution: z8.string().optional()
|
|
527
|
-
});
|
|
528
|
-
var aiUsageRecordSchema = aiUsageDataSchema.extend({
|
|
529
|
-
id: z8.string().uuid(),
|
|
530
|
-
createdAt: z8.date()
|
|
531
|
-
});
|
|
532
|
-
var aiUsageSummarySchema = z8.object({
|
|
533
|
-
totalInputTokens: z8.number(),
|
|
534
|
-
totalOutputTokens: z8.number(),
|
|
535
|
-
totalTokens: z8.number(),
|
|
536
|
-
totalImageCount: z8.number(),
|
|
537
|
-
totalRequests: z8.number()
|
|
538
|
-
});
|
|
539
|
-
|
|
540
|
-
// node_modules/@insforge/shared-schemas/dist/ai-api.schema.js
|
|
541
|
-
import { z as z9 } from "zod";
|
|
542
|
-
var chatMessageSchema = z9.object({
|
|
543
|
-
role: z9.enum(["user", "assistant", "system"]),
|
|
544
|
-
content: z9.string(),
|
|
545
|
-
images: z9.array(z9.object({
|
|
546
|
-
url: z9.string()
|
|
547
|
-
})).optional()
|
|
548
|
-
});
|
|
549
|
-
var chatCompletionRequestSchema = z9.object({
|
|
550
|
-
model: z9.string(),
|
|
551
|
-
messages: z9.array(chatMessageSchema),
|
|
552
|
-
temperature: z9.number().min(0).max(2).optional(),
|
|
553
|
-
maxTokens: z9.number().positive().optional(),
|
|
554
|
-
topP: z9.number().min(0).max(1).optional(),
|
|
555
|
-
stream: z9.boolean().optional()
|
|
556
|
-
});
|
|
557
|
-
var chatCompletionResponseSchema = z9.object({
|
|
558
|
-
text: z9.string(),
|
|
559
|
-
metadata: z9.object({
|
|
560
|
-
model: z9.string(),
|
|
561
|
-
usage: z9.object({
|
|
562
|
-
promptTokens: z9.number().optional(),
|
|
563
|
-
completionTokens: z9.number().optional(),
|
|
564
|
-
totalTokens: z9.number().optional()
|
|
565
|
-
}).optional()
|
|
566
|
-
}).optional()
|
|
567
|
-
});
|
|
568
|
-
var imageGenerationRequestSchema = z9.object({
|
|
569
|
-
model: z9.string(),
|
|
570
|
-
prompt: z9.string(),
|
|
571
|
-
images: z9.array(z9.object({
|
|
572
|
-
url: z9.string()
|
|
573
|
-
})).optional()
|
|
574
|
-
});
|
|
575
|
-
var imageGenerationResponseSchema = z9.object({
|
|
576
|
-
text: z9.string().optional(),
|
|
577
|
-
images: z9.array(z9.object({
|
|
578
|
-
type: z9.literal("imageUrl"),
|
|
579
|
-
imageUrl: z9.string()
|
|
580
|
-
})),
|
|
581
|
-
metadata: z9.object({
|
|
582
|
-
model: z9.string(),
|
|
583
|
-
usage: z9.object({
|
|
584
|
-
promptTokens: z9.number().optional(),
|
|
585
|
-
completionTokens: z9.number().optional(),
|
|
586
|
-
totalTokens: z9.number().optional()
|
|
587
|
-
}).optional()
|
|
588
|
-
}).optional()
|
|
589
|
-
});
|
|
590
|
-
var openRouterModelSchema = z9.object({
|
|
591
|
-
id: z9.string(),
|
|
592
|
-
name: z9.string(),
|
|
593
|
-
created: z9.number(),
|
|
594
|
-
description: z9.string().optional(),
|
|
595
|
-
architecture: z9.object({
|
|
596
|
-
inputModalities: z9.array(z9.string()),
|
|
597
|
-
outputModalities: z9.array(z9.string()),
|
|
598
|
-
tokenizer: z9.string(),
|
|
599
|
-
instructType: z9.string()
|
|
600
|
-
}).optional(),
|
|
601
|
-
topProvider: z9.object({
|
|
602
|
-
isModerated: z9.boolean(),
|
|
603
|
-
contextLength: z9.number(),
|
|
604
|
-
maxCompletionTokens: z9.number()
|
|
605
|
-
}).optional(),
|
|
606
|
-
pricing: z9.object({
|
|
607
|
-
prompt: z9.string(),
|
|
608
|
-
completion: z9.string(),
|
|
609
|
-
image: z9.string().optional(),
|
|
610
|
-
request: z9.string().optional(),
|
|
611
|
-
webSearch: z9.string().optional(),
|
|
612
|
-
internalReasoning: z9.string().optional(),
|
|
613
|
-
inputCacheRead: z9.string().optional(),
|
|
614
|
-
inputCacheWrite: z9.string().optional()
|
|
615
|
-
})
|
|
616
|
-
});
|
|
617
|
-
var listModelsResponseSchema = z9.object({
|
|
618
|
-
text: z9.array(z9.object({
|
|
619
|
-
provider: z9.string(),
|
|
620
|
-
configured: z9.boolean(),
|
|
621
|
-
models: z9.array(openRouterModelSchema)
|
|
622
|
-
})),
|
|
623
|
-
image: z9.array(z9.object({
|
|
624
|
-
provider: z9.string(),
|
|
625
|
-
configured: z9.boolean(),
|
|
626
|
-
models: z9.array(openRouterModelSchema)
|
|
627
|
-
}))
|
|
628
|
-
});
|
|
629
|
-
var createAIConfigurationRequestSchema = aiConfigurationSchema.omit({
|
|
630
|
-
id: true
|
|
631
|
-
});
|
|
632
|
-
var updateAIConfigurationRequestSchema = z9.object({
|
|
633
|
-
systemPrompt: z9.string().nullable()
|
|
634
|
-
});
|
|
635
|
-
var listAIUsageResponseSchema = z9.object({
|
|
636
|
-
records: z9.array(aiUsageRecordSchema),
|
|
637
|
-
total: z9.number()
|
|
638
|
-
});
|
|
639
|
-
var getAIUsageRequestSchema = z9.object({
|
|
640
|
-
startDate: z9.string().datetime().optional(),
|
|
641
|
-
endDate: z9.string().datetime().optional(),
|
|
642
|
-
limit: z9.string().regex(/^\d+$/).default("50"),
|
|
643
|
-
offset: z9.string().regex(/^\d+$/).default("0")
|
|
644
|
-
});
|
|
645
|
-
var getAIUsageSummaryRequestSchema = z9.object({
|
|
646
|
-
configId: z9.string().uuid().optional(),
|
|
647
|
-
startDate: z9.string().datetime().optional(),
|
|
648
|
-
endDate: z9.string().datetime().optional()
|
|
649
|
-
});
|
|
650
|
-
|
|
651
|
-
// node_modules/@insforge/shared-schemas/dist/logs.schema.js
|
|
652
|
-
import { z as z10 } from "zod";
|
|
653
|
-
var auditLogSchema = z10.object({
|
|
654
|
-
id: z10.string(),
|
|
655
|
-
actor: z10.string(),
|
|
656
|
-
action: z10.string(),
|
|
657
|
-
module: z10.string(),
|
|
658
|
-
details: z10.record(z10.unknown()).nullable(),
|
|
659
|
-
ipAddress: z10.string().nullable(),
|
|
660
|
-
createdAt: z10.string(),
|
|
661
|
-
updatedAt: z10.string()
|
|
662
|
-
});
|
|
663
|
-
|
|
664
|
-
// node_modules/@insforge/shared-schemas/dist/logs-api.schema.js
|
|
665
|
-
import { z as z11 } from "zod";
|
|
666
|
-
var getAuditLogsRequestSchema = z11.object({
|
|
667
|
-
limit: z11.number().default(100),
|
|
668
|
-
offset: z11.number().default(0),
|
|
669
|
-
actor: z11.string().optional(),
|
|
670
|
-
action: z11.string().optional(),
|
|
671
|
-
module: z11.string().optional(),
|
|
672
|
-
startDate: z11.string().optional(),
|
|
673
|
-
endDate: z11.string().optional()
|
|
674
|
-
});
|
|
675
|
-
var getAuditLogsResponseSchema = z11.object({
|
|
676
|
-
data: z11.array(auditLogSchema),
|
|
677
|
-
pagination: z11.object({
|
|
678
|
-
limit: z11.number(),
|
|
679
|
-
offset: z11.number(),
|
|
680
|
-
total: z11.number()
|
|
681
|
-
})
|
|
682
|
-
});
|
|
683
|
-
var getAuditLogStatsRequestSchema = z11.object({
|
|
684
|
-
days: z11.number().default(7)
|
|
685
|
-
});
|
|
686
|
-
var getAuditLogStatsResponseSchema = z11.object({
|
|
687
|
-
totalLogs: z11.number(),
|
|
688
|
-
uniqueActors: z11.number(),
|
|
689
|
-
uniqueModules: z11.number(),
|
|
690
|
-
actionsByModule: z11.record(z11.number()),
|
|
691
|
-
recentActivity: z11.array(auditLogSchema)
|
|
692
|
-
});
|
|
693
|
-
var clearAuditLogsRequestSchema = z11.object({
|
|
694
|
-
daysToKeep: z11.number().default(90)
|
|
695
|
-
});
|
|
696
|
-
var clearAuditLogsResponseSchema = z11.object({
|
|
697
|
-
message: z11.string(),
|
|
698
|
-
deleted: z11.number()
|
|
699
|
-
});
|
|
700
|
-
|
|
701
|
-
// src/index.ts
|
|
702
10
|
program.option("--api_key <value>", "API Key");
|
|
703
11
|
program.parse(process.argv);
|
|
704
12
|
var options = program.opts();
|
|
705
13
|
var { api_key } = options;
|
|
706
|
-
var GLOBAL_API_KEY = api_key || process.env.API_KEY || "";
|
|
707
14
|
var server = new McpServer({
|
|
708
15
|
name: "insforge-mcp",
|
|
709
16
|
version: "1.0.0"
|
|
710
17
|
});
|
|
711
|
-
var
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
await usageTracker.trackUsage(toolName, success);
|
|
716
|
-
}
|
|
717
|
-
}
|
|
718
|
-
function withUsageTracking(toolName, handler) {
|
|
719
|
-
return async (...args) => {
|
|
720
|
-
try {
|
|
721
|
-
const result = await handler(...args);
|
|
722
|
-
await trackToolUsage(toolName, true);
|
|
723
|
-
return result;
|
|
724
|
-
} catch (error) {
|
|
725
|
-
await trackToolUsage(toolName, false);
|
|
726
|
-
throw error;
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
var getApiKey = (toolApiKey) => {
|
|
731
|
-
if (GLOBAL_API_KEY) {
|
|
732
|
-
return GLOBAL_API_KEY;
|
|
733
|
-
}
|
|
734
|
-
if (toolApiKey) {
|
|
735
|
-
return toolApiKey;
|
|
736
|
-
}
|
|
737
|
-
throw new Error(
|
|
738
|
-
"API key is required. Either pass --api_key as command line argument or provide api_key in tool calls."
|
|
739
|
-
);
|
|
740
|
-
};
|
|
741
|
-
var fetchDocumentation = async (docType) => {
|
|
742
|
-
try {
|
|
743
|
-
const response = await fetch2(`${API_BASE_URL}/api/docs/${docType}`, {
|
|
744
|
-
method: "GET",
|
|
745
|
-
headers: {
|
|
746
|
-
"Content-Type": "application/json"
|
|
747
|
-
}
|
|
748
|
-
});
|
|
749
|
-
const result = await handleApiResponse(response);
|
|
750
|
-
if (result && typeof result === "object" && "content" in result) {
|
|
751
|
-
let content = result.content;
|
|
752
|
-
content = content.replace(/http:\/\/localhost:7130/g, API_BASE_URL);
|
|
753
|
-
return content;
|
|
754
|
-
}
|
|
755
|
-
throw new Error("Invalid response format from documentation endpoint");
|
|
756
|
-
} catch (error) {
|
|
757
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
758
|
-
throw new Error(`Unable to retrieve ${docType} documentation: ${errMsg}`);
|
|
759
|
-
}
|
|
760
|
-
};
|
|
761
|
-
var fetchInsforgeInstructionsContext = async () => {
|
|
762
|
-
try {
|
|
763
|
-
return await fetchDocumentation("instructions");
|
|
764
|
-
} catch (error) {
|
|
765
|
-
console.error("Failed to fetch insforge-instructions.md:", error);
|
|
766
|
-
return null;
|
|
767
|
-
}
|
|
768
|
-
};
|
|
769
|
-
var addBackgroundContext = async (response) => {
|
|
770
|
-
const context = await fetchInsforgeInstructionsContext();
|
|
771
|
-
if (context && response.content && Array.isArray(response.content)) {
|
|
772
|
-
response.content.push({
|
|
773
|
-
type: "text",
|
|
774
|
-
text: `
|
|
775
|
-
|
|
776
|
-
---
|
|
777
|
-
\u{1F527} INSFORGE DEVELOPMENT RULES (Auto-loaded):
|
|
778
|
-
${context}`
|
|
779
|
-
});
|
|
780
|
-
}
|
|
781
|
-
return response;
|
|
782
|
-
};
|
|
783
|
-
server.tool(
|
|
784
|
-
"get-instructions",
|
|
785
|
-
"Instruction Essential backend setup tool. <critical>MANDATORY: You MUST use this tool FIRST before attempting any backend operations. Contains required API endpoints, authentication details, and setup instructions.</critical>",
|
|
786
|
-
{},
|
|
787
|
-
withUsageTracking("get-instructions", async () => {
|
|
788
|
-
try {
|
|
789
|
-
const content = await fetchDocumentation("instructions");
|
|
790
|
-
const response = {
|
|
791
|
-
content: [
|
|
792
|
-
{
|
|
793
|
-
type: "text",
|
|
794
|
-
text: content
|
|
795
|
-
}
|
|
796
|
-
]
|
|
797
|
-
};
|
|
798
|
-
return await addBackgroundContext(response);
|
|
799
|
-
} catch (error) {
|
|
800
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
801
|
-
const errorResponse = {
|
|
802
|
-
content: [{ type: "text", text: `Error: ${errMsg}` }]
|
|
803
|
-
};
|
|
804
|
-
return await addBackgroundContext(errorResponse);
|
|
805
|
-
}
|
|
806
|
-
})
|
|
807
|
-
);
|
|
808
|
-
server.tool(
|
|
809
|
-
"get-api-key",
|
|
810
|
-
"Retrieves the API key for the Insforge OSS backend. This is used to authenticate all requests to the backend.",
|
|
811
|
-
{},
|
|
812
|
-
async () => {
|
|
813
|
-
try {
|
|
814
|
-
return await addBackgroundContext({
|
|
815
|
-
content: [{ type: "text", text: `API key: ${getApiKey()}` }]
|
|
816
|
-
});
|
|
817
|
-
} catch (error) {
|
|
818
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
819
|
-
return await addBackgroundContext({
|
|
820
|
-
content: [{ type: "text", text: `Error: ${errMsg}` }]
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
);
|
|
825
|
-
server.tool(
|
|
826
|
-
"get-table-schema",
|
|
827
|
-
"Returns the schema of a specific table",
|
|
828
|
-
{
|
|
829
|
-
apiKey: z12.string().optional().describe("API key for authentication (optional if provided via --api_key)"),
|
|
830
|
-
tableName: z12.string().describe("Name of the table")
|
|
831
|
-
},
|
|
832
|
-
withUsageTracking("get-table-schema", async ({ apiKey, tableName }) => {
|
|
833
|
-
try {
|
|
834
|
-
const actualApiKey = getApiKey(apiKey);
|
|
835
|
-
const response = await fetch2(`${API_BASE_URL}/api/metadata/${tableName}`, {
|
|
836
|
-
method: "GET",
|
|
837
|
-
headers: {
|
|
838
|
-
"x-api-key": actualApiKey
|
|
839
|
-
}
|
|
840
|
-
});
|
|
841
|
-
const result = await handleApiResponse(response);
|
|
842
|
-
return await addBackgroundContext({
|
|
843
|
-
content: [
|
|
844
|
-
{
|
|
845
|
-
type: "text",
|
|
846
|
-
text: formatSuccessMessage("Schema retrieved", result)
|
|
847
|
-
}
|
|
848
|
-
]
|
|
849
|
-
});
|
|
850
|
-
} catch (error) {
|
|
851
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
852
|
-
return await addBackgroundContext({
|
|
853
|
-
content: [
|
|
854
|
-
{
|
|
855
|
-
type: "text",
|
|
856
|
-
text: `Error getting table schema: ${errMsg}`
|
|
857
|
-
}
|
|
858
|
-
],
|
|
859
|
-
isError: true
|
|
860
|
-
});
|
|
861
|
-
}
|
|
862
|
-
})
|
|
863
|
-
);
|
|
864
|
-
server.tool(
|
|
865
|
-
"get-backend-metadata",
|
|
866
|
-
"Index all backend metadata",
|
|
867
|
-
{
|
|
868
|
-
apiKey: z12.string().optional().describe("API key for authentication (optional if provided via --api_key)")
|
|
869
|
-
},
|
|
870
|
-
withUsageTracking("get-backend-metadata", async ({ apiKey }) => {
|
|
871
|
-
try {
|
|
872
|
-
const actualApiKey = getApiKey(apiKey);
|
|
873
|
-
const response = await fetch2(`${API_BASE_URL}/api/metadata?mcp=true`, {
|
|
874
|
-
method: "GET",
|
|
875
|
-
headers: {
|
|
876
|
-
"x-api-key": actualApiKey
|
|
877
|
-
}
|
|
878
|
-
});
|
|
879
|
-
const metadata = await handleApiResponse(response);
|
|
880
|
-
return await addBackgroundContext({
|
|
881
|
-
content: [
|
|
882
|
-
{
|
|
883
|
-
type: "text",
|
|
884
|
-
text: `Backend metadata:
|
|
885
|
-
|
|
886
|
-
${JSON.stringify(metadata, null, 2)}`
|
|
887
|
-
}
|
|
888
|
-
]
|
|
889
|
-
});
|
|
890
|
-
} catch (error) {
|
|
891
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
892
|
-
return await addBackgroundContext({
|
|
893
|
-
content: [
|
|
894
|
-
{
|
|
895
|
-
type: "text",
|
|
896
|
-
text: `Error retrieving backend metadata: ${errMsg}`
|
|
897
|
-
}
|
|
898
|
-
],
|
|
899
|
-
isError: true
|
|
900
|
-
});
|
|
901
|
-
}
|
|
902
|
-
})
|
|
903
|
-
);
|
|
904
|
-
server.tool(
|
|
905
|
-
"run-raw-sql",
|
|
906
|
-
"Execute raw SQL query with optional parameters. Admin access required. Use with caution as it can modify data directly.",
|
|
907
|
-
{
|
|
908
|
-
apiKey: z12.string().optional().describe("API key for authentication (optional if provided via --api_key)"),
|
|
909
|
-
...rawSQLRequestSchema.shape
|
|
910
|
-
},
|
|
911
|
-
withUsageTracking("run-raw-sql", async ({ apiKey, query, params }) => {
|
|
912
|
-
try {
|
|
913
|
-
const actualApiKey = getApiKey(apiKey);
|
|
914
|
-
const requestBody = {
|
|
915
|
-
query,
|
|
916
|
-
params: params || []
|
|
917
|
-
};
|
|
918
|
-
const response = await fetch2(`${API_BASE_URL}/api/database/advance/rawsql`, {
|
|
919
|
-
method: "POST",
|
|
920
|
-
headers: {
|
|
921
|
-
"x-api-key": actualApiKey,
|
|
922
|
-
"Content-Type": "application/json"
|
|
923
|
-
},
|
|
924
|
-
body: JSON.stringify(requestBody)
|
|
925
|
-
});
|
|
926
|
-
const result = await handleApiResponse(response);
|
|
927
|
-
return await addBackgroundContext({
|
|
928
|
-
content: [
|
|
929
|
-
{
|
|
930
|
-
type: "text",
|
|
931
|
-
text: formatSuccessMessage("SQL query executed", result)
|
|
932
|
-
}
|
|
933
|
-
]
|
|
934
|
-
});
|
|
935
|
-
} catch (error) {
|
|
936
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
937
|
-
return await addBackgroundContext({
|
|
938
|
-
content: [
|
|
939
|
-
{
|
|
940
|
-
type: "text",
|
|
941
|
-
text: `Error executing SQL query: ${errMsg}`
|
|
942
|
-
}
|
|
943
|
-
],
|
|
944
|
-
isError: true
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
})
|
|
948
|
-
);
|
|
949
|
-
server.tool(
|
|
950
|
-
"bulk-upsert",
|
|
951
|
-
"Bulk insert or update data from CSV or JSON file. Supports upsert operations with a unique key.",
|
|
952
|
-
{
|
|
953
|
-
apiKey: z12.string().optional().describe("API key for authentication (optional if provided via --api_key)"),
|
|
954
|
-
...bulkUpsertRequestSchema.shape,
|
|
955
|
-
filePath: z12.string().describe("Path to CSV or JSON file containing data to import")
|
|
956
|
-
},
|
|
957
|
-
withUsageTracking("bulk-upsert", async ({ apiKey, table, filePath, upsertKey }) => {
|
|
958
|
-
try {
|
|
959
|
-
const actualApiKey = getApiKey(apiKey);
|
|
960
|
-
const fileBuffer = await fs.readFile(filePath);
|
|
961
|
-
const fileName = filePath.split("/").pop() || "data.csv";
|
|
962
|
-
const formData = new FormData();
|
|
963
|
-
formData.append("file", fileBuffer, fileName);
|
|
964
|
-
formData.append("table", table);
|
|
965
|
-
if (upsertKey) {
|
|
966
|
-
formData.append("upsertKey", upsertKey);
|
|
967
|
-
}
|
|
968
|
-
const response = await fetch2(`${API_BASE_URL}/api/database/advance/bulk-upsert`, {
|
|
969
|
-
method: "POST",
|
|
970
|
-
headers: {
|
|
971
|
-
"x-api-key": actualApiKey,
|
|
972
|
-
...formData.getHeaders()
|
|
973
|
-
},
|
|
974
|
-
body: formData
|
|
975
|
-
});
|
|
976
|
-
const result = await handleApiResponse(response);
|
|
977
|
-
const message = result.success ? `Successfully processed ${result.rowsAffected} of ${result.totalRecords} records into table "${result.table}"` : result.message || "Bulk upsert operation completed";
|
|
978
|
-
return await addBackgroundContext({
|
|
979
|
-
content: [
|
|
980
|
-
{
|
|
981
|
-
type: "text",
|
|
982
|
-
text: formatSuccessMessage("Bulk upsert completed", {
|
|
983
|
-
message,
|
|
984
|
-
table: result.table,
|
|
985
|
-
rowsAffected: result.rowsAffected,
|
|
986
|
-
totalRecords: result.totalRecords,
|
|
987
|
-
errors: result.errors
|
|
988
|
-
})
|
|
989
|
-
}
|
|
990
|
-
]
|
|
991
|
-
});
|
|
992
|
-
} catch (error) {
|
|
993
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
994
|
-
return await addBackgroundContext({
|
|
995
|
-
content: [
|
|
996
|
-
{
|
|
997
|
-
type: "text",
|
|
998
|
-
text: `Error performing bulk upsert: ${errMsg}`
|
|
999
|
-
}
|
|
1000
|
-
],
|
|
1001
|
-
isError: true
|
|
1002
|
-
});
|
|
1003
|
-
}
|
|
1004
|
-
})
|
|
1005
|
-
);
|
|
1006
|
-
server.tool(
|
|
1007
|
-
"create-bucket",
|
|
1008
|
-
"Create new storage bucket",
|
|
1009
|
-
{
|
|
1010
|
-
apiKey: z12.string().optional().describe("API key for authentication (optional if provided via --api_key)"),
|
|
1011
|
-
...createBucketRequestSchema.shape
|
|
1012
|
-
},
|
|
1013
|
-
withUsageTracking("create-bucket", async ({ apiKey, bucketName, isPublic }) => {
|
|
1014
|
-
try {
|
|
1015
|
-
const actualApiKey = getApiKey(apiKey);
|
|
1016
|
-
const response = await fetch2(`${API_BASE_URL}/api/storage/buckets`, {
|
|
1017
|
-
method: "POST",
|
|
1018
|
-
headers: {
|
|
1019
|
-
"x-api-key": actualApiKey,
|
|
1020
|
-
"Content-Type": "application/json"
|
|
1021
|
-
},
|
|
1022
|
-
body: JSON.stringify({ bucketName, isPublic })
|
|
1023
|
-
});
|
|
1024
|
-
const result = await handleApiResponse(response);
|
|
1025
|
-
return await addBackgroundContext({
|
|
1026
|
-
content: [
|
|
1027
|
-
{
|
|
1028
|
-
type: "text",
|
|
1029
|
-
text: formatSuccessMessage("Bucket created", result)
|
|
1030
|
-
}
|
|
1031
|
-
]
|
|
1032
|
-
});
|
|
1033
|
-
} catch (error) {
|
|
1034
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1035
|
-
return await addBackgroundContext({
|
|
1036
|
-
content: [
|
|
1037
|
-
{
|
|
1038
|
-
type: "text",
|
|
1039
|
-
text: `Error creating bucket: ${errMsg}`
|
|
1040
|
-
}
|
|
1041
|
-
],
|
|
1042
|
-
isError: true
|
|
1043
|
-
});
|
|
1044
|
-
}
|
|
1045
|
-
})
|
|
1046
|
-
);
|
|
1047
|
-
server.tool(
|
|
1048
|
-
"list-buckets",
|
|
1049
|
-
"Lists all storage buckets",
|
|
1050
|
-
{},
|
|
1051
|
-
withUsageTracking("list-buckets", async () => {
|
|
1052
|
-
try {
|
|
1053
|
-
const response = await fetch2(`${API_BASE_URL}/api/storage/buckets`, {
|
|
1054
|
-
method: "GET",
|
|
1055
|
-
headers: {
|
|
1056
|
-
"x-api-key": getApiKey()
|
|
1057
|
-
// Still need API key for protected endpoint
|
|
1058
|
-
}
|
|
1059
|
-
});
|
|
1060
|
-
const result = await handleApiResponse(response);
|
|
1061
|
-
return await addBackgroundContext({
|
|
1062
|
-
content: [
|
|
1063
|
-
{
|
|
1064
|
-
type: "text",
|
|
1065
|
-
text: formatSuccessMessage("Buckets retrieved", result)
|
|
1066
|
-
}
|
|
1067
|
-
]
|
|
1068
|
-
});
|
|
1069
|
-
} catch (error) {
|
|
1070
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1071
|
-
return await addBackgroundContext({
|
|
1072
|
-
content: [
|
|
1073
|
-
{
|
|
1074
|
-
type: "text",
|
|
1075
|
-
text: `Error listing buckets: ${errMsg}`
|
|
1076
|
-
}
|
|
1077
|
-
],
|
|
1078
|
-
isError: true
|
|
1079
|
-
});
|
|
1080
|
-
}
|
|
1081
|
-
})
|
|
1082
|
-
);
|
|
1083
|
-
server.tool(
|
|
1084
|
-
"delete-bucket",
|
|
1085
|
-
"Deletes a storage bucket",
|
|
1086
|
-
{
|
|
1087
|
-
apiKey: z12.string().optional().describe("API key for authentication (optional if provided via --api_key)"),
|
|
1088
|
-
bucketName: z12.string().describe("Name of the bucket to delete")
|
|
1089
|
-
},
|
|
1090
|
-
withUsageTracking("delete-bucket", async ({ apiKey, bucketName }) => {
|
|
1091
|
-
try {
|
|
1092
|
-
const actualApiKey = getApiKey(apiKey);
|
|
1093
|
-
const response = await fetch2(`${API_BASE_URL}/api/storage/buckets/${bucketName}`, {
|
|
1094
|
-
method: "DELETE",
|
|
1095
|
-
headers: {
|
|
1096
|
-
"x-api-key": actualApiKey
|
|
1097
|
-
}
|
|
1098
|
-
});
|
|
1099
|
-
const result = await handleApiResponse(response);
|
|
1100
|
-
return await addBackgroundContext({
|
|
1101
|
-
content: [
|
|
1102
|
-
{
|
|
1103
|
-
type: "text",
|
|
1104
|
-
text: formatSuccessMessage("Bucket deleted", result)
|
|
1105
|
-
}
|
|
1106
|
-
]
|
|
1107
|
-
});
|
|
1108
|
-
} catch (error) {
|
|
1109
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1110
|
-
return await addBackgroundContext({
|
|
1111
|
-
content: [
|
|
1112
|
-
{
|
|
1113
|
-
type: "text",
|
|
1114
|
-
text: `Error deleting bucket: ${errMsg}`
|
|
1115
|
-
}
|
|
1116
|
-
],
|
|
1117
|
-
isError: true
|
|
1118
|
-
});
|
|
1119
|
-
}
|
|
1120
|
-
})
|
|
1121
|
-
);
|
|
1122
|
-
server.tool(
|
|
1123
|
-
"create-function",
|
|
1124
|
-
"Create a new edge function that runs in Deno runtime. The code must be written to a file first for version control",
|
|
1125
|
-
{
|
|
1126
|
-
slug: z12.string().regex(/^[a-zA-Z0-9_-]+$/, "Slug must be alphanumeric with hyphens or underscores only").describe(
|
|
1127
|
-
'URL-friendly identifier (alphanumeric, hyphens, underscores only). Example: "my-calculator"'
|
|
1128
|
-
),
|
|
1129
|
-
name: z12.string().describe('Function display name. Example: "Calculator Function"'),
|
|
1130
|
-
codeFile: z12.string().describe(
|
|
1131
|
-
"Path to JavaScript file containing the function code. Must export: module.exports = async function(request) { return new Response(...) }"
|
|
1132
|
-
),
|
|
1133
|
-
description: z12.string().optional().describe("Description of what the function does"),
|
|
1134
|
-
active: z12.boolean().optional().describe("Set to true to deploy immediately, false for draft mode")
|
|
1135
|
-
},
|
|
1136
|
-
withUsageTracking("create-function", async (args) => {
|
|
1137
|
-
try {
|
|
1138
|
-
let code;
|
|
1139
|
-
try {
|
|
1140
|
-
code = await fs.readFile(args.codeFile, "utf-8");
|
|
1141
|
-
} catch (fileError) {
|
|
1142
|
-
throw new Error(
|
|
1143
|
-
`Failed to read code file '${args.codeFile}': ${fileError instanceof Error ? fileError.message : "Unknown error"}`
|
|
1144
|
-
);
|
|
1145
|
-
}
|
|
1146
|
-
const response = await fetch2(`${API_BASE_URL}/api/functions`, {
|
|
1147
|
-
method: "POST",
|
|
1148
|
-
headers: {
|
|
1149
|
-
"Content-Type": "application/json",
|
|
1150
|
-
"x-api-key": getApiKey()
|
|
1151
|
-
},
|
|
1152
|
-
body: JSON.stringify({
|
|
1153
|
-
slug: args.slug,
|
|
1154
|
-
name: args.name,
|
|
1155
|
-
code,
|
|
1156
|
-
description: args.description || "",
|
|
1157
|
-
status: args.active ? "active" : "draft"
|
|
1158
|
-
})
|
|
1159
|
-
});
|
|
1160
|
-
const result = await handleApiResponse(response);
|
|
1161
|
-
return await addBackgroundContext({
|
|
1162
|
-
content: [
|
|
1163
|
-
{
|
|
1164
|
-
type: "text",
|
|
1165
|
-
text: formatSuccessMessage(
|
|
1166
|
-
`Edge function '${args.slug}' created successfully from ${args.codeFile}`,
|
|
1167
|
-
result
|
|
1168
|
-
)
|
|
1169
|
-
}
|
|
1170
|
-
]
|
|
1171
|
-
});
|
|
1172
|
-
} catch (error) {
|
|
1173
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1174
|
-
return await addBackgroundContext({
|
|
1175
|
-
content: [
|
|
1176
|
-
{
|
|
1177
|
-
type: "text",
|
|
1178
|
-
text: `Error creating function: ${errMsg}`
|
|
1179
|
-
}
|
|
1180
|
-
],
|
|
1181
|
-
isError: true
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
})
|
|
1185
|
-
);
|
|
1186
|
-
server.tool(
|
|
1187
|
-
"get-function",
|
|
1188
|
-
"Get details of a specific edge function including its code",
|
|
1189
|
-
{
|
|
1190
|
-
slug: z12.string().describe("The slug identifier of the function")
|
|
1191
|
-
},
|
|
1192
|
-
withUsageTracking("get-function", async (args) => {
|
|
1193
|
-
try {
|
|
1194
|
-
const response = await fetch2(`${API_BASE_URL}/api/functions/${args.slug}`, {
|
|
1195
|
-
method: "GET",
|
|
1196
|
-
headers: {
|
|
1197
|
-
"x-api-key": getApiKey()
|
|
1198
|
-
}
|
|
1199
|
-
});
|
|
1200
|
-
const result = await handleApiResponse(response);
|
|
1201
|
-
return await addBackgroundContext({
|
|
1202
|
-
content: [
|
|
1203
|
-
{
|
|
1204
|
-
type: "text",
|
|
1205
|
-
text: formatSuccessMessage(`Edge function '${args.slug}' details`, result)
|
|
1206
|
-
}
|
|
1207
|
-
]
|
|
1208
|
-
});
|
|
1209
|
-
} catch (error) {
|
|
1210
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1211
|
-
return await addBackgroundContext({
|
|
1212
|
-
content: [
|
|
1213
|
-
{
|
|
1214
|
-
type: "text",
|
|
1215
|
-
text: `Error getting function: ${errMsg}`
|
|
1216
|
-
}
|
|
1217
|
-
],
|
|
1218
|
-
isError: true
|
|
1219
|
-
});
|
|
1220
|
-
}
|
|
1221
|
-
})
|
|
1222
|
-
);
|
|
1223
|
-
server.tool(
|
|
1224
|
-
"update-function",
|
|
1225
|
-
"Update an existing edge function code or metadata",
|
|
1226
|
-
{
|
|
1227
|
-
slug: z12.string().describe("The slug identifier of the function to update"),
|
|
1228
|
-
name: z12.string().optional().describe("New display name"),
|
|
1229
|
-
codeFile: z12.string().optional().describe(
|
|
1230
|
-
"Path to JavaScript file containing the new function code. Must export: module.exports = async function(request) { return new Response(...) }"
|
|
1231
|
-
),
|
|
1232
|
-
description: z12.string().optional().describe("New description"),
|
|
1233
|
-
status: z12.string().optional().describe('Function status: "draft" (not deployed), "active" (deployed), or "error"')
|
|
1234
|
-
},
|
|
1235
|
-
withUsageTracking("update-function", async (args) => {
|
|
1236
|
-
try {
|
|
1237
|
-
const updateData = {};
|
|
1238
|
-
if (args.name) {
|
|
1239
|
-
updateData.name = args.name;
|
|
1240
|
-
}
|
|
1241
|
-
if (args.codeFile) {
|
|
1242
|
-
try {
|
|
1243
|
-
updateData.code = await fs.readFile(args.codeFile, "utf-8");
|
|
1244
|
-
} catch (fileError) {
|
|
1245
|
-
throw new Error(
|
|
1246
|
-
`Failed to read code file '${args.codeFile}': ${fileError instanceof Error ? fileError.message : "Unknown error"}`
|
|
1247
|
-
);
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
if (args.description !== void 0) {
|
|
1251
|
-
updateData.description = args.description;
|
|
1252
|
-
}
|
|
1253
|
-
if (args.status) {
|
|
1254
|
-
updateData.status = args.status;
|
|
1255
|
-
}
|
|
1256
|
-
const response = await fetch2(`${API_BASE_URL}/api/functions/${args.slug}`, {
|
|
1257
|
-
method: "PUT",
|
|
1258
|
-
headers: {
|
|
1259
|
-
"Content-Type": "application/json",
|
|
1260
|
-
"x-api-key": getApiKey()
|
|
1261
|
-
},
|
|
1262
|
-
body: JSON.stringify(updateData)
|
|
1263
|
-
});
|
|
1264
|
-
const result = await handleApiResponse(response);
|
|
1265
|
-
const fileInfo = args.codeFile ? ` from ${args.codeFile}` : "";
|
|
1266
|
-
return await addBackgroundContext({
|
|
1267
|
-
content: [
|
|
1268
|
-
{
|
|
1269
|
-
type: "text",
|
|
1270
|
-
text: formatSuccessMessage(
|
|
1271
|
-
`Edge function '${args.slug}' updated successfully${fileInfo}`,
|
|
1272
|
-
result
|
|
1273
|
-
)
|
|
1274
|
-
}
|
|
1275
|
-
]
|
|
1276
|
-
});
|
|
1277
|
-
} catch (error) {
|
|
1278
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1279
|
-
return await addBackgroundContext({
|
|
1280
|
-
content: [
|
|
1281
|
-
{
|
|
1282
|
-
type: "text",
|
|
1283
|
-
text: `Error updating function: ${errMsg}`
|
|
1284
|
-
}
|
|
1285
|
-
],
|
|
1286
|
-
isError: true
|
|
1287
|
-
});
|
|
1288
|
-
}
|
|
1289
|
-
})
|
|
1290
|
-
);
|
|
1291
|
-
server.tool(
|
|
1292
|
-
"delete-function",
|
|
1293
|
-
"Delete an edge function permanently",
|
|
1294
|
-
{
|
|
1295
|
-
slug: z12.string().describe("The slug identifier of the function to delete")
|
|
1296
|
-
},
|
|
1297
|
-
withUsageTracking("delete-function", async (args) => {
|
|
1298
|
-
try {
|
|
1299
|
-
const response = await fetch2(`${API_BASE_URL}/api/functions/${args.slug}`, {
|
|
1300
|
-
method: "DELETE",
|
|
1301
|
-
headers: {
|
|
1302
|
-
"x-api-key": getApiKey()
|
|
1303
|
-
}
|
|
1304
|
-
});
|
|
1305
|
-
const result = await handleApiResponse(response);
|
|
1306
|
-
return await addBackgroundContext({
|
|
1307
|
-
content: [
|
|
1308
|
-
{
|
|
1309
|
-
type: "text",
|
|
1310
|
-
text: formatSuccessMessage(`Edge function '${args.slug}' deleted successfully`, result)
|
|
1311
|
-
}
|
|
1312
|
-
]
|
|
1313
|
-
});
|
|
1314
|
-
} catch (error) {
|
|
1315
|
-
const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
|
|
1316
|
-
return await addBackgroundContext({
|
|
1317
|
-
content: [
|
|
1318
|
-
{
|
|
1319
|
-
type: "text",
|
|
1320
|
-
text: `Error deleting function: ${errMsg}`
|
|
1321
|
-
}
|
|
1322
|
-
],
|
|
1323
|
-
isError: true
|
|
1324
|
-
});
|
|
1325
|
-
}
|
|
1326
|
-
})
|
|
1327
|
-
);
|
|
18
|
+
var toolsConfig = registerInsforgeTools(server, {
|
|
19
|
+
apiKey: api_key,
|
|
20
|
+
apiBaseUrl: process.env.API_BASE_URL
|
|
21
|
+
});
|
|
1328
22
|
async function main() {
|
|
1329
23
|
const transport = new StdioServerTransport();
|
|
1330
24
|
await server.connect(transport);
|
|
1331
25
|
console.error("Insforge MCP server started");
|
|
26
|
+
if (toolsConfig.apiKey) {
|
|
27
|
+
console.error(`API Key: Configured`);
|
|
28
|
+
} else {
|
|
29
|
+
console.error("API Key: Not configured (will require api_key in tool calls)");
|
|
30
|
+
}
|
|
31
|
+
console.error(`API Base URL: ${toolsConfig.apiBaseUrl}`);
|
|
32
|
+
console.error(`Tools registered: ${toolsConfig.toolCount}`);
|
|
1332
33
|
}
|
|
1333
34
|
main().catch(console.error);
|