@lightdash-tools/mcp 0.23.0 → 0.25.0

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.
Files changed (87) hide show
  1. package/README.md +2 -2
  2. package/dist/auth/oauth-broker/as-metadata.d.ts +1 -0
  3. package/dist/auth/oauth-broker/as-metadata.js +5 -1
  4. package/dist/auth/oauth-broker/client-crypto.d.ts +12 -0
  5. package/dist/auth/oauth-broker/client-crypto.js +80 -0
  6. package/dist/auth/oauth-broker/client-directory.d.ts +39 -0
  7. package/dist/auth/oauth-broker/client-directory.js +104 -0
  8. package/dist/auth/oauth-broker/client-directory.test.d.ts +1 -0
  9. package/dist/auth/oauth-broker/client-directory.test.js +134 -0
  10. package/dist/auth/oauth-broker/lightdash-token.d.ts +8 -0
  11. package/dist/auth/oauth-broker/lightdash-token.js +72 -8
  12. package/dist/auth/oauth-broker/mcp-access-token.d.ts +3 -0
  13. package/dist/auth/oauth-broker/mcp-access-token.js +9 -1
  14. package/dist/auth/oauth-broker/pending-store.d.ts +16 -4
  15. package/dist/auth/oauth-broker/pending-store.js +40 -18
  16. package/dist/auth/oauth-broker/refresh-crypto.d.ts +19 -0
  17. package/dist/auth/oauth-broker/refresh-crypto.js +70 -0
  18. package/dist/auth/oauth-broker/refresh-crypto.test.d.ts +1 -0
  19. package/dist/auth/oauth-broker/refresh-crypto.test.js +40 -0
  20. package/dist/auth/oauth-broker/refresh-flow.test.d.ts +1 -0
  21. package/dist/auth/oauth-broker/refresh-flow.test.js +350 -0
  22. package/dist/auth/oauth-broker/refresh-grant.d.ts +46 -0
  23. package/dist/auth/oauth-broker/refresh-grant.js +288 -0
  24. package/dist/auth/oauth-broker/refresh-store.conformance.test.d.ts +1 -0
  25. package/dist/auth/oauth-broker/refresh-store.conformance.test.js +254 -0
  26. package/dist/auth/oauth-broker/refresh-store.d.ts +61 -0
  27. package/dist/auth/oauth-broker/refresh-store.js +124 -0
  28. package/dist/auth/oauth-broker/routes.d.ts +6 -4
  29. package/dist/auth/oauth-broker/routes.js +114 -51
  30. package/dist/auth/oauth-broker/routes.test.js +48 -0
  31. package/dist/auth/oauth-broker/stores/client-kv.d.ts +46 -0
  32. package/dist/auth/oauth-broker/stores/client-kv.js +182 -0
  33. package/dist/auth/oauth-broker/stores/firestore.d.ts +29 -0
  34. package/dist/auth/oauth-broker/stores/firestore.js +201 -0
  35. package/dist/auth/oauth-broker/stores/open-client-directory.d.ts +4 -0
  36. package/dist/auth/oauth-broker/stores/open-client-directory.js +30 -0
  37. package/dist/auth/oauth-broker/stores/open-refresh-store.d.ts +4 -0
  38. package/dist/auth/oauth-broker/stores/open-refresh-store.js +24 -0
  39. package/dist/auth/oauth-broker/stores/postgres.d.ts +13 -0
  40. package/dist/auth/oauth-broker/stores/postgres.js +193 -0
  41. package/dist/auth/oauth-broker/stores/redis.d.ts +25 -0
  42. package/dist/auth/oauth-broker/stores/redis.js +337 -0
  43. package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +1 -1
  44. package/dist/config/env.d.ts +13 -0
  45. package/dist/config/env.js +14 -1
  46. package/dist/config/load-mcp-config.d.ts +20 -0
  47. package/dist/config/load-mcp-config.js +53 -1
  48. package/dist/config/load-mcp-config.test.js +53 -0
  49. package/dist/config/oauth-store-key.d.ts +2 -0
  50. package/dist/config/oauth-store-key.js +17 -0
  51. package/dist/policy/content-developer.d.ts +4 -1
  52. package/dist/policy/content-developer.js +7 -3
  53. package/dist/policy/preview-ledger.d.ts +11 -1
  54. package/dist/policy/preview-ledger.js +29 -3
  55. package/dist/policy/rename-rejected.d.ts +9 -0
  56. package/dist/policy/rename-rejected.js +15 -0
  57. package/dist/profiles/content-developer/v1/index.js +6 -0
  58. package/dist/profiles/content-developer/v1/prompt-specs.d.ts +1 -1
  59. package/dist/profiles/content-developer/v1/resources/playbooks/core.md +15 -0
  60. package/dist/profiles/content-developer/v1/resources/playbooks/recovery/preview-stale.md +1 -0
  61. package/dist/profiles/content-reader/v1/prompt-specs.d.ts +1 -1
  62. package/dist/profiles/semantic-layer/v1/prompts.js +3 -3
  63. package/dist/profiles/semantic-layer/v1/resources/playbooks/compose-compile.md +6 -3
  64. package/dist/profiles/semantic-layer/v1/resources/playbooks/core.md +1 -1
  65. package/dist/server/capabilities.d.ts +1 -1
  66. package/dist/stdio.process.test.js +3 -1
  67. package/dist/tools/project/content.js +8 -1
  68. package/dist/tools/project/developer-content.js +1 -1
  69. package/dist/tools/project/developer-helpers.d.ts +1 -0
  70. package/dist/tools/project/developer-helpers.test.js +1 -0
  71. package/dist/tools/project/developer-rename.d.ts +13 -0
  72. package/dist/tools/project/developer-rename.js +319 -0
  73. package/dist/tools/project/developer-rename.test.d.ts +5 -0
  74. package/dist/tools/project/developer-rename.test.js +296 -0
  75. package/dist/tools/project/reader-content.js +10 -3
  76. package/dist/tools/project/rename-instruction.d.ts +58 -0
  77. package/dist/tools/project/rename-instruction.js +104 -0
  78. package/dist/tools/query/reader-tool-helpers.d.ts +1 -1
  79. package/dist/tools/query/reader-tool-helpers.js +4 -0
  80. package/dist/tools/registry.d.ts +1 -1
  81. package/dist/tools/semantic/explore-helpers.d.ts +6 -0
  82. package/dist/tools/semantic/explore-helpers.js +43 -0
  83. package/dist/tools/semantic/explore-helpers.test.js +17 -0
  84. package/dist/tools/semantic/query.js +9 -19
  85. package/dist/tools/semantic/query.test.js +71 -0
  86. package/dist/transports/streamable-http.js +33 -7
  87. package/package.json +13 -9
@@ -0,0 +1,25 @@
1
+ import type { OAuthRefreshConfig } from '../../../config/load-mcp-config.js';
2
+ import type { RefreshStore } from '../refresh-store.js';
3
+ export type RedisExecResult = Array<[Error | null, unknown]> | null;
4
+ export interface RedisMulti {
5
+ set(key: string, value: string, expirySeconds?: number): RedisMulti;
6
+ sadd(key: string, member: string): RedisMulti;
7
+ srem(key: string, member: string): RedisMulti;
8
+ expire(key: string, seconds: number): RedisMulti;
9
+ del(...keys: string[]): RedisMulti;
10
+ exec(): Promise<RedisExecResult>;
11
+ }
12
+ /** Subset of ioredis used by the refresh adapter. Tests can supply the same shape. */
13
+ export interface RedisCommandClient {
14
+ watch(...keys: string[]): Promise<unknown>;
15
+ unwatch(): Promise<unknown>;
16
+ get(key: string): Promise<string | null>;
17
+ smembers(key: string): Promise<string[]>;
18
+ multi(): RedisMulti;
19
+ }
20
+ export declare function createRedisRefreshStore(client: RedisCommandClient, options: {
21
+ maxSessionSeconds: number;
22
+ }): RefreshStore;
23
+ export declare function openRedisRefreshStore(config: Extract<OAuthRefreshConfig, {
24
+ kind: 'redis';
25
+ }>): Promise<RefreshStore>;
@@ -0,0 +1,337 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createRedisRefreshStore = createRedisRefreshStore;
7
+ exports.openRedisRefreshStore = openRedisRefreshStore;
8
+ const ioredis_1 = __importDefault(require("ioredis"));
9
+ const refresh_store_js_1 = require("../refresh-store.js");
10
+ const DATA_PREFIX = 'lightdash-tools:oauth-refresh:';
11
+ const FAMILY_PREFIX = 'lightdash-tools:oauth-refresh-family:';
12
+ const REVOKED_PREFIX = 'lightdash-tools:oauth-refresh-revoked:';
13
+ const MAX_ATTEMPTS = 8;
14
+ function createRedisRefreshStore(client, options) {
15
+ return new RedisRefreshStore(client, options.maxSessionSeconds);
16
+ }
17
+ async function openRedisRefreshStore(config) {
18
+ const client = new ioredis_1.default(config.redisUrl.expose(), {
19
+ lazyConnect: true,
20
+ maxRetriesPerRequest: 2,
21
+ enableOfflineQueue: false,
22
+ });
23
+ client.on('error', (error) => {
24
+ console.error(`Redis refresh client error (${(0, refresh_store_js_1.storeErrorCode)(error)})`);
25
+ });
26
+ try {
27
+ await client.connect();
28
+ await client.ping();
29
+ }
30
+ catch (error) {
31
+ client.disconnect();
32
+ console.error(`Redis refresh store connection failed (${(0, refresh_store_js_1.storeErrorCode)(error)})`);
33
+ throw new Error('Redis refresh store is unavailable');
34
+ }
35
+ const store = createRedisRefreshStore(asRedisCommandClient(client), {
36
+ maxSessionSeconds: config.maxSessionSeconds,
37
+ });
38
+ return (0, refresh_store_js_1.withClose)(store, async () => {
39
+ await client.quit();
40
+ });
41
+ }
42
+ class RedisRefreshStore {
43
+ constructor(client, maxSessionSeconds) {
44
+ this.client = client;
45
+ this.maxSessionSeconds = maxSessionSeconds;
46
+ this.chain = Promise.resolve();
47
+ this.dirtyWatch = false;
48
+ }
49
+ async put(handleDigest, record) {
50
+ const key = dataKey(handleDigest);
51
+ const familyKey = familySetKey(record.familyId);
52
+ const revokedKey = revokedDataKey(record.familyId);
53
+ const ttl = this.ttlSeconds(record.firstIssuedAtMs);
54
+ if (ttl <= 0) {
55
+ throw new refresh_store_js_1.RefreshStoreError('Refresh session has ended');
56
+ }
57
+ await this.failAsStore(async () => {
58
+ for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt += 1) {
59
+ await this.watch(revokedKey);
60
+ const revoked = await this.client.get(revokedKey);
61
+ if (revoked !== null) {
62
+ await this.unwatch();
63
+ throw new refresh_store_js_1.RefreshStoreError('Refresh family is revoked');
64
+ }
65
+ const multi = this.client.multi();
66
+ multi.set(key, JSON.stringify(toPayload(record, false)), ttl);
67
+ multi.sadd(familyKey, handleDigest);
68
+ multi.expire(familyKey, ttl);
69
+ const result = await this.commit(multi);
70
+ if (result !== null)
71
+ return;
72
+ }
73
+ throw new refresh_store_js_1.RefreshStoreError('Redis refresh put was not applied');
74
+ });
75
+ }
76
+ async consume(handleDigest) {
77
+ const key = dataKey(handleDigest);
78
+ return this.failAsStore(async () => {
79
+ const updated = await this.compareAndSet(key, (payload, revoked) => {
80
+ if (revoked !== null)
81
+ return { write: false, drop: true, payload };
82
+ if (payload.consumed)
83
+ return { write: false, payload };
84
+ return { write: true, payload: Object.assign(Object.assign({}, payload), { consumed: true }) };
85
+ }, (payload) => revokedDataKey(payload.familyId));
86
+ if (updated === 'missing')
87
+ return { status: 'missing' };
88
+ if (!updated.wrote) {
89
+ if (updated.drop)
90
+ await this.commit(this.client.multi().del(key));
91
+ return { status: 'reused', record: toRecord(updated.payload) };
92
+ }
93
+ return { status: 'ok', record: toRecord(updated.payload) };
94
+ });
95
+ }
96
+ async release(handleDigest) {
97
+ const key = dataKey(handleDigest);
98
+ await this.failAsStore(async () => {
99
+ await this.compareAndSet(key, (payload) => ({
100
+ write: true,
101
+ payload: Object.assign(Object.assign({}, payload), { consumed: false }),
102
+ }));
103
+ });
104
+ }
105
+ async revokeFamily(familyId) {
106
+ const familyKey = familySetKey(familyId);
107
+ await this.failAsStore(async () => {
108
+ for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt += 1) {
109
+ await this.watch(familyKey);
110
+ const members = await this.client.smembers(familyKey);
111
+ const multi = this.client.multi();
112
+ multi.set(revokedDataKey(familyId), '1', this.maxSessionSeconds);
113
+ if (members.length > 0) {
114
+ multi.del(...members.map((digest) => dataKey(digest)));
115
+ }
116
+ multi.del(familyKey);
117
+ const applied = await this.commit(multi);
118
+ if (applied !== null)
119
+ return;
120
+ }
121
+ throw new refresh_store_js_1.RefreshStoreError('Redis refresh revoke was not applied');
122
+ });
123
+ }
124
+ async delete(handleDigest) {
125
+ const key = dataKey(handleDigest);
126
+ await this.failAsStore(async () => {
127
+ const raw = await this.client.get(key);
128
+ const multi = this.client.multi();
129
+ if (raw !== null) {
130
+ const familyId = tryReadFamilyId(raw);
131
+ if (familyId !== undefined)
132
+ multi.srem(familySetKey(familyId), handleDigest);
133
+ }
134
+ multi.del(key);
135
+ await this.commit(multi);
136
+ });
137
+ }
138
+ /**
139
+ * One Redis connection cannot interleave two WATCH/MULTI transactions.
140
+ * Serialize them in-process. Other replicas still rely on WATCH.
141
+ */
142
+ async failAsStore(fn) {
143
+ const run = this.chain.then(() => (0, refresh_store_js_1.wrapStoreError)('Redis refresh store request failed', async () => {
144
+ if (this.dirtyWatch)
145
+ await this.unwatch();
146
+ return fn();
147
+ }));
148
+ this.chain = run.then(() => undefined, () => undefined);
149
+ return run;
150
+ }
151
+ async watch(...keys) {
152
+ this.dirtyWatch = true;
153
+ await this.client.watch(...keys);
154
+ }
155
+ async unwatch() {
156
+ await this.client.unwatch();
157
+ this.dirtyWatch = false;
158
+ }
159
+ async commit(multi) {
160
+ const result = await multi.exec();
161
+ this.dirtyWatch = false;
162
+ if (result === null)
163
+ return null;
164
+ for (const [error] of result) {
165
+ if (error !== null) {
166
+ throw new refresh_store_js_1.RefreshStoreError('Redis refresh transaction command failed', { cause: error });
167
+ }
168
+ }
169
+ return result;
170
+ }
171
+ async compareAndSet(key, decide, relatedKey) {
172
+ for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt += 1) {
173
+ const decision = await this.readForUpdate(key, decide, relatedKey);
174
+ if (decision === 'missing')
175
+ return 'missing';
176
+ if (!decision.write) {
177
+ return { payload: decision.payload, wrote: false, drop: decision.drop };
178
+ }
179
+ const stored = await this.writePayload(key, decision.payload);
180
+ if (stored)
181
+ return { payload: decision.payload, wrote: true };
182
+ }
183
+ throw new refresh_store_js_1.RefreshStoreError('Redis refresh update conflicted');
184
+ }
185
+ async readForUpdate(key, decide, relatedKey) {
186
+ await this.watch(key);
187
+ const raw = await this.client.get(key);
188
+ if (raw === null) {
189
+ await this.unwatch();
190
+ return 'missing';
191
+ }
192
+ const payload = parsePayload(raw);
193
+ const extra = relatedKey === null || relatedKey === void 0 ? void 0 : relatedKey(payload);
194
+ if (extra !== undefined)
195
+ await this.watch(extra);
196
+ const related = extra === undefined ? null : await this.client.get(extra);
197
+ const decision = decide(payload, related);
198
+ if (!decision.write)
199
+ await this.unwatch();
200
+ return decision;
201
+ }
202
+ /** Keeps a consumed payload until the grant applies the session cap. */
203
+ async writePayload(key, payload) {
204
+ const ttl = Math.max(1, this.ttlSeconds(payload.firstIssuedAtMs));
205
+ const result = await this.commit(this.client.multi().set(key, JSON.stringify(payload), ttl));
206
+ return result !== null;
207
+ }
208
+ /** Seconds until the session cap. Zero means the cap has already passed. */
209
+ ttlSeconds(firstIssuedAtMs) {
210
+ const remainingMs = (0, refresh_store_js_1.sessionEndMs)(firstIssuedAtMs, this.maxSessionSeconds) - Date.now();
211
+ if (remainingMs <= 0)
212
+ return 0;
213
+ return Math.ceil(remainingMs / 1000);
214
+ }
215
+ }
216
+ function asRedisCommandClient(client) {
217
+ let connectionEpoch = 0;
218
+ let watchedEpoch;
219
+ client.on('close', () => {
220
+ connectionEpoch += 1;
221
+ });
222
+ return {
223
+ watch: (...keys) => {
224
+ watchedEpoch = connectionEpoch;
225
+ return client.watch(...keys);
226
+ },
227
+ unwatch: () => {
228
+ watchedEpoch = undefined;
229
+ return client.unwatch();
230
+ },
231
+ get: (key) => client.get(key),
232
+ smembers: (key) => client.smembers(key),
233
+ multi() {
234
+ const pending = client.multi();
235
+ const wrapped = {
236
+ set(key, value, expirySeconds) {
237
+ if (expirySeconds === undefined)
238
+ pending.set(key, value);
239
+ else
240
+ pending.set(key, value, 'EX', expirySeconds);
241
+ return wrapped;
242
+ },
243
+ sadd(key, member) {
244
+ pending.sadd(key, member);
245
+ return wrapped;
246
+ },
247
+ srem(key, member) {
248
+ pending.srem(key, member);
249
+ return wrapped;
250
+ },
251
+ expire(key, seconds) {
252
+ pending.expire(key, seconds);
253
+ return wrapped;
254
+ },
255
+ del(...keys) {
256
+ pending.del(...keys);
257
+ return wrapped;
258
+ },
259
+ async exec() {
260
+ const startedEpoch = watchedEpoch;
261
+ watchedEpoch = undefined;
262
+ if (startedEpoch !== undefined && startedEpoch !== connectionEpoch) {
263
+ throw new refresh_store_js_1.RefreshStoreError('Redis connection reset during watched transaction');
264
+ }
265
+ return pending.exec();
266
+ },
267
+ };
268
+ return wrapped;
269
+ },
270
+ };
271
+ }
272
+ function tryReadFamilyId(raw) {
273
+ try {
274
+ return parsePayload(raw).familyId;
275
+ }
276
+ catch (_a) {
277
+ return undefined;
278
+ }
279
+ }
280
+ function dataKey(digest) {
281
+ return `${DATA_PREFIX}${digest}`;
282
+ }
283
+ function familySetKey(familyId) {
284
+ return `${FAMILY_PREFIX}${familyId}`;
285
+ }
286
+ function revokedDataKey(familyId) {
287
+ return `${REVOKED_PREFIX}${familyId}`;
288
+ }
289
+ function toPayload(record, consumed) {
290
+ var _a;
291
+ return {
292
+ familyId: record.familyId,
293
+ firstIssuedAtMs: record.firstIssuedAtMs,
294
+ clientId: record.clientId,
295
+ resource: record.resource,
296
+ scope: (_a = record.scope) !== null && _a !== void 0 ? _a : null,
297
+ encryptedRefreshToken: record.encryptedRefreshToken,
298
+ consumed,
299
+ };
300
+ }
301
+ function toRecord(payload) {
302
+ var _a;
303
+ return {
304
+ familyId: payload.familyId,
305
+ firstIssuedAtMs: payload.firstIssuedAtMs,
306
+ clientId: payload.clientId,
307
+ resource: payload.resource,
308
+ scope: (_a = payload.scope) !== null && _a !== void 0 ? _a : undefined,
309
+ encryptedRefreshToken: payload.encryptedRefreshToken,
310
+ };
311
+ }
312
+ function parsePayload(raw) {
313
+ let parsed;
314
+ try {
315
+ parsed = JSON.parse(raw);
316
+ }
317
+ catch (error) {
318
+ throw new refresh_store_js_1.RefreshStoreError('Invalid Redis refresh payload', { cause: error });
319
+ }
320
+ if (!isPayload(parsed)) {
321
+ throw new refresh_store_js_1.RefreshStoreError('Invalid Redis refresh payload');
322
+ }
323
+ return parsed;
324
+ }
325
+ function isPayload(value) {
326
+ if (typeof value !== 'object' || value === null)
327
+ return false;
328
+ const record = value;
329
+ return (typeof record.familyId === 'string' &&
330
+ typeof record.firstIssuedAtMs === 'number' &&
331
+ Number.isSafeInteger(record.firstIssuedAtMs) &&
332
+ typeof record.clientId === 'string' &&
333
+ typeof record.resource === 'string' &&
334
+ (record.scope === null || typeof record.scope === 'string') &&
335
+ typeof record.encryptedRefreshToken === 'string' &&
336
+ typeof record.consumed === 'boolean');
337
+ }
@@ -1,5 +1,5 @@
1
- import type { ValidatedLightdashUser } from './lightdash-token-validation.js';
2
1
  import type { McpHttpConfig } from '../../config/load-mcp-config.js';
2
+ import type { ValidatedLightdashUser } from './lightdash-token-validation.js';
3
3
  import type { IncomingMessage, ServerResponse } from 'node:http';
4
4
  export interface OAuthAuthSuccess {
5
5
  ok: true;
@@ -35,6 +35,19 @@ export declare const ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS = "LI
35
35
  /** Lightdash OAuth application credentials (server-held confidential client). */
36
36
  export declare const ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = "LIGHTDASH_TOOLS_OAUTH_CLIENT_ID";
37
37
  export declare const ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = "LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET";
38
+ /**
39
+ * Optional refresh store (ADR-0037): `postgres` | `redis` | `firestore`.
40
+ * Unset keeps refresh off. Distinct from the obsolete `LIGHTDASH_TOOLS_MCP_STORE`.
41
+ */
42
+ export declare const ENV_LIGHTDASH_TOOLS_OAUTH_STORE = "LIGHTDASH_TOOLS_OAUTH_STORE";
43
+ /** Base64-encoded 32-byte AES key for refresh tokens at rest. Required when the store is set. */
44
+ export declare const ENV_LIGHTDASH_TOOLS_OAUTH_STORE_KEY = "LIGHTDASH_TOOLS_OAUTH_STORE_KEY";
45
+ /** Absolute MCP session cap in seconds. Required when the store is set. No default. */
46
+ export declare const ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS = "LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS";
47
+ export declare const ENV_LIGHTDASH_TOOLS_OAUTH_STORE_POSTGRES_URL = "LIGHTDASH_TOOLS_OAUTH_STORE_POSTGRES_URL";
48
+ export declare const ENV_LIGHTDASH_TOOLS_OAUTH_STORE_REDIS_URL = "LIGHTDASH_TOOLS_OAUTH_STORE_REDIS_URL";
49
+ export declare const ENV_LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_PROJECT = "LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_PROJECT";
50
+ export declare const ENV_LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_COLLECTION = "LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_COLLECTION";
38
51
  /** Obsolete — rejected at startup (ADR-0019 removed Redis store; others are legacy auth flags). */
39
52
  export declare const ENV_LIGHTDASH_TOOLS_MCP_STORE = "LIGHTDASH_TOOLS_MCP_STORE";
40
53
  export declare const ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL = "LIGHTDASH_TOOLS_MCP_REDIS_URL";
@@ -4,7 +4,7 @@
4
4
  * Legacy `MCP_*` aliases are resolved in load-mcp-config.ts.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.OAUTH_AUTHORIZATION_SERVER_METADATA_PATH = exports.OAUTH_REGISTER_PATH = exports.OAUTH_TOKEN_PATH = exports.OAUTH_AUTHORIZE_PATH = exports.OAUTH_CALLBACK_PATH = exports.ENV_MCP_MAX_BODY_BYTES = exports.ENV_MCP_ALLOWED_ORIGINS = exports.ENV_MCP_API_KEY = exports.ENV_MCP_AUTH_ENABLED = exports.ENV_MCP_PUBLIC_URL = exports.ENV_MCP_SERVER_PORT = exports.ENV_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOW_INSECURE_PUBLIC_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_EXPERIMENTAL_IDENTITY_OAUTH = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_ANY_ORIGIN = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_UNAUTHENTICATED = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_GRANT_ALL_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_SKIP_TOKEN_VALIDATION = exports.ENV_LIGHTDASH_TOOLS_MCP_INSECURE_DEV = exports.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_STORE = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = exports.ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS = exports.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN = exports.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED = exports.ENV_LIGHTDASH_TOOLS_MCP_REQUIRED_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOWED_ORIGINS = exports.ENV_LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY = exports.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = exports.ENV_LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT = exports.ENV_LIGHTDASH_TOOLS_MCP_PROFILES = exports.ENV_LIGHTDASH_TOOLS_MCP_PATH = exports.ENV_LIGHTDASH_TOOLS_MCP_INVOKE_ORIGINS = exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = exports.ENV_PLATFORM_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST = void 0;
7
+ exports.OAUTH_AUTHORIZATION_SERVER_METADATA_PATH = exports.OAUTH_REGISTER_PATH = exports.OAUTH_TOKEN_PATH = exports.OAUTH_AUTHORIZE_PATH = exports.OAUTH_CALLBACK_PATH = exports.ENV_MCP_MAX_BODY_BYTES = exports.ENV_MCP_ALLOWED_ORIGINS = exports.ENV_MCP_API_KEY = exports.ENV_MCP_AUTH_ENABLED = exports.ENV_MCP_PUBLIC_URL = exports.ENV_MCP_SERVER_PORT = exports.ENV_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOW_INSECURE_PUBLIC_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_EXPERIMENTAL_IDENTITY_OAUTH = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_ANY_ORIGIN = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_ALLOW_UNAUTHENTICATED = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_GRANT_ALL_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_DANGEROUSLY_SKIP_TOKEN_VALIDATION = exports.ENV_LIGHTDASH_TOOLS_MCP_INSECURE_DEV = exports.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_STORE = exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_COLLECTION = exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_PROJECT = exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_REDIS_URL = exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_POSTGRES_URL = exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS = exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_KEY = exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = exports.ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS = exports.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN = exports.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED = exports.ENV_LIGHTDASH_TOOLS_MCP_REQUIRED_SCOPES = exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES = exports.ENV_LIGHTDASH_TOOLS_MCP_ALLOWED_ORIGINS = exports.ENV_LIGHTDASH_TOOLS_MCP_REQUEST_STATE_KEY = exports.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = exports.ENV_LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT = exports.ENV_LIGHTDASH_TOOLS_MCP_PROFILES = exports.ENV_LIGHTDASH_TOOLS_MCP_PATH = exports.ENV_LIGHTDASH_TOOLS_MCP_INVOKE_ORIGINS = exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = exports.ENV_PLATFORM_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST = void 0;
8
8
  exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST = 'LIGHTDASH_TOOLS_MCP_HTTP_HOST';
9
9
  exports.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT = 'LIGHTDASH_TOOLS_MCP_HTTP_PORT';
10
10
  /** Platform listen port (Cloud Run / many PaaS). Used only when dedicated MCP port env is unset. */
@@ -38,6 +38,19 @@ exports.ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS = 'LIGHTDASH_TOOLS
38
38
  /** Lightdash OAuth application credentials (server-held confidential client). */
39
39
  exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_ID = 'LIGHTDASH_TOOLS_OAUTH_CLIENT_ID';
40
40
  exports.ENV_LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET = 'LIGHTDASH_TOOLS_OAUTH_CLIENT_SECRET';
41
+ /**
42
+ * Optional refresh store (ADR-0037): `postgres` | `redis` | `firestore`.
43
+ * Unset keeps refresh off. Distinct from the obsolete `LIGHTDASH_TOOLS_MCP_STORE`.
44
+ */
45
+ exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE = 'LIGHTDASH_TOOLS_OAUTH_STORE';
46
+ /** Base64-encoded 32-byte AES key for refresh tokens at rest. Required when the store is set. */
47
+ exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_KEY = 'LIGHTDASH_TOOLS_OAUTH_STORE_KEY';
48
+ /** Absolute MCP session cap in seconds. Required when the store is set. No default. */
49
+ exports.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS = 'LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS';
50
+ exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_POSTGRES_URL = 'LIGHTDASH_TOOLS_OAUTH_STORE_POSTGRES_URL';
51
+ exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_REDIS_URL = 'LIGHTDASH_TOOLS_OAUTH_STORE_REDIS_URL';
52
+ exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_PROJECT = 'LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_PROJECT';
53
+ exports.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_COLLECTION = 'LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_COLLECTION';
41
54
  /** Obsolete — rejected at startup (ADR-0019 removed Redis store; others are legacy auth flags). */
42
55
  exports.ENV_LIGHTDASH_TOOLS_MCP_STORE = 'LIGHTDASH_TOOLS_MCP_STORE';
43
56
  exports.ENV_LIGHTDASH_TOOLS_MCP_REDIS_URL = 'LIGHTDASH_TOOLS_MCP_REDIS_URL';
@@ -2,6 +2,24 @@ import { SecretString } from '@lightdash-tools/client';
2
2
  import { type EnabledProfilesPolicy } from './enabled-profiles.js';
3
3
  import { type PromptContextPolicy } from './prompt-context-policy.js';
4
4
  import type { McpAuthMode } from '../auth/auth-mode.js';
5
+ /** Fields the refresh grant reads. The store connection lives on `OAuthRefreshConfig`. */
6
+ export interface OAuthRefreshPolicy {
7
+ /** Base64 store key. Decode with `decodeStoreKey` at use. */
8
+ key: SecretString;
9
+ maxSessionSeconds: number;
10
+ }
11
+ /** Opt-in refresh persistence (ADR-0037). Absent when `LIGHTDASH_TOOLS_OAUTH_STORE` is unset. */
12
+ export type OAuthRefreshConfig = (OAuthRefreshPolicy & {
13
+ kind: 'firestore';
14
+ firestoreProjectId: string;
15
+ firestoreCollection: string;
16
+ }) | (OAuthRefreshPolicy & {
17
+ kind: 'postgres';
18
+ postgresUrl: SecretString;
19
+ }) | (OAuthRefreshPolicy & {
20
+ kind: 'redis';
21
+ redisUrl: SecretString;
22
+ });
5
23
  export interface McpHttpConfig {
6
24
  lightdashUrl: string;
7
25
  proxyAuthorization?: SecretString;
@@ -21,6 +39,8 @@ export interface McpHttpConfig {
21
39
  oauthClientId?: string;
22
40
  /** Server-held Lightdash OAuth application client secret (broker mode). */
23
41
  oauthClientSecret?: SecretString;
42
+ /** Set only when optional refresh storage is enabled. */
43
+ oauthRefresh?: OAuthRefreshConfig;
24
44
  allowedOrigins: string[];
25
45
  maxBodyBytes: number;
26
46
  requiredScopes: string[];
@@ -11,6 +11,7 @@ const index_js_1 = require("../profiles/index.js");
11
11
  const enabled_profiles_js_1 = require("./enabled-profiles.js");
12
12
  const env_js_1 = require("./env.js");
13
13
  const normalize_url_js_1 = require("./normalize-url.js");
14
+ const oauth_store_key_js_1 = require("./oauth-store-key.js");
14
15
  const obsolete_env_js_1 = require("./obsolete-env.js");
15
16
  const prompt_context_policy_js_1 = require("./prompt-context-policy.js");
16
17
  const public_url_js_1 = require("./public-url.js");
@@ -231,6 +232,57 @@ function resolveOAuthCredentials(authMode, oauthClientId, oauthClientSecretRaw)
231
232
  : undefined,
232
233
  };
233
234
  }
235
+ function isOAuthRefreshStoreKind(value) {
236
+ return value === 'postgres' || value === 'redis' || value === 'firestore';
237
+ }
238
+ function requireRefreshEnv(name, env) {
239
+ const value = (0, read_env_js_1.readEnv)(name, env);
240
+ if (!value) {
241
+ throw new Error(`${name} is required when ${env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE} is set`);
242
+ }
243
+ return value;
244
+ }
245
+ function resolveOAuthRefresh(env, authMode) {
246
+ const kindRaw = (0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE, env);
247
+ if (kindRaw === undefined)
248
+ return undefined;
249
+ if (authMode !== auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH) {
250
+ throw new Error(`${env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE} requires hosted OAuth credentials`);
251
+ }
252
+ if (!isOAuthRefreshStoreKind(kindRaw)) {
253
+ throw new Error(`${env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE} must be postgres, redis, or firestore`);
254
+ }
255
+ const keyRaw = requireRefreshEnv(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_KEY, env);
256
+ try {
257
+ (0, oauth_store_key_js_1.decodeStoreKey)(keyRaw);
258
+ }
259
+ catch (_a) {
260
+ throw new Error(`${env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_KEY} must be a base64-encoded 32-byte key`);
261
+ }
262
+ const maxRaw = requireRefreshEnv(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS, env);
263
+ const maxSessionSeconds = parsePositiveIntegerEnv(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS, maxRaw);
264
+ if (!Number.isSafeInteger(maxSessionSeconds) ||
265
+ maxSessionSeconds < 1 ||
266
+ maxSessionSeconds > 3153600000) {
267
+ throw new Error(`${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS} must be a positive integer`);
268
+ }
269
+ return refreshConfigForKind(kindRaw, { key: new client_1.SecretString(keyRaw), maxSessionSeconds }, env);
270
+ }
271
+ function refreshConfigForKind(kind, policy, env) {
272
+ var _a;
273
+ switch (kind) {
274
+ case 'postgres':
275
+ return Object.assign(Object.assign({}, policy), { kind, postgresUrl: new client_1.SecretString(requireRefreshEnv(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_POSTGRES_URL, env)) });
276
+ case 'redis':
277
+ return Object.assign(Object.assign({}, policy), { kind, redisUrl: new client_1.SecretString(requireRefreshEnv(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_REDIS_URL, env)) });
278
+ case 'firestore':
279
+ return Object.assign(Object.assign({}, policy), { kind, firestoreProjectId: requireRefreshEnv(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_PROJECT, env), firestoreCollection: (_a = (0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_COLLECTION, env)) !== null && _a !== void 0 ? _a : 'oauth_refresh' });
280
+ default: {
281
+ const unreachable = kind;
282
+ return unreachable;
283
+ }
284
+ }
285
+ }
234
286
  /**
235
287
  * Load Streamable HTTP MCP config from env.
236
288
  * When `options.promptContextPolicy` is set (CLI path), that value wins and
@@ -279,7 +331,7 @@ function loadMcpHttpConfig(env = process.env, options) {
279
331
  mcpPath,
280
332
  enabledProfiles,
281
333
  promptContextPolicy,
282
- authMode, sharedKey: sharedKeyRaw ? new client_1.SecretString(sharedKeyRaw) : undefined }, resolveOAuthCredentials(authMode, oauthClientId, oauthClientSecretRaw)), { allowedOrigins, maxBodyBytes: readNumberEnv(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES, [{ name: env_js_1.ENV_MCP_MAX_BODY_BYTES, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES }], 1024 * 1024), requiredScopes, scopesSupported: readScopeList(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED, authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH ? [] : [...DEFAULT_SCOPES_SUPPORTED]), validateToken, tokenValidationCacheTtlMs: readNumberEnv(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS, [], 10000) });
334
+ authMode, sharedKey: sharedKeyRaw ? new client_1.SecretString(sharedKeyRaw) : undefined }, resolveOAuthCredentials(authMode, oauthClientId, oauthClientSecretRaw)), { oauthRefresh: resolveOAuthRefresh(env, authMode), allowedOrigins, maxBodyBytes: readNumberEnv(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES, [{ name: env_js_1.ENV_MCP_MAX_BODY_BYTES, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_BODY_BYTES }], 1024 * 1024), requiredScopes, scopesSupported: readScopeList(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED, authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH ? [] : [...DEFAULT_SCOPES_SUPPORTED]), validateToken, tokenValidationCacheTtlMs: readNumberEnv(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_TOKEN_VALIDATION_CACHE_TTL_MS, [], 10000) });
283
335
  }
284
336
  function requiresLightdashApiKey(authMode) {
285
337
  return authMode === auth_mode_js_1.MCP_AUTH_MODE_NONE || authMode === auth_mode_js_1.MCP_AUTH_MODE_SHARED_KEY;
@@ -323,4 +323,57 @@ function setOAuthCreds() {
323
323
  (0, vitest_1.expect)(config.authMode).toBe('lightdash-oauth');
324
324
  (0, vitest_1.expect)(config.allowedOrigins).toEqual([]);
325
325
  });
326
+ (0, vitest_1.it)('leaves refresh disabled when the store env is unset', () => {
327
+ setOAuthCreds();
328
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
329
+ (0, vitest_1.expect)(config.oauthRefresh).toBeUndefined();
330
+ });
331
+ (0, vitest_1.it)('requires the store key, session cap, and connection when refresh is enabled', () => {
332
+ var _a, _b, _c;
333
+ setOAuthCreds();
334
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE] = 'postgres';
335
+ (0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_KEY);
336
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_KEY] = Buffer.alloc(32, 4).toString('base64');
337
+ (0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS);
338
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS] = '3600';
339
+ (0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_POSTGRES_URL);
340
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_POSTGRES_URL] = 'postgres://localhost/refresh';
341
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
342
+ (0, vitest_1.expect)((_a = config.oauthRefresh) === null || _a === void 0 ? void 0 : _a.kind).toBe('postgres');
343
+ (0, vitest_1.expect)((_b = config.oauthRefresh) === null || _b === void 0 ? void 0 : _b.maxSessionSeconds).toBe(3600);
344
+ if (((_c = config.oauthRefresh) === null || _c === void 0 ? void 0 : _c.kind) !== 'postgres') {
345
+ throw new Error('expected the postgres refresh store');
346
+ }
347
+ (0, vitest_1.expect)(config.oauthRefresh.postgresUrl.expose()).toBe('postgres://localhost/refresh');
348
+ });
349
+ (0, vitest_1.it)('rejects a store key that is not 32 bytes', () => {
350
+ setOAuthCreds();
351
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE] = 'redis';
352
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_KEY] = 'short';
353
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS] = '60';
354
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_REDIS_URL] = 'redis://localhost:6379';
355
+ (0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_KEY);
356
+ });
357
+ (0, vitest_1.it)('rejects refresh storage without hosted OAuth', () => {
358
+ process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
359
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE] = 'redis';
360
+ (0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE);
361
+ });
362
+ (0, vitest_1.it)('loads firestore refresh storage with the default collection and rejects unsafe session caps', () => {
363
+ var _a, _b;
364
+ setOAuthCreds();
365
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE] = 'firestore';
366
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_KEY] = Buffer.alloc(32, 4).toString('base64');
367
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS] = '86400';
368
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_OAUTH_STORE_FIRESTORE_PROJECT] = 'demo-project';
369
+ const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
370
+ (0, vitest_1.expect)((_a = config.oauthRefresh) === null || _a === void 0 ? void 0 : _a.kind).toBe('firestore');
371
+ if (((_b = config.oauthRefresh) === null || _b === void 0 ? void 0 : _b.kind) !== 'firestore') {
372
+ throw new Error('expected the firestore refresh store');
373
+ }
374
+ (0, vitest_1.expect)(config.oauthRefresh.firestoreProjectId).toBe('demo-project');
375
+ (0, vitest_1.expect)(config.oauthRefresh.firestoreCollection).toBe('oauth_refresh');
376
+ process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS] = '999999999999999';
377
+ (0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_MAX_SESSION_SECONDS);
378
+ });
326
379
  });
@@ -0,0 +1,2 @@
1
+ /** Decodes a standard or URL-safe base64 32-byte store key. */
2
+ export declare function decodeStoreKey(encoded: string): Buffer;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.decodeStoreKey = decodeStoreKey;
4
+ const KEY_BYTES = 32;
5
+ /** Decodes a standard or URL-safe base64 32-byte store key. */
6
+ function decodeStoreKey(encoded) {
7
+ const trimmed = encoded.trim();
8
+ const decoded = [Buffer.from(trimmed, 'base64'), Buffer.from(trimmed, 'base64url')];
9
+ for (const key of decoded) {
10
+ if (key.length !== KEY_BYTES)
11
+ continue;
12
+ if (trimmed === key.toString('base64') || trimmed === key.toString('base64url')) {
13
+ return key;
14
+ }
15
+ }
16
+ throw new Error('OAuth store key must be 32 bytes, base64-encoded');
17
+ }
@@ -35,6 +35,9 @@ export declare function registerContentDeveloperTool(server: McpServer, shortNam
35
35
  * throwing PreviewLedgerError (adds recovery extras when the code is known).
36
36
  */
37
37
  export declare function developerCodedErrorResult(code: string, message: string): TextContent;
38
- /** Map ProjectScopeError / PreviewLedgerError to a coded tool error result; rethrow anything else. */
38
+ /**
39
+ * Map ProjectScopeError / PreviewLedgerError / RenameRejectedError to a coded tool error
40
+ * result; rethrow anything else.
41
+ */
39
42
  export declare function developerErrorResult(err: unknown): TextContent;
40
43
  export {};
@@ -16,6 +16,7 @@ const playbook_resources_js_1 = require("../profiles/lib/playbook-resources.js")
16
16
  const reader_tool_helpers_js_1 = require("../tools/query/reader-tool-helpers.js");
17
17
  const shared_js_1 = require("../tools/shared.js");
18
18
  const preview_ledger_js_1 = require("./preview-ledger.js");
19
+ const rename_rejected_js_1 = require("./rename-rejected.js");
19
20
  const MUTABILITY_WRITE_NONDESTRUCTIVE = 'write-nondestructive';
20
21
  /** Discovery / passthrough reads (get_project, search_content, list_spaces, ...). */
21
22
  exports.DISCOVERY_SAFETY = {
@@ -96,7 +97,7 @@ const PREVIEW_RECOVERY_EXTRAS = {
96
97
  },
97
98
  };
98
99
  function recoveryExtrasForPreviewCode(code) {
99
- // eslint-disable-next-line security/detect-object-injection -- keys from PreviewLedgerError codes
100
+ // eslint-disable-next-line security/detect-object-injection -- keys from PreviewLedgerError and RenameRejectedError codes
100
101
  return PREVIEW_RECOVERY_EXTRAS[code];
101
102
  }
102
103
  /**
@@ -106,9 +107,12 @@ function recoveryExtrasForPreviewCode(code) {
106
107
  function developerCodedErrorResult(code, message) {
107
108
  return (0, reader_tool_helpers_js_1.codedErrorResult)(code, message, recoveryExtrasForPreviewCode(code));
108
109
  }
109
- /** Map ProjectScopeError / PreviewLedgerError to a coded tool error result; rethrow anything else. */
110
+ /**
111
+ * Map ProjectScopeError / PreviewLedgerError / RenameRejectedError to a coded tool error
112
+ * result; rethrow anything else.
113
+ */
110
114
  function developerErrorResult(err) {
111
- if (err instanceof preview_ledger_js_1.PreviewLedgerError) {
115
+ if (err instanceof preview_ledger_js_1.PreviewLedgerError || err instanceof rename_rejected_js_1.RenameRejectedError) {
112
116
  return developerCodedErrorResult(err.code, err.message);
113
117
  }
114
118
  return (0, reader_tool_helpers_js_1.projectScopeErrorResult)(err);