@lightdash-tools/mcp 0.14.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -14
- package/dist/auth/oauth-broker/as-metadata.d.ts +6 -2
- package/dist/auth/oauth-broker/as-metadata.js +8 -4
- package/dist/auth/oauth-broker/invoke-origins.d.ts +16 -0
- package/dist/auth/oauth-broker/invoke-origins.js +112 -0
- package/dist/auth/oauth-broker/invoke-origins.test.d.ts +1 -0
- package/dist/auth/oauth-broker/invoke-origins.test.js +82 -0
- 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 +124 -48
- package/dist/auth/oauth-broker/routes.test.js +191 -16
- package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +3 -1
- package/dist/auth/resource-server/lightdash-oauth-middleware.js +65 -41
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +95 -59
- package/dist/auth/resource-server/oauth-protected-resource.d.ts +2 -2
- package/dist/auth/resource-server/oauth-protected-resource.js +8 -11
- package/dist/auth/resource-server/www-authenticate.test.js +3 -3
- package/dist/bin.js +33 -7
- package/dist/config/env.d.ts +10 -0
- package/dist/config/env.js +11 -1
- package/dist/config/load-mcp-config.d.ts +14 -1
- package/dist/config/load-mcp-config.js +35 -8
- package/dist/config/load-mcp-config.test.js +49 -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.helpers.d.ts +50 -0
- package/dist/http.integration.helpers.js +190 -0
- package/dist/http.integration.test.js +81 -187
- package/dist/http.invoke-origin.integration.test.d.ts +1 -0
- package/dist/http.invoke-origin.integration.test.js +108 -0
- 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 +13 -4
- package/dist/transports/streamable-http.test.js +8 -3
- package/package.json +3 -3
|
@@ -7,135 +7,8 @@ const vitest_1 = require("vitest");
|
|
|
7
7
|
const oauth_protected_resource_js_1 = require("./auth/resource-server/oauth-protected-resource.js");
|
|
8
8
|
const enabled_profiles_js_1 = require("./config/enabled-profiles.js");
|
|
9
9
|
const test_mcp_http_config_js_1 = require("./config/test-mcp-http-config.js");
|
|
10
|
+
const http_integration_helpers_js_1 = require("./http.integration.helpers.js");
|
|
10
11
|
const streamable_http_js_1 = require("./transports/streamable-http.js");
|
|
11
|
-
const TOKEN_A = scopedAccessToken('mcp:read mcp:write', 'token-a');
|
|
12
|
-
const TOKEN_B = scopedAccessToken('mcp:read mcp:write', 'token-b');
|
|
13
|
-
const TOKEN_READ_ONLY = scopedAccessToken('mcp:read', 'token-read-only');
|
|
14
|
-
const OPAQUE_TOKEN_A = 'opaque-token-user-a';
|
|
15
|
-
const USER_A = { userUuid: 'user-a-uuid', email: 'a@example.com', organizationUuid: 'org-a-uuid' };
|
|
16
|
-
const USER_B = { userUuid: 'user-b-uuid', email: 'b@example.com', organizationUuid: 'org-b-uuid' };
|
|
17
|
-
function scopedAccessToken(scope, subject) {
|
|
18
|
-
const header = Buffer.from(JSON.stringify({ alg: 'none', typ: 'JWT' })).toString('base64url');
|
|
19
|
-
const payload = Buffer.from(JSON.stringify({ scope, sub: subject })).toString('base64url');
|
|
20
|
-
return `${header}.${payload}.signature`;
|
|
21
|
-
}
|
|
22
|
-
const INITIALIZE_BODY = {
|
|
23
|
-
jsonrpc: '2.0',
|
|
24
|
-
method: 'initialize',
|
|
25
|
-
params: {
|
|
26
|
-
protocolVersion: '2024-11-05',
|
|
27
|
-
capabilities: {},
|
|
28
|
-
clientInfo: { name: 'integration-test', version: '1.0.0' },
|
|
29
|
-
},
|
|
30
|
-
id: 1,
|
|
31
|
-
};
|
|
32
|
-
function listen(server, port, host) {
|
|
33
|
-
return new Promise((resolve, reject) => {
|
|
34
|
-
server.once('error', reject);
|
|
35
|
-
server.listen(port, host, () => {
|
|
36
|
-
server.removeListener('error', reject);
|
|
37
|
-
resolve();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
async function startMockLightdashServer() {
|
|
42
|
-
const authorizationHeaders = [];
|
|
43
|
-
const users = {
|
|
44
|
-
[TOKEN_A]: USER_A,
|
|
45
|
-
[TOKEN_B]: USER_B,
|
|
46
|
-
[TOKEN_READ_ONLY]: USER_A,
|
|
47
|
-
[OPAQUE_TOKEN_A]: USER_A,
|
|
48
|
-
};
|
|
49
|
-
let issuerBaseUrl = '';
|
|
50
|
-
const server = (0, node_http_1.createServer)((req, res) => {
|
|
51
|
-
var _a;
|
|
52
|
-
const authHeader = req.headers.authorization;
|
|
53
|
-
const auth = typeof authHeader === 'string' ? authHeader : ((_a = authHeader === null || authHeader === void 0 ? void 0 : authHeader[0]) !== null && _a !== void 0 ? _a : '');
|
|
54
|
-
authorizationHeaders.push(auth);
|
|
55
|
-
if (req.method === 'GET' && req.url === '/.well-known/oauth-authorization-server') {
|
|
56
|
-
res.writeHead(200, { 'Content-Type': 'application/json' }).end(JSON.stringify({
|
|
57
|
-
issuer: issuerBaseUrl,
|
|
58
|
-
authorization_endpoint: `${issuerBaseUrl}/api/v1/oauth/authorize`,
|
|
59
|
-
token_endpoint: `${issuerBaseUrl}/api/v1/oauth/token`,
|
|
60
|
-
revocation_endpoint: `${issuerBaseUrl}/api/v1/oauth/revoke`,
|
|
61
|
-
registration_endpoint: `${issuerBaseUrl}/api/v1/oauth/register`,
|
|
62
|
-
userinfo_endpoint: `${issuerBaseUrl}/api/v1/oauth/userinfo`,
|
|
63
|
-
}));
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
if (req.method === 'GET' && req.url === '/api/v1/user') {
|
|
67
|
-
const token = auth.startsWith('Bearer ') ? auth.slice('Bearer '.length).trim() : '';
|
|
68
|
-
const user = users[token];
|
|
69
|
-
if (!user) {
|
|
70
|
-
res.writeHead(401, { 'Content-Type': 'application/json' }).end(JSON.stringify({
|
|
71
|
-
status: 'error',
|
|
72
|
-
error: { statusCode: 401, name: 'Unauthorized', message: 'Invalid token' },
|
|
73
|
-
}));
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
res
|
|
77
|
-
.writeHead(200, { 'Content-Type': 'application/json' })
|
|
78
|
-
.end(JSON.stringify({ status: 'ok', results: user }));
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (req.method === 'GET' && req.url === '/api/v1/org/projects') {
|
|
82
|
-
const token = auth.startsWith('Bearer ') ? auth.slice('Bearer '.length).trim() : '';
|
|
83
|
-
if (!users[token]) {
|
|
84
|
-
res.writeHead(401, { 'Content-Type': 'application/json' }).end(JSON.stringify({
|
|
85
|
-
status: 'error',
|
|
86
|
-
error: { statusCode: 401, name: 'Unauthorized', message: 'Invalid token' },
|
|
87
|
-
}));
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
res.writeHead(200, { 'Content-Type': 'application/json' }).end(JSON.stringify({
|
|
91
|
-
status: 'ok',
|
|
92
|
-
results: [
|
|
93
|
-
{
|
|
94
|
-
projectUuid: 'project-a-uuid',
|
|
95
|
-
name: 'Project A',
|
|
96
|
-
type: 'DEFAULT',
|
|
97
|
-
},
|
|
98
|
-
],
|
|
99
|
-
}));
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
res.writeHead(404).end();
|
|
103
|
-
});
|
|
104
|
-
await listen(server, 0, '127.0.0.1');
|
|
105
|
-
const address = server.address();
|
|
106
|
-
issuerBaseUrl = `http://127.0.0.1:${address.port}`;
|
|
107
|
-
return {
|
|
108
|
-
baseUrl: issuerBaseUrl,
|
|
109
|
-
authorizationHeaders,
|
|
110
|
-
close: () => new Promise((resolve, reject) => {
|
|
111
|
-
server.close((err) => {
|
|
112
|
-
if (err)
|
|
113
|
-
reject(err);
|
|
114
|
-
else
|
|
115
|
-
resolve();
|
|
116
|
-
});
|
|
117
|
-
}),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function baseOAuthConfig(lightdashUrl, overrides) {
|
|
121
|
-
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));
|
|
122
|
-
}
|
|
123
|
-
async function postMcp(baseUrl, body, options) {
|
|
124
|
-
var _a;
|
|
125
|
-
const headers = {
|
|
126
|
-
'Content-Type': 'application/json',
|
|
127
|
-
Accept: 'application/json, text/event-stream',
|
|
128
|
-
};
|
|
129
|
-
if (options === null || options === void 0 ? void 0 : options.token) {
|
|
130
|
-
headers.Authorization = `Bearer ${options.token}`;
|
|
131
|
-
}
|
|
132
|
-
const path = (_a = options === null || options === void 0 ? void 0 : options.path) !== null && _a !== void 0 ? _a : '/semantic-layer/v1/mcp';
|
|
133
|
-
return fetch(`${baseUrl}${path}`, {
|
|
134
|
-
method: 'POST',
|
|
135
|
-
headers,
|
|
136
|
-
body: JSON.stringify(body),
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
12
|
function parseSseOrJsonToolText(raw) {
|
|
140
13
|
if (raw.includes('data:')) {
|
|
141
14
|
const lines = raw
|
|
@@ -152,8 +25,8 @@ function parseSseOrJsonToolText(raw) {
|
|
|
152
25
|
(0, vitest_1.beforeEach)(async () => {
|
|
153
26
|
vitest_1.vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
|
154
27
|
vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
155
|
-
mockLightdash = await startMockLightdashServer();
|
|
156
|
-
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign({}, baseOAuthConfig(mockLightdash.baseUrl)));
|
|
28
|
+
mockLightdash = await (0, http_integration_helpers_js_1.startMockLightdashServer)();
|
|
29
|
+
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign({}, (0, http_integration_helpers_js_1.baseOAuthConfig)(mockLightdash.baseUrl)));
|
|
157
30
|
});
|
|
158
31
|
(0, vitest_1.afterEach)(async () => {
|
|
159
32
|
await mcpServer.close();
|
|
@@ -161,7 +34,7 @@ function parseSseOrJsonToolText(raw) {
|
|
|
161
34
|
vitest_1.vi.restoreAllMocks();
|
|
162
35
|
});
|
|
163
36
|
(0, vitest_1.it)('returns 401 with WWW-Authenticate resource_metadata when OAuth token is missing', async () => {
|
|
164
|
-
const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY);
|
|
37
|
+
const response = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY);
|
|
165
38
|
(0, vitest_1.expect)(response.status).toBe(401);
|
|
166
39
|
const wwwAuthenticate = response.headers.get('www-authenticate');
|
|
167
40
|
(0, vitest_1.expect)(wwwAuthenticate).toContain('resource_metadata=');
|
|
@@ -169,18 +42,21 @@ function parseSseOrJsonToolText(raw) {
|
|
|
169
42
|
});
|
|
170
43
|
(0, vitest_1.it)('returns 401 without echoing invalid bearer token in response body', async () => {
|
|
171
44
|
const invalidToken = 'not-a-valid-token';
|
|
172
|
-
const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: invalidToken });
|
|
45
|
+
const response = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, { token: invalidToken });
|
|
173
46
|
(0, vitest_1.expect)(response.status).toBe(401);
|
|
174
47
|
const body = await response.text();
|
|
175
48
|
(0, vitest_1.expect)(body).not.toContain(invalidToken);
|
|
176
49
|
(0, vitest_1.expect)(response.headers.get('www-authenticate')).toContain('invalid_token');
|
|
177
50
|
});
|
|
178
|
-
(0, vitest_1.it)('handles initialize with
|
|
179
|
-
const
|
|
51
|
+
(0, vitest_1.it)('handles initialize with an MCP bearer and validates the downstream Lightdash bearer', async () => {
|
|
52
|
+
const mcpToken = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.TOKEN_A);
|
|
53
|
+
const response = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, { token: mcpToken });
|
|
180
54
|
(0, vitest_1.expect)(response.status).toBe(200);
|
|
181
|
-
// Sessionless: no session-id header is set
|
|
55
|
+
// Sessionless: no session-id header is set.
|
|
182
56
|
(0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeFalsy();
|
|
183
|
-
(0, vitest_1.expect)(
|
|
57
|
+
(0, vitest_1.expect)(mcpToken).not.toBe(http_integration_helpers_js_1.TOKEN_A);
|
|
58
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${http_integration_helpers_js_1.TOKEN_A}`);
|
|
59
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpToken}`);
|
|
184
60
|
});
|
|
185
61
|
(0, vitest_1.it)('returns 401 before parsing malformed JSON when OAuth token is missing', async () => {
|
|
186
62
|
const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
|
|
@@ -195,19 +71,20 @@ function parseSseOrJsonToolText(raw) {
|
|
|
195
71
|
(0, vitest_1.expect)(response.headers.get('www-authenticate')).toContain('resource_metadata=');
|
|
196
72
|
});
|
|
197
73
|
(0, vitest_1.it)('returns 401 invalid_token for invalid bearer before accepting valid JSON', async () => {
|
|
198
|
-
const response = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
|
|
74
|
+
const response = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, {
|
|
199
75
|
token: 'not-a-valid-token',
|
|
200
76
|
});
|
|
201
77
|
(0, vitest_1.expect)(response.status).toBe(401);
|
|
202
78
|
(0, vitest_1.expect)(response.headers.get('www-authenticate')).toContain('invalid_token');
|
|
203
79
|
});
|
|
204
80
|
(0, vitest_1.it)('returns 400 for malformed JSON only after successful OAuth authentication', async () => {
|
|
81
|
+
const mcpToken = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.TOKEN_A);
|
|
205
82
|
const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
|
|
206
83
|
method: 'POST',
|
|
207
84
|
headers: {
|
|
208
85
|
'Content-Type': 'application/json',
|
|
209
86
|
Accept: 'application/json, text/event-stream',
|
|
210
|
-
Authorization: `Bearer ${
|
|
87
|
+
Authorization: `Bearer ${mcpToken}`,
|
|
211
88
|
},
|
|
212
89
|
body: '{not-json',
|
|
213
90
|
});
|
|
@@ -253,7 +130,7 @@ function parseSseOrJsonToolText(raw) {
|
|
|
253
130
|
const response = await fetch(`${mcpServer.baseUrl}/organization-audit/v1/mcp`, {
|
|
254
131
|
method: 'POST',
|
|
255
132
|
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
256
|
-
body: JSON.stringify(INITIALIZE_BODY),
|
|
133
|
+
body: JSON.stringify(http_integration_helpers_js_1.INITIALIZE_BODY),
|
|
257
134
|
});
|
|
258
135
|
(0, vitest_1.expect)(response.status).toBe(401);
|
|
259
136
|
const wwwAuthenticate = response.headers.get('www-authenticate');
|
|
@@ -264,7 +141,7 @@ function parseSseOrJsonToolText(raw) {
|
|
|
264
141
|
const response = await fetch(`${mcpServer.baseUrl}/content-reader/v1/mcp`, {
|
|
265
142
|
method: 'POST',
|
|
266
143
|
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
267
|
-
body: JSON.stringify(INITIALIZE_BODY),
|
|
144
|
+
body: JSON.stringify(http_integration_helpers_js_1.INITIALIZE_BODY),
|
|
268
145
|
});
|
|
269
146
|
(0, vitest_1.expect)(response.status).toBe(401);
|
|
270
147
|
const wwwAuthenticate = response.headers.get('www-authenticate');
|
|
@@ -275,24 +152,29 @@ function parseSseOrJsonToolText(raw) {
|
|
|
275
152
|
const response = await fetch(`${mcpServer.baseUrl}/content-governance/v1/mcp`, {
|
|
276
153
|
method: 'POST',
|
|
277
154
|
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
|
|
278
|
-
body: JSON.stringify(INITIALIZE_BODY),
|
|
155
|
+
body: JSON.stringify(http_integration_helpers_js_1.INITIALIZE_BODY),
|
|
279
156
|
});
|
|
280
157
|
(0, vitest_1.expect)(response.status).toBe(401);
|
|
281
158
|
const wwwAuthenticate = response.headers.get('www-authenticate');
|
|
282
159
|
(0, vitest_1.expect)(wwwAuthenticate).toContain(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource/content-governance/v1/mcp`);
|
|
283
160
|
(0, vitest_1.expect)(wwwAuthenticate).not.toContain('semantic-layer/v1/mcp');
|
|
284
161
|
});
|
|
285
|
-
(0, vitest_1.it)('maps
|
|
286
|
-
const
|
|
287
|
-
const
|
|
162
|
+
(0, vitest_1.it)('maps two MCP tokens to distinct authenticated users upstream', async () => {
|
|
163
|
+
const mcpTokenA = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.TOKEN_A);
|
|
164
|
+
const mcpTokenB = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.TOKEN_B);
|
|
165
|
+
const responseA = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, { token: mcpTokenA });
|
|
166
|
+
const responseB = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, { token: mcpTokenB });
|
|
288
167
|
(0, vitest_1.expect)(responseA.status).toBe(200);
|
|
289
168
|
(0, vitest_1.expect)(responseB.status).toBe(200);
|
|
290
|
-
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
|
|
291
|
-
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_B}`);
|
|
169
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${http_integration_helpers_js_1.TOKEN_A}`);
|
|
170
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${http_integration_helpers_js_1.TOKEN_B}`);
|
|
171
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpTokenA}`);
|
|
172
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpTokenB}`);
|
|
292
173
|
});
|
|
293
174
|
(0, vitest_1.it)('accepts form-elicitation caps from per-request _meta on content-governance tools/call', async () => {
|
|
294
175
|
const governancePath = '/content-governance/v1/mcp';
|
|
295
|
-
const
|
|
176
|
+
const mcpToken = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.TOKEN_A, { path: governancePath });
|
|
177
|
+
const call = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, {
|
|
296
178
|
jsonrpc: '2.0',
|
|
297
179
|
method: 'tools/call',
|
|
298
180
|
params: {
|
|
@@ -306,7 +188,7 @@ function parseSseOrJsonToolText(raw) {
|
|
|
306
188
|
},
|
|
307
189
|
},
|
|
308
190
|
id: 2,
|
|
309
|
-
}, { token:
|
|
191
|
+
}, { token: mcpToken, path: governancePath });
|
|
310
192
|
(0, vitest_1.expect)(call.status).toBe(200);
|
|
311
193
|
const text = parseSseOrJsonToolText(await call.text());
|
|
312
194
|
// Per-request envelope caps: past ELICITATION_REQUIRED into chart resolve (mock has no chart).
|
|
@@ -320,12 +202,13 @@ function parseSseOrJsonToolText(raw) {
|
|
|
320
202
|
error: { statusCode: 503, name: 'ServiceUnavailable', message: 'Down' },
|
|
321
203
|
}));
|
|
322
204
|
});
|
|
323
|
-
await listen(unavailableServer, 0, '127.0.0.1');
|
|
205
|
+
await (0, http_integration_helpers_js_1.listen)(unavailableServer, 0, '127.0.0.1');
|
|
324
206
|
const unavailableAddress = unavailableServer.address();
|
|
325
207
|
const unavailableUrl = `http://127.0.0.1:${unavailableAddress.port}`;
|
|
326
|
-
const downServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign({}, baseOAuthConfig(unavailableUrl)));
|
|
208
|
+
const downServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign({}, (0, http_integration_helpers_js_1.baseOAuthConfig)(unavailableUrl)));
|
|
327
209
|
try {
|
|
328
|
-
const
|
|
210
|
+
const mcpToken = (0, http_integration_helpers_js_1.brokerAccessToken)(downServer.baseUrl, http_integration_helpers_js_1.TOKEN_A);
|
|
211
|
+
const response = await (0, http_integration_helpers_js_1.postMcp)(downServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, { token: mcpToken });
|
|
329
212
|
(0, vitest_1.expect)(response.status).toBe(503);
|
|
330
213
|
(0, vitest_1.expect)(await response.json()).toEqual({
|
|
331
214
|
error: 'temporarily_unavailable',
|
|
@@ -351,8 +234,8 @@ function parseSseOrJsonToolText(raw) {
|
|
|
351
234
|
(0, vitest_1.beforeEach)(async () => {
|
|
352
235
|
vitest_1.vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
|
353
236
|
vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
354
|
-
mockLightdash = await startMockLightdashServer();
|
|
355
|
-
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign({}, baseOAuthConfig(mockLightdash.baseUrl)));
|
|
237
|
+
mockLightdash = await (0, http_integration_helpers_js_1.startMockLightdashServer)();
|
|
238
|
+
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign({}, (0, http_integration_helpers_js_1.baseOAuthConfig)(mockLightdash.baseUrl)));
|
|
356
239
|
});
|
|
357
240
|
(0, vitest_1.afterEach)(async () => {
|
|
358
241
|
await mcpServer.close();
|
|
@@ -373,33 +256,41 @@ function parseSseOrJsonToolText(raw) {
|
|
|
373
256
|
(0, vitest_1.expect)(asMetadata.token_endpoint).toBe(`${mcpServer.baseUrl}/oauth/token`);
|
|
374
257
|
(0, vitest_1.expect)(asMetadata.registration_endpoint).toBe(`${mcpServer.baseUrl}/oauth/register`);
|
|
375
258
|
});
|
|
376
|
-
(0, vitest_1.it)('handles initialize
|
|
377
|
-
const
|
|
259
|
+
(0, vitest_1.it)('handles initialize when the downstream Lightdash credential is opaque', async () => {
|
|
260
|
+
const mcpToken = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.OPAQUE_TOKEN_A);
|
|
261
|
+
const response = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, { token: mcpToken });
|
|
378
262
|
(0, vitest_1.expect)(response.status).toBe(200);
|
|
379
263
|
(0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeFalsy();
|
|
380
|
-
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${OPAQUE_TOKEN_A}`);
|
|
264
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${http_integration_helpers_js_1.OPAQUE_TOKEN_A}`);
|
|
265
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpToken}`);
|
|
381
266
|
});
|
|
382
|
-
(0, vitest_1.it)('accepts
|
|
383
|
-
const
|
|
384
|
-
|
|
267
|
+
(0, vitest_1.it)('accepts an MCP token carrying mcp:read scope on initialize', async () => {
|
|
268
|
+
const mcpToken = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.TOKEN_READ_ONLY, { scope: 'mcp:read' });
|
|
269
|
+
const response = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, {
|
|
270
|
+
token: mcpToken,
|
|
385
271
|
});
|
|
386
272
|
(0, vitest_1.expect)(response.status).toBe(200);
|
|
387
|
-
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_READ_ONLY}`);
|
|
273
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${http_integration_helpers_js_1.TOKEN_READ_ONLY}`);
|
|
388
274
|
});
|
|
389
|
-
(0, vitest_1.it)('accepts
|
|
390
|
-
const
|
|
391
|
-
|
|
275
|
+
(0, vitest_1.it)('accepts an MCP token carrying mcp:read mcp:write scope on initialize', async () => {
|
|
276
|
+
const mcpToken = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.TOKEN_A, {
|
|
277
|
+
scope: 'mcp:read mcp:write',
|
|
278
|
+
});
|
|
279
|
+
const response = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, {
|
|
280
|
+
token: mcpToken,
|
|
392
281
|
});
|
|
393
282
|
(0, vitest_1.expect)(response.status).toBe(200);
|
|
394
|
-
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${TOKEN_A}`);
|
|
283
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).toContain(`Bearer ${http_integration_helpers_js_1.TOKEN_A}`);
|
|
395
284
|
});
|
|
396
|
-
(0, vitest_1.it)('forwards
|
|
397
|
-
const
|
|
398
|
-
|
|
285
|
+
(0, vitest_1.it)('forwards only the decrypted downstream bearer to Lightdash', async () => {
|
|
286
|
+
const mcpToken = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.OPAQUE_TOKEN_A);
|
|
287
|
+
const response = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, {
|
|
288
|
+
token: mcpToken,
|
|
399
289
|
});
|
|
400
290
|
(0, vitest_1.expect)(response.status).toBe(200);
|
|
401
|
-
const
|
|
402
|
-
(0, vitest_1.expect)(
|
|
291
|
+
const downstreamHeaders = mockLightdash.authorizationHeaders.filter((header) => header === `Bearer ${http_integration_helpers_js_1.OPAQUE_TOKEN_A}`);
|
|
292
|
+
(0, vitest_1.expect)(downstreamHeaders.length).toBeGreaterThan(0);
|
|
293
|
+
(0, vitest_1.expect)(mockLightdash.authorizationHeaders).not.toContain(`Bearer ${mcpToken}`);
|
|
403
294
|
});
|
|
404
295
|
});
|
|
405
296
|
(0, vitest_1.describe)('MCP HTTP CORS integration', () => {
|
|
@@ -408,8 +299,8 @@ function parseSseOrJsonToolText(raw) {
|
|
|
408
299
|
(0, vitest_1.beforeEach)(async () => {
|
|
409
300
|
vitest_1.vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
|
410
301
|
vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
411
|
-
mockLightdash = await startMockLightdashServer();
|
|
412
|
-
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign(Object.assign({}, baseOAuthConfig(mockLightdash.baseUrl)), { allowedOrigins: ['https://app.example.com'] }));
|
|
302
|
+
mockLightdash = await (0, http_integration_helpers_js_1.startMockLightdashServer)();
|
|
303
|
+
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign(Object.assign({}, (0, http_integration_helpers_js_1.baseOAuthConfig)(mockLightdash.baseUrl)), { allowedOrigins: ['https://app.example.com'] }));
|
|
413
304
|
});
|
|
414
305
|
(0, vitest_1.afterEach)(async () => {
|
|
415
306
|
await mcpServer.close();
|
|
@@ -451,8 +342,8 @@ function parseSseOrJsonToolText(raw) {
|
|
|
451
342
|
(0, vitest_1.beforeEach)(async () => {
|
|
452
343
|
vitest_1.vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
|
453
344
|
vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
454
|
-
mockLightdash = await startMockLightdashServer();
|
|
455
|
-
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign(Object.assign({}, baseOAuthConfig(mockLightdash.baseUrl)), { maxBodyBytes: 512 }));
|
|
345
|
+
mockLightdash = await (0, http_integration_helpers_js_1.startMockLightdashServer)();
|
|
346
|
+
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign(Object.assign({}, (0, http_integration_helpers_js_1.baseOAuthConfig)(mockLightdash.baseUrl)), { maxBodyBytes: 512 }));
|
|
456
347
|
});
|
|
457
348
|
(0, vitest_1.afterEach)(async () => {
|
|
458
349
|
await mcpServer.close();
|
|
@@ -460,13 +351,14 @@ function parseSseOrJsonToolText(raw) {
|
|
|
460
351
|
vitest_1.vi.restoreAllMocks();
|
|
461
352
|
});
|
|
462
353
|
(0, vitest_1.it)('returns 413 for oversized JSON body after OAuth authentication', async () => {
|
|
463
|
-
const hugeBody = JSON.stringify(Object.assign(Object.assign({}, INITIALIZE_BODY), { params: Object.assign(Object.assign({}, INITIALIZE_BODY.params), { padding: 'x'.repeat(1024) }) }));
|
|
354
|
+
const hugeBody = JSON.stringify(Object.assign(Object.assign({}, http_integration_helpers_js_1.INITIALIZE_BODY), { params: Object.assign(Object.assign({}, http_integration_helpers_js_1.INITIALIZE_BODY.params), { padding: 'x'.repeat(1024) }) }));
|
|
355
|
+
const mcpToken = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.TOKEN_A);
|
|
464
356
|
const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
|
|
465
357
|
method: 'POST',
|
|
466
358
|
headers: {
|
|
467
359
|
'Content-Type': 'application/json',
|
|
468
360
|
Accept: 'application/json, text/event-stream',
|
|
469
|
-
Authorization: `Bearer ${
|
|
361
|
+
Authorization: `Bearer ${mcpToken}`,
|
|
470
362
|
},
|
|
471
363
|
body: hugeBody,
|
|
472
364
|
});
|
|
@@ -478,7 +370,7 @@ function parseSseOrJsonToolText(raw) {
|
|
|
478
370
|
method: 'GET',
|
|
479
371
|
headers: {
|
|
480
372
|
Accept: 'application/json, text/event-stream',
|
|
481
|
-
Authorization: `Bearer ${TOKEN_A}`,
|
|
373
|
+
Authorization: `Bearer ${http_integration_helpers_js_1.TOKEN_A}`,
|
|
482
374
|
},
|
|
483
375
|
});
|
|
484
376
|
(0, vitest_1.expect)(response.status).toBe(405);
|
|
@@ -487,7 +379,7 @@ function parseSseOrJsonToolText(raw) {
|
|
|
487
379
|
const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
|
|
488
380
|
method: 'DELETE',
|
|
489
381
|
headers: {
|
|
490
|
-
Authorization: `Bearer ${TOKEN_A}`,
|
|
382
|
+
Authorization: `Bearer ${http_integration_helpers_js_1.TOKEN_A}`,
|
|
491
383
|
},
|
|
492
384
|
});
|
|
493
385
|
(0, vitest_1.expect)(response.status).toBe(405);
|
|
@@ -499,8 +391,8 @@ function parseSseOrJsonToolText(raw) {
|
|
|
499
391
|
(0, vitest_1.beforeEach)(async () => {
|
|
500
392
|
vitest_1.vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
|
501
393
|
vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
502
|
-
mockLightdash = await startMockLightdashServer();
|
|
503
|
-
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(baseOAuthConfig(mockLightdash.baseUrl, {
|
|
394
|
+
mockLightdash = await (0, http_integration_helpers_js_1.startMockLightdashServer)();
|
|
395
|
+
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)((0, http_integration_helpers_js_1.baseOAuthConfig)(mockLightdash.baseUrl, {
|
|
504
396
|
enabledProfiles: (0, enabled_profiles_js_1.parseEnabledProfiles)('content-reader'),
|
|
505
397
|
}));
|
|
506
398
|
});
|
|
@@ -510,15 +402,17 @@ function parseSseOrJsonToolText(raw) {
|
|
|
510
402
|
vitest_1.vi.restoreAllMocks();
|
|
511
403
|
});
|
|
512
404
|
(0, vitest_1.it)('404s disabled profile MCP paths and their path-specific PRM', async () => {
|
|
513
|
-
const mcpResponse = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, { token: TOKEN_A });
|
|
405
|
+
const mcpResponse = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, { token: http_integration_helpers_js_1.TOKEN_A });
|
|
514
406
|
(0, vitest_1.expect)(mcpResponse.status).toBe(404);
|
|
515
407
|
const prmResponse = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource/semantic-layer/v1/mcp`);
|
|
516
408
|
(0, vitest_1.expect)(prmResponse.status).toBe(404);
|
|
517
409
|
});
|
|
518
410
|
(0, vitest_1.it)('keeps enabled profile MCP and PRM reachable', async () => {
|
|
519
|
-
const
|
|
520
|
-
|
|
521
|
-
|
|
411
|
+
const contentReaderPath = '/content-reader/v1/mcp';
|
|
412
|
+
const mcpToken = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.TOKEN_A, { path: contentReaderPath });
|
|
413
|
+
const mcpResponse = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, {
|
|
414
|
+
token: mcpToken,
|
|
415
|
+
path: contentReaderPath,
|
|
522
416
|
});
|
|
523
417
|
(0, vitest_1.expect)(mcpResponse.status).toBe(200);
|
|
524
418
|
const prmResponse = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource/content-reader/v1/mcp`);
|
|
@@ -558,9 +452,9 @@ function parseSseOrJsonToolText(raw) {
|
|
|
558
452
|
vitest_1.vi.restoreAllMocks();
|
|
559
453
|
});
|
|
560
454
|
(0, vitest_1.it)('requires shared key on MCP endpoint', async () => {
|
|
561
|
-
const unauthorized = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY);
|
|
455
|
+
const unauthorized = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY);
|
|
562
456
|
(0, vitest_1.expect)(unauthorized.status).toBe(401);
|
|
563
|
-
const authorized = await postMcp(mcpServer.baseUrl, INITIALIZE_BODY, {
|
|
457
|
+
const authorized = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, {
|
|
564
458
|
token: 'shared-secret',
|
|
565
459
|
});
|
|
566
460
|
(0, vitest_1.expect)(authorized.status).toBe(200);
|
|
@@ -568,7 +462,7 @@ function parseSseOrJsonToolText(raw) {
|
|
|
568
462
|
(0, vitest_1.expect)(authorized.headers.get('mcp-session-id')).toBeFalsy();
|
|
569
463
|
});
|
|
570
464
|
(0, vitest_1.it)('returns 401 before reading oversized bodies when shared key is missing', async () => {
|
|
571
|
-
const hugeBody = JSON.stringify(Object.assign(Object.assign({}, INITIALIZE_BODY), { params: Object.assign(Object.assign({}, INITIALIZE_BODY.params), { padding: 'x'.repeat(2048) }) }));
|
|
465
|
+
const hugeBody = JSON.stringify(Object.assign(Object.assign({}, http_integration_helpers_js_1.INITIALIZE_BODY), { params: Object.assign(Object.assign({}, http_integration_helpers_js_1.INITIALIZE_BODY.params), { padding: 'x'.repeat(2048) }) }));
|
|
572
466
|
const response = await fetch(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`, {
|
|
573
467
|
method: 'POST',
|
|
574
468
|
headers: {
|
|
@@ -588,7 +482,7 @@ function parseSseOrJsonToolText(raw) {
|
|
|
588
482
|
Accept: 'application/json, text/event-stream',
|
|
589
483
|
'X-API-Key': 'shared-secret',
|
|
590
484
|
},
|
|
591
|
-
body: JSON.stringify(INITIALIZE_BODY),
|
|
485
|
+
body: JSON.stringify(http_integration_helpers_js_1.INITIALIZE_BODY),
|
|
592
486
|
});
|
|
593
487
|
(0, vitest_1.expect)(response.status).toBe(200);
|
|
594
488
|
(0, vitest_1.expect)(response.headers.get('mcp-session-id')).toBeFalsy();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const http_integration_helpers_js_1 = require("./http.integration.helpers.js");
|
|
5
|
+
const streamable_http_js_1 = require("./transports/streamable-http.js");
|
|
6
|
+
(0, vitest_1.describe)('MCP HTTP extra invoke-origin OAuth', () => {
|
|
7
|
+
const invokeHost = 'mcp.ilb.internal';
|
|
8
|
+
const invokeOrigin = `http://${invokeHost}`;
|
|
9
|
+
let mockLightdash;
|
|
10
|
+
let mcpServer;
|
|
11
|
+
(0, vitest_1.beforeEach)(async () => {
|
|
12
|
+
vitest_1.vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
|
13
|
+
vitest_1.vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
|
14
|
+
mockLightdash = await (0, http_integration_helpers_js_1.startMockLightdashServer)();
|
|
15
|
+
mcpServer = await (0, streamable_http_js_1.createStreamableHttpServer)(Object.assign({}, (0, http_integration_helpers_js_1.baseOAuthConfig)(mockLightdash.baseUrl, {
|
|
16
|
+
invokeOrigins: [new URL(invokeOrigin)],
|
|
17
|
+
})));
|
|
18
|
+
});
|
|
19
|
+
(0, vitest_1.afterEach)(async () => {
|
|
20
|
+
await mcpServer.close();
|
|
21
|
+
await mockLightdash.close();
|
|
22
|
+
vitest_1.vi.restoreAllMocks();
|
|
23
|
+
});
|
|
24
|
+
(0, vitest_1.it)('keeps public PRM and AS metadata on the listen Host', async () => {
|
|
25
|
+
const prm = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-protected-resource`);
|
|
26
|
+
(0, vitest_1.expect)(prm.status).toBe(200);
|
|
27
|
+
const prmBody = (await prm.json());
|
|
28
|
+
(0, vitest_1.expect)(prmBody.authorization_servers).toEqual([mcpServer.baseUrl]);
|
|
29
|
+
(0, vitest_1.expect)(prmBody.resource).toBe(`${mcpServer.baseUrl}/semantic-layer/v1/mcp`);
|
|
30
|
+
const asRes = await fetch(`${mcpServer.baseUrl}/.well-known/oauth-authorization-server`);
|
|
31
|
+
const asBody = (await asRes.json());
|
|
32
|
+
(0, vitest_1.expect)(asBody.issuer).toBe(mcpServer.baseUrl);
|
|
33
|
+
(0, vitest_1.expect)(asBody.token_endpoint).toBe(`${mcpServer.baseUrl}/oauth/token`);
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.it)('advertises invoke-origin PRM and token/DCR when Host matches', async () => {
|
|
36
|
+
const headers = { host: invokeHost, 'x-forwarded-proto': 'http' };
|
|
37
|
+
const prm = await (0, http_integration_helpers_js_1.nodeRequest)({
|
|
38
|
+
baseUrl: mcpServer.baseUrl,
|
|
39
|
+
path: '/.well-known/oauth-protected-resource',
|
|
40
|
+
headers,
|
|
41
|
+
});
|
|
42
|
+
(0, vitest_1.expect)(prm.status).toBe(200);
|
|
43
|
+
(0, vitest_1.expect)(prm.json).toEqual({
|
|
44
|
+
resource: `${invokeOrigin}/semantic-layer/v1/mcp`,
|
|
45
|
+
authorization_servers: [invokeOrigin],
|
|
46
|
+
bearer_methods_supported: ['header'],
|
|
47
|
+
scopes_supported: [],
|
|
48
|
+
});
|
|
49
|
+
const asRes = await (0, http_integration_helpers_js_1.nodeRequest)({
|
|
50
|
+
baseUrl: mcpServer.baseUrl,
|
|
51
|
+
path: '/.well-known/oauth-authorization-server',
|
|
52
|
+
headers,
|
|
53
|
+
});
|
|
54
|
+
(0, vitest_1.expect)(asRes.status).toBe(200);
|
|
55
|
+
const asBody = asRes.json;
|
|
56
|
+
(0, vitest_1.expect)(asBody.issuer).toBe(mcpServer.baseUrl);
|
|
57
|
+
(0, vitest_1.expect)(asBody.authorization_endpoint).toBe(`${mcpServer.baseUrl}/oauth/authorize`);
|
|
58
|
+
(0, vitest_1.expect)(asBody.token_endpoint).toBe(`${invokeOrigin}/oauth/token`);
|
|
59
|
+
(0, vitest_1.expect)(asBody.registration_endpoint).toBe(`${invokeOrigin}/oauth/register`);
|
|
60
|
+
});
|
|
61
|
+
(0, vitest_1.it)('does not inherit invoke metadata for the same hostname on another port', async () => {
|
|
62
|
+
const prm = await (0, http_integration_helpers_js_1.nodeRequest)({
|
|
63
|
+
baseUrl: mcpServer.baseUrl,
|
|
64
|
+
path: '/.well-known/oauth-protected-resource',
|
|
65
|
+
headers: { host: `${invokeHost}:9999`, 'x-forwarded-proto': 'http' },
|
|
66
|
+
});
|
|
67
|
+
(0, vitest_1.expect)(prm.status).toBe(200);
|
|
68
|
+
const body = prm.json;
|
|
69
|
+
(0, vitest_1.expect)(body.authorization_servers).toEqual([mcpServer.baseUrl]);
|
|
70
|
+
});
|
|
71
|
+
(0, vitest_1.it)('verifies an invoke-origin token only when Host matches that origin', async () => {
|
|
72
|
+
const invokeToken = (0, http_integration_helpers_js_1.brokerAccessToken)(invokeOrigin, http_integration_helpers_js_1.TOKEN_A);
|
|
73
|
+
const invokeHeaders = {
|
|
74
|
+
host: invokeHost,
|
|
75
|
+
'x-forwarded-proto': 'http',
|
|
76
|
+
'content-type': 'application/json',
|
|
77
|
+
accept: 'application/json, text/event-stream',
|
|
78
|
+
authorization: `Bearer ${invokeToken}`,
|
|
79
|
+
};
|
|
80
|
+
const ok = await (0, http_integration_helpers_js_1.nodeRequest)({
|
|
81
|
+
baseUrl: mcpServer.baseUrl,
|
|
82
|
+
path: '/semantic-layer/v1/mcp',
|
|
83
|
+
method: 'POST',
|
|
84
|
+
headers: invokeHeaders,
|
|
85
|
+
body: JSON.stringify(http_integration_helpers_js_1.INITIALIZE_BODY),
|
|
86
|
+
});
|
|
87
|
+
(0, vitest_1.expect)(ok.status).toBe(200);
|
|
88
|
+
const mismatch = await (0, http_integration_helpers_js_1.postMcp)(mcpServer.baseUrl, http_integration_helpers_js_1.INITIALIZE_BODY, { token: invokeToken });
|
|
89
|
+
(0, vitest_1.expect)(mismatch.status).toBe(401);
|
|
90
|
+
});
|
|
91
|
+
(0, vitest_1.it)('rejects a public-audience token when Host is the extra invoke origin', async () => {
|
|
92
|
+
const publicToken = (0, http_integration_helpers_js_1.brokerAccessToken)(mcpServer.baseUrl, http_integration_helpers_js_1.TOKEN_A);
|
|
93
|
+
const res = await (0, http_integration_helpers_js_1.nodeRequest)({
|
|
94
|
+
baseUrl: mcpServer.baseUrl,
|
|
95
|
+
path: '/semantic-layer/v1/mcp',
|
|
96
|
+
method: 'POST',
|
|
97
|
+
headers: {
|
|
98
|
+
host: invokeHost,
|
|
99
|
+
'x-forwarded-proto': 'http',
|
|
100
|
+
'content-type': 'application/json',
|
|
101
|
+
accept: 'application/json, text/event-stream',
|
|
102
|
+
authorization: `Bearer ${publicToken}`,
|
|
103
|
+
},
|
|
104
|
+
body: JSON.stringify(http_integration_helpers_js_1.INITIALIZE_BODY),
|
|
105
|
+
});
|
|
106
|
+
(0, vitest_1.expect)(res.status).toBe(401);
|
|
107
|
+
});
|
|
108
|
+
});
|
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;
|