@lightdash-tools/mcp 0.5.0 → 0.7.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 +133 -58
- package/dist/audit/audit.d.ts +5 -0
- package/dist/{audit.js → audit/audit.js} +1 -2
- package/dist/audit/tool-audit-context.d.ts +6 -0
- package/dist/audit/tool-audit-context.js +12 -0
- package/dist/audit/tool-audit-context.test.d.ts +1 -0
- package/dist/audit/tool-audit-context.test.js +19 -0
- package/dist/auth/auth-mode.d.ts +4 -0
- package/dist/auth/auth-mode.js +6 -0
- package/dist/auth/bearer.d.ts +3 -0
- package/dist/auth/bearer.js +13 -0
- package/dist/auth/lightdash-oauth-upstream-contract.d.ts +22 -0
- package/dist/auth/lightdash-oauth-upstream-contract.js +36 -0
- package/dist/auth/lightdash-oauth-upstream-contract.test.d.ts +1 -0
- package/dist/auth/lightdash-oauth-upstream-contract.test.js +56 -0
- package/dist/auth/oauth-broker/as-metadata.d.ts +14 -0
- package/dist/auth/oauth-broker/as-metadata.js +20 -0
- package/dist/auth/oauth-broker/lightdash-token.d.ts +20 -0
- package/dist/auth/oauth-broker/lightdash-token.js +76 -0
- package/dist/auth/oauth-broker/pending-store.d.ts +76 -0
- package/dist/auth/oauth-broker/pending-store.js +124 -0
- package/dist/auth/oauth-broker/pkce.d.ts +2 -0
- package/dist/auth/oauth-broker/pkce.js +17 -0
- package/dist/auth/oauth-broker/routes.d.ts +9 -0
- package/dist/auth/oauth-broker/routes.js +447 -0
- package/dist/auth/oauth-broker/routes.test.d.ts +1 -0
- package/dist/auth/oauth-broker/routes.test.js +237 -0
- package/dist/auth/providers/bearer-context-provider.d.ts +24 -0
- package/dist/auth/providers/bearer-context-provider.js +52 -0
- package/dist/auth/providers/env-context-provider.d.ts +13 -0
- package/dist/auth/providers/env-context-provider.js +19 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.d.ts +23 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.js +115 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.d.ts +1 -0
- package/dist/auth/resource-server/lightdash-oauth-middleware.test.js +202 -0
- package/dist/auth/resource-server/lightdash-token-validation.d.ts +14 -0
- package/dist/auth/resource-server/lightdash-token-validation.js +82 -0
- package/dist/auth/resource-server/lightdash-token-validation.test.d.ts +1 -0
- package/dist/auth/resource-server/lightdash-token-validation.test.js +177 -0
- package/dist/auth/resource-server/oauth-protected-resource.d.ts +25 -0
- package/dist/auth/resource-server/oauth-protected-resource.js +67 -0
- package/dist/auth/resource-server/shared-key-middleware.d.ts +13 -0
- package/dist/auth/resource-server/shared-key-middleware.js +24 -0
- package/dist/auth/resource-server/token-scopes.d.ts +15 -0
- package/dist/auth/resource-server/token-scopes.js +76 -0
- package/dist/auth/resource-server/token-scopes.test.d.ts +1 -0
- package/dist/auth/resource-server/token-scopes.test.js +51 -0
- package/dist/auth/resource-server/token-validation-cache.d.ts +15 -0
- package/dist/auth/resource-server/token-validation-cache.js +44 -0
- package/dist/auth/resource-server/token-validation-cache.test.d.ts +1 -0
- package/dist/auth/resource-server/token-validation-cache.test.js +41 -0
- package/dist/auth/resource-server/token-validation-error.d.ts +6 -0
- package/dist/auth/resource-server/token-validation-error.js +13 -0
- package/dist/auth/resource-server/www-authenticate.d.ts +8 -0
- package/dist/auth/resource-server/www-authenticate.js +24 -0
- package/dist/auth/resource-server/www-authenticate.test.d.ts +1 -0
- package/dist/auth/resource-server/www-authenticate.test.js +64 -0
- package/dist/auth/token-hash.d.ts +2 -0
- package/dist/auth/token-hash.js +8 -0
- package/dist/bin.d.ts +0 -4
- package/dist/bin.js +41 -33
- package/dist/config/env.d.ts +50 -0
- package/dist/config/env.js +53 -0
- package/dist/config/load-mcp-config.d.ts +30 -0
- package/dist/config/load-mcp-config.js +282 -0
- package/dist/config/load-mcp-config.test.d.ts +1 -0
- package/dist/config/load-mcp-config.test.js +195 -0
- package/dist/config/normalize-url.d.ts +13 -0
- package/dist/config/normalize-url.js +52 -0
- package/dist/config/normalize-url.test.d.ts +1 -0
- package/dist/config/normalize-url.test.js +41 -0
- package/dist/config/public-url.d.ts +3 -0
- package/dist/config/public-url.js +10 -0
- package/dist/config/runtime.d.ts +15 -0
- package/dist/config/runtime.js +48 -0
- package/dist/config/runtime.test.d.ts +1 -0
- package/dist/config/runtime.test.js +69 -0
- package/dist/config/test-mcp-http-config.d.ts +3 -0
- package/dist/config/test-mcp-http-config.js +7 -0
- package/dist/governance/project-pin.d.ts +14 -0
- package/dist/governance/project-pin.js +44 -0
- package/dist/governance/project-pin.test.d.ts +1 -0
- package/dist/governance/project-pin.test.js +35 -0
- package/dist/http.d.ts +1 -2
- package/dist/http.integration.test.d.ts +1 -0
- package/dist/http.integration.test.js +688 -0
- package/dist/http.js +3 -170
- package/dist/http.test.d.ts +4 -0
- package/dist/http.test.js +131 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.integration.test.js +73 -30
- package/dist/index.js +28 -27
- package/dist/index.test.js +3 -3
- package/dist/logging/structured.d.ts +27 -0
- package/dist/logging/structured.js +32 -0
- package/dist/logging/structured.test.d.ts +1 -0
- package/dist/logging/structured.test.js +33 -0
- package/dist/personas/index.d.ts +19 -0
- package/dist/personas/index.js +57 -0
- package/dist/personas/index.test.d.ts +1 -0
- package/dist/personas/index.test.js +58 -0
- package/dist/personas/organization-audit/v1/index.d.ts +8 -0
- package/dist/personas/organization-audit/v1/index.js +42 -0
- package/dist/personas/organization-audit/v1/prompts.d.ts +5 -0
- package/dist/personas/organization-audit/v1/prompts.js +111 -0
- package/dist/personas/organization-audit/v1/prompts.test.d.ts +4 -0
- package/dist/personas/organization-audit/v1/prompts.test.js +25 -0
- package/dist/personas/organization-audit/v1/resources/playbook.d.ts +11 -0
- package/dist/personas/organization-audit/v1/resources/playbook.js +40 -0
- package/dist/personas/organization-audit/v1/resources/playbook.md +52 -0
- package/dist/personas/semantic-layer/v1/index.d.ts +8 -0
- package/dist/personas/semantic-layer/v1/index.js +32 -0
- package/dist/personas/semantic-layer/v1/prompts.d.ts +5 -0
- package/dist/personas/semantic-layer/v1/prompts.js +107 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.d.ts +12 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.js +42 -0
- package/dist/personas/semantic-layer/v1/resources/playbook.md +153 -0
- package/dist/personas/types.d.ts +19 -0
- package/dist/personas/types.js +5 -0
- package/dist/protocol-contract.test.d.ts +1 -0
- package/dist/protocol-contract.test.js +42 -0
- package/dist/server/capabilities.d.ts +15 -0
- package/dist/server/capabilities.js +19 -0
- package/dist/server/capabilities.test.d.ts +1 -0
- package/dist/server/capabilities.test.js +39 -0
- package/dist/server/errors.test.d.ts +1 -0
- package/dist/server/errors.test.js +53 -0
- package/dist/server/request-context.d.ts +13 -0
- package/dist/server/request-context.js +2 -0
- package/dist/server/server.d.ts +4 -0
- package/dist/server/server.js +17 -0
- package/dist/server/server.test.d.ts +1 -0
- package/dist/server/server.test.js +15 -0
- package/dist/server/version.d.ts +1 -0
- package/dist/server/version.js +7 -0
- package/dist/server/version.test.d.ts +1 -0
- package/dist/server/version.test.js +9 -0
- package/dist/stdio.process.test.d.ts +1 -0
- package/dist/stdio.process.test.js +126 -0
- package/dist/tools/index.d.ts +2 -4
- package/dist/tools/index.js +4 -30
- package/dist/tools/index.test.d.ts +1 -0
- package/dist/tools/index.test.js +72 -0
- package/dist/tools/lib/api-errors.d.ts +9 -0
- package/dist/tools/lib/api-errors.js +22 -0
- package/dist/tools/lib/api-shape.d.ts +16 -0
- package/dist/tools/lib/api-shape.js +47 -0
- package/dist/tools/lib/assert-safe.d.ts +13 -0
- package/dist/tools/lib/assert-safe.js +21 -0
- package/dist/tools/lib/assert-safe.test.d.ts +4 -0
- package/dist/tools/lib/assert-safe.test.js +32 -0
- package/dist/tools/lib/concurrency.d.ts +4 -0
- package/dist/tools/lib/concurrency.js +24 -0
- package/dist/tools/lib/contracts.d.ts +34 -0
- package/dist/tools/lib/contracts.js +30 -0
- package/dist/tools/lib/redaction.d.ts +107 -0
- package/dist/tools/lib/redaction.js +299 -0
- package/dist/tools/lib/redaction.test.d.ts +4 -0
- package/dist/tools/lib/redaction.test.js +216 -0
- package/dist/tools/lib/register-org-audit.d.ts +9 -0
- package/dist/tools/lib/register-org-audit.js +20 -0
- package/dist/tools/lib/schema-fields.d.ts +9 -0
- package/dist/tools/lib/schema-fields.js +19 -0
- package/dist/tools/organization/binding.d.ts +14 -0
- package/dist/tools/organization/binding.js +31 -0
- package/dist/tools/organization/invariants.test.d.ts +4 -0
- package/dist/tools/organization/invariants.test.js +28 -0
- package/dist/tools/organization/inventory.d.ts +10 -0
- package/dist/tools/organization/inventory.js +189 -0
- package/dist/tools/organization/roles.d.ts +10 -0
- package/dist/tools/organization/roles.js +213 -0
- package/dist/tools/project/content.d.ts +9 -0
- package/dist/tools/project/content.js +192 -0
- package/dist/tools/project/projects.d.ts +7 -0
- package/dist/tools/project/projects.js +42 -0
- package/dist/tools/project/projects.test.d.ts +1 -0
- package/dist/tools/project/projects.test.js +117 -0
- package/dist/tools/project/schedulers.d.ts +7 -0
- package/dist/tools/project/schedulers.js +115 -0
- package/dist/tools/registry.d.ts +104 -0
- package/dist/tools/registry.js +59 -0
- package/dist/tools/semantic/explore-helpers.d.ts +56 -0
- package/dist/tools/semantic/explore-helpers.js +115 -0
- package/dist/tools/semantic/explore-helpers.test.d.ts +1 -0
- package/dist/tools/semantic/explore-helpers.test.js +170 -0
- package/dist/tools/semantic/explores.d.ts +9 -0
- package/dist/tools/semantic/explores.js +80 -0
- package/dist/tools/semantic/metrics.d.ts +7 -0
- package/dist/tools/semantic/metrics.js +53 -0
- package/dist/tools/semantic/query.d.ts +6 -0
- package/dist/tools/semantic/query.js +42 -0
- package/dist/tools/semantic/schema-fields.d.ts +3 -0
- package/dist/tools/semantic/schema-fields.js +7 -0
- package/dist/tools/shared.d.ts +26 -13
- package/dist/tools/shared.js +112 -157
- package/dist/tools/shared.test.js +132 -183
- package/dist/tools/space/access.d.ts +66 -0
- package/dist/tools/space/access.js +322 -0
- package/dist/tools/space/access.test.d.ts +4 -0
- package/dist/tools/space/access.test.js +90 -0
- package/dist/transports/http-body.d.ts +5 -0
- package/dist/transports/http-body.js +50 -0
- package/dist/transports/http-request-utils.d.ts +2 -0
- package/dist/transports/http-request-utils.js +13 -0
- package/dist/transports/http-response.d.ts +6 -0
- package/dist/transports/http-response.js +56 -0
- package/dist/transports/session-store.d.ts +40 -0
- package/dist/transports/session-store.js +88 -0
- package/dist/transports/session-store.test.d.ts +1 -0
- package/dist/transports/session-store.test.js +111 -0
- package/dist/transports/streamable-http.d.ts +9 -0
- package/dist/transports/streamable-http.js +454 -0
- package/dist/transports/streamable-http.test.d.ts +1 -0
- package/dist/transports/streamable-http.test.js +95 -0
- package/package.json +25 -10
- package/dist/audit.d.ts +0 -6
- package/dist/config.d.ts +0 -47
- package/dist/config.js +0 -82
- package/dist/tools/ai-agents.d.ts +0 -6
- package/dist/tools/ai-agents.js +0 -388
- package/dist/tools/charts.d.ts +0 -6
- package/dist/tools/charts.js +0 -55
- package/dist/tools/content.d.ts +0 -6
- package/dist/tools/content.js +0 -37
- package/dist/tools/dashboards.d.ts +0 -6
- package/dist/tools/dashboards.js +0 -28
- package/dist/tools/explores.d.ts +0 -6
- package/dist/tools/explores.js +0 -65
- package/dist/tools/groups.d.ts +0 -6
- package/dist/tools/groups.js +0 -121
- package/dist/tools/metrics.d.ts +0 -6
- package/dist/tools/metrics.js +0 -45
- package/dist/tools/projects.d.ts +0 -6
- package/dist/tools/projects.js +0 -58
- package/dist/tools/query.d.ts +0 -6
- package/dist/tools/query.js +0 -34
- package/dist/tools/schedulers.d.ts +0 -6
- package/dist/tools/schedulers.js +0 -45
- package/dist/tools/spaces.d.ts +0 -6
- package/dist/tools/spaces.js +0 -128
- package/dist/tools/tags.d.ts +0 -6
- package/dist/tools/tags.js +0 -28
- package/dist/tools/users.d.ts +0 -6
- package/dist/tools/users.js +0 -50
- package/src/audit.ts +0 -6
- package/src/bin.ts +0 -58
- package/src/config.ts +0 -83
- package/src/errors.ts +0 -27
- package/src/http.ts +0 -187
- package/src/index.integration.test.ts +0 -57
- package/src/index.test.ts +0 -8
- package/src/index.ts +0 -31
- package/src/tools/ai-agents.ts +0 -759
- package/src/tools/charts.ts +0 -85
- package/src/tools/content.ts +0 -44
- package/src/tools/dashboards.ts +0 -25
- package/src/tools/explores.ts +0 -98
- package/src/tools/groups.ts +0 -180
- package/src/tools/index.ts +0 -35
- package/src/tools/metrics.ts +0 -42
- package/src/tools/projects.ts +0 -74
- package/src/tools/query.ts +0 -47
- package/src/tools/schedulers.ts +0 -42
- package/src/tools/shared.test.ts +0 -365
- package/src/tools/shared.ts +0 -274
- package/src/tools/spaces.ts +0 -217
- package/src/tools/tags.ts +0 -25
- package/src/tools/users.ts +0 -64
- package/tsconfig.json +0 -13
- /package/dist/{errors.d.ts → server/errors.d.ts} +0 -0
- /package/dist/{errors.js → server/errors.js} +0 -0
package/dist/http.js
CHANGED
|
@@ -1,174 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* MCP server entrypoint (Streamable HTTP).
|
|
4
|
-
* Optional: MCP_AUTH_ENABLED, MCP_API_KEY. Logging: stderr only.
|
|
3
|
+
* MCP server entrypoint (Streamable HTTP).
|
|
5
4
|
*/
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var _a;
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
20
|
-
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
21
|
-
const config_js_1 = require("./config.js");
|
|
22
|
-
const audit_js_1 = require("./audit.js");
|
|
23
|
-
const index_js_1 = require("./tools/index.js");
|
|
24
|
-
const MCP_PATH = '/mcp';
|
|
25
|
-
const PORT = Number((_a = process.env.MCP_HTTP_PORT) !== null && _a !== void 0 ? _a : '3100');
|
|
26
|
-
const sessionMap = new Map();
|
|
27
|
-
const sharedClient = (0, config_js_1.getClient)();
|
|
28
|
-
function isAuthEnabled() {
|
|
29
|
-
const v = process.env.MCP_AUTH_ENABLED;
|
|
30
|
-
return v === '1' || v === 'true' || v === 'yes';
|
|
31
|
-
}
|
|
32
|
-
function getExpectedApiKey() {
|
|
33
|
-
return process.env.MCP_API_KEY;
|
|
34
|
-
}
|
|
35
|
-
function authMiddleware(req, res) {
|
|
36
|
-
if (!isAuthEnabled())
|
|
37
|
-
return true;
|
|
38
|
-
const expected = getExpectedApiKey();
|
|
39
|
-
if (!expected) {
|
|
40
|
-
console.error('MCP_AUTH_ENABLED is set but MCP_API_KEY is missing');
|
|
41
|
-
res
|
|
42
|
-
.writeHead(500, { 'Content-Type': 'application/json' })
|
|
43
|
-
.end(JSON.stringify({ error: 'Server auth misconfiguration' }));
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
const bearer = req.headers.authorization;
|
|
47
|
-
const apiKey = req.headers['x-api-key'];
|
|
48
|
-
const token = typeof bearer === 'string' && bearer.startsWith('Bearer ') ? bearer.slice(7).trim() : undefined;
|
|
49
|
-
const key = typeof apiKey === 'string' ? apiKey.trim() : undefined;
|
|
50
|
-
const provided = token !== null && token !== void 0 ? token : key;
|
|
51
|
-
if (!provided || provided !== expected) {
|
|
52
|
-
res
|
|
53
|
-
.writeHead(401, { 'Content-Type': 'application/json' })
|
|
54
|
-
.end(JSON.stringify({ error: 'Unauthorized' }));
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
return true;
|
|
58
|
-
}
|
|
59
|
-
function createSessionTransport() {
|
|
60
|
-
const server = new mcp_js_1.McpServer({ name: 'lightdash-mcp', version: '1.0.0' });
|
|
61
|
-
(0, index_js_1.registerTools)(server, sharedClient);
|
|
62
|
-
const transport = new streamableHttp_js_1.StreamableHTTPServerTransport({
|
|
63
|
-
sessionIdGenerator: () => (0, node_crypto_1.randomUUID)(),
|
|
64
|
-
onsessioninitialized: (sessionId) => {
|
|
65
|
-
sessionMap.set(sessionId, transport);
|
|
66
|
-
},
|
|
67
|
-
onsessionclosed: (sessionId) => {
|
|
68
|
-
sessionMap.delete(sessionId);
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
server.connect(transport).catch((err) => {
|
|
72
|
-
console.error('MCP server connect error:', err);
|
|
73
|
-
});
|
|
74
|
-
return transport;
|
|
75
|
-
}
|
|
76
|
-
function readBody(req) {
|
|
77
|
-
return new Promise((resolve, reject) => {
|
|
78
|
-
const chunks = [];
|
|
79
|
-
req.on('data', (chunk) => chunks.push(chunk));
|
|
80
|
-
req.on('end', () => resolve(Buffer.concat(chunks)));
|
|
81
|
-
req.on('error', reject);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function parseJsonBody(buffer) {
|
|
85
|
-
const text = buffer.toString('utf-8');
|
|
86
|
-
if (!text.trim())
|
|
87
|
-
return undefined;
|
|
88
|
-
return JSON.parse(text);
|
|
89
|
-
}
|
|
90
|
-
function isInitializeMessage(body) {
|
|
91
|
-
if (body === undefined)
|
|
92
|
-
return false;
|
|
93
|
-
const msg = Array.isArray(body) ? body[0] : body;
|
|
94
|
-
return (typeof msg === 'object' &&
|
|
95
|
-
msg !== null &&
|
|
96
|
-
'method' in msg &&
|
|
97
|
-
msg.method === 'initialize');
|
|
98
|
-
}
|
|
99
|
-
function handleRequest(req, res) {
|
|
100
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
var _a;
|
|
102
|
-
if (!authMiddleware(req, res))
|
|
103
|
-
return;
|
|
104
|
-
const url = (_a = req.url) !== null && _a !== void 0 ? _a : '';
|
|
105
|
-
const path = url.split('?')[0];
|
|
106
|
-
if (path !== MCP_PATH) {
|
|
107
|
-
res
|
|
108
|
-
.writeHead(404, { 'Content-Type': 'application/json' })
|
|
109
|
-
.end(JSON.stringify({ error: 'Not Found' }));
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const sessionId = req.headers['mcp-session-id'];
|
|
113
|
-
const sid = typeof sessionId === 'string' ? sessionId : Array.isArray(sessionId) ? sessionId[0] : undefined;
|
|
114
|
-
if (req.method === 'POST') {
|
|
115
|
-
const raw = yield readBody(req);
|
|
116
|
-
const body = raw.length > 0 ? parseJsonBody(raw) : undefined;
|
|
117
|
-
if (sid) {
|
|
118
|
-
const transport = sessionMap.get(sid);
|
|
119
|
-
if (!transport) {
|
|
120
|
-
res
|
|
121
|
-
.writeHead(404, { 'Content-Type': 'application/json' })
|
|
122
|
-
.end(JSON.stringify({ error: 'Session not found' }));
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
yield transport.handleRequest(req, res, body);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (body !== undefined && isInitializeMessage(body)) {
|
|
129
|
-
const transport = createSessionTransport();
|
|
130
|
-
yield transport.handleRequest(req, res, body);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
res.writeHead(400, { 'Content-Type': 'application/json' }).end(JSON.stringify({
|
|
134
|
-
error: 'Bad Request: Mcp-Session-Id required for non-initialize requests',
|
|
135
|
-
}));
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (req.method === 'GET' || req.method === 'DELETE') {
|
|
139
|
-
if (!sid) {
|
|
140
|
-
res
|
|
141
|
-
.writeHead(400, { 'Content-Type': 'application/json' })
|
|
142
|
-
.end(JSON.stringify({ error: 'Bad Request: Mcp-Session-Id required' }));
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const transport = sessionMap.get(sid);
|
|
146
|
-
if (!transport) {
|
|
147
|
-
res
|
|
148
|
-
.writeHead(404, { 'Content-Type': 'application/json' })
|
|
149
|
-
.end(JSON.stringify({ error: 'Session not found' }));
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
yield transport.handleRequest(req, res);
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
res.writeHead(405, { Allow: 'GET, POST, DELETE' }).end();
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
function main() {
|
|
159
|
-
(0, audit_js_1.initAuditLog)((0, config_js_1.getAuditLogPath)());
|
|
160
|
-
const server = (0, node_http_1.createServer)((req, res) => {
|
|
161
|
-
handleRequest(req, res).catch((err) => {
|
|
162
|
-
console.error('MCP HTTP handler error:', err);
|
|
163
|
-
if (!res.headersSent) {
|
|
164
|
-
res
|
|
165
|
-
.writeHead(500, { 'Content-Type': 'application/json' })
|
|
166
|
-
.end(JSON.stringify({ error: 'Internal Server Error' }));
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
});
|
|
170
|
-
server.listen(PORT, () => {
|
|
171
|
-
console.error(`Lightdash MCP server listening on http://localhost:${PORT}${MCP_PATH}`);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
main();
|
|
6
|
+
const streamable_http_js_1 = require("./transports/streamable-http.js");
|
|
7
|
+
(0, streamable_http_js_1.startStreamableHttpServer)();
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Unit tests for MCP HTTP transport helpers.
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_events_1 = require("node:events");
|
|
7
|
+
const vitest_1 = require("vitest");
|
|
8
|
+
const http_body_js_1 = require("./transports/http-body.js");
|
|
9
|
+
const http_request_utils_js_1 = require("./transports/http-request-utils.js");
|
|
10
|
+
const http_response_js_1 = require("./transports/http-response.js");
|
|
11
|
+
function createMockResponse() {
|
|
12
|
+
const res = {
|
|
13
|
+
statusCode: 200,
|
|
14
|
+
headers: {},
|
|
15
|
+
writeHead(status, headers) {
|
|
16
|
+
this.statusCode = status;
|
|
17
|
+
if (headers)
|
|
18
|
+
this.headers = Object.assign(Object.assign({}, this.headers), headers);
|
|
19
|
+
return this;
|
|
20
|
+
},
|
|
21
|
+
end(chunk) {
|
|
22
|
+
this.body = chunk;
|
|
23
|
+
return this;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
(0, vitest_1.describe)('HTTP transport helpers', () => {
|
|
29
|
+
(0, vitest_1.describe)('origin validation', () => {
|
|
30
|
+
(0, vitest_1.it)('allows requests without Origin header', () => {
|
|
31
|
+
const allowed = ['https://app.example.com'];
|
|
32
|
+
(0, vitest_1.expect)((0, http_response_js_1.checkOrigin)(undefined, allowed)).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
(0, vitest_1.it)('rejects browser origins when allowlist is empty and dangerouslyAllowAnyOrigin is false', () => {
|
|
35
|
+
(0, vitest_1.expect)((0, http_response_js_1.checkOrigin)('https://evil.example.com', [], false)).toBe(false);
|
|
36
|
+
});
|
|
37
|
+
(0, vitest_1.it)('allows browser origins when dangerouslyAllowAnyOrigin is true', () => {
|
|
38
|
+
(0, vitest_1.expect)((0, http_response_js_1.checkOrigin)('https://browser.example.com', [], true)).toBe(true);
|
|
39
|
+
});
|
|
40
|
+
(0, vitest_1.it)('allows listed origins', () => {
|
|
41
|
+
const allowed = ['https://app.example.com', 'https://admin.example.com'];
|
|
42
|
+
(0, vitest_1.expect)((0, http_response_js_1.checkOrigin)('https://app.example.com', allowed)).toBe(true);
|
|
43
|
+
(0, vitest_1.expect)((0, http_response_js_1.checkOrigin)('https://admin.example.com', allowed)).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.it)('rejects unlisted origins when allowlist is configured', () => {
|
|
46
|
+
const allowed = ['https://app.example.com'];
|
|
47
|
+
(0, vitest_1.expect)((0, http_response_js_1.checkOrigin)('https://other.example.com', allowed)).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
(0, vitest_1.it)('builds CORS headers for allowed origins', () => {
|
|
50
|
+
const allowed = ['https://app.example.com'];
|
|
51
|
+
(0, vitest_1.expect)((0, http_response_js_1.buildCorsHeaders)('https://app.example.com', allowed)).toEqual({
|
|
52
|
+
'Access-Control-Allow-Origin': 'https://app.example.com',
|
|
53
|
+
'Access-Control-Allow-Methods': 'GET, POST, DELETE, OPTIONS',
|
|
54
|
+
'Access-Control-Allow-Headers': 'Content-Type, Accept, Authorization, Mcp-Session-Id, MCP-Protocol-Version, X-API-Key, X-Lightdash-Project',
|
|
55
|
+
'Access-Control-Expose-Headers': 'Mcp-Session-Id, WWW-Authenticate',
|
|
56
|
+
Vary: 'Origin',
|
|
57
|
+
});
|
|
58
|
+
(0, vitest_1.expect)((0, http_response_js_1.buildCorsHeaders)('https://other.example.com', allowed)).toEqual({});
|
|
59
|
+
(0, vitest_1.expect)((0, http_response_js_1.buildCorsHeaders)(undefined, allowed)).toEqual({});
|
|
60
|
+
});
|
|
61
|
+
(0, vitest_1.it)('omits CORS headers when allowlist is empty and dangerouslyAllowAnyOrigin is false', () => {
|
|
62
|
+
(0, vitest_1.expect)((0, http_response_js_1.buildCorsHeaders)('https://browser.example.com', [], false)).toEqual({});
|
|
63
|
+
});
|
|
64
|
+
(0, vitest_1.it)('echoes CORS headers when dangerouslyAllowAnyOrigin is true (OAuth/discovery paths)', () => {
|
|
65
|
+
(0, vitest_1.expect)((0, http_response_js_1.buildCorsHeaders)('http://localhost:8787', [], true)).toEqual({
|
|
66
|
+
'Access-Control-Allow-Origin': 'http://localhost:8787',
|
|
67
|
+
'Access-Control-Allow-Methods': 'GET, POST, DELETE, OPTIONS',
|
|
68
|
+
'Access-Control-Allow-Headers': 'Content-Type, Accept, Authorization, Mcp-Session-Id, MCP-Protocol-Version, X-API-Key, X-Lightdash-Project',
|
|
69
|
+
'Access-Control-Expose-Headers': 'Mcp-Session-Id, WWW-Authenticate',
|
|
70
|
+
Vary: 'Origin',
|
|
71
|
+
});
|
|
72
|
+
(0, vitest_1.expect)((0, http_response_js_1.buildCorsHeaders)(undefined, [], true)).toEqual({});
|
|
73
|
+
// Non-empty allowlist wins over the flag — OAuth paths must pass `[]` explicitly.
|
|
74
|
+
(0, vitest_1.expect)((0, http_response_js_1.buildCorsHeaders)('http://localhost:8787', ['https://app.example.com'], true)).toEqual({});
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
(0, vitest_1.describe)('auth token comparison', () => {
|
|
78
|
+
(0, vitest_1.it)('accepts equal API keys with timing-safe comparison', () => {
|
|
79
|
+
(0, vitest_1.expect)((0, http_response_js_1.timingSafeEqualString)('secret-key', 'secret-key')).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
(0, vitest_1.it)('rejects mismatched API keys', () => {
|
|
82
|
+
(0, vitest_1.expect)((0, http_response_js_1.timingSafeEqualString)('secret-key', 'wrong-key')).toBe(false);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
(0, vitest_1.describe)('body size rejection', () => {
|
|
86
|
+
(0, vitest_1.it)('rejects payloads larger than MCP_MAX_BODY_BYTES', async () => {
|
|
87
|
+
var _a;
|
|
88
|
+
const req = new node_events_1.EventEmitter();
|
|
89
|
+
req.destroy = () => req.removeAllListeners();
|
|
90
|
+
const res = createMockResponse();
|
|
91
|
+
const maxBytes = 16;
|
|
92
|
+
const readPromise = (0, http_body_js_1.readBody)(req, res, maxBytes);
|
|
93
|
+
req.emit('data', Buffer.from('a'.repeat(20)));
|
|
94
|
+
req.emit('end');
|
|
95
|
+
const body = await readPromise;
|
|
96
|
+
(0, vitest_1.expect)(body).toBeUndefined();
|
|
97
|
+
(0, vitest_1.expect)(res.statusCode).toBe(413);
|
|
98
|
+
(0, vitest_1.expect)(JSON.parse((_a = res.body) !== null && _a !== void 0 ? _a : '{}')).toEqual({ error: 'Payload Too Large' });
|
|
99
|
+
});
|
|
100
|
+
(0, vitest_1.it)('accepts payloads within MCP_MAX_BODY_BYTES', async () => {
|
|
101
|
+
const req = new node_events_1.EventEmitter();
|
|
102
|
+
const res = createMockResponse();
|
|
103
|
+
const payload = Buffer.from('{"jsonrpc":"2.0"}');
|
|
104
|
+
const readPromise = (0, http_body_js_1.readBody)(req, res, 1024);
|
|
105
|
+
req.emit('data', payload);
|
|
106
|
+
req.emit('end');
|
|
107
|
+
const body = await readPromise;
|
|
108
|
+
(0, vitest_1.expect)(body === null || body === void 0 ? void 0 : body.toString('utf-8')).toBe(payload.toString('utf-8'));
|
|
109
|
+
(0, vitest_1.expect)(res.statusCode).toBe(200);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
(0, vitest_1.describe)('JSON parsing', () => {
|
|
113
|
+
(0, vitest_1.it)('throws on malformed JSON', () => {
|
|
114
|
+
(0, vitest_1.expect)(() => (0, http_body_js_1.parseJsonBody)(Buffer.from('{not-json'))).toThrow(SyntaxError);
|
|
115
|
+
});
|
|
116
|
+
(0, vitest_1.it)('returns undefined for empty body', () => {
|
|
117
|
+
(0, vitest_1.expect)((0, http_body_js_1.parseJsonBody)(Buffer.from(' '))).toBeUndefined();
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
(0, vitest_1.describe)('initialize detection', () => {
|
|
121
|
+
(0, vitest_1.it)('detects initialize POST body', () => {
|
|
122
|
+
(0, vitest_1.expect)((0, http_request_utils_js_1.isInitializeMessage)({ jsonrpc: '2.0', method: 'initialize', id: 1 })).toBe(true);
|
|
123
|
+
});
|
|
124
|
+
(0, vitest_1.it)('detects initialize in batch array', () => {
|
|
125
|
+
(0, vitest_1.expect)((0, http_request_utils_js_1.isInitializeMessage)([{ jsonrpc: '2.0', method: 'initialize', id: 1 }])).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
(0, vitest_1.it)('returns false for non-initialize methods', () => {
|
|
128
|
+
(0, vitest_1.expect)((0, http_request_utils_js_1.isInitializeMessage)({ jsonrpc: '2.0', method: 'tools/list', id: 1 })).toBe(false);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,42 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const client_1 = require("@lightdash-tools/client");
|
|
4
|
+
const client_2 = require("@modelcontextprotocol/client");
|
|
5
|
+
const server_1 = require("@modelcontextprotocol/server");
|
|
12
6
|
const vitest_1 = require("vitest");
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const tools_1 = require("./tools");
|
|
7
|
+
const env_context_provider_js_1 = require("./auth/providers/env-context-provider.js");
|
|
8
|
+
const lightdash_token_validation_js_1 = require("./auth/resource-server/lightdash-token-validation.js");
|
|
9
|
+
const runtime_js_1 = require("./config/runtime.js");
|
|
10
|
+
const server_js_1 = require("./server/server.js");
|
|
18
11
|
const shared_1 = require("./tools/shared");
|
|
19
12
|
const hasCredentials = !!process.env.LIGHTDASH_API_KEY && !!process.env.LIGHTDASH_URL;
|
|
13
|
+
const hasOAuthToken = !!process.env.LIGHTDASH_TOOLS_TEST_OAUTH_ACCESS_TOKEN && !!process.env.LIGHTDASH_URL;
|
|
20
14
|
vitest_1.describe.runIf(hasCredentials)('MCP Integration (Real API)', () => {
|
|
21
|
-
(0, vitest_1.it)('should authenticate and fetch current organization', () =>
|
|
22
|
-
const client = (0,
|
|
15
|
+
(0, vitest_1.it)('should authenticate and fetch current organization', async () => {
|
|
16
|
+
const client = (0, runtime_js_1.getClient)();
|
|
23
17
|
// getCurrentOrganization is a better test for connectivity
|
|
24
|
-
const org =
|
|
18
|
+
const org = await client.v1.organizations.getCurrentOrganization();
|
|
25
19
|
(0, vitest_1.expect)(org).toBeDefined();
|
|
26
20
|
(0, vitest_1.expect)(org.organizationUuid).toBeDefined();
|
|
27
21
|
(0, vitest_1.expect)(org.name).toBeDefined();
|
|
28
22
|
console.error(`Authenticated to organization: ${org.name}`);
|
|
29
|
-
})
|
|
30
|
-
(0, vitest_1.it)('should execute list_projects tool with real API', () =>
|
|
31
|
-
const client = (0,
|
|
32
|
-
const
|
|
33
|
-
(0,
|
|
34
|
-
const [serverTransport, clientTransport] =
|
|
35
|
-
|
|
36
|
-
const mcpClient = new
|
|
37
|
-
|
|
23
|
+
});
|
|
24
|
+
(0, vitest_1.it)('should execute list_projects tool with real API', async () => {
|
|
25
|
+
const client = (0, runtime_js_1.getClient)();
|
|
26
|
+
const contextProvider = new env_context_provider_js_1.EnvContextProvider({ client });
|
|
27
|
+
const server = (0, server_js_1.createLightdashMcpServer)(contextProvider);
|
|
28
|
+
const [serverTransport, clientTransport] = server_1.InMemoryTransport.createLinkedPair();
|
|
29
|
+
await server.connect(serverTransport);
|
|
30
|
+
const mcpClient = new client_2.Client({ name: 'test-client', version: '1.0.0' }, { capabilities: {} });
|
|
31
|
+
await mcpClient.connect(clientTransport);
|
|
38
32
|
// Call the tool through the MCP client
|
|
39
|
-
const result =
|
|
33
|
+
const result = await mcpClient.callTool({
|
|
40
34
|
name: shared_1.TOOL_PREFIX + 'list_projects',
|
|
41
35
|
arguments: {},
|
|
42
36
|
});
|
|
@@ -52,7 +46,56 @@ vitest_1.describe.runIf(hasCredentials)('MCP Integration (Real API)', () => {
|
|
|
52
46
|
(0, vitest_1.expect)(typeof textContent.text).toBe('string');
|
|
53
47
|
console.error(`Tool list_projects output: ${textContent.text.slice(0, 100)}...`);
|
|
54
48
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
})
|
|
49
|
+
await mcpClient.close();
|
|
50
|
+
await server.close();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
vitest_1.describe.runIf(hasOAuthToken)('MCP Integration (OAuth access token)', () => {
|
|
54
|
+
(0, vitest_1.it)('validates live OAuth bearer token against Lightdash via GET /api/v1/user', async () => {
|
|
55
|
+
var _a;
|
|
56
|
+
const lightdashUrl = process.env.LIGHTDASH_URL.replace(/\/$/, '');
|
|
57
|
+
const accessToken = process.env.LIGHTDASH_TOOLS_TEST_OAUTH_ACCESS_TOKEN;
|
|
58
|
+
const config = {
|
|
59
|
+
lightdashUrl,
|
|
60
|
+
host: '127.0.0.1',
|
|
61
|
+
port: 3100,
|
|
62
|
+
publicUrl: 'https://mcp.example.com',
|
|
63
|
+
mcpPath: '/semantic-layer/v1/mcp',
|
|
64
|
+
authMode: 'lightdash-oauth',
|
|
65
|
+
allowedOrigins: [],
|
|
66
|
+
maxBodyBytes: 1024 * 1024,
|
|
67
|
+
sessionTtlMs: 60000,
|
|
68
|
+
maxSessions: 10,
|
|
69
|
+
maxSessionsPerSubject: 10,
|
|
70
|
+
sessionCleanupMs: 60000,
|
|
71
|
+
requiredScopes: ['mcp:read'],
|
|
72
|
+
scopesSupported: ['mcp:read', 'mcp:write'],
|
|
73
|
+
validateToken: true,
|
|
74
|
+
tokenValidationCacheTtlMs: 30000,
|
|
75
|
+
};
|
|
76
|
+
const user = await (0, lightdash_token_validation_js_1.validateLightdashAccessToken)(config, accessToken);
|
|
77
|
+
(0, vitest_1.expect)(user.userUuid).toBeDefined();
|
|
78
|
+
(0, vitest_1.expect)(user.email).toBeDefined();
|
|
79
|
+
if (user.organizationUuid !== undefined) {
|
|
80
|
+
(0, vitest_1.expect)(typeof user.organizationUuid).toBe('string');
|
|
81
|
+
}
|
|
82
|
+
console.error(`OAuth token authenticated as: ${user.email} (${user.userUuid}) org=${(_a = user.organizationUuid) !== null && _a !== void 0 ? _a : 'none'}`);
|
|
83
|
+
});
|
|
84
|
+
(0, vitest_1.it)('accepts the same live OAuth bearer on LightdashClient.getAuthenticatedUser()', async () => {
|
|
85
|
+
var _a;
|
|
86
|
+
const lightdashUrl = process.env.LIGHTDASH_URL.replace(/\/$/, '');
|
|
87
|
+
const accessToken = process.env.LIGHTDASH_TOOLS_TEST_OAUTH_ACCESS_TOKEN;
|
|
88
|
+
const client = new client_1.LightdashClient({
|
|
89
|
+
baseUrl: lightdashUrl,
|
|
90
|
+
auth: { type: 'bearer', token: new client_1.SecretString(accessToken) },
|
|
91
|
+
retry: { maxRetries: 0 },
|
|
92
|
+
timeout: 10000,
|
|
93
|
+
});
|
|
94
|
+
const user = await client.v1.users.getAuthenticatedUser();
|
|
95
|
+
(0, vitest_1.expect)(user.userUuid).toBeDefined();
|
|
96
|
+
if (user.organizationUuid !== undefined) {
|
|
97
|
+
(0, vitest_1.expect)(typeof user.organizationUuid).toBe('string');
|
|
98
|
+
}
|
|
99
|
+
console.error(`LightdashClient bearer GET /api/v1/user: ${(_a = user.email) !== null && _a !== void 0 ? _a : 'no-email'} (${user.userUuid})`);
|
|
100
|
+
});
|
|
58
101
|
});
|
package/dist/index.js
CHANGED
|
@@ -2,35 +2,36 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* MCP server entrypoint (Stdio). Use LIGHTDASH_URL and LIGHTDASH_API_KEY.
|
|
4
4
|
* Logging: stderr only (stdout is JSON-RPC).
|
|
5
|
+
*
|
|
6
|
+
* Optional persona via LIGHTDASH_TOOLS_MCP_STDIO_PERSONA (set by bin subcommands).
|
|
5
7
|
*/
|
|
6
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
7
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
10
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
11
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
12
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const index_js_1 = require("./
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
const stdio_1 = require("@modelcontextprotocol/server/stdio");
|
|
10
|
+
const audit_js_1 = require("./audit/audit.js");
|
|
11
|
+
const env_context_provider_js_1 = require("./auth/providers/env-context-provider.js");
|
|
12
|
+
const runtime_js_1 = require("./config/runtime.js");
|
|
13
|
+
const index_js_1 = require("./personas/index.js");
|
|
14
|
+
const server_js_1 = require("./server/server.js");
|
|
15
|
+
function resolveStdioPersona() {
|
|
16
|
+
const raw = process.env.LIGHTDASH_TOOLS_MCP_STDIO_PERSONA;
|
|
17
|
+
if (!raw) {
|
|
18
|
+
return (0, index_js_1.getDefaultPersona)();
|
|
19
|
+
}
|
|
20
|
+
const id = (0, index_js_1.parsePersonaId)(raw);
|
|
21
|
+
if (!id) {
|
|
22
|
+
throw new Error(`Invalid LIGHTDASH_TOOLS_MCP_STDIO_PERSONA='${raw}'. Expected semantic-layer or organization-audit.`);
|
|
23
|
+
}
|
|
24
|
+
return (0, index_js_1.getPersona)(id);
|
|
25
|
+
}
|
|
26
|
+
async function main() {
|
|
27
|
+
(0, runtime_js_1.warnIgnoredCliGuardrailEnvVars)();
|
|
28
|
+
(0, audit_js_1.initAuditLog)((0, runtime_js_1.getAuditLogPath)());
|
|
29
|
+
const persona = resolveStdioPersona();
|
|
30
|
+
const contextProvider = new env_context_provider_js_1.EnvContextProvider();
|
|
31
|
+
const server = (0, server_js_1.createLightdashMcpServer)(contextProvider, { persona });
|
|
32
|
+
const transport = new stdio_1.StdioServerTransport();
|
|
33
|
+
await server.connect(transport);
|
|
34
|
+
console.error(`Lightdash MCP server (${persona.id}) running on stdio`);
|
|
34
35
|
}
|
|
35
36
|
main().catch((err) => {
|
|
36
37
|
console.error('Fatal:', err);
|
package/dist/index.test.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const vitest_1 = require("vitest");
|
|
4
4
|
const tools_1 = require("./tools");
|
|
5
|
-
(0, vitest_1.describe)('
|
|
6
|
-
(0, vitest_1.it)('
|
|
7
|
-
(0, vitest_1.expect)(typeof tools_1.
|
|
5
|
+
(0, vitest_1.describe)('tools barrel', () => {
|
|
6
|
+
(0, vitest_1.it)('exports registerToolsByIds', () => {
|
|
7
|
+
(0, vitest_1.expect)(typeof tools_1.registerToolsByIds).toBe('function');
|
|
8
8
|
});
|
|
9
9
|
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RFC structured logging for the MCP HTTP server (stderr NDJSON).
|
|
3
|
+
*
|
|
4
|
+
* Distinct from the audit log: operational events (startup, sessions, errors)
|
|
5
|
+
* rather than per-tool invocation records.
|
|
6
|
+
*/
|
|
7
|
+
export type StructuredLogLevel = 'debug' | 'error' | 'info' | 'warn';
|
|
8
|
+
export type StructuredLogEntry = Record<string, unknown> & {
|
|
9
|
+
timestamp: string;
|
|
10
|
+
level: StructuredLogLevel;
|
|
11
|
+
component: string;
|
|
12
|
+
event: string;
|
|
13
|
+
message: string;
|
|
14
|
+
sessionId?: string;
|
|
15
|
+
};
|
|
16
|
+
export type StructuredLogInput = Record<string, unknown> & {
|
|
17
|
+
timestamp?: string;
|
|
18
|
+
sessionId?: string;
|
|
19
|
+
level: StructuredLogLevel;
|
|
20
|
+
component: string;
|
|
21
|
+
event: string;
|
|
22
|
+
message: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Emits one RFC-shaped JSON log line to stderr.
|
|
26
|
+
*/
|
|
27
|
+
export declare function emitStructuredLog(input: StructuredLogInput): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* RFC structured logging for the MCP HTTP server (stderr NDJSON).
|
|
4
|
+
*
|
|
5
|
+
* Distinct from the audit log: operational events (startup, sessions, errors)
|
|
6
|
+
* rather than per-tool invocation records.
|
|
7
|
+
*/
|
|
8
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
9
|
+
var t = {};
|
|
10
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
11
|
+
t[p] = s[p];
|
|
12
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
13
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
14
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
15
|
+
t[p[i]] = s[p[i]];
|
|
16
|
+
}
|
|
17
|
+
return t;
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.emitStructuredLog = emitStructuredLog;
|
|
21
|
+
const audit_js_1 = require("../audit/audit.js");
|
|
22
|
+
/**
|
|
23
|
+
* Emits one RFC-shaped JSON log line to stderr.
|
|
24
|
+
*/
|
|
25
|
+
function emitStructuredLog(input) {
|
|
26
|
+
const { timestamp, sessionId, level, component, event, message } = input, rest = __rest(input, ["timestamp", "sessionId", "level", "component", "event", "message"]);
|
|
27
|
+
const entry = Object.assign(Object.assign({}, rest), { timestamp: timestamp !== null && timestamp !== void 0 ? timestamp : new Date().toISOString(), sessionId: sessionId !== null && sessionId !== void 0 ? sessionId : (0, audit_js_1.getSessionId)(), level,
|
|
28
|
+
component,
|
|
29
|
+
event,
|
|
30
|
+
message });
|
|
31
|
+
process.stderr.write(`${JSON.stringify(entry)}\n`);
|
|
32
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const structured_js_1 = require("./structured.js");
|
|
5
|
+
(0, vitest_1.describe)('emitStructuredLog', () => {
|
|
6
|
+
let stderrSpy;
|
|
7
|
+
(0, vitest_1.beforeEach)(() => {
|
|
8
|
+
stderrSpy = vitest_1.vi.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
9
|
+
});
|
|
10
|
+
(0, vitest_1.afterEach)(() => {
|
|
11
|
+
stderrSpy.mockRestore();
|
|
12
|
+
});
|
|
13
|
+
(0, vitest_1.it)('writes one RFC-shaped NDJSON line to stderr', () => {
|
|
14
|
+
var _a;
|
|
15
|
+
(0, structured_js_1.emitStructuredLog)({
|
|
16
|
+
level: 'info',
|
|
17
|
+
component: 'mcp.http',
|
|
18
|
+
event: 'server.start',
|
|
19
|
+
message: 'HTTP server listening',
|
|
20
|
+
port: 3100,
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.expect)(stderrSpy).toHaveBeenCalledOnce();
|
|
23
|
+
const line = String((_a = stderrSpy.mock.calls[0]) === null || _a === void 0 ? void 0 : _a[0]);
|
|
24
|
+
const parsed = JSON.parse(line.trim());
|
|
25
|
+
(0, vitest_1.expect)(parsed.level).toBe('info');
|
|
26
|
+
(0, vitest_1.expect)(parsed.component).toBe('mcp.http');
|
|
27
|
+
(0, vitest_1.expect)(parsed.event).toBe('server.start');
|
|
28
|
+
(0, vitest_1.expect)(parsed.message).toBe('HTTP server listening');
|
|
29
|
+
(0, vitest_1.expect)(parsed.port).toBe(3100);
|
|
30
|
+
(0, vitest_1.expect)(typeof parsed.timestamp).toBe('string');
|
|
31
|
+
(0, vitest_1.expect)(typeof parsed.sessionId).toBe('string');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shipped MCP personas (path → definition). No PERSONA/PATH env knobs.
|
|
3
|
+
*/
|
|
4
|
+
import type { PersonaDefinition, PersonaId } from './types.js';
|
|
5
|
+
export type { PersonaDefinition, PersonaId } from './types.js';
|
|
6
|
+
export { SEMANTIC_LAYER_PERSONA_PATH } from './semantic-layer/v1/index.js';
|
|
7
|
+
export { ORGANIZATION_AUDIT_PERSONA_PATH } from './organization-audit/v1/index.js';
|
|
8
|
+
/** Default stdio persona (backward compatible). */
|
|
9
|
+
export declare const DEFAULT_PERSONA_ID: PersonaId;
|
|
10
|
+
export declare const PERSONAS: Record<PersonaId, PersonaDefinition>;
|
|
11
|
+
export declare function getPersona(id: PersonaId): PersonaDefinition;
|
|
12
|
+
export declare function getDefaultPersona(): PersonaDefinition;
|
|
13
|
+
/** Resolve persona from an HTTP request path, or undefined if unknown. */
|
|
14
|
+
export declare function getPersonaByPath(path: string): PersonaDefinition | undefined;
|
|
15
|
+
export declare function listPersonaPaths(): string[];
|
|
16
|
+
/** Parse a CLI persona id; returns undefined when invalid. */
|
|
17
|
+
export declare function parsePersonaId(value: string): PersonaId | undefined;
|
|
18
|
+
/** MCP server display name for a persona. */
|
|
19
|
+
export declare function getPersonaServerName(persona: PersonaDefinition): string;
|