inistate-mcp 1.5.0 → 1.5.1

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/README.md CHANGED
@@ -227,7 +227,28 @@ mcp-publisher publish
227
227
  ## Deployment
228
228
 
229
229
  Deployment is done by hand; there is no CI deploy. After a release, update the server
230
- (see PM2 below): pull `production`, `npm ci`, `npm run build`, then `npm run pm2:restart`.
230
+ (see PM2 below):
231
+
232
+ ```bash
233
+ npm run update # git pull, npm ci only if the lockfile changed, then deploy
234
+ npm run rollback # if it went wrong after the fact: restores build-prev
235
+ ```
236
+
237
+ Do not run `npm run build` on the server while it is serving: it starts with `rimraf build`, and
238
+ pm2 runs the live server from `build/`, so the server is left on an empty or half-written folder
239
+ and stalls. (Installing no longer builds: there is no `prepare` script, only `prepublishOnly`.) `npm run deploy` (run by `npm run update`) compiles
240
+ into `build-next` and only renames folders once that succeeded; if the new build does not answer
241
+ `/health` it puts the previous one back.
242
+
243
+ `npm ci` also deletes `node_modules` while the server is running, so run it only when
244
+ dependencies changed, and follow it at once with `npm run deploy`.
245
+
246
+ The PM2 app runs in cluster mode with **one** instance, so `pm2 reload` starts the new process,
247
+ waits for it to report ready, then stops the old one (in-flight requests get 8 s to finish).
248
+ Keep `instances: 1`: the OAuth provider keeps pending logins and tokens in process memory, and a
249
+ login that reached two different workers would fail. After the first deploy of this change run
250
+ `pm2 delete inistate-mcp && npm run pm2:start && npx pm2 save` once, because an existing fork-mode
251
+ app does not switch to cluster mode on reload.
231
252
 
232
253
  ## PM2 (Ubuntu/AWS)
233
254
 
package/build/api.d.ts CHANGED
@@ -1,3 +1,9 @@
1
+ /**
2
+ * A link the API handed out, under the configured API base. The API cannot see its own public origin behind its
3
+ * balancer (it once answered https://api.inistate.com:85/...), so whatever origin the link carries - none, an
4
+ * internal port, another host, protocol-relative - is dropped: only its path, query and fragment are kept.
5
+ */
6
+ export declare function absoluteUrl(link: string): string;
1
7
  /**
2
8
  * Point the current call at a workspace. The MCP keeps no state between calls: this writes the
3
9
  * call's own request context — every tool call runs in one (tools.ts registerTool), as does every
package/build/api.js CHANGED
@@ -3,6 +3,16 @@ const BASE_URL = (process.env.INISTATE_API_BASE ||
3
3
  process.env.INISTATE_API_URL ||
4
4
  process.env.INISTATE_BASE_URL ||
5
5
  "https://api.inistate.com").replace(/\/+$/, "");
6
+ /**
7
+ * A link the API handed out, under the configured API base. The API cannot see its own public origin behind its
8
+ * balancer (it once answered https://api.inistate.com:85/...), so whatever origin the link carries - none, an
9
+ * internal port, another host, protocol-relative - is dropped: only its path, query and fragment are kept.
10
+ */
11
+ export function absoluteUrl(link) {
12
+ // A base resolves a bare or protocol-relative link too; its own origin is thrown away with the link's.
13
+ const u = new URL(link, "http://origin.invalid");
14
+ return `${BASE_URL}${u.pathname}${u.search}${u.hash}`;
15
+ }
6
16
  const LOG_ENABLED = process.env.INISTATE_LOG !== "0";
7
17
  function log(message, data) {
8
18
  if (!LOG_ENABLED)
package/build/backend.js CHANGED
@@ -205,7 +205,7 @@ export class CloudBackend {
205
205
  confirmUpload(p) {
206
206
  return api.post("/api/mcp/confirm-upload", { s3Key: p.s3Key });
207
207
  }
208
- getDocument(p) {
208
+ async getDocument(p) {
209
209
  // `as` travels only when given: without it the server picks (a link, or the file for an Inistate-designed document).
210
210
  const body = { module: p.module, entry: p.entry };
211
211
  if (p.document)
@@ -214,7 +214,13 @@ export class CloudBackend {
214
214
  body.format = p.format;
215
215
  if (p.as)
216
216
  body.as = p.as;
217
- return api.post("/api/mcp/document", body);
217
+ const data = await api.post("/api/mcp/document", body);
218
+ // The API answers the link as a path (/doc/link/...); it goes out under the configured API base.
219
+ if (data && typeof data === "object" && typeof data.link === "string") {
220
+ const d = data;
221
+ d.link = api.absoluteUrl(d.link);
222
+ }
223
+ return data;
218
224
  }
219
225
  // The hosted Platform designs modules directly and does not introspect
220
226
  // external stores; capabilities().scaffold is false, so the tool gates this
package/build/http.js CHANGED
@@ -88,8 +88,14 @@ registerAppAuthorizeRoutes(app, oauthProvider, ISSUER_URL);
88
88
  /* ------------------------------------------------------------------ */
89
89
  /* Health check */
90
90
  /* ------------------------------------------------------------------ */
91
+ let shuttingDown = false;
92
+ const STARTED_AT = Date.now();
91
93
  app.get("/health", (_req, res) => {
92
- res.json({ status: "ok" });
94
+ if (shuttingDown) {
95
+ res.status(503).json({ status: "draining" });
96
+ return;
97
+ }
98
+ res.json({ status: "ok", uptimeSeconds: Math.round((Date.now() - STARTED_AT) / 1000) });
93
99
  });
94
100
  /* ------------------------------------------------------------------ */
95
101
  /* MCP endpoint (stateless) */
@@ -171,13 +177,39 @@ app.get("/.well-known/openai-apps-challenge", (_, res) => {
171
177
  /* ------------------------------------------------------------------ */
172
178
  /* Start */
173
179
  /* ------------------------------------------------------------------ */
174
- app.listen(PORT, () => {
180
+ const httpServer = app.listen(PORT, () => {
175
181
  console.log(`Inistate MCP HTTP server listening on port ${PORT}`);
176
182
  console.log(` MCP: POST http://localhost:${PORT}/mcp`);
177
183
  console.log(` OAuth: GET http://localhost:${PORT}/.well-known/oauth-authorization-server`);
178
184
  console.log(` Health: GET http://localhost:${PORT}/health`);
185
+ // pm2 (wait_ready) holds the old process until the new one says it is listening, so a
186
+ // `pm2 reload` never leaves a gap with nothing accepting requests.
187
+ process.send?.("ready");
179
188
  });
180
- process.on("SIGINT", () => {
181
- console.log("Shutting down...");
182
- process.exit(0);
183
- });
189
+ /* ------------------------------------------------------------------ */
190
+ /* Graceful shutdown */
191
+ /* ------------------------------------------------------------------ */
192
+ // A restart used to be process.exit(0) on SIGINT only (pm2 sends SIGINT, then SIGKILL), which cut
193
+ // in-flight tool calls off. Now: stop accepting, let running requests finish, then exit. /health
194
+ // answers 503 while draining so a load balancer or deploy script stops sending new work.
195
+ const SHUTDOWN_GRACE_MS = Number(process.env.SHUTDOWN_GRACE_MS) || 8000; // keep below pm2 kill_timeout
196
+ function shutdown(signal) {
197
+ if (shuttingDown)
198
+ return;
199
+ shuttingDown = true;
200
+ console.log(`${signal} received, draining (up to ${SHUTDOWN_GRACE_MS} ms)...`);
201
+ httpServer.close((err) => {
202
+ if (err)
203
+ console.error("Error while closing the HTTP server:", err);
204
+ console.log("Drained, exiting.");
205
+ process.exit(err ? 1 : 0);
206
+ });
207
+ httpServer.closeIdleConnections();
208
+ setTimeout(() => {
209
+ console.error("Grace period over, closing remaining connections.");
210
+ httpServer.closeAllConnections();
211
+ process.exit(0);
212
+ }, SHUTDOWN_GRACE_MS).unref();
213
+ }
214
+ process.on("SIGINT", () => shutdown("SIGINT"));
215
+ process.on("SIGTERM", () => shutdown("SIGTERM"));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "inistate-mcp",
3
3
  "mcpName": "io.github.Inistate/inistate-mcp",
4
- "version": "1.5.0",
4
+ "version": "1.5.1",
5
5
  "description": "MCP server for the Inistate platform — no-code apps creation powered by AI",
6
6
  "type": "module",
7
7
  "author": "Inistate",
@@ -49,7 +49,8 @@
49
49
  "scripts": {
50
50
  "clean": "rimraf build",
51
51
  "build": "npm run clean && tsc",
52
- "prepare": "npm run build",
52
+ "prepublishOnly": "npm run build",
53
+ "check": "tsc --noEmit",
53
54
  "watch": "tsc --watch",
54
55
  "test": "vitest run",
55
56
  "test:watch": "vitest",
@@ -61,9 +62,15 @@
61
62
  "start:http": "node build/http.js",
62
63
  "inspector": "npx @modelcontextprotocol/inspector build/index.js",
63
64
  "test-rig": "node scripts/run-scenario.mjs",
65
+ "install:server": "npm ci --include=dev --no-audit --no-fund",
66
+ "update": "node scripts/update.mjs",
67
+ "deploy": "node scripts/deploy.mjs",
68
+ "deploy:swap": "node scripts/deploy.mjs --no-reload",
69
+ "rollback": "node scripts/deploy.mjs --rollback",
64
70
  "pm2:start": "pm2 start ecosystem.config.cjs --env production",
65
- "pm2:restart": "pm2 restart inistate-mcp",
71
+ "pm2:restart": "pm2 reload inistate-mcp",
66
72
  "pm2:stop": "pm2 stop inistate-mcp",
73
+ "pm2:status": "pm2 describe inistate-mcp",
67
74
  "pm2:logs": "pm2 logs inistate-mcp"
68
75
  },
69
76
  "dependencies": {
package/server.json CHANGED
@@ -8,13 +8,13 @@
8
8
  "url": "https://github.com/inistate/inistate-mcp",
9
9
  "source": "github"
10
10
  },
11
- "version": "1.5.0",
11
+ "version": "1.5.1",
12
12
  "packages": [
13
13
  {
14
14
  "registryType": "npm",
15
15
  "registryBaseUrl": "https://registry.npmjs.org",
16
16
  "identifier": "inistate-mcp",
17
- "version": "1.5.0",
17
+ "version": "1.5.1",
18
18
  "transport": {
19
19
  "type": "stdio"
20
20
  },