@lightdash-tools/mcp 0.13.2 → 0.16.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 +54 -18
- package/dist/auth/oauth-broker/lightdash-token.d.ts +6 -5
- package/dist/auth/oauth-broker/lightdash-token.js +6 -10
- package/dist/auth/oauth-broker/mcp-access-token.d.ts +31 -0
- package/dist/auth/oauth-broker/mcp-access-token.js +109 -0
- package/dist/auth/oauth-broker/mcp-access-token.test.d.ts +1 -0
- package/dist/auth/oauth-broker/mcp-access-token.test.js +61 -0
- package/dist/auth/oauth-broker/pending-store.d.ts +9 -3
- package/dist/auth/oauth-broker/pending-store.js +5 -3
- package/dist/auth/oauth-broker/pending-store.test.js +28 -44
- package/dist/auth/oauth-broker/routes.d.ts +2 -1
- package/dist/auth/oauth-broker/routes.js +97 -45
- package/dist/auth/oauth-broker/routes.test.js +81 -13
- package/dist/auth/request-state-key.d.ts +1 -1
- package/dist/auth/request-state-key.js +1 -1
- package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +2 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.js +58 -37
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +59 -57
- package/dist/auth/resource-server/oauth-protected-resource.d.ts +2 -2
- package/dist/auth/resource-server/oauth-protected-resource.js +10 -9
- package/dist/bin.js +34 -8
- package/dist/config/enabled-profiles.d.ts +23 -0
- package/dist/config/enabled-profiles.js +57 -0
- package/dist/config/enabled-profiles.test.d.ts +1 -0
- package/dist/config/enabled-profiles.test.js +62 -0
- package/dist/config/env.d.ts +7 -0
- package/dist/config/env.js +8 -1
- package/dist/config/load-mcp-config.d.ts +15 -1
- package/dist/config/load-mcp-config.js +21 -9
- package/dist/config/load-mcp-config.test.js +61 -0
- package/dist/config/prompt-context-policy.d.ts +18 -0
- package/dist/config/prompt-context-policy.js +40 -0
- package/dist/config/prompt-context-policy.test.d.ts +4 -0
- package/dist/config/prompt-context-policy.test.js +35 -0
- package/dist/config/test-mcp-http-config.js +4 -1
- package/dist/governance/mcp-post-factory-context.d.ts +2 -0
- package/dist/http.d.ts +7 -1
- package/dist/http.integration.test.js +102 -44
- package/dist/http.js +10 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.integration.test.js +3 -12
- package/dist/index.js +6 -3
- package/dist/policy/content-developer.d.ts +5 -0
- package/dist/policy/content-developer.js +25 -1
- package/dist/policy/content-developer.test.js +29 -0
- package/dist/profiles/ai-agent-ops/v1/invariants.d.ts +27 -0
- package/dist/profiles/ai-agent-ops/v1/invariants.js +39 -0
- package/dist/profiles/ai-agent-ops/v1/prompts.d.ts +3 -2
- package/dist/profiles/ai-agent-ops/v1/prompts.js +67 -41
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks.d.ts +2 -1
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks.js +10 -3
- package/dist/profiles/content-developer/v1/invariants.d.ts +69 -0
- package/dist/profiles/content-developer/v1/invariants.js +95 -0
- package/dist/profiles/content-developer/v1/prompt-specs.d.ts +32 -0
- package/dist/profiles/content-developer/v1/prompt-specs.js +56 -0
- package/dist/profiles/content-developer/v1/prompts.d.ts +4 -3
- package/dist/profiles/content-developer/v1/prompts.js +65 -71
- package/dist/profiles/content-developer/v1/prompts.test.js +61 -7
- package/dist/profiles/content-developer/v1/resources/playbooks/chart-types.md +2 -1
- package/dist/profiles/content-developer/v1/resources/playbooks/core.md +3 -1
- package/dist/profiles/content-developer/v1/resources/playbooks/dashboard-design.md +11 -1
- package/dist/profiles/content-developer/v1/resources/playbooks/dashboards.md +1 -1
- package/dist/profiles/content-developer/v1/resources/playbooks/index.md +11 -8
- package/dist/profiles/content-developer/v1/resources/playbooks/recovery/dashboard-diff.md +15 -0
- package/dist/profiles/content-developer/v1/resources/playbooks/recovery/preview-required.md +14 -0
- package/dist/profiles/content-developer/v1/resources/playbooks/recovery/preview-stale.md +21 -0
- package/dist/profiles/content-developer/v1/resources/playbooks/table-calculations.md +15 -3
- package/dist/profiles/content-developer/v1/resources/playbooks.d.ts +3 -2
- package/dist/profiles/content-developer/v1/resources/playbooks.js +35 -21
- package/dist/profiles/content-governance/v1/invariants.d.ts +27 -0
- package/dist/profiles/content-governance/v1/invariants.js +39 -0
- package/dist/profiles/content-governance/v1/prompts.d.ts +4 -2
- package/dist/profiles/content-governance/v1/prompts.js +31 -19
- package/dist/profiles/content-governance/v1/resources/playbooks.d.ts +2 -1
- package/dist/profiles/content-governance/v1/resources/playbooks.js +8 -9
- package/dist/profiles/content-reader/v1/index.js +1 -0
- package/dist/profiles/content-reader/v1/invariants.d.ts +33 -0
- package/dist/profiles/content-reader/v1/invariants.js +47 -0
- package/dist/profiles/content-reader/v1/prompt-specs.d.ts +18 -0
- package/dist/profiles/content-reader/v1/prompt-specs.js +33 -0
- package/dist/profiles/content-reader/v1/prompts.d.ts +3 -2
- package/dist/profiles/content-reader/v1/prompts.js +69 -75
- package/dist/profiles/content-reader/v1/resources/playbooks/compare.md +1 -1
- package/dist/profiles/content-reader/v1/resources/playbooks/core.md +1 -0
- package/dist/profiles/content-reader/v1/resources/playbooks/discover.md +12 -3
- package/dist/profiles/content-reader/v1/resources/playbooks/explain-run.md +2 -1
- package/dist/profiles/content-reader/v1/resources/playbooks.d.ts +2 -1
- package/dist/profiles/content-reader/v1/resources/playbooks.js +10 -11
- package/dist/profiles/data-analyst/v1/invariants.d.ts +21 -0
- package/dist/profiles/data-analyst/v1/invariants.js +31 -0
- package/dist/profiles/data-analyst/v1/prompts.d.ts +3 -2
- package/dist/profiles/data-analyst/v1/prompts.js +17 -9
- package/dist/profiles/data-analyst/v1/resources/playbooks.d.ts +2 -1
- package/dist/profiles/data-analyst/v1/resources/playbooks.js +6 -7
- package/dist/profiles/index.d.ts +2 -1
- package/dist/profiles/index.js +2 -1
- package/dist/profiles/index.test.js +2 -1
- package/dist/profiles/lib/playbook-resources.d.ts +16 -34
- package/dist/profiles/lib/playbook-resources.js +55 -76
- package/dist/profiles/lib/prompt-context.d.ts +71 -0
- package/dist/profiles/lib/prompt-context.js +205 -0
- package/dist/profiles/lib/prompt-context.test.d.ts +4 -0
- package/dist/profiles/lib/prompt-context.test.js +154 -0
- package/dist/profiles/lib/prompt-invariants.d.ts +20 -0
- package/dist/profiles/lib/prompt-invariants.js +54 -0
- package/dist/profiles/organization-audit/v1/invariants.d.ts +24 -0
- package/dist/profiles/organization-audit/v1/invariants.js +35 -0
- package/dist/profiles/organization-audit/v1/prompts.d.ts +3 -2
- package/dist/profiles/organization-audit/v1/prompts.js +44 -28
- package/dist/profiles/organization-audit/v1/resources/playbooks.d.ts +2 -1
- package/dist/profiles/organization-audit/v1/resources/playbooks.js +10 -3
- package/dist/profiles/semantic-layer/v1/invariants.d.ts +27 -0
- package/dist/profiles/semantic-layer/v1/invariants.js +39 -0
- package/dist/profiles/semantic-layer/v1/prompts.d.ts +3 -2
- package/dist/profiles/semantic-layer/v1/prompts.js +37 -26
- package/dist/profiles/semantic-layer/v1/resources/playbooks.d.ts +2 -4
- package/dist/profiles/semantic-layer/v1/resources/playbooks.js +8 -7
- package/dist/profiles/test-support/prompt-context-budget.test.d.ts +5 -0
- package/dist/profiles/test-support/prompt-context-budget.test.js +72 -0
- package/dist/profiles/types.d.ts +6 -1
- package/dist/server/capabilities.d.ts +3 -0
- package/dist/server/capabilities.js +4 -2
- package/dist/stdio.process.test.js +2 -1
- package/dist/tools/lib/schema-fields.d.ts +4 -0
- package/dist/tools/lib/schema-fields.js +8 -1
- package/dist/tools/project/developer-content-preview.js +1 -1
- package/dist/tools/project/developer-content.js +2 -2
- package/dist/tools/project/reader-content.d.ts +2 -0
- package/dist/tools/project/reader-content.js +28 -1
- package/dist/tools/query/reader-tool-helpers.d.ts +2 -2
- package/dist/tools/query/reader-tool-helpers.js +2 -2
- package/dist/tools/query/reader-tool-helpers.test.js +1 -0
- package/dist/tools/shared.d.ts +6 -1
- package/dist/tools/shared.js +12 -2
- package/dist/transports/streamable-http.js +16 -6
- package/dist/transports/streamable-http.test.js +16 -0
- package/package.json +3 -3
|
@@ -7,9 +7,11 @@ exports.getOAuthCallbackUrl = getOAuthCallbackUrl;
|
|
|
7
7
|
const client_1 = require("@lightdash-tools/client");
|
|
8
8
|
const auth_mode_js_1 = require("../auth/auth-mode.js");
|
|
9
9
|
const index_js_1 = require("../profiles/index.js");
|
|
10
|
+
const enabled_profiles_js_1 = require("./enabled-profiles.js");
|
|
10
11
|
const env_js_1 = require("./env.js");
|
|
11
12
|
const normalize_url_js_1 = require("./normalize-url.js");
|
|
12
13
|
const obsolete_env_js_1 = require("./obsolete-env.js");
|
|
14
|
+
const prompt_context_policy_js_1 = require("./prompt-context-policy.js");
|
|
13
15
|
const public_url_js_1 = require("./public-url.js");
|
|
14
16
|
const read_env_js_1 = require("./read-env.js");
|
|
15
17
|
const DEFAULT_SCOPES_SUPPORTED = ['read', 'write', 'mcp:read', 'mcp:write'];
|
|
@@ -143,13 +145,13 @@ function emitLightdashOAuthSecurityWarnings(config) {
|
|
|
143
145
|
if (config.authMode !== auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH) {
|
|
144
146
|
return;
|
|
145
147
|
}
|
|
146
|
-
console.warn('Note: hosted OAuth uses a server-held Lightdash confidential client
|
|
147
|
-
'
|
|
148
|
-
'
|
|
148
|
+
console.warn('Note: hosted OAuth uses a dual-leg broker with a server-held Lightdash confidential client. ' +
|
|
149
|
+
'MCP clients receive resource-bound broker tokens; delegated Lightdash access tokens remain ' +
|
|
150
|
+
'encrypted inside the broker token and are recovered only server-side for upstream calls. ' +
|
|
149
151
|
`Register redirect URI ${getOAuthCallbackUrl(config)} in Lightdash.`);
|
|
150
152
|
if (!config.validateToken) {
|
|
151
|
-
console.warn(`Warning: ${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN}=false — MCP
|
|
152
|
-
'Use only for local development.');
|
|
153
|
+
console.warn(`Warning: ${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN}=false — broker-issued MCP tokens are still authenticated and audience-bound, ` +
|
|
154
|
+
'but downstream Lightdash user/token validation is skipped. Use only for local development.');
|
|
153
155
|
}
|
|
154
156
|
emitNgrokFreeInterstitialWarning(config.publicUrl);
|
|
155
157
|
}
|
|
@@ -215,8 +217,14 @@ function resolveOAuthCredentials(authMode, oauthClientId, oauthClientSecretRaw)
|
|
|
215
217
|
: undefined,
|
|
216
218
|
};
|
|
217
219
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
+
/**
|
|
221
|
+
* Load Streamable HTTP MCP config from env.
|
|
222
|
+
* When `options.promptContextPolicy` is set (CLI path), that value wins and
|
|
223
|
+
* `LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT` is not re-resolved — so invalid env
|
|
224
|
+
* cannot fail a start that already resolved a valid CLI policy.
|
|
225
|
+
*/
|
|
226
|
+
function loadMcpHttpConfig(env = process.env, options) {
|
|
227
|
+
var _a, _b;
|
|
220
228
|
const lightdashUrlRaw = (0, read_env_js_1.readEnv)(client_1.ENV_LIGHTDASH_URL, env);
|
|
221
229
|
if (!lightdashUrlRaw) {
|
|
222
230
|
throw new Error(`${client_1.ENV_LIGHTDASH_URL} is required.`);
|
|
@@ -236,7 +244,9 @@ function loadMcpHttpConfig(env = process.env) {
|
|
|
236
244
|
]);
|
|
237
245
|
const allowedOrigins = parseCsv(allowedOriginsRaw);
|
|
238
246
|
const proxyAuth = (0, read_env_js_1.readEnv)(client_1.ENV_LIGHTDASH_PROXY_AUTHORIZATION, env);
|
|
239
|
-
const
|
|
247
|
+
const enabledProfiles = (0, enabled_profiles_js_1.parseEnabledProfiles)((0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES, env));
|
|
248
|
+
const promptContextPolicy = (_a = options === null || options === void 0 ? void 0 : options.promptContextPolicy) !== null && _a !== void 0 ? _a : (0, prompt_context_policy_js_1.resolvePromptContextPolicy)({ env });
|
|
249
|
+
const mcpPath = (0, enabled_profiles_js_1.resolveRootMcpPath)(enabledProfiles);
|
|
240
250
|
const publicUrl = publicUrlRaw ? (0, normalize_url_js_1.normalizePublicUrl)(publicUrlRaw, (0, index_js_1.listProfilePaths)()) : undefined;
|
|
241
251
|
assertPublicUrlSecurity(authMode, publicUrl);
|
|
242
252
|
const validateToken = parseBooleanEnv(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN, (0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN, env), authMode === auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH);
|
|
@@ -244,11 +254,13 @@ function loadMcpHttpConfig(env = process.env) {
|
|
|
244
254
|
const requiredScopes = readScopeList(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_REQUIRED_SCOPES, []);
|
|
245
255
|
const scopesSupportedEnvSet = (0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED, env) !== undefined;
|
|
246
256
|
assertLightdashOAuthScopePolicy(authMode, requiredScopes, scopesSupportedEnvSet);
|
|
247
|
-
return Object.assign(Object.assign({ lightdashUrl: (0, normalize_url_js_1.normalizeLightdashUrl)(lightdashUrlRaw), proxyAuthorization: proxyAuth ? new client_1.SecretString(proxyAuth) : undefined, host: (
|
|
257
|
+
return Object.assign(Object.assign({ lightdashUrl: (0, normalize_url_js_1.normalizeLightdashUrl)(lightdashUrlRaw), proxyAuthorization: proxyAuth ? new client_1.SecretString(proxyAuth) : undefined, host: (_b = (0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_HOST, env)) !== null && _b !== void 0 ? _b : '0.0.0.0', port: readNumberEnv(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT, [
|
|
248
258
|
{ name: env_js_1.ENV_MCP_HTTP_PORT, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT },
|
|
249
259
|
{ name: env_js_1.ENV_MCP_SERVER_PORT, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT },
|
|
250
260
|
], 3100, env_js_1.ENV_PLATFORM_PORT), publicUrl,
|
|
251
261
|
mcpPath,
|
|
262
|
+
enabledProfiles,
|
|
263
|
+
promptContextPolicy,
|
|
252
264
|
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) });
|
|
253
265
|
}
|
|
254
266
|
function requiresLightdashApiKey(authMode) {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
|
+
const index_js_1 = require("../profiles/index.js");
|
|
5
|
+
const enabled_profiles_js_1 = require("./enabled-profiles.js");
|
|
4
6
|
const env_js_1 = require("./env.js");
|
|
5
7
|
const load_mcp_config_js_1 = require("./load-mcp-config.js");
|
|
6
8
|
const originalEnv = Object.assign({}, process.env);
|
|
@@ -31,6 +33,26 @@ function setOAuthCreds() {
|
|
|
31
33
|
vitest_1.vi.restoreAllMocks();
|
|
32
34
|
});
|
|
33
35
|
(0, vitest_1.describe)('loadMcpHttpConfig', () => {
|
|
36
|
+
(0, vitest_1.it)('defaults promptContextPolicy to compact and accepts overrides', () => {
|
|
37
|
+
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
38
|
+
process.env.NODE_ENV = 'development';
|
|
39
|
+
(0, vitest_1.expect)((0, load_mcp_config_js_1.loadMcpHttpConfig)().promptContextPolicy).toBe('compact');
|
|
40
|
+
process.env.LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT = 'embedded';
|
|
41
|
+
(0, vitest_1.expect)((0, load_mcp_config_js_1.loadMcpHttpConfig)().promptContextPolicy).toBe('embedded');
|
|
42
|
+
});
|
|
43
|
+
(0, vitest_1.it)('fails closed on invalid LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT', () => {
|
|
44
|
+
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
45
|
+
process.env.NODE_ENV = 'development';
|
|
46
|
+
process.env.LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT = 'uri-only';
|
|
47
|
+
(0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(/LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT/);
|
|
48
|
+
});
|
|
49
|
+
(0, vitest_1.it)('uses explicit promptContextPolicy and skips invalid env resolve', () => {
|
|
50
|
+
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
51
|
+
process.env.NODE_ENV = 'development';
|
|
52
|
+
process.env.LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT = 'uri-only';
|
|
53
|
+
const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)(process.env, { promptContextPolicy: 'compact' });
|
|
54
|
+
(0, vitest_1.expect)(config.promptContextPolicy).toBe('compact');
|
|
55
|
+
});
|
|
34
56
|
(0, vitest_1.it)('prefers LIGHTDASH_TOOLS_MCP_HTTP_PORT over MCP_HTTP_PORT', () => {
|
|
35
57
|
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
36
58
|
process.env.LIGHTDASH_TOOLS_MCP_HTTP_PORT = '3200';
|
|
@@ -189,6 +211,45 @@ function setOAuthCreds() {
|
|
|
189
211
|
const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
|
|
190
212
|
(0, vitest_1.expect)(config.validateToken).toBe(false);
|
|
191
213
|
});
|
|
214
|
+
(0, vitest_1.it)('keeps default mcpPath when MCP_PROFILES is unset', () => {
|
|
215
|
+
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
216
|
+
process.env.NODE_ENV = 'development';
|
|
217
|
+
const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
|
|
218
|
+
(0, vitest_1.expect)(config.enabledProfiles).toEqual(enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES);
|
|
219
|
+
(0, vitest_1.expect)(config.mcpPath).toBe(index_js_1.SEMANTIC_LAYER_PROFILE_PATH);
|
|
220
|
+
});
|
|
221
|
+
(0, vitest_1.it)('keeps semantic-layer mcpPath when that id is in the allowlist', () => {
|
|
222
|
+
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
223
|
+
process.env.NODE_ENV = 'development';
|
|
224
|
+
process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES] = 'semantic-layer, content-reader';
|
|
225
|
+
const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
|
|
226
|
+
(0, vitest_1.expect)(config.enabledProfiles.restricted).toBe(true);
|
|
227
|
+
(0, vitest_1.expect)(config.mcpPath).toBe(index_js_1.SEMANTIC_LAYER_PROFILE_PATH);
|
|
228
|
+
});
|
|
229
|
+
(0, vitest_1.it)('uses first PROFILE_IDS-enabled mcpPath when semantic-layer is omitted', () => {
|
|
230
|
+
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
231
|
+
process.env.NODE_ENV = 'development';
|
|
232
|
+
process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES] = 'content-reader,content-developer';
|
|
233
|
+
const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
|
|
234
|
+
(0, vitest_1.expect)(config.mcpPath).toBe(index_js_1.CONTENT_DEVELOPER_PROFILE_PATH);
|
|
235
|
+
});
|
|
236
|
+
(0, vitest_1.it)('rejects unknown MCP_PROFILES ids and empty segments', () => {
|
|
237
|
+
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
238
|
+
process.env.NODE_ENV = 'development';
|
|
239
|
+
process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES] = 'not-a-profile';
|
|
240
|
+
(0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES);
|
|
241
|
+
process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES] = 'content-reader,';
|
|
242
|
+
(0, vitest_1.expect)(() => (0, load_mcp_config_js_1.loadMcpHttpConfig)()).toThrow(/empty segments/);
|
|
243
|
+
});
|
|
244
|
+
(0, vitest_1.it)('still strips disabled profile suffixes from PUBLIC_URL', () => {
|
|
245
|
+
setOAuthCreds();
|
|
246
|
+
process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROFILES] = 'content-reader';
|
|
247
|
+
process.env[env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL] =
|
|
248
|
+
'https://mcp.example.com/content-governance/v1/mcp';
|
|
249
|
+
const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)();
|
|
250
|
+
(0, vitest_1.expect)(config.publicUrl).toBe('https://mcp.example.com');
|
|
251
|
+
(0, vitest_1.expect)(config.mcpPath).toBe(index_js_1.CONTENT_READER_PROFILE_PATH);
|
|
252
|
+
});
|
|
192
253
|
(0, vitest_1.it)('rejects LIGHTDASH_TOOLS_MCP_PATH', () => {
|
|
193
254
|
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
194
255
|
process.env.NODE_ENV = 'development';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt-context policy for progressive-disclosure playbook embedding (RFC).
|
|
3
|
+
*
|
|
4
|
+
* Canonical: `LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT`.
|
|
5
|
+
* CLI `--prompt-context` overrides env. Unset → package default (`compact`).
|
|
6
|
+
* Invalid values fail closed.
|
|
7
|
+
*/
|
|
8
|
+
export declare const PROMPT_CONTEXT_POLICIES: readonly ["compact", "compatible", "embedded"];
|
|
9
|
+
export type PromptContextPolicy = (typeof PROMPT_CONTEXT_POLICIES)[number];
|
|
10
|
+
/** Package default after progressive-disclosure migration. */
|
|
11
|
+
export declare const DEFAULT_PROMPT_CONTEXT_POLICY: PromptContextPolicy;
|
|
12
|
+
export declare function isPromptContextPolicy(value: string): value is PromptContextPolicy;
|
|
13
|
+
export declare function parsePromptContextPolicy(raw: string | undefined): PromptContextPolicy;
|
|
14
|
+
/** CLI flag wins when present (non-empty). */
|
|
15
|
+
export declare function resolvePromptContextPolicy(opts: {
|
|
16
|
+
cli?: string;
|
|
17
|
+
env?: NodeJS.ProcessEnv;
|
|
18
|
+
}): PromptContextPolicy;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prompt-context policy for progressive-disclosure playbook embedding (RFC).
|
|
4
|
+
*
|
|
5
|
+
* Canonical: `LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT`.
|
|
6
|
+
* CLI `--prompt-context` overrides env. Unset → package default (`compact`).
|
|
7
|
+
* Invalid values fail closed.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DEFAULT_PROMPT_CONTEXT_POLICY = exports.PROMPT_CONTEXT_POLICIES = void 0;
|
|
11
|
+
exports.isPromptContextPolicy = isPromptContextPolicy;
|
|
12
|
+
exports.parsePromptContextPolicy = parsePromptContextPolicy;
|
|
13
|
+
exports.resolvePromptContextPolicy = resolvePromptContextPolicy;
|
|
14
|
+
const env_js_1 = require("./env.js");
|
|
15
|
+
const read_env_js_1 = require("./read-env.js");
|
|
16
|
+
exports.PROMPT_CONTEXT_POLICIES = ['compact', 'compatible', 'embedded'];
|
|
17
|
+
/** Package default after progressive-disclosure migration. */
|
|
18
|
+
exports.DEFAULT_PROMPT_CONTEXT_POLICY = 'compact';
|
|
19
|
+
function isPromptContextPolicy(value) {
|
|
20
|
+
return exports.PROMPT_CONTEXT_POLICIES.includes(value);
|
|
21
|
+
}
|
|
22
|
+
function parsePromptContextPolicy(raw) {
|
|
23
|
+
if (raw === undefined || raw.trim() === '') {
|
|
24
|
+
return exports.DEFAULT_PROMPT_CONTEXT_POLICY;
|
|
25
|
+
}
|
|
26
|
+
const value = raw.trim();
|
|
27
|
+
if (!isPromptContextPolicy(value)) {
|
|
28
|
+
throw new Error(`${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT} must be one of: ${exports.PROMPT_CONTEXT_POLICIES.join(', ')} (got '${value}')`);
|
|
29
|
+
}
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
/** CLI flag wins when present (non-empty). */
|
|
33
|
+
function resolvePromptContextPolicy(opts) {
|
|
34
|
+
var _a, _b;
|
|
35
|
+
const fromCli = (_a = opts.cli) === null || _a === void 0 ? void 0 : _a.trim();
|
|
36
|
+
if (fromCli) {
|
|
37
|
+
return parsePromptContextPolicy(fromCli);
|
|
38
|
+
}
|
|
39
|
+
return parsePromptContextPolicy((0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT, (_b = opts.env) !== null && _b !== void 0 ? _b : process.env));
|
|
40
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Prompt-context policy unit tests.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const vitest_1 = require("vitest");
|
|
7
|
+
const prompt_context_policy_js_1 = require("./prompt-context-policy.js");
|
|
8
|
+
(0, vitest_1.describe)('parsePromptContextPolicy', () => {
|
|
9
|
+
(0, vitest_1.it)('defaults to compact when unset or empty', () => {
|
|
10
|
+
(0, vitest_1.expect)((0, prompt_context_policy_js_1.parsePromptContextPolicy)(undefined)).toBe(prompt_context_policy_js_1.DEFAULT_PROMPT_CONTEXT_POLICY);
|
|
11
|
+
(0, vitest_1.expect)((0, prompt_context_policy_js_1.parsePromptContextPolicy)('')).toBe('compact');
|
|
12
|
+
(0, vitest_1.expect)((0, prompt_context_policy_js_1.parsePromptContextPolicy)(' ')).toBe('compact');
|
|
13
|
+
});
|
|
14
|
+
(0, vitest_1.it)('accepts allowed values', () => {
|
|
15
|
+
(0, vitest_1.expect)((0, prompt_context_policy_js_1.parsePromptContextPolicy)('compact')).toBe('compact');
|
|
16
|
+
(0, vitest_1.expect)((0, prompt_context_policy_js_1.parsePromptContextPolicy)('compatible')).toBe('compatible');
|
|
17
|
+
(0, vitest_1.expect)((0, prompt_context_policy_js_1.parsePromptContextPolicy)('embedded')).toBe('embedded');
|
|
18
|
+
});
|
|
19
|
+
(0, vitest_1.it)('fails closed on unknown values', () => {
|
|
20
|
+
(0, vitest_1.expect)(() => (0, prompt_context_policy_js_1.parsePromptContextPolicy)('uri-only')).toThrow(/LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT/);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
(0, vitest_1.describe)('resolvePromptContextPolicy', () => {
|
|
24
|
+
(0, vitest_1.it)('prefers CLI over env', () => {
|
|
25
|
+
(0, vitest_1.expect)((0, prompt_context_policy_js_1.resolvePromptContextPolicy)({
|
|
26
|
+
cli: 'embedded',
|
|
27
|
+
env: { LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT: 'compatible' },
|
|
28
|
+
})).toBe('embedded');
|
|
29
|
+
});
|
|
30
|
+
(0, vitest_1.it)('uses env when CLI omitted', () => {
|
|
31
|
+
(0, vitest_1.expect)((0, prompt_context_policy_js_1.resolvePromptContextPolicy)({
|
|
32
|
+
env: { LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT: 'compatible' },
|
|
33
|
+
})).toBe('compatible');
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeTestMcpHttpConfig = makeTestMcpHttpConfig;
|
|
4
|
+
const enabled_profiles_js_1 = require("./enabled-profiles.js");
|
|
4
5
|
/** Shared base `McpHttpConfig` for MCP package unit/integration tests. */
|
|
5
6
|
function makeTestMcpHttpConfig(overrides) {
|
|
6
|
-
|
|
7
|
+
var _a;
|
|
8
|
+
const enabledProfiles = (_a = overrides === null || overrides === void 0 ? void 0 : overrides.enabledProfiles) !== null && _a !== void 0 ? _a : enabled_profiles_js_1.UNRESTRICTED_ENABLED_PROFILES;
|
|
9
|
+
return Object.assign({ lightdashUrl: 'https://app.lightdash.cloud', host: '127.0.0.1', port: 3100, publicUrl: 'https://mcp.example.com', mcpPath: (0, enabled_profiles_js_1.resolveRootMcpPath)(enabledProfiles), enabledProfiles, promptContextPolicy: 'compact', authMode: 'lightdash-oauth', allowedOrigins: [], maxBodyBytes: 1024, requiredScopes: ['mcp:read'], scopesSupported: ['mcp:read', 'mcp:write'], validateToken: true, tokenValidationCacheTtlMs: 30000 }, overrides);
|
|
7
10
|
}
|
|
@@ -3,11 +3,13 @@
|
|
|
3
3
|
* Auth / Origin / pin stay outside the handler; the factory only needs
|
|
4
4
|
* contextProvider + profile (ADR-0019).
|
|
5
5
|
*/
|
|
6
|
+
import type { PromptContextPolicy } from '../config/prompt-context-policy.js';
|
|
6
7
|
import type { ProfileDefinition } from '../profiles/types.js';
|
|
7
8
|
import type { McpContextProvider } from '../server/request-context.js';
|
|
8
9
|
export type McpPostFactoryStore = {
|
|
9
10
|
contextProvider: McpContextProvider;
|
|
10
11
|
profile: ProfileDefinition;
|
|
12
|
+
promptContextPolicy?: PromptContextPolicy;
|
|
11
13
|
};
|
|
12
14
|
export declare function getMcpPostFactoryStore(): McpPostFactoryStore | undefined;
|
|
13
15
|
export declare function runWithMcpPostFactoryAsync<T>(store: McpPostFactoryStore, fn: () => Promise<T>): Promise<T>;
|
package/dist/http.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MCP server entrypoint (Streamable HTTP).
|
|
3
|
+
* Prefer `lightdash-mcp http` (bin) which resolves prompt-context before start.
|
|
3
4
|
*/
|
|
4
|
-
|
|
5
|
+
import type { PromptContextPolicy } from './config/prompt-context-policy.js';
|
|
6
|
+
export type StartHttpOptions = {
|
|
7
|
+
promptContextPolicy?: PromptContextPolicy;
|
|
8
|
+
};
|
|
9
|
+
/** Start Streamable HTTP MCP (optional resolved prompt-context policy from CLI). */
|
|
10
|
+
export declare function startHttp(options?: StartHttpOptions): Promise<void>;
|
|
@@ -4,8 +4,13 @@ const node_http_1 = require("node:http");
|
|
|
4
4
|
const client_1 = require("@lightdash-tools/client");
|
|
5
5
|
const server_1 = require("@modelcontextprotocol/server");
|
|
6
6
|
const vitest_1 = require("vitest");
|
|
7
|
+
const mcp_access_token_js_1 = require("./auth/oauth-broker/mcp-access-token.js");
|
|
7
8
|
const oauth_protected_resource_js_1 = require("./auth/resource-server/oauth-protected-resource.js");
|
|
9
|
+
const enabled_profiles_js_1 = require("./config/enabled-profiles.js");
|
|
10
|
+
const test_mcp_http_config_js_1 = require("./config/test-mcp-http-config.js");
|
|
8
11
|
const streamable_http_js_1 = require("./transports/streamable-http.js");
|
|
12
|
+
// These constants model downstream Lightdash credentials only. MCP clients never send
|
|
13
|
+
// them directly after ADR-0026; tests wrap them in broker-issued MCP access tokens.
|
|
9
14
|
const TOKEN_A = scopedAccessToken('mcp:read mcp:write', 'token-a');
|
|
10
15
|
const TOKEN_B = scopedAccessToken('mcp:read mcp:write', 'token-b');
|
|
11
16
|
const TOKEN_READ_ONLY = scopedAccessToken('mcp:read', 'token-read-only');
|
|
@@ -115,23 +120,19 @@ async function startMockLightdashServer() {
|
|
|
115
120
|
}),
|
|
116
121
|
};
|
|
117
122
|
}
|
|
118
|
-
function baseOAuthConfig(lightdashUrl) {
|
|
119
|
-
return {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
scopesSupported: [],
|
|
132
|
-
validateToken: true,
|
|
133
|
-
tokenValidationCacheTtlMs: 30000,
|
|
134
|
-
};
|
|
123
|
+
function baseOAuthConfig(lightdashUrl, overrides) {
|
|
124
|
+
return (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)(Object.assign({ lightdashUrl, port: 0, publicUrl: 'http://127.0.0.1:0', oauthClientId: 'test-client-id', oauthClientSecret: new client_1.SecretString('test-client-secret'), maxBodyBytes: 1024 * 1024, requiredScopes: [], scopesSupported: [] }, overrides));
|
|
125
|
+
}
|
|
126
|
+
function brokerAccessToken(mcpBaseUrl, lightdashAccessToken, options = {}) {
|
|
127
|
+
var _a;
|
|
128
|
+
const path = (_a = options.path) !== null && _a !== void 0 ? _a : '/semantic-layer/v1/mcp';
|
|
129
|
+
return (0, mcp_access_token_js_1.mintMcpAccessToken)(baseOAuthConfig('https://lightdash.invalid'), {
|
|
130
|
+
lightdashAccessToken,
|
|
131
|
+
clientId: 'integration-test-client',
|
|
132
|
+
resource: `${mcpBaseUrl}${path}`,
|
|
133
|
+
scope: options.scope,
|
|
134
|
+
expiresAtMs: Date.now() + 60000,
|
|
135
|
+
}).accessToken;
|
|
135
136
|
}
|
|
136
137
|
async function postMcp(baseUrl, body, options) {
|
|
137
138
|
var _a;
|
|
@@ -188,12 +189,15 @@ function parseSseOrJsonToolText(raw) {
|
|
|
188
189
|
(0, vitest_1.expect)(body).not.toContain(invalidToken);
|
|
189
190
|
(0, vitest_1.expect)(response.headers.get('www-authenticate')).toContain('invalid_token');
|
|
190
191
|
});
|
|
191
|
-
(0, vitest_1.it)('handles initialize with
|
|
192
|
-
const
|
|
192
|
+
(0, vitest_1.it)('handles initialize with an MCP bearer and validates the downstream Lightdash bearer', async () => {
|
|
193
|
+
const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A);
|
|
194
|
+
const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: mcpToken });
|
|
193
195
|
(0, vitest_1.expect)(response.status).toBe(200);
|
|
194
|
-
// Sessionless: no session-id header is set
|
|
196
|
+
// Sessionless: no session-id header is set.
|
|
195
197
|
(0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeFalsy();
|
|
198
|
+
(0, vitest_1.expect)(mcpToken).not.toBe(TOKEN_A);
|
|
196
199
|
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
|
|
200
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpToken}`);
|
|
197
201
|
});
|
|
198
202
|
(0, vitest_1.it)('returns 401 before parsing malformed JSON when OAuth token is missing', async () => {
|
|
199
203
|
const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
|
|
@@ -215,12 +219,13 @@ function parseSseOrJsonToolText(raw) {
|
|
|
215
219
|
(0, vitest_1.expect)(response.headers.get('www-authenticate')).toContain('invalid_token');
|
|
216
220
|
});
|
|
217
221
|
(0, vitest_1.it)('returns 400 for malformed JSON only after successful OAuth authentication', async () => {
|
|
222
|
+
const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A);
|
|
218
223
|
const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
|
|
219
224
|
method: 'POST',
|
|
220
225
|
headers: {
|
|
221
226
|
'Content-Type': 'application/json',
|
|
222
227
|
Accept: 'application/json, text/event-stream',
|
|
223
|
-
Authorization: `Bearer ${
|
|
228
|
+
Authorization: `Bearer ${mcpToken}`,
|
|
224
229
|
},
|
|
225
230
|
body: '{not-json',
|
|
226
231
|
});
|
|
@@ -295,16 +300,21 @@ function parseSseOrJsonToolText(raw) {
|
|
|
295
300
|
(0, vitest_1.expect)(wwwAuthenticate).toContain(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource/content-governance/v1/mcp`);
|
|
296
301
|
(0, vitest_1.expect)(wwwAuthenticate).not.toContain('semantic-layer/v1/mcp');
|
|
297
302
|
});
|
|
298
|
-
(0, vitest_1.it)('maps
|
|
299
|
-
const
|
|
300
|
-
const
|
|
303
|
+
(0, vitest_1.it)('maps two MCP tokens to distinct authenticated users upstream', async () => {
|
|
304
|
+
const mcpTokenA = brokerAccessToken(mcpServer.baseUrl, TOKEN_A);
|
|
305
|
+
const mcpTokenB = brokerAccessToken(mcpServer.baseUrl, TOKEN_B);
|
|
306
|
+
const responseA = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: mcpTokenA });
|
|
307
|
+
const responseB = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: mcpTokenB });
|
|
301
308
|
(0, vitest_1.expect)(responseA.status).toBe(200);
|
|
302
309
|
(0, vitest_1.expect)(responseB.status).toBe(200);
|
|
303
310
|
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
|
|
304
311
|
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_B}`);
|
|
312
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpTokenA}`);
|
|
313
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpTokenB}`);
|
|
305
314
|
});
|
|
306
315
|
(0, vitest_1.it)('accepts form-elicitation caps from per-request _meta on content-governance tools/call', async () => {
|
|
307
316
|
const governancePath = '/content-governance/v1/mcp';
|
|
317
|
+
const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A, { path: governancePath });
|
|
308
318
|
const call = await postMcp(mcpServer.baseUrl, {
|
|
309
319
|
jsonrpc: '2.0',
|
|
310
320
|
method: 'tools/call',
|
|
@@ -319,7 +329,7 @@ function parseSseOrJsonToolText(raw) {
|
|
|
319
329
|
},
|
|
320
330
|
},
|
|
321
331
|
id: 2,
|
|
322
|
-
}, { token:
|
|
332
|
+
}, { token: mcpToken, path: governancePath });
|
|
323
333
|
(0, vitest_1.expect)(call.status).toBe(200);
|
|
324
334
|
const text = parseSseOrJsonToolText(await call.text());
|
|
325
335
|
// Per-request envelope caps: past ELICITATION_REQUIRED into chart resolve (mock has no chart).
|
|
@@ -338,7 +348,8 @@ function parseSseOrJsonToolText(raw) {
|
|
|
338
348
|
const unavailableUrl = `http://127.0.0.1:${unavailableAddress.port}`;
|
|
339
349
|
const downServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign({}, baseOAuthConfig(unavailableUrl)));
|
|
340
350
|
try {
|
|
341
|
-
const
|
|
351
|
+
const mcpToken = brokerAccessToken(downServer.baseUrl, TOKEN_A);
|
|
352
|
+
const response = await postMcp(downServer.baseUrl, INITIALIZE_BODY, { token: mcpToken });
|
|
342
353
|
(0, vitest_1.expect)(response.status).toBe(503);
|
|
343
354
|
(0, vitest_1.expect)(await response.json()).toEqual({
|
|
344
355
|
error: 'temporarily_unavailable',
|
|
@@ -386,33 +397,41 @@ function parseSseOrJsonToolText(raw) {
|
|
|
386
397
|
(0, vitest_1.expect)(asMetadata.token_endpoint).toBe(`${mcpServer.baseUrl}/oauth/token`);
|
|
387
398
|
(0, vitest_1.expect)(asMetadata.registration_endpoint).toBe(`${mcpServer.baseUrl}/oauth/register`);
|
|
388
399
|
});
|
|
389
|
-
(0, vitest_1.it)('handles initialize
|
|
390
|
-
const
|
|
400
|
+
(0, vitest_1.it)('handles initialize when the downstream Lightdash credential is opaque', async () => {
|
|
401
|
+
const mcpToken = brokerAccessToken(mcpServer.baseUrl, OPAQUE_TOKEN_A);
|
|
402
|
+
const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: mcpToken });
|
|
391
403
|
(0, vitest_1.expect)(response.status).toBe(200);
|
|
392
404
|
(0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeFalsy();
|
|
393
405
|
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${OPAQUE_TOKEN_A}`);
|
|
406
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpToken}`);
|
|
394
407
|
});
|
|
395
|
-
(0, vitest_1.it)('accepts
|
|
408
|
+
(0, vitest_1.it)('accepts an MCP token carrying mcp:read scope on initialize', async () => {
|
|
409
|
+
const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_READ_ONLY, { scope: 'mcp:read' });
|
|
396
410
|
const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
|
|
397
|
-
token:
|
|
411
|
+
token: mcpToken,
|
|
398
412
|
});
|
|
399
413
|
(0, vitest_1.expect)(response.status).toBe(200);
|
|
400
414
|
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_READ_ONLY}`);
|
|
401
415
|
});
|
|
402
|
-
(0, vitest_1.it)('accepts
|
|
416
|
+
(0, vitest_1.it)('accepts an MCP token carrying mcp:read mcp:write scope on initialize', async () => {
|
|
417
|
+
const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A, {
|
|
418
|
+
scope: 'mcp:read mcp:write',
|
|
419
|
+
});
|
|
403
420
|
const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
|
|
404
|
-
token:
|
|
421
|
+
token: mcpToken,
|
|
405
422
|
});
|
|
406
423
|
(0, vitest_1.expect)(response.status).toBe(200);
|
|
407
424
|
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
|
|
408
425
|
});
|
|
409
|
-
(0, vitest_1.it)('forwards
|
|
426
|
+
(0, vitest_1.it)('forwards only the decrypted downstream bearer to Lightdash', async () => {
|
|
427
|
+
const mcpToken = brokerAccessToken(mcpServer.baseUrl, OPAQUE_TOKEN_A);
|
|
410
428
|
const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
|
|
411
|
-
token:
|
|
429
|
+
token: mcpToken,
|
|
412
430
|
});
|
|
413
431
|
(0, vitest_1.expect)(response.status).toBe(200);
|
|
414
|
-
const
|
|
415
|
-
(0, vitest_1.expect)(
|
|
432
|
+
const downstreamHeaders = mockLightdash.authorizationHeaders.filter((header) => header === `Bearer ${OPAQUE_TOKEN_A}`);
|
|
433
|
+
(0, vitest_1.expect)(downstreamHeaders.length).toBeGreaterThan(0);
|
|
434
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpToken}`);
|
|
416
435
|
});
|
|
417
436
|
});
|
|
418
437
|
(0, vitest_1.describe)('MCP HTTP CORS integration', () => {
|
|
@@ -474,12 +493,13 @@ function parseSseOrJsonToolText(raw) {
|
|
|
474
493
|
});
|
|
475
494
|
(0, vitest_1.it)('returns 413 for oversized JSON body after OAuth authentication', async () => {
|
|
476
495
|
const hugeBody = JSON.stringify(Object.assign(Object.assign({}, INITIALIZE_BODY), { params: Object.assign(Object.assign({}, INITIALIZE_BODY.params), { padding: 'x'.repeat(1024) }) }));
|
|
496
|
+
const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A);
|
|
477
497
|
const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
|
|
478
498
|
method: 'POST',
|
|
479
499
|
headers: {
|
|
480
500
|
'Content-Type': 'application/json',
|
|
481
501
|
Accept: 'application/json, text/event-stream',
|
|
482
|
-
Authorization: `Bearer ${
|
|
502
|
+
Authorization: `Bearer ${mcpToken}`,
|
|
483
503
|
},
|
|
484
504
|
body: hugeBody,
|
|
485
505
|
});
|
|
@@ -506,6 +526,48 @@ function parseSseOrJsonToolText(raw) {
|
|
|
506
526
|
(0, vitest_1.expect)(response.status).toBe(405);
|
|
507
527
|
});
|
|
508
528
|
});
|
|
529
|
+
(0, vitest_1.describe)('MCP HTTP profile mount allowlist', () => {
|
|
530
|
+
let mockLightdash;
|
|
531
|
+
let mcpServer;
|
|
532
|
+
(0, vitest_1.beforeEach)(async () => {
|
|
533
|
+
vitest_1.vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
|
534
|
+
vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
535
|
+
mockLightdash = await startMockLightdashServer();
|
|
536
|
+
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(baseOAuthConfig(mockLightdash.baseUrl, {
|
|
537
|
+
enabledProfiles: (0, enabled_profiles_js_1.parseEnabledProfiles)('content-reader'),
|
|
538
|
+
}));
|
|
539
|
+
});
|
|
540
|
+
(0, vitest_1.afterEach)(async () => {
|
|
541
|
+
await mcpServer.close();
|
|
542
|
+
await mockLightdash.close();
|
|
543
|
+
vitest_1.vi.restoreAllMocks();
|
|
544
|
+
});
|
|
545
|
+
(0, vitest_1.it)('404s disabled profile MCP paths and their path-specific PRM', async () => {
|
|
546
|
+
const mcpResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
|
|
547
|
+
(0, vitest_1.expect)(mcpResponse.status).toBe(404);
|
|
548
|
+
const prmResponse = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource/semantic-layer/v1/mcp`);
|
|
549
|
+
(0, vitest_1.expect)(prmResponse.status).toBe(404);
|
|
550
|
+
});
|
|
551
|
+
(0, vitest_1.it)('keeps enabled profile MCP and PRM reachable', async () => {
|
|
552
|
+
const contentReaderPath = '/content-reader/v1/mcp';
|
|
553
|
+
const mcpToken = brokerAccessToken(mcpServer.baseUrl, TOKEN_A, { path: contentReaderPath });
|
|
554
|
+
const mcpResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
|
|
555
|
+
token: mcpToken,
|
|
556
|
+
path: contentReaderPath,
|
|
557
|
+
});
|
|
558
|
+
(0, vitest_1.expect)(mcpResponse.status).toBe(200);
|
|
559
|
+
const prmResponse = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource/content-reader/v1/mcp`);
|
|
560
|
+
(0, vitest_1.expect)(prmResponse.status).toBe(200);
|
|
561
|
+
const metadata = (await prmResponse.json());
|
|
562
|
+
(0, vitest_1.expect)(metadata.resource).toBe(`${mcpServer.baseUrl}/content-reader/v1/mcp`);
|
|
563
|
+
});
|
|
564
|
+
(0, vitest_1.it)('serves root PRM for the first enabled profile path', async () => {
|
|
565
|
+
const response = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource`);
|
|
566
|
+
(0, vitest_1.expect)(response.status).toBe(200);
|
|
567
|
+
const metadata = (await response.json());
|
|
568
|
+
(0, vitest_1.expect)(metadata.resource).toBe(`${mcpServer.baseUrl}/content-reader/v1/mcp`);
|
|
569
|
+
});
|
|
570
|
+
});
|
|
509
571
|
(0, vitest_1.describe)('MCP HTTP shared-key integration', () => {
|
|
510
572
|
let mcpServer;
|
|
511
573
|
const originalEnv = Object.assign({}, process.env);
|
|
@@ -514,20 +576,16 @@ function parseSseOrJsonToolText(raw) {
|
|
|
514
576
|
vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
515
577
|
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
516
578
|
process.env.LIGHTDASH_API_KEY = 'ldpat_test_key';
|
|
517
|
-
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)({
|
|
518
|
-
lightdashUrl: 'https://app.lightdash.cloud',
|
|
519
|
-
host: '127.0.0.1',
|
|
579
|
+
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)((0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
|
|
520
580
|
port: 0,
|
|
521
|
-
|
|
581
|
+
publicUrl: undefined,
|
|
522
582
|
authMode: 'shared-key',
|
|
523
583
|
sharedKey: new client_1.SecretString('shared-secret'),
|
|
524
|
-
allowedOrigins: [],
|
|
525
584
|
maxBodyBytes: 1024 * 1024,
|
|
526
585
|
requiredScopes: [],
|
|
527
586
|
scopesSupported: ['mcp:read'],
|
|
528
587
|
validateToken: false,
|
|
529
|
-
|
|
530
|
-
});
|
|
588
|
+
}));
|
|
531
589
|
});
|
|
532
590
|
(0, vitest_1.afterEach)(async () => {
|
|
533
591
|
await mcpServer.close();
|
package/dist/http.js
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* MCP server entrypoint (Streamable HTTP).
|
|
4
|
+
* Prefer `lightdash-mcp http` (bin) which resolves prompt-context before start.
|
|
4
5
|
*/
|
|
5
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.startHttp = startHttp;
|
|
8
|
+
const load_mcp_config_js_1 = require("./config/load-mcp-config.js");
|
|
6
9
|
const streamable_http_js_1 = require("./transports/streamable-http.js");
|
|
7
|
-
(
|
|
10
|
+
/** Start Streamable HTTP MCP (optional resolved prompt-context policy from CLI). */
|
|
11
|
+
async function startHttp(options) {
|
|
12
|
+
const config = (0, load_mcp_config_js_1.loadMcpHttpConfig)(process.env, (options === null || options === void 0 ? void 0 : options.promptContextPolicy) !== undefined
|
|
13
|
+
? { promptContextPolicy: options.promptContextPolicy }
|
|
14
|
+
: undefined);
|
|
15
|
+
await (0, streamable_http_js_1.startStreamableHttpServer)(config);
|
|
16
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
* via `legacy: 'serve'`). Hand-wiring `StdioServerTransport` + `connect()` stays
|
|
10
10
|
* on the 2025-era wire only.
|
|
11
11
|
*/
|
|
12
|
+
import { type PromptContextPolicy } from './config/prompt-context-policy.js';
|
|
12
13
|
import type { ProfileId } from './profiles/types.js';
|
|
14
|
+
export type StartStdioOptions = {
|
|
15
|
+
/** Explicit policy; when omitted, resolve from env (default compact). */
|
|
16
|
+
promptContextPolicy?: PromptContextPolicy;
|
|
17
|
+
};
|
|
13
18
|
/** Start stdio MCP for an explicit profile (CLI-selected). */
|
|
14
|
-
export declare function startStdio(profileId: ProfileId): void;
|
|
19
|
+
export declare function startStdio(profileId: ProfileId, options?: StartStdioOptions): void;
|
|
@@ -7,6 +7,7 @@ const vitest_1 = require("vitest");
|
|
|
7
7
|
const env_context_provider_js_1 = require("./auth/providers/env-context-provider.js");
|
|
8
8
|
const lightdash_token_validation_js_1 = require("./auth/resource-server/lightdash-token-validation.js");
|
|
9
9
|
const runtime_js_1 = require("./config/runtime.js");
|
|
10
|
+
const test_mcp_http_config_js_1 = require("./config/test-mcp-http-config.js");
|
|
10
11
|
const server_js_1 = require("./server/server.js");
|
|
11
12
|
const shared_1 = require("./tools/shared");
|
|
12
13
|
const hasCredentials = !!process.env.LIGHTDASH_API_KEY && !!process.env.LIGHTDASH_URL;
|
|
@@ -55,20 +56,10 @@ vitest_1.describe.runIf(hasOAuthToken)('MCP Integration (OAuth access token)', (
|
|
|
55
56
|
var _a;
|
|
56
57
|
const lightdashUrl = process.env.LIGHTDASH_URL.replace(/\/$/, '');
|
|
57
58
|
const accessToken = process.env.LIGHTDASH_TOOLS_TEST_OAUTH_ACCESS_TOKEN;
|
|
58
|
-
const config = {
|
|
59
|
+
const config = (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
|
|
59
60
|
lightdashUrl,
|
|
60
|
-
host: '127.0.0.1',
|
|
61
|
-
port: 3100,
|
|
62
|
-
publicUrl: 'https://mcp.example.com',
|
|
63
|
-
mcpPath: '/semantic-layer/v1/mcp',
|
|
64
|
-
authMode: 'lightdash-oauth',
|
|
65
|
-
allowedOrigins: [],
|
|
66
61
|
maxBodyBytes: 1024 * 1024,
|
|
67
|
-
|
|
68
|
-
scopesSupported: ['mcp:read', 'mcp:write'],
|
|
69
|
-
validateToken: true,
|
|
70
|
-
tokenValidationCacheTtlMs: 30000,
|
|
71
|
-
};
|
|
62
|
+
});
|
|
72
63
|
const user = await (0, lightdash_token_validation_js_1.validateLightdashAccessToken)(config, accessToken);
|
|
73
64
|
(0, vitest_1.expect)(user.userUuid).toBeDefined();
|
|
74
65
|
(0, vitest_1.expect)(user.email).toBeDefined();
|