inistate-mcp 1.1.3 → 1.1.4

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.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * SS05806 - durable OAuth Dynamic Client Registration store.
3
+ *
4
+ * DCR client_ids used to live only in a process-local Map, so every restart (deploy, crash,
5
+ * container reschedule, `pm2 restart`) wiped them. A connector that had registered days earlier
6
+ * then hit /authorize and got `invalid_client`, and the only way back was to delete and re-add
7
+ * the connector so it registered afresh. Every restart re-broke every cached client.
8
+ *
9
+ * Registrations are now written to a JSON file and reloaded on startup.
10
+ *
11
+ * Deliberately NOT persisted here: issued access tokens, authorization codes and pending auths.
12
+ * Codes and pending auths expire in minutes, so losing them on restart is harmless. Tokens are
13
+ * bearer secrets - writing them to disk is a security tradeoff that deserves its own decision,
14
+ * not a side effect of fixing client registration. Losing them on restart degrades attribution
15
+ * (see verifyAccessToken), it does not lock anyone out the way a lost client_id does.
16
+ *
17
+ * Every disk operation fails soft: if the file cannot be read or written the store keeps working
18
+ * in memory and logs. An unwritable disk must never take authentication down with it.
19
+ *
20
+ * Scope: this is per-process state on local disk, so it fixes restarts, not replicas. If the
21
+ * server is ever scaled out, point OAUTH_CLIENTS_FILE at shared storage or move the map to a DB
22
+ * - otherwise a client registered on one replica is unknown to the others (same caveat
23
+ * mode-store.ts carries).
24
+ */
25
+ import type { OAuthRegisteredClientsStore } from "@modelcontextprotocol/sdk/server/auth/clients.js";
26
+ import type { OAuthClientInformationFull } from "@modelcontextprotocol/sdk/shared/auth.js";
27
+ /** Where registrations are kept. Override for containers that mount a volume elsewhere. */
28
+ export declare function defaultClientsFile(): string;
29
+ export declare class FileClientsStore implements OAuthRegisteredClientsStore {
30
+ private clients;
31
+ private readonly file;
32
+ /** Set when the file is unusable, so we warn once rather than on every registration. */
33
+ private writeDisabled;
34
+ constructor(file?: string);
35
+ getClient(clientId: string): OAuthClientInformationFull | undefined;
36
+ registerClient(client: Omit<OAuthClientInformationFull, "client_id" | "client_id_issued_at">): OAuthClientInformationFull;
37
+ dump(): OAuthClientInformationFull[];
38
+ private load;
39
+ /**
40
+ * OAUTH_KNOWN_CLIENTS keeps working exactly as before. Seeded entries are applied AFTER the
41
+ * file load so an operator-pinned client always wins, and are not written back - the env var
42
+ * stays the source of truth for them.
43
+ */
44
+ private seedFromEnv;
45
+ private persist;
46
+ }
@@ -0,0 +1,120 @@
1
+ /**
2
+ * SS05806 - durable OAuth Dynamic Client Registration store.
3
+ *
4
+ * DCR client_ids used to live only in a process-local Map, so every restart (deploy, crash,
5
+ * container reschedule, `pm2 restart`) wiped them. A connector that had registered days earlier
6
+ * then hit /authorize and got `invalid_client`, and the only way back was to delete and re-add
7
+ * the connector so it registered afresh. Every restart re-broke every cached client.
8
+ *
9
+ * Registrations are now written to a JSON file and reloaded on startup.
10
+ *
11
+ * Deliberately NOT persisted here: issued access tokens, authorization codes and pending auths.
12
+ * Codes and pending auths expire in minutes, so losing them on restart is harmless. Tokens are
13
+ * bearer secrets - writing them to disk is a security tradeoff that deserves its own decision,
14
+ * not a side effect of fixing client registration. Losing them on restart degrades attribution
15
+ * (see verifyAccessToken), it does not lock anyone out the way a lost client_id does.
16
+ *
17
+ * Every disk operation fails soft: if the file cannot be read or written the store keeps working
18
+ * in memory and logs. An unwritable disk must never take authentication down with it.
19
+ *
20
+ * Scope: this is per-process state on local disk, so it fixes restarts, not replicas. If the
21
+ * server is ever scaled out, point OAUTH_CLIENTS_FILE at shared storage or move the map to a DB
22
+ * - otherwise a client registered on one replica is unknown to the others (same caveat
23
+ * mode-store.ts carries).
24
+ */
25
+ import { randomUUID } from "node:crypto";
26
+ import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
27
+ import { dirname, join } from "node:path";
28
+ /** Where registrations are kept. Override for containers that mount a volume elsewhere. */
29
+ export function defaultClientsFile() {
30
+ return (process.env.OAUTH_CLIENTS_FILE ||
31
+ join(process.env.INISTATE_DATA_DIR || ".inistate", "oauth-clients.json"));
32
+ }
33
+ export class FileClientsStore {
34
+ clients = new Map();
35
+ file;
36
+ /** Set when the file is unusable, so we warn once rather than on every registration. */
37
+ writeDisabled = false;
38
+ constructor(file = defaultClientsFile()) {
39
+ this.file = file;
40
+ this.load();
41
+ this.seedFromEnv();
42
+ }
43
+ getClient(clientId) {
44
+ return this.clients.get(clientId);
45
+ }
46
+ registerClient(client) {
47
+ const full = {
48
+ ...client,
49
+ client_id: randomUUID(),
50
+ client_id_issued_at: Math.floor(Date.now() / 1000),
51
+ };
52
+ this.clients.set(full.client_id, full);
53
+ this.persist();
54
+ return full;
55
+ }
56
+ dump() {
57
+ return [...this.clients.values()];
58
+ }
59
+ /* ---------------------------------------------------------------- */
60
+ load() {
61
+ try {
62
+ if (!existsSync(this.file))
63
+ return;
64
+ const parsed = JSON.parse(readFileSync(this.file, "utf8"));
65
+ if (!Array.isArray(parsed)) {
66
+ console.error(`OAuth client store at ${this.file} is not a JSON array — ignoring it`);
67
+ return;
68
+ }
69
+ for (const entry of parsed) {
70
+ const client = entry;
71
+ // A row without a client_id cannot be looked up; skip rather than poison the map.
72
+ if (client && typeof client.client_id === "string" && client.client_id) {
73
+ this.clients.set(client.client_id, client);
74
+ }
75
+ }
76
+ console.log(`OAuth client store loaded ${this.clients.size} client(s) from ${this.file}`);
77
+ }
78
+ catch (err) {
79
+ // A corrupt or unreadable file must not stop the server booting. Keep the file for
80
+ // inspection - overwriting it would destroy the only copy of the registrations.
81
+ console.error(`Failed to read OAuth client store at ${this.file}:`, err);
82
+ this.writeDisabled = true;
83
+ }
84
+ }
85
+ /**
86
+ * OAUTH_KNOWN_CLIENTS keeps working exactly as before. Seeded entries are applied AFTER the
87
+ * file load so an operator-pinned client always wins, and are not written back - the env var
88
+ * stays the source of truth for them.
89
+ */
90
+ seedFromEnv() {
91
+ const seed = process.env.OAUTH_KNOWN_CLIENTS;
92
+ if (!seed)
93
+ return;
94
+ try {
95
+ for (const client of JSON.parse(seed)) {
96
+ this.clients.set(client.client_id, client);
97
+ }
98
+ console.log(`OAuth client store seeded with ${this.clients.size} client(s)`);
99
+ }
100
+ catch {
101
+ console.error("Failed to parse OAUTH_KNOWN_CLIENTS — must be a JSON array");
102
+ }
103
+ }
104
+ persist() {
105
+ if (this.writeDisabled)
106
+ return;
107
+ try {
108
+ mkdirSync(dirname(this.file), { recursive: true });
109
+ // Write-then-rename so a crash mid-write cannot leave a truncated file that would
110
+ // silently drop every registration on the next boot.
111
+ const tmp = `${this.file}.${process.pid}.tmp`;
112
+ writeFileSync(tmp, JSON.stringify(this.dump(), null, 2), "utf8");
113
+ renameSync(tmp, this.file);
114
+ }
115
+ catch (err) {
116
+ this.writeDisabled = true;
117
+ console.error(`Failed to persist OAuth client store to ${this.file} — registrations will be lost on restart:`, err);
118
+ }
119
+ }
120
+ }
@@ -1,6 +1,6 @@
1
1
  import type { Response } from "express";
2
2
  import type { OAuthServerProvider, AuthorizationParams } from "@modelcontextprotocol/sdk/server/auth/provider.js";
3
- import type { OAuthRegisteredClientsStore } from "@modelcontextprotocol/sdk/server/auth/clients.js";
3
+ import { FileClientsStore } from "./client-store.js";
4
4
  import type { OAuthClientInformationFull, OAuthTokens, OAuthTokenRevocationRequest } from "@modelcontextprotocol/sdk/shared/auth.js";
5
5
  import type { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
6
6
  /**
@@ -28,15 +28,8 @@ export declare class ConnectionMintDeniedError extends Error {
28
28
  export declare function connectionModeKey(token: string): string;
29
29
  /** Decode the `sub` claim from a JWT payload without verifying the signature. */
30
30
  export declare function decodeJwtSub(jwt: string): string | undefined;
31
- declare class InMemoryClientsStore implements OAuthRegisteredClientsStore {
32
- private clients;
33
- constructor();
34
- getClient(clientId: string): OAuthClientInformationFull | undefined;
35
- registerClient(client: Omit<OAuthClientInformationFull, "client_id" | "client_id_issued_at">): OAuthClientInformationFull;
36
- dump(): OAuthClientInformationFull[];
37
- }
38
31
  export declare class InistateOAuthProvider implements OAuthServerProvider {
39
- readonly clientsStore: InMemoryClientsStore;
32
+ readonly clientsStore: FileClientsStore;
40
33
  private codes;
41
34
  private pendingAuth;
42
35
  private tokens;
@@ -77,4 +70,3 @@ export declare class InistateOAuthProvider implements OAuthServerProvider {
77
70
  revokeToken(_client: OAuthClientInformationFull, request: OAuthTokenRevocationRequest): Promise<void>;
78
71
  private cleanup;
79
72
  }
80
- export {};
@@ -1,4 +1,5 @@
1
1
  import { createHash, randomUUID } from "node:crypto";
2
+ import { FileClientsStore } from "./client-store.js";
2
3
  import { InvalidGrantError } from "@modelcontextprotocol/sdk/server/auth/errors.js";
3
4
  const CODE_TTL_MS = 5 * 60 * 1000; // 5 minutes
4
5
  const PAT_VERIFY_TTL_MS = 5 * 60 * 1000; // whoami re-check cadence for connection tokens
@@ -98,38 +99,12 @@ function expiresInFromExp(exp) {
98
99
  const remaining = exp - Math.floor(Date.now() / 1000);
99
100
  return remaining > 0 ? remaining : 0;
100
101
  }
101
- class InMemoryClientsStore {
102
- clients = new Map();
103
- constructor() {
104
- const seed = process.env.OAUTH_KNOWN_CLIENTS;
105
- if (seed) {
106
- try {
107
- for (const client of JSON.parse(seed)) {
108
- this.clients.set(client.client_id, client);
109
- }
110
- console.log(`OAuth client store seeded with ${this.clients.size} client(s)`);
111
- }
112
- catch {
113
- console.error("Failed to parse OAUTH_KNOWN_CLIENTS — must be a JSON array");
114
- }
115
- }
116
- }
117
- getClient(clientId) {
118
- return this.clients.get(clientId);
119
- }
120
- registerClient(client) {
121
- const full = {
122
- ...client,
123
- client_id: randomUUID(),
124
- client_id_issued_at: Math.floor(Date.now() / 1000),
125
- };
126
- this.clients.set(full.client_id, full);
127
- return full;
128
- }
129
- dump() {
130
- return [...this.clients.values()];
131
- }
132
- }
102
+ /*
103
+ * SS05806: the clients store used to be a process-local Map, so every restart wiped every
104
+ * DCR-registered client_id and previously-registered connectors got `invalid_client` at
105
+ * /authorize. FileClientsStore keeps the same shape but survives a restart. See client-store.ts
106
+ * for what is deliberately NOT persisted (tokens, codes, pending auths).
107
+ */
133
108
  /* ------------------------------------------------------------------ */
134
109
  /* Provider */
135
110
  /* ------------------------------------------------------------------ */
@@ -144,7 +119,7 @@ export class InistateOAuthProvider {
144
119
  mcpUrl;
145
120
  loginPath;
146
121
  constructor(inistateBaseUrl, appUrl, mcpUrl, loginPath = "/#/login") {
147
- this.clientsStore = new InMemoryClientsStore();
122
+ this.clientsStore = new FileClientsStore();
148
123
  this.baseUrl = inistateBaseUrl.replace(/\/+$/, "");
149
124
  this.appUrl = appUrl.replace(/\/$/, "");
150
125
  this.mcpUrl = mcpUrl;
package/package.json CHANGED
@@ -1,87 +1,87 @@
1
- {
2
- "name": "inistate-mcp",
3
- "mcpName": "io.github.Inistate/inistate-mcp",
4
- "version": "1.1.3",
5
- "description": "MCP server for the Inistate platform — no-code apps creation powered by AI",
6
- "type": "module",
7
- "author": "Inistate",
8
- "homepage": "https://github.com/Inistate/inistate-mcp#readme",
9
- "repository": {
10
- "type": "git",
11
- "url": "git+https://github.com/Inistate/inistate-mcp.git"
12
- },
13
- "bugs": {
14
- "url": "https://github.com/Inistate/inistate-mcp/issues"
15
- },
16
- "keywords": [
17
- "mcp",
18
- "model-context-protocol",
19
- "inistate",
20
- "workflow",
21
- "low-code",
22
- "ai-agent",
23
- "claude"
24
- ],
25
- "bin": {
26
- "inistate-mcp": "build/index.js",
27
- "inistate-mcp-http": "build/http.js"
28
- },
29
- "main": "./build/lib.js",
30
- "types": "./build/lib.d.ts",
31
- "exports": {
32
- ".": {
33
- "types": "./build/lib.d.ts",
34
- "import": "./build/lib.js"
35
- },
36
- "./package.json": "./package.json"
37
- },
38
- "files": [
39
- "build/**/*.js",
40
- "build/**/*.d.ts",
41
- "README.md",
42
- "LICENSE",
43
- "server.json",
44
- "inistate-schema.json",
45
- "facts-module-design-guide.md",
46
- "facts-frontend-guide.md"
47
- ],
48
- "scripts": {
49
- "clean": "rimraf build",
50
- "build": "npm run clean && tsc",
51
- "prepare": "npm run build",
52
- "watch": "tsc --watch",
53
- "test": "vitest run",
54
- "test:watch": "vitest",
55
- "changeset": "changeset",
56
- "version": "npx changeset version && node scripts/sync-server-json.js",
57
- "release:mcp": "npm run test && npm run version && mcp-publisher login github && mcp-publisher publish",
58
- "release:npm": "npm run build && npm run test && npm run version && npm publish",
59
- "release": "npm i && npm run test && npm run version && mcp-publisher validate && npm publish && mcp-publisher login github && mcp-publisher publish",
60
- "sync:server": "node scripts/sync-server-json.js",
61
- "start:http": "node build/http.js",
62
- "inspector": "npx @modelcontextprotocol/inspector build/index.js",
63
- "pm2:start": "pm2 start ecosystem.config.cjs --env production",
64
- "pm2:restart": "pm2 restart inistate-mcp",
65
- "pm2:stop": "pm2 stop inistate-mcp",
66
- "pm2:logs": "pm2 logs inistate-mcp"
67
- },
68
- "dependencies": {
69
- "@iarna/toml": "^2.2.5",
70
- "@modelcontextprotocol/sdk": "^1.27.1",
71
- "dotenv": "^17.3.1",
72
- "express": "^5.2.1",
73
- "zod": "^3.25.0"
74
- },
75
- "devDependencies": {
76
- "@changesets/cli": "^2.31.0",
77
- "@types/express": "^5.0.6",
78
- "@types/iarna__toml": "^2.0.5",
79
- "@types/node": "^22.0.0",
80
- "eslint": "^9.0.0",
81
- "rimraf": "^6.0.0",
82
- "pm2": "^7.0.1",
83
- "typescript": "^5.8.0",
84
- "vitest": "^3.2.4"
85
- },
86
- "license": "Apache-2.0"
87
- }
1
+ {
2
+ "name": "inistate-mcp",
3
+ "mcpName": "io.github.Inistate/inistate-mcp",
4
+ "version": "1.1.4",
5
+ "description": "MCP server for the Inistate platform — no-code apps creation powered by AI",
6
+ "type": "module",
7
+ "author": "Inistate",
8
+ "homepage": "https://github.com/Inistate/inistate-mcp#readme",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Inistate/inistate-mcp.git"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/Inistate/inistate-mcp/issues"
15
+ },
16
+ "keywords": [
17
+ "mcp",
18
+ "model-context-protocol",
19
+ "inistate",
20
+ "workflow",
21
+ "low-code",
22
+ "ai-agent",
23
+ "claude"
24
+ ],
25
+ "bin": {
26
+ "inistate-mcp": "build/index.js",
27
+ "inistate-mcp-http": "build/http.js"
28
+ },
29
+ "main": "./build/lib.js",
30
+ "types": "./build/lib.d.ts",
31
+ "exports": {
32
+ ".": {
33
+ "types": "./build/lib.d.ts",
34
+ "import": "./build/lib.js"
35
+ },
36
+ "./package.json": "./package.json"
37
+ },
38
+ "files": [
39
+ "build/**/*.js",
40
+ "build/**/*.d.ts",
41
+ "README.md",
42
+ "LICENSE",
43
+ "server.json",
44
+ "inistate-schema.json",
45
+ "facts-module-design-guide.md",
46
+ "facts-frontend-guide.md"
47
+ ],
48
+ "scripts": {
49
+ "clean": "rimraf build",
50
+ "build": "npm run clean && tsc",
51
+ "prepare": "npm run build",
52
+ "watch": "tsc --watch",
53
+ "test": "vitest run",
54
+ "test:watch": "vitest",
55
+ "changeset": "changeset",
56
+ "version": "npx changeset version && node scripts/sync-server-json.js",
57
+ "release:mcp": "npm run test && npm run version && mcp-publisher login github && mcp-publisher publish",
58
+ "release:npm": "npm run build && npm run test && npm run version && npm publish",
59
+ "release": "npm i && npm run test && npm run version && mcp-publisher validate && npm publish && mcp-publisher login github && mcp-publisher publish",
60
+ "sync:server": "node scripts/sync-server-json.js",
61
+ "start:http": "node build/http.js",
62
+ "inspector": "npx @modelcontextprotocol/inspector build/index.js",
63
+ "pm2:start": "pm2 start ecosystem.config.cjs --env production",
64
+ "pm2:restart": "pm2 restart inistate-mcp",
65
+ "pm2:stop": "pm2 stop inistate-mcp",
66
+ "pm2:logs": "pm2 logs inistate-mcp"
67
+ },
68
+ "dependencies": {
69
+ "@iarna/toml": "^2.2.5",
70
+ "@modelcontextprotocol/sdk": "^1.27.1",
71
+ "dotenv": "^17.3.1",
72
+ "express": "^5.2.1",
73
+ "zod": "^3.25.0"
74
+ },
75
+ "devDependencies": {
76
+ "@changesets/cli": "^2.31.0",
77
+ "@types/express": "^5.0.6",
78
+ "@types/iarna__toml": "^2.0.5",
79
+ "@types/node": "^22.0.0",
80
+ "eslint": "^9.0.0",
81
+ "rimraf": "^6.0.0",
82
+ "pm2": "^7.0.1",
83
+ "typescript": "^5.8.0",
84
+ "vitest": "^3.2.4"
85
+ },
86
+ "license": "Apache-2.0"
87
+ }
package/server.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
- "name": "io.github.Inistate/inistate-mcp",
4
- "description": "MCP server for the Inistate platform: module discovery, entry management, and activity submission.",
5
- "title": "Inistate MCP",
6
- "websiteUrl": "https://inistate.com",
7
- "repository": {
8
- "url": "https://github.com/inistate/inistate-mcp",
9
- "source": "github"
10
- },
11
- "version": "1.1.3",
12
- "packages": [
13
- {
14
- "registryType": "npm",
15
- "registryBaseUrl": "https://registry.npmjs.org",
16
- "identifier": "inistate-mcp",
17
- "version": "1.1.3",
18
- "transport": {
19
- "type": "stdio"
20
- },
21
- "environmentVariables": [
22
- {
23
- "name": "INISTATE_API_TOKEN",
24
- "description": "Bearer token for Inistate API authentication.",
25
- "isRequired": true,
26
- "isSecret": true
27
- },
28
- {
29
- "name": "INISTATE_API_BASE",
30
- "description": "Inistate API base URL.",
31
- "default": "https://api.inistate.com"
32
- }
33
- ]
34
- }
35
- ],
36
- "remotes": [
37
- {
38
- "type": "streamable-http",
39
- "url": "https://mcp.inistate.com/mcp"
40
- }
41
- ]
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.Inistate/inistate-mcp",
4
+ "description": "MCP server for the Inistate platform: module discovery, entry management, and activity submission.",
5
+ "title": "Inistate MCP",
6
+ "websiteUrl": "https://inistate.com",
7
+ "repository": {
8
+ "url": "https://github.com/inistate/inistate-mcp",
9
+ "source": "github"
10
+ },
11
+ "version": "1.1.4",
12
+ "packages": [
13
+ {
14
+ "registryType": "npm",
15
+ "registryBaseUrl": "https://registry.npmjs.org",
16
+ "identifier": "inistate-mcp",
17
+ "version": "1.1.4",
18
+ "transport": {
19
+ "type": "stdio"
20
+ },
21
+ "environmentVariables": [
22
+ {
23
+ "name": "INISTATE_API_TOKEN",
24
+ "description": "Bearer token for Inistate API authentication.",
25
+ "isRequired": true,
26
+ "isSecret": true
27
+ },
28
+ {
29
+ "name": "INISTATE_API_BASE",
30
+ "description": "Inistate API base URL.",
31
+ "default": "https://api.inistate.com"
32
+ }
33
+ ]
34
+ }
35
+ ],
36
+ "remotes": [
37
+ {
38
+ "type": "streamable-http",
39
+ "url": "https://mcp.inistate.com/mcp"
40
+ }
41
+ ]
42
42
  }