@insforge/mcp 1.1.7-dev.27 → 1.1.7-dev.29

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.
@@ -838,6 +838,9 @@ function registerInsforgeTools(server, config = {}) {
838
838
  "Content-Type": "application/json"
839
839
  }
840
840
  });
841
+ if (response.status === 404) {
842
+ throw new Error("Documentation not found");
843
+ }
841
844
  const result = await handleApiResponse(response);
842
845
  if (result && typeof result === "object" && "content" in result) {
843
846
  let content = result.content;
@@ -851,6 +854,36 @@ function registerInsforgeTools(server, config = {}) {
851
854
  throw new Error(`Unable to retrieve ${docType} documentation: ${errMsg}`);
852
855
  }
853
856
  };
857
+ const fetchInsforgeInstructionsContext = async () => {
858
+ try {
859
+ return await fetchDocumentation("instructions");
860
+ } catch (error) {
861
+ console.error("Failed to fetch insforge-instructions.md:", error);
862
+ return null;
863
+ }
864
+ };
865
+ const addBackgroundContext = async (response) => {
866
+ try {
867
+ const currentVersion = await getBackendVersion();
868
+ const isLegacyVersion = compareVersions(currentVersion, "1.7.0") < 0;
869
+ if (isLegacyVersion) {
870
+ const context = await fetchInsforgeInstructionsContext();
871
+ if (context && response.content && Array.isArray(response.content)) {
872
+ response.content.push({
873
+ type: "text",
874
+ text: `
875
+
876
+ ---
877
+ \u{1F527} INSFORGE DEVELOPMENT RULES (Auto-loaded):
878
+ ${context}`
879
+ });
880
+ }
881
+ }
882
+ } catch {
883
+ console.warn("Could not determine backend version, skipping background context");
884
+ }
885
+ return response;
886
+ };
854
887
  server.tool(
855
888
  "fetch-docs",
856
889
  'Fetch Insforge documentation. Use "instructions" for essential backend setup (MANDATORY FIRST), or select specific SDK docs for database, auth, storage, functions, or AI integration.',
@@ -862,29 +895,24 @@ function registerInsforgeTools(server, config = {}) {
862
895
  withUsageTracking("fetch-docs", async ({ docType }) => {
863
896
  try {
864
897
  const content = await fetchDocumentation(docType);
865
- return {
898
+ return await addBackgroundContext({
866
899
  content: [
867
900
  {
868
901
  type: "text",
869
902
  text: content
870
903
  }
871
904
  ]
872
- };
905
+ });
873
906
  } catch (error) {
874
- if (error instanceof Error && error.message.includes("404")) {
875
- try {
876
- const instructionsContent = await fetchDocumentation("instructions");
877
- return {
878
- content: [{ type: "text", text: instructionsContent }]
879
- };
880
- } catch (fallbackError) {
881
- const fallbackErrMsg = fallbackError instanceof Error ? fallbackError.message : "Unknown error occurred";
882
- return {
883
- content: [{ type: "text", text: `Error fetching documentation: ${fallbackErrMsg}` }]
884
- };
885
- }
886
- }
887
907
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
908
+ if (errMsg.includes("404") || errMsg.toLowerCase().includes("not found")) {
909
+ return {
910
+ content: [{
911
+ type: "text",
912
+ text: `Documentation for "${docType}" is not available. This is likely because your backend version is too old and doesn't support this documentation endpoint yet. This won't affect the functionality of the tools - they will still work correctly.`
913
+ }]
914
+ };
915
+ }
888
916
  return {
889
917
  content: [{ type: "text", text: `Error fetching ${docType} documentation: ${errMsg}` }]
890
918
  };
@@ -908,14 +936,14 @@ function registerInsforgeTools(server, config = {}) {
908
936
  }
909
937
  });
910
938
  const result = await handleApiResponse(response);
911
- return {
939
+ return await addBackgroundContext({
912
940
  content: [
913
941
  {
914
942
  type: "text",
915
943
  text: formatSuccessMessage("Anonymous token generated", result)
916
944
  }
917
945
  ]
918
- };
946
+ });
919
947
  } catch (error) {
920
948
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
921
949
  return {
@@ -947,14 +975,14 @@ function registerInsforgeTools(server, config = {}) {
947
975
  }
948
976
  });
949
977
  const result = await handleApiResponse(response);
950
- return {
978
+ return await addBackgroundContext({
951
979
  content: [
952
980
  {
953
981
  type: "text",
954
982
  text: formatSuccessMessage("Schema retrieved", result)
955
983
  }
956
984
  ]
957
- };
985
+ });
958
986
  } catch (error) {
959
987
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
960
988
  return {
@@ -985,7 +1013,7 @@ function registerInsforgeTools(server, config = {}) {
985
1013
  }
986
1014
  });
987
1015
  const metadata = await handleApiResponse(response);
988
- return {
1016
+ return await addBackgroundContext({
989
1017
  content: [
990
1018
  {
991
1019
  type: "text",
@@ -994,7 +1022,7 @@ function registerInsforgeTools(server, config = {}) {
994
1022
  ${JSON.stringify(metadata, null, 2)}`
995
1023
  }
996
1024
  ]
997
- };
1025
+ });
998
1026
  } catch (error) {
999
1027
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1000
1028
  return {
@@ -1032,14 +1060,14 @@ ${JSON.stringify(metadata, null, 2)}`
1032
1060
  body: JSON.stringify(requestBody)
1033
1061
  });
1034
1062
  const result = await handleApiResponse(response);
1035
- return {
1063
+ return await addBackgroundContext({
1036
1064
  content: [
1037
1065
  {
1038
1066
  type: "text",
1039
1067
  text: formatSuccessMessage("SQL query executed", result)
1040
1068
  }
1041
1069
  ]
1042
- };
1070
+ });
1043
1071
  } catch (error) {
1044
1072
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1045
1073
  return {
@@ -1085,9 +1113,9 @@ ${JSON.stringify(metadata, null, 2)}`
1085
1113
  console.error(`[download-template] Removing existing template at ${templatePath}`);
1086
1114
  await fs.rm(templatePath, { recursive: true, force: true });
1087
1115
  }
1088
- } catch (error) {
1116
+ } catch {
1089
1117
  }
1090
- const command = `npx create-insforge-app ${targetDir} --frame ${frame} --base-url ${API_BASE_URL} --anon-key ${anonKey}`;
1118
+ const command = `npx create-insforge-app ${targetDir} --frame ${frame} --base-url ${API_BASE_URL} --anon-key ${anonKey} --skip-install`;
1091
1119
  const { stdout, stderr } = await execAsync(command, {
1092
1120
  maxBuffer: 10 * 1024 * 1024,
1093
1121
  // 10MB buffer
@@ -1097,7 +1125,7 @@ ${JSON.stringify(metadata, null, 2)}`
1097
1125
  if (output.toLowerCase().includes("error") && !output.includes("successfully")) {
1098
1126
  throw new Error(`Failed to download template: ${output}`);
1099
1127
  }
1100
- return {
1128
+ return await addBackgroundContext({
1101
1129
  content: [
1102
1130
  {
1103
1131
  type: "text",
@@ -1115,7 +1143,7 @@ To: Your current project directory
1115
1143
  `
1116
1144
  }
1117
1145
  ]
1118
- };
1146
+ });
1119
1147
  } catch (error) {
1120
1148
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1121
1149
  return {
@@ -1159,7 +1187,7 @@ To: Your current project directory
1159
1187
  });
1160
1188
  const result = await handleApiResponse(response);
1161
1189
  const message = result.success ? `Successfully processed ${result.rowsAffected} of ${result.totalRecords} records into table "${result.table}"` : result.message || "Bulk upsert operation completed";
1162
- return {
1190
+ return await addBackgroundContext({
1163
1191
  content: [
1164
1192
  {
1165
1193
  type: "text",
@@ -1172,7 +1200,7 @@ To: Your current project directory
1172
1200
  })
1173
1201
  }
1174
1202
  ]
1175
- };
1203
+ });
1176
1204
  } catch (error) {
1177
1205
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1178
1206
  return {
@@ -1206,14 +1234,14 @@ To: Your current project directory
1206
1234
  body: JSON.stringify({ bucketName, isPublic })
1207
1235
  });
1208
1236
  const result = await handleApiResponse(response);
1209
- return {
1237
+ return await addBackgroundContext({
1210
1238
  content: [
1211
1239
  {
1212
1240
  type: "text",
1213
1241
  text: formatSuccessMessage("Bucket created", result)
1214
1242
  }
1215
1243
  ]
1216
- };
1244
+ });
1217
1245
  } catch (error) {
1218
1246
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1219
1247
  return {
@@ -1241,14 +1269,14 @@ To: Your current project directory
1241
1269
  }
1242
1270
  });
1243
1271
  const result = await handleApiResponse(response);
1244
- return {
1272
+ return await addBackgroundContext({
1245
1273
  content: [
1246
1274
  {
1247
1275
  type: "text",
1248
1276
  text: formatSuccessMessage("Buckets retrieved", result)
1249
1277
  }
1250
1278
  ]
1251
- };
1279
+ });
1252
1280
  } catch (error) {
1253
1281
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1254
1282
  return {
@@ -1280,14 +1308,14 @@ To: Your current project directory
1280
1308
  }
1281
1309
  });
1282
1310
  const result = await handleApiResponse(response);
1283
- return {
1311
+ return await addBackgroundContext({
1284
1312
  content: [
1285
1313
  {
1286
1314
  type: "text",
1287
1315
  text: formatSuccessMessage("Bucket deleted", result)
1288
1316
  }
1289
1317
  ]
1290
- };
1318
+ });
1291
1319
  } catch (error) {
1292
1320
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1293
1321
  return {
@@ -1336,7 +1364,7 @@ To: Your current project directory
1336
1364
  })
1337
1365
  });
1338
1366
  const result = await handleApiResponse(response);
1339
- return {
1367
+ return await addBackgroundContext({
1340
1368
  content: [
1341
1369
  {
1342
1370
  type: "text",
@@ -1346,7 +1374,7 @@ To: Your current project directory
1346
1374
  )
1347
1375
  }
1348
1376
  ]
1349
- };
1377
+ });
1350
1378
  } catch (error) {
1351
1379
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1352
1380
  return {
@@ -1376,14 +1404,14 @@ To: Your current project directory
1376
1404
  }
1377
1405
  });
1378
1406
  const result = await handleApiResponse(response);
1379
- return {
1407
+ return await addBackgroundContext({
1380
1408
  content: [
1381
1409
  {
1382
1410
  type: "text",
1383
1411
  text: formatSuccessMessage(`Edge function '${args.slug}' details`, result)
1384
1412
  }
1385
1413
  ]
1386
- };
1414
+ });
1387
1415
  } catch (error) {
1388
1416
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1389
1417
  return {
@@ -1439,7 +1467,7 @@ To: Your current project directory
1439
1467
  });
1440
1468
  const result = await handleApiResponse(response);
1441
1469
  const fileInfo = args.codeFile ? ` from ${args.codeFile}` : "";
1442
- return {
1470
+ return await addBackgroundContext({
1443
1471
  content: [
1444
1472
  {
1445
1473
  type: "text",
@@ -1449,7 +1477,7 @@ To: Your current project directory
1449
1477
  )
1450
1478
  }
1451
1479
  ]
1452
- };
1480
+ });
1453
1481
  } catch (error) {
1454
1482
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1455
1483
  return {
@@ -1479,14 +1507,14 @@ To: Your current project directory
1479
1507
  }
1480
1508
  });
1481
1509
  const result = await handleApiResponse(response);
1482
- return {
1510
+ return await addBackgroundContext({
1483
1511
  content: [
1484
1512
  {
1485
1513
  type: "text",
1486
1514
  text: formatSuccessMessage(`Edge function '${args.slug}' deleted successfully`, result)
1487
1515
  }
1488
1516
  ]
1489
- };
1517
+ });
1490
1518
  } catch (error) {
1491
1519
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1492
1520
  return {
@@ -1529,125 +1557,21 @@ To: Your current project directory
1529
1557
  });
1530
1558
  }
1531
1559
  const result = await handleApiResponse(response);
1532
- return {
1560
+ return await addBackgroundContext({
1533
1561
  content: [
1534
1562
  {
1535
1563
  type: "text",
1536
1564
  text: formatSuccessMessage(`Latest logs from ${source}`, result)
1537
1565
  }
1538
1566
  ]
1539
- };
1540
- } catch (error) {
1541
- const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1542
- return {
1543
- content: [
1544
- {
1545
- type: "text",
1546
- text: `Error retrieving container logs: ${errMsg}`
1547
- }
1548
- ],
1549
- isError: true
1550
- };
1551
- }
1552
- })
1553
- );
1554
- server.tool(
1555
- "upsert-schedule",
1556
- "Create or update a cron job schedule. If id is provided, updates existing schedule; otherwise creates a new one.",
1557
- {
1558
- apiKey: z14.string().optional().describe("API key for authentication (optional if provided via --api_key)"),
1559
- id: z14.string().uuid().optional().describe("The UUID of the schedule to update. If omitted, a new schedule will be created."),
1560
- name: z14.string().min(3).describe("Schedule name (at least 3 characters)"),
1561
- cronSchedule: z14.string().describe('Cron schedule format (5 or 6 parts, e.g., "0 */2 * * *" for every 2 hours)'),
1562
- functionUrl: z14.string().url().describe("The URL to call when the schedule triggers"),
1563
- httpMethod: z14.enum(["GET", "POST", "PUT", "PATCH", "DELETE"]).optional().default("POST").describe("HTTP method to use"),
1564
- headers: z14.record(z14.string()).optional().describe('HTTP headers. Values starting with "secret:" will be resolved from secrets store.'),
1565
- body: z14.record(z14.unknown()).optional().describe("JSON body to send with the request")
1566
- },
1567
- withUsageTracking("upsert-schedule", async ({ apiKey, id, name, cronSchedule, functionUrl, httpMethod, headers, body }) => {
1568
- try {
1569
- await checkToolVersion("upsert-schedule");
1570
- const actualApiKey = getApiKey(apiKey);
1571
- const requestBody = {
1572
- name,
1573
- cronSchedule,
1574
- functionUrl,
1575
- httpMethod: httpMethod || "POST"
1576
- };
1577
- if (id) {
1578
- requestBody.id = id;
1579
- }
1580
- if (headers) {
1581
- requestBody.headers = headers;
1582
- }
1583
- if (body) {
1584
- requestBody.body = body;
1585
- }
1586
- const response = await fetch2(`${API_BASE_URL}/api/schedules`, {
1587
- method: "POST",
1588
- headers: {
1589
- "x-api-key": actualApiKey,
1590
- "Content-Type": "application/json"
1591
- },
1592
- body: JSON.stringify(requestBody)
1593
- });
1594
- const result = await handleApiResponse(response);
1595
- const action = id ? "updated" : "created";
1596
- return {
1597
- content: [
1598
- {
1599
- type: "text",
1600
- text: formatSuccessMessage(`Schedule '${name}' ${action} successfully`, result)
1601
- }
1602
- ]
1603
- };
1604
- } catch (error) {
1605
- const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1606
- return {
1607
- content: [
1608
- {
1609
- type: "text",
1610
- text: `Error upserting schedule: ${errMsg}`
1611
- }
1612
- ],
1613
- isError: true
1614
- };
1615
- }
1616
- })
1617
- );
1618
- server.tool(
1619
- "delete-schedule",
1620
- "Delete a cron job schedule permanently",
1621
- {
1622
- apiKey: z14.string().optional().describe("API key for authentication (optional if provided via --api_key)"),
1623
- scheduleId: z14.string().uuid().describe("The UUID of the schedule to delete")
1624
- },
1625
- withUsageTracking("delete-schedule", async ({ apiKey, scheduleId }) => {
1626
- try {
1627
- await checkToolVersion("delete-schedule");
1628
- const actualApiKey = getApiKey(apiKey);
1629
- const response = await fetch2(`${API_BASE_URL}/api/schedules/${scheduleId}`, {
1630
- method: "DELETE",
1631
- headers: {
1632
- "x-api-key": actualApiKey
1633
- }
1634
1567
  });
1635
- const result = await handleApiResponse(response);
1636
- return {
1637
- content: [
1638
- {
1639
- type: "text",
1640
- text: formatSuccessMessage(`Schedule ${scheduleId} deleted successfully`, result)
1641
- }
1642
- ]
1643
- };
1644
1568
  } catch (error) {
1645
1569
  const errMsg = error instanceof Error ? error.message : "Unknown error occurred";
1646
1570
  return {
1647
1571
  content: [
1648
1572
  {
1649
1573
  type: "text",
1650
- text: `Error deleting schedule: ${errMsg}`
1574
+ text: `Error retrieving container logs: ${errMsg}`
1651
1575
  }
1652
1576
  ],
1653
1577
  isError: true
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  registerInsforgeTools
4
- } from "./chunk-MIGS7PIQ.js";
4
+ } from "./chunk-QVPU2PDE.js";
5
5
 
6
6
  // src/http/server.ts
7
7
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  registerInsforgeTools
4
- } from "./chunk-MIGS7PIQ.js";
4
+ } from "./chunk-QVPU2PDE.js";
5
5
 
6
6
  // src/stdio/index.ts
7
7
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@insforge/mcp",
3
- "version": "1.1.7-dev.27",
3
+ "version": "1.1.7-dev.29",
4
4
  "description": "MCP (Model Context Protocol) server for Insforge backend-as-a-service",
5
5
  "mcpName": "io.github.InsForge/insforge-mcp",
6
6
  "type": "module",