@lightdash-tools/mcp 0.14.0 → 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 +30 -11
- 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/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.js +2 -2
- package/dist/bin.js +33 -7
- package/dist/config/env.d.ts +5 -0
- package/dist/config/env.js +6 -1
- package/dist/config/load-mcp-config.d.ts +12 -1
- package/dist/config/load-mcp-config.js +17 -8
- package/dist/config/load-mcp-config.test.js +20 -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 +1 -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 +57 -22
- package/dist/http.js +10 -1
- package/dist/index.d.ts +6 -1
- 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/core.md +1 -0
- 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.d.ts +3 -2
- package/dist/profiles/content-developer/v1/resources/playbooks.js +35 -22
- 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/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 -76
- 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/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/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/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 +10 -3
- package/package.json +3 -3
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_1 = require("@lightdash-tools/client");
|
|
3
4
|
const vitest_1 = require("vitest");
|
|
4
5
|
const test_mcp_http_config_js_1 = require("../../config/test-mcp-http-config.js");
|
|
5
6
|
const index_js_1 = require("../../profiles/organization-audit/v1/index.js");
|
|
6
7
|
const index_js_2 = require("../../profiles/semantic-layer/v1/index.js");
|
|
8
|
+
const mcp_access_token_js_1 = require("../oauth-broker/mcp-access-token.js");
|
|
7
9
|
const lightdash_oauth_middleware_js_1 = require("./lightdash-oauth-middleware.js");
|
|
8
10
|
const lightdash_token_validation_js_1 = require("./lightdash-token-validation.js");
|
|
9
11
|
const token_validation_error_js_1 = require("./token-validation-error.js");
|
|
@@ -11,19 +13,33 @@ vitest_1.vi.mock('./lightdash-token-validation.js', () => ({
|
|
|
11
13
|
validateLightdashAccessToken: vitest_1.vi.fn(),
|
|
12
14
|
}));
|
|
13
15
|
const baseConfig = (0, test_mcp_http_config_js_1.makeTestMcpHttpConfig)({
|
|
16
|
+
oauthClientId: 'ld-client',
|
|
17
|
+
oauthClientSecret: new client_1.SecretString('test-lightdash-confidential-client-secret'),
|
|
14
18
|
requiredScopes: [],
|
|
15
19
|
});
|
|
16
|
-
function jwtWithScope(scope) {
|
|
17
|
-
const header = Buffer.from(JSON.stringify({ alg: 'none', typ: 'JWT' })).toString('base64url');
|
|
18
|
-
const payload = Buffer.from(JSON.stringify({ scope })).toString('base64url');
|
|
19
|
-
return `${header}.${payload}.signature`;
|
|
20
|
-
}
|
|
21
20
|
function createRequest(authorization) {
|
|
22
21
|
return {
|
|
23
22
|
headers: authorization ? { authorization } : {},
|
|
24
23
|
};
|
|
25
24
|
}
|
|
25
|
+
function resourceFor(path) {
|
|
26
|
+
return `https://mcp.example.com${path}`;
|
|
27
|
+
}
|
|
28
|
+
function mcpToken(options = {}) {
|
|
29
|
+
var _a, _b, _c;
|
|
30
|
+
const path = (_a = options.path) !== null && _a !== void 0 ? _a : index_js_2.SEMANTIC_LAYER_PROFILE_PATH;
|
|
31
|
+
return (0, mcp_access_token_js_1.mintMcpAccessToken)(baseConfig, {
|
|
32
|
+
lightdashAccessToken: (_b = options.lightdashAccessToken) !== null && _b !== void 0 ? _b : 'ld-upstream-token',
|
|
33
|
+
clientId: 'mcp-client-1',
|
|
34
|
+
resource: resourceFor(path),
|
|
35
|
+
scope: options.scope,
|
|
36
|
+
expiresAtMs: (_c = options.expiresAtMs) !== null && _c !== void 0 ? _c : Date.now() + 60000,
|
|
37
|
+
}).accessToken;
|
|
38
|
+
}
|
|
26
39
|
(0, vitest_1.describe)('authenticateLightdashOAuth', () => {
|
|
40
|
+
(0, vitest_1.beforeEach)(() => {
|
|
41
|
+
vitest_1.vi.clearAllMocks();
|
|
42
|
+
});
|
|
27
43
|
(0, vitest_1.it)('returns 401 with WWW-Authenticate resource_metadata when token is missing', async () => {
|
|
28
44
|
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
29
45
|
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
@@ -46,22 +62,43 @@ function createRequest(authorization) {
|
|
|
46
62
|
(0, vitest_1.expect)(result.wwwAuthenticate).toContain('https://mcp.example.com/.well-known/oauth-protected-resource/organization-audit/v1/mcp');
|
|
47
63
|
(0, vitest_1.expect)(result.wwwAuthenticate).not.toContain('semantic-layer/v1/mcp');
|
|
48
64
|
});
|
|
49
|
-
(0, vitest_1.it)('
|
|
65
|
+
(0, vitest_1.it)('rejects a raw downstream Lightdash bearer before calling Lightdash', async () => {
|
|
66
|
+
const token = 'ld-upstream-token';
|
|
67
|
+
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
68
|
+
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
69
|
+
if (result.ok)
|
|
70
|
+
return;
|
|
71
|
+
(0, vitest_1.expect)(result.status).toBe(401);
|
|
72
|
+
(0, vitest_1.expect)(result.body.error).toBe('invalid_token');
|
|
73
|
+
(0, vitest_1.expect)(JSON.stringify(result.body)).not.toContain(token);
|
|
74
|
+
(0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).not.toHaveBeenCalled();
|
|
75
|
+
});
|
|
76
|
+
(0, vitest_1.it)('rejects a valid broker token at a different profile resource', async () => {
|
|
77
|
+
const token = mcpToken({ path: index_js_1.ORGANIZATION_AUDIT_PROFILE_PATH });
|
|
78
|
+
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
79
|
+
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
80
|
+
if (result.ok)
|
|
81
|
+
return;
|
|
82
|
+
(0, vitest_1.expect)(result.status).toBe(401);
|
|
83
|
+
(0, vitest_1.expect)(result.body.error_description).toContain('wrong-audience');
|
|
84
|
+
(0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).not.toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
(0, vitest_1.it)('returns 401 without echoing the MCP bearer when downstream validation fails', async () => {
|
|
50
87
|
vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockRejectedValue(new token_validation_error_js_1.TokenValidationError('invalid_token', 'Invalid or expired Lightdash access token'));
|
|
51
|
-
const token =
|
|
88
|
+
const token = mcpToken();
|
|
52
89
|
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
53
90
|
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
54
91
|
if (result.ok)
|
|
55
92
|
return;
|
|
56
93
|
(0, vitest_1.expect)(result.status).toBe(401);
|
|
57
94
|
(0, vitest_1.expect)(result.body.error).toBe('invalid_token');
|
|
58
|
-
(0, vitest_1.expect)(result.body.error_description).toBe('Invalid or expired Lightdash access token');
|
|
59
95
|
(0, vitest_1.expect)(JSON.stringify(result.body)).not.toContain(token);
|
|
60
96
|
(0, vitest_1.expect)(result.wwwAuthenticate).toContain('error="invalid_token"');
|
|
97
|
+
(0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).toHaveBeenCalledWith(baseConfig, 'ld-upstream-token');
|
|
61
98
|
});
|
|
62
99
|
(0, vitest_1.it)('returns 503 when Lightdash upstream is unavailable', async () => {
|
|
63
100
|
vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockRejectedValue(new token_validation_error_js_1.TokenValidationError('upstream_unavailable', 'Lightdash is temporarily unavailable'));
|
|
64
|
-
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(
|
|
101
|
+
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${mcpToken()}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
65
102
|
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
66
103
|
if (result.ok)
|
|
67
104
|
return;
|
|
@@ -74,78 +111,42 @@ function createRequest(authorization) {
|
|
|
74
111
|
});
|
|
75
112
|
(0, vitest_1.it)('returns 503 with Retry-After when upstream is rate limited', async () => {
|
|
76
113
|
vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockRejectedValue(new token_validation_error_js_1.TokenValidationError('upstream_unavailable', 'Lightdash is temporarily unavailable', 60));
|
|
77
|
-
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(
|
|
114
|
+
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${mcpToken()}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
78
115
|
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
79
116
|
if (result.ok)
|
|
80
117
|
return;
|
|
81
118
|
(0, vitest_1.expect)(result.status).toBe(503);
|
|
82
119
|
(0, vitest_1.expect)(result.headers).toEqual({ 'Retry-After': '60' });
|
|
83
120
|
});
|
|
84
|
-
(0, vitest_1.it)('returns user context
|
|
121
|
+
(0, vitest_1.it)('returns downstream user context only after broker-token validation succeeds', async () => {
|
|
85
122
|
vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
|
|
86
123
|
userUuid: 'user-uuid-1',
|
|
87
124
|
email: 'user@example.com',
|
|
88
125
|
});
|
|
89
|
-
const token =
|
|
126
|
+
const token = mcpToken({ scope: 'mcp:read mcp:write' });
|
|
90
127
|
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
91
128
|
(0, vitest_1.expect)(result).toEqual({
|
|
92
129
|
ok: true,
|
|
93
|
-
accessToken: token,
|
|
130
|
+
accessToken: 'ld-upstream-token',
|
|
94
131
|
user: { userUuid: 'user-uuid-1', email: 'user@example.com' },
|
|
95
132
|
scopes: ['mcp:read', 'mcp:write'],
|
|
96
133
|
});
|
|
97
|
-
(0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).toHaveBeenCalledWith(baseConfig, token);
|
|
134
|
+
(0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).toHaveBeenCalledWith(baseConfig, 'ld-upstream-token');
|
|
98
135
|
});
|
|
99
|
-
(0, vitest_1.it)('accepts
|
|
136
|
+
(0, vitest_1.it)('accepts an MCP token without scopes when endpoint scope requirements are unset', async () => {
|
|
100
137
|
vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
|
|
101
138
|
userUuid: 'user-uuid-1',
|
|
102
139
|
email: 'user@example.com',
|
|
103
140
|
});
|
|
104
|
-
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(
|
|
105
|
-
(0, vitest_1.expect)(result).toEqual({
|
|
106
|
-
ok: true,
|
|
107
|
-
accessToken: 'opaque-token',
|
|
108
|
-
user: { userUuid: 'user-uuid-1', email: 'user@example.com' },
|
|
109
|
-
scopes: undefined,
|
|
110
|
-
});
|
|
111
|
-
});
|
|
112
|
-
(0, vitest_1.it)('accepts JWTs without scope claims when endpoint scope requirements are unset', async () => {
|
|
113
|
-
vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
|
|
114
|
-
userUuid: 'user-uuid-1',
|
|
115
|
-
email: 'user@example.com',
|
|
116
|
-
});
|
|
117
|
-
const header = Buffer.from(JSON.stringify({ alg: 'none', typ: 'JWT' })).toString('base64url');
|
|
118
|
-
const payload = Buffer.from(JSON.stringify({ sub: 'user-uuid-1' })).toString('base64url');
|
|
119
|
-
const token = `${header}.${payload}.signature`;
|
|
120
|
-
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
141
|
+
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${mcpToken()}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
121
142
|
(0, vitest_1.expect)(result.ok).toBe(true);
|
|
122
143
|
if (!result.ok)
|
|
123
144
|
return;
|
|
124
145
|
(0, vitest_1.expect)(result.scopes).toBeUndefined();
|
|
125
146
|
});
|
|
126
|
-
(0, vitest_1.it)('returns 403 insufficient_scope when
|
|
127
|
-
vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
|
|
128
|
-
userUuid: 'user-uuid-1',
|
|
129
|
-
email: 'user@example.com',
|
|
130
|
-
});
|
|
131
|
-
const scopedConfig = Object.assign(Object.assign({}, baseConfig), { requiredScopes: ['mcp:read'] });
|
|
132
|
-
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest('Bearer opaque-token'), scopedConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
133
|
-
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
134
|
-
if (result.ok)
|
|
135
|
-
return;
|
|
136
|
-
(0, vitest_1.expect)(result.status).toBe(403);
|
|
137
|
-
(0, vitest_1.expect)(result.body.error).toBe('insufficient_scope');
|
|
138
|
-
(0, vitest_1.expect)(result.wwwAuthenticate).toContain('scope="mcp:read"');
|
|
139
|
-
});
|
|
140
|
-
(0, vitest_1.it)('returns 403 insufficient_scope when required scopes are missing from token claims', async () => {
|
|
141
|
-
vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
|
|
142
|
-
userUuid: 'user-uuid-1',
|
|
143
|
-
email: 'user@example.com',
|
|
144
|
-
});
|
|
145
|
-
const header = Buffer.from(JSON.stringify({ alg: 'none', typ: 'JWT' })).toString('base64url');
|
|
146
|
-
const payload = Buffer.from(JSON.stringify({ scope: 'mcp:write' })).toString('base64url');
|
|
147
|
-
const token = `${header}.${payload}.signature`;
|
|
147
|
+
(0, vitest_1.it)('returns 403 insufficient_scope before calling Lightdash when MCP scopes are missing', async () => {
|
|
148
148
|
const scopedConfig = Object.assign(Object.assign({}, baseConfig), { requiredScopes: ['mcp:read'] });
|
|
149
|
+
const token = mcpToken({ scope: 'mcp:write' });
|
|
149
150
|
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`Bearer ${token}`), scopedConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
150
151
|
(0, vitest_1.expect)(result.ok).toBe(false);
|
|
151
152
|
if (result.ok)
|
|
@@ -153,18 +154,19 @@ function createRequest(authorization) {
|
|
|
153
154
|
(0, vitest_1.expect)(result.status).toBe(403);
|
|
154
155
|
(0, vitest_1.expect)(result.body.error).toBe('insufficient_scope');
|
|
155
156
|
(0, vitest_1.expect)(result.wwwAuthenticate).toContain('error="insufficient_scope"');
|
|
157
|
+
(0, vitest_1.expect)(result.wwwAuthenticate).toContain('scope="mcp:read"');
|
|
158
|
+
(0, vitest_1.expect)(lightdash_token_validation_js_1.validateLightdashAccessToken).not.toHaveBeenCalled();
|
|
156
159
|
});
|
|
157
160
|
(0, vitest_1.it)('accepts lowercase bearer scheme prefix', async () => {
|
|
158
161
|
vitest_1.vi.mocked(lightdash_token_validation_js_1.validateLightdashAccessToken).mockResolvedValue({
|
|
159
162
|
userUuid: 'user-uuid-1',
|
|
160
163
|
email: 'user@example.com',
|
|
161
164
|
});
|
|
162
|
-
const
|
|
163
|
-
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`bearer ${token}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
165
|
+
const result = await (0, lightdash_oauth_middleware_js_1.authenticateLightdashOAuth)(createRequest(`bearer ${mcpToken()}`), baseConfig, index_js_2.SEMANTIC_LAYER_PROFILE_PATH);
|
|
164
166
|
(0, vitest_1.expect)(result.ok).toBe(true);
|
|
165
167
|
if (!result.ok)
|
|
166
168
|
return;
|
|
167
|
-
(0, vitest_1.expect)(result.accessToken).toBe(token);
|
|
169
|
+
(0, vitest_1.expect)(result.accessToken).toBe('ld-upstream-token');
|
|
168
170
|
});
|
|
169
171
|
});
|
|
170
172
|
(0, vitest_1.describe)('writeOAuthAuthFailure', () => {
|
|
@@ -23,8 +23,8 @@ function buildOAuthProtectedResourceMetadata(config, mcpPath) {
|
|
|
23
23
|
const path = (0, normalize_url_js_1.normalizeMcpPath)(mcpPath);
|
|
24
24
|
// Broker mode: authorization_servers is the MCP host (PUBLIC_URL). Clients discover
|
|
25
25
|
// AS metadata at {PUBLIC_URL}/.well-known/oauth-authorization-server and never need
|
|
26
|
-
// the Lightdash client secret.
|
|
27
|
-
//
|
|
26
|
+
// the Lightdash client secret. The broker issues its own access token bound to this
|
|
27
|
+
// exact resource; the downstream Lightdash credential remains a separate OAuth leg.
|
|
28
28
|
return {
|
|
29
29
|
resource: `${publicUrl}${path}`,
|
|
30
30
|
authorization_servers: [publicUrl],
|
package/dist/bin.js
CHANGED
|
@@ -37,18 +37,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
37
37
|
const common_1 = require("@lightdash-tools/common");
|
|
38
38
|
const commander_1 = require("commander");
|
|
39
39
|
const cli_help_js_1 = require("./cli-help.js");
|
|
40
|
+
const env_js_1 = require("./config/env.js");
|
|
41
|
+
const prompt_context_policy_js_1 = require("./config/prompt-context-policy.js");
|
|
40
42
|
const index_js_1 = require("./profiles/index.js");
|
|
41
43
|
const version_js_1 = require("./server/version.js");
|
|
42
44
|
const program = new commander_1.Command();
|
|
43
|
-
function
|
|
45
|
+
function resolvePolicyOrExit(cli) {
|
|
46
|
+
try {
|
|
47
|
+
return (0, prompt_context_policy_js_1.resolvePromptContextPolicy)({
|
|
48
|
+
cli,
|
|
49
|
+
env: process.env,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
catch (err) {
|
|
53
|
+
console.error(err instanceof Error ? err.message : err);
|
|
54
|
+
process.exitCode = 1;
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function runStdio(profileId, promptContext) {
|
|
59
|
+
const promptContextPolicy = resolvePolicyOrExit(promptContext);
|
|
60
|
+
if (!promptContextPolicy)
|
|
61
|
+
return;
|
|
44
62
|
void Promise.resolve().then(() => __importStar(require('./index.js'))).then((m) => {
|
|
45
|
-
m.startStdio(profileId);
|
|
63
|
+
m.startStdio(profileId, { promptContextPolicy });
|
|
46
64
|
});
|
|
47
65
|
}
|
|
48
|
-
function runHttp() {
|
|
49
|
-
|
|
66
|
+
function runHttp(promptContext) {
|
|
67
|
+
const policy = resolvePolicyOrExit(promptContext);
|
|
68
|
+
if (!policy)
|
|
69
|
+
return;
|
|
70
|
+
void Promise.resolve().then(() => __importStar(require('./http.js'))).then((m) => {
|
|
71
|
+
void m.startHttp({ promptContextPolicy: policy });
|
|
72
|
+
});
|
|
50
73
|
}
|
|
51
74
|
const profileList = common_1.PROFILE_IDS.join(', ');
|
|
75
|
+
const promptContextHelp = `Prompt context policy (${prompt_context_policy_js_1.PROMPT_CONTEXT_POLICIES.join('|')}; env: ${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT})`;
|
|
52
76
|
program
|
|
53
77
|
.name('lightdash-mcp')
|
|
54
78
|
.description(`MCP server for Lightdash (${profileList}). Use \`stdio --profile <id>\` or \`http\`.`)
|
|
@@ -65,6 +89,7 @@ program
|
|
|
65
89
|
.command('stdio')
|
|
66
90
|
.description('Run MCP server on stdio')
|
|
67
91
|
.requiredOption('--profile <id>', `Profile id (${profileList})`)
|
|
92
|
+
.option('--prompt-context <policy>', promptContextHelp)
|
|
68
93
|
.addHelpText('after', cli_help_js_1.formatProfilesHelp)
|
|
69
94
|
.action((opts) => {
|
|
70
95
|
const id = (0, index_js_1.parseProfileId)(opts.profile);
|
|
@@ -73,13 +98,14 @@ program
|
|
|
73
98
|
process.exitCode = 1;
|
|
74
99
|
return;
|
|
75
100
|
}
|
|
76
|
-
runStdio(id);
|
|
101
|
+
runStdio(id, opts.promptContext);
|
|
77
102
|
});
|
|
78
103
|
program
|
|
79
104
|
.command('http')
|
|
80
105
|
.description('Run MCP server over Streamable HTTP (fixed profile paths)')
|
|
106
|
+
.option('--prompt-context <policy>', promptContextHelp)
|
|
81
107
|
.addHelpText('after', cli_help_js_1.formatProfilesHelp)
|
|
82
|
-
.action(() => {
|
|
83
|
-
runHttp();
|
|
108
|
+
.action((opts) => {
|
|
109
|
+
runHttp(opts.promptContext);
|
|
84
110
|
});
|
|
85
111
|
program.parse(process.argv);
|
package/dist/config/env.d.ts
CHANGED
|
@@ -11,6 +11,11 @@ export declare const ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = "LIGHTDASH_TOOLS_MCP_P
|
|
|
11
11
|
export declare const ENV_LIGHTDASH_TOOLS_MCP_PATH = "LIGHTDASH_TOOLS_MCP_PATH";
|
|
12
12
|
/** Optional HTTP mount allowlist (comma-separated ProfileIds). Unset/empty → all. Stdio ignores. */
|
|
13
13
|
export declare const ENV_LIGHTDASH_TOOLS_MCP_PROFILES = "LIGHTDASH_TOOLS_MCP_PROFILES";
|
|
14
|
+
/**
|
|
15
|
+
* Prompt playbook embedding policy: `compact` | `compatible` | `embedded`.
|
|
16
|
+
* Unset → package default (`compact`). Stdio `--prompt-context` overrides.
|
|
17
|
+
*/
|
|
18
|
+
export declare const ENV_LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT = "LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT";
|
|
14
19
|
/** Rejected — auth mode is inferred from credentials (ADR-0007). */
|
|
15
20
|
export declare const ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = "LIGHTDASH_TOOLS_MCP_AUTH_MODE";
|
|
16
21
|
export declare const ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = "LIGHTDASH_TOOLS_MCP_SHARED_KEY";
|
package/dist/config/env.js
CHANGED
|
@@ -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_PROFILES = exports.ENV_LIGHTDASH_TOOLS_MCP_PATH = 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_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_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. */
|
|
@@ -14,6 +14,11 @@ exports.ENV_LIGHTDASH_TOOLS_MCP_PUBLIC_URL = 'LIGHTDASH_TOOLS_MCP_PUBLIC_URL';
|
|
|
14
14
|
exports.ENV_LIGHTDASH_TOOLS_MCP_PATH = 'LIGHTDASH_TOOLS_MCP_PATH';
|
|
15
15
|
/** Optional HTTP mount allowlist (comma-separated ProfileIds). Unset/empty → all. Stdio ignores. */
|
|
16
16
|
exports.ENV_LIGHTDASH_TOOLS_MCP_PROFILES = 'LIGHTDASH_TOOLS_MCP_PROFILES';
|
|
17
|
+
/**
|
|
18
|
+
* Prompt playbook embedding policy: `compact` | `compatible` | `embedded`.
|
|
19
|
+
* Unset → package default (`compact`). Stdio `--prompt-context` overrides.
|
|
20
|
+
*/
|
|
21
|
+
exports.ENV_LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT = 'LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT';
|
|
17
22
|
/** Rejected — auth mode is inferred from credentials (ADR-0007). */
|
|
18
23
|
exports.ENV_LIGHTDASH_TOOLS_MCP_AUTH_MODE = 'LIGHTDASH_TOOLS_MCP_AUTH_MODE';
|
|
19
24
|
exports.ENV_LIGHTDASH_TOOLS_MCP_SHARED_KEY = 'LIGHTDASH_TOOLS_MCP_SHARED_KEY';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { SecretString } from '@lightdash-tools/client';
|
|
2
2
|
import { type EnabledProfilesPolicy } from './enabled-profiles.js';
|
|
3
|
+
import { type PromptContextPolicy } from './prompt-context-policy.js';
|
|
3
4
|
import type { McpAuthMode } from '../auth/auth-mode.js';
|
|
4
5
|
export interface McpHttpConfig {
|
|
5
6
|
lightdashUrl: string;
|
|
@@ -10,6 +11,8 @@ export interface McpHttpConfig {
|
|
|
10
11
|
mcpPath: string;
|
|
11
12
|
/** HTTP mount allowlist. Unrestricted when LIGHTDASH_TOOLS_MCP_PROFILES is unset. */
|
|
12
13
|
enabledProfiles: EnabledProfilesPolicy;
|
|
14
|
+
/** Progressive-disclosure prompt embedding policy (default compact). */
|
|
15
|
+
promptContextPolicy: PromptContextPolicy;
|
|
13
16
|
authMode: McpAuthMode;
|
|
14
17
|
sharedKey?: SecretString;
|
|
15
18
|
/** Server-held Lightdash OAuth application client id (broker mode). */
|
|
@@ -24,6 +27,14 @@ export interface McpHttpConfig {
|
|
|
24
27
|
tokenValidationCacheTtlMs: number;
|
|
25
28
|
}
|
|
26
29
|
export declare function emitMcpHttpSecurityWarnings(config: McpHttpConfig): void;
|
|
27
|
-
|
|
30
|
+
/**
|
|
31
|
+
* Load Streamable HTTP MCP config from env.
|
|
32
|
+
* When `options.promptContextPolicy` is set (CLI path), that value wins and
|
|
33
|
+
* `LIGHTDASH_TOOLS_MCP_PROMPT_CONTEXT` is not re-resolved — so invalid env
|
|
34
|
+
* cannot fail a start that already resolved a valid CLI policy.
|
|
35
|
+
*/
|
|
36
|
+
export declare function loadMcpHttpConfig(env?: NodeJS.ProcessEnv, options?: {
|
|
37
|
+
promptContextPolicy?: PromptContextPolicy;
|
|
38
|
+
}): McpHttpConfig;
|
|
28
39
|
export declare function requiresLightdashApiKey(authMode: McpAuthMode): boolean;
|
|
29
40
|
export declare function getOAuthCallbackUrl(config: McpHttpConfig): string;
|
|
@@ -11,6 +11,7 @@ const enabled_profiles_js_1 = require("./enabled-profiles.js");
|
|
|
11
11
|
const env_js_1 = require("./env.js");
|
|
12
12
|
const normalize_url_js_1 = require("./normalize-url.js");
|
|
13
13
|
const obsolete_env_js_1 = require("./obsolete-env.js");
|
|
14
|
+
const prompt_context_policy_js_1 = require("./prompt-context-policy.js");
|
|
14
15
|
const public_url_js_1 = require("./public-url.js");
|
|
15
16
|
const read_env_js_1 = require("./read-env.js");
|
|
16
17
|
const DEFAULT_SCOPES_SUPPORTED = ['read', 'write', 'mcp:read', 'mcp:write'];
|
|
@@ -144,13 +145,13 @@ function emitLightdashOAuthSecurityWarnings(config) {
|
|
|
144
145
|
if (config.authMode !== auth_mode_js_1.MCP_AUTH_MODE_LIGHTDASH_OAUTH) {
|
|
145
146
|
return;
|
|
146
147
|
}
|
|
147
|
-
console.warn('Note: hosted OAuth uses a server-held Lightdash confidential client
|
|
148
|
-
'
|
|
149
|
-
'
|
|
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. ' +
|
|
150
151
|
`Register redirect URI ${getOAuthCallbackUrl(config)} in Lightdash.`);
|
|
151
152
|
if (!config.validateToken) {
|
|
152
|
-
console.warn(`Warning: ${env_js_1.ENV_LIGHTDASH_TOOLS_MCP_VALIDATE_TOKEN}=false — MCP
|
|
153
|
-
'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.');
|
|
154
155
|
}
|
|
155
156
|
emitNgrokFreeInterstitialWarning(config.publicUrl);
|
|
156
157
|
}
|
|
@@ -216,8 +217,14 @@ function resolveOAuthCredentials(authMode, oauthClientId, oauthClientSecretRaw)
|
|
|
216
217
|
: undefined,
|
|
217
218
|
};
|
|
218
219
|
}
|
|
219
|
-
|
|
220
|
-
|
|
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;
|
|
221
228
|
const lightdashUrlRaw = (0, read_env_js_1.readEnv)(client_1.ENV_LIGHTDASH_URL, env);
|
|
222
229
|
if (!lightdashUrlRaw) {
|
|
223
230
|
throw new Error(`${client_1.ENV_LIGHTDASH_URL} is required.`);
|
|
@@ -238,6 +245,7 @@ function loadMcpHttpConfig(env = process.env) {
|
|
|
238
245
|
const allowedOrigins = parseCsv(allowedOriginsRaw);
|
|
239
246
|
const proxyAuth = (0, read_env_js_1.readEnv)(client_1.ENV_LIGHTDASH_PROXY_AUTHORIZATION, env);
|
|
240
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 });
|
|
241
249
|
const mcpPath = (0, enabled_profiles_js_1.resolveRootMcpPath)(enabledProfiles);
|
|
242
250
|
const publicUrl = publicUrlRaw ? (0, normalize_url_js_1.normalizePublicUrl)(publicUrlRaw, (0, index_js_1.listProfilePaths)()) : undefined;
|
|
243
251
|
assertPublicUrlSecurity(authMode, publicUrl);
|
|
@@ -246,12 +254,13 @@ function loadMcpHttpConfig(env = process.env) {
|
|
|
246
254
|
const requiredScopes = readScopeList(env, env_js_1.ENV_LIGHTDASH_TOOLS_MCP_REQUIRED_SCOPES, []);
|
|
247
255
|
const scopesSupportedEnvSet = (0, read_env_js_1.readEnv)(env_js_1.ENV_LIGHTDASH_TOOLS_MCP_SCOPES_SUPPORTED, env) !== undefined;
|
|
248
256
|
assertLightdashOAuthScopePolicy(authMode, requiredScopes, scopesSupportedEnvSet);
|
|
249
|
-
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, [
|
|
250
258
|
{ name: env_js_1.ENV_MCP_HTTP_PORT, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT },
|
|
251
259
|
{ name: env_js_1.ENV_MCP_SERVER_PORT, newName: env_js_1.ENV_LIGHTDASH_TOOLS_MCP_HTTP_PORT },
|
|
252
260
|
], 3100, env_js_1.ENV_PLATFORM_PORT), publicUrl,
|
|
253
261
|
mcpPath,
|
|
254
262
|
enabledProfiles,
|
|
263
|
+
promptContextPolicy,
|
|
255
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) });
|
|
256
265
|
}
|
|
257
266
|
function requiresLightdashApiKey(authMode) {
|
|
@@ -33,6 +33,26 @@ function setOAuthCreds() {
|
|
|
33
33
|
vitest_1.vi.restoreAllMocks();
|
|
34
34
|
});
|
|
35
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
|
+
});
|
|
36
56
|
(0, vitest_1.it)('prefers LIGHTDASH_TOOLS_MCP_HTTP_PORT over MCP_HTTP_PORT', () => {
|
|
37
57
|
process.env.LIGHTDASH_URL = 'https://app.lightdash.cloud';
|
|
38
58
|
process.env.LIGHTDASH_TOOLS_MCP_HTTP_PORT = '3200';
|
|
@@ -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
|
+
});
|
|
@@ -6,5 +6,5 @@ const enabled_profiles_js_1 = require("./enabled-profiles.js");
|
|
|
6
6
|
function makeTestMcpHttpConfig(overrides) {
|
|
7
7
|
var _a;
|
|
8
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, authMode: 'lightdash-oauth', allowedOrigins: [], maxBodyBytes: 1024, requiredScopes: ['mcp:read'], scopesSupported: ['mcp:read', 'mcp:write'], validateToken: true, tokenValidationCacheTtlMs: 30000 }, overrides);
|
|
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);
|
|
10
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>;
|