@lightdash-tools/mcp 0.13.0 → 0.13.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/notifications/operation-reporter.d.ts +13 -0
- package/dist/notifications/operation-reporter.js +45 -0
- package/dist/notifications/operation-reporter.test.d.ts +1 -0
- package/dist/notifications/operation-reporter.test.js +79 -0
- package/dist/tools/shared.d.ts +3 -0
- package/dist/tools/shared.js +4 -1
- package/package.json +3 -3
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ServerContext } from '@modelcontextprotocol/server';
|
|
2
|
+
export type OperationPhase = 'calling-service' | 'completed' | 'preparing' | 'processing-response' | 'waiting';
|
|
3
|
+
export type OperationPhaseEvent = {
|
|
4
|
+
phase: OperationPhase;
|
|
5
|
+
operation: string;
|
|
6
|
+
message: string;
|
|
7
|
+
completedUnits?: number;
|
|
8
|
+
totalUnits?: number;
|
|
9
|
+
};
|
|
10
|
+
export interface OperationReporter {
|
|
11
|
+
phase(event: OperationPhaseEvent): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function createOperationReporter(context: ServerContext | undefined): OperationReporter;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createOperationReporter = createOperationReporter;
|
|
4
|
+
class NoopOperationReporter {
|
|
5
|
+
async phase() {
|
|
6
|
+
// Intentionally empty when the client did not opt in to progress notifications.
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class McpProgressOperationReporter {
|
|
10
|
+
constructor(token, notify) {
|
|
11
|
+
this.token = token;
|
|
12
|
+
this.notify = notify;
|
|
13
|
+
this.current = 0;
|
|
14
|
+
}
|
|
15
|
+
async phase(event) {
|
|
16
|
+
var _a;
|
|
17
|
+
const requestedProgress = (_a = event.completedUnits) !== null && _a !== void 0 ? _a : this.current + 1;
|
|
18
|
+
this.current = Math.max(this.current + 1, requestedProgress);
|
|
19
|
+
const params = {
|
|
20
|
+
progressToken: this.token,
|
|
21
|
+
progress: this.current,
|
|
22
|
+
message: event.message,
|
|
23
|
+
};
|
|
24
|
+
if (event.totalUnits !== undefined) {
|
|
25
|
+
params.total = event.totalUnits;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
await this.notify({ method: 'notifications/progress', params });
|
|
29
|
+
}
|
|
30
|
+
catch (_b) {
|
|
31
|
+
// Progress reporting is best-effort and must never fail the tool invocation.
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function createOperationReporter(context) {
|
|
36
|
+
var _a;
|
|
37
|
+
const progressContext = context;
|
|
38
|
+
const mcpReq = progressContext === null || progressContext === void 0 ? void 0 : progressContext.mcpReq;
|
|
39
|
+
const token = (_a = mcpReq === null || mcpReq === void 0 ? void 0 : mcpReq._meta) === null || _a === void 0 ? void 0 : _a.progressToken;
|
|
40
|
+
const notify = mcpReq === null || mcpReq === void 0 ? void 0 : mcpReq.notify;
|
|
41
|
+
if (token === undefined || notify === undefined) {
|
|
42
|
+
return new NoopOperationReporter();
|
|
43
|
+
}
|
|
44
|
+
return new McpProgressOperationReporter(token, notify.bind(mcpReq));
|
|
45
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const operation_reporter_js_1 = require("./operation-reporter.js");
|
|
5
|
+
(0, vitest_1.describe)('createOperationReporter', () => {
|
|
6
|
+
(0, vitest_1.it)('is a no-op when the client did not provide a progress token', async () => {
|
|
7
|
+
const notify = vitest_1.vi.fn();
|
|
8
|
+
const reporter = (0, operation_reporter_js_1.createOperationReporter)({
|
|
9
|
+
mcpReq: { notify },
|
|
10
|
+
});
|
|
11
|
+
await reporter.phase({
|
|
12
|
+
phase: 'preparing',
|
|
13
|
+
operation: 'list explores',
|
|
14
|
+
message: 'Preparing to list explores',
|
|
15
|
+
});
|
|
16
|
+
(0, vitest_1.expect)(notify).not.toHaveBeenCalled();
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.it)('is a no-op when notify is missing even if a progress token is present', async () => {
|
|
19
|
+
const reporter = (0, operation_reporter_js_1.createOperationReporter)({
|
|
20
|
+
mcpReq: { _meta: { progressToken: 'progress-1' } },
|
|
21
|
+
});
|
|
22
|
+
await (0, vitest_1.expect)(reporter.phase({
|
|
23
|
+
phase: 'preparing',
|
|
24
|
+
operation: 'list explores',
|
|
25
|
+
message: 'Preparing to list explores',
|
|
26
|
+
})).resolves.toBeUndefined();
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.it)('sends monotonic progress notifications for a request-scoped token', async () => {
|
|
29
|
+
const notify = vitest_1.vi.fn().mockResolvedValue(undefined);
|
|
30
|
+
const reporter = (0, operation_reporter_js_1.createOperationReporter)({
|
|
31
|
+
mcpReq: { _meta: { progressToken: 'progress-1' }, notify },
|
|
32
|
+
});
|
|
33
|
+
await reporter.phase({
|
|
34
|
+
phase: 'preparing',
|
|
35
|
+
operation: 'list explores',
|
|
36
|
+
message: 'Preparing to list explores',
|
|
37
|
+
completedUnits: 1,
|
|
38
|
+
totalUnits: 4,
|
|
39
|
+
});
|
|
40
|
+
await reporter.phase({
|
|
41
|
+
phase: 'calling-service',
|
|
42
|
+
operation: 'list explores',
|
|
43
|
+
message: 'Loading explores from Lightdash',
|
|
44
|
+
completedUnits: 1,
|
|
45
|
+
totalUnits: 4,
|
|
46
|
+
});
|
|
47
|
+
(0, vitest_1.expect)(notify).toHaveBeenNthCalledWith(1, {
|
|
48
|
+
method: 'notifications/progress',
|
|
49
|
+
params: {
|
|
50
|
+
progressToken: 'progress-1',
|
|
51
|
+
progress: 1,
|
|
52
|
+
total: 4,
|
|
53
|
+
message: 'Preparing to list explores',
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
(0, vitest_1.expect)(notify).toHaveBeenNthCalledWith(2, {
|
|
57
|
+
method: 'notifications/progress',
|
|
58
|
+
params: {
|
|
59
|
+
progressToken: 'progress-1',
|
|
60
|
+
progress: 2,
|
|
61
|
+
total: 4,
|
|
62
|
+
message: 'Loading explores from Lightdash',
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
(0, vitest_1.it)('does not fail the operation when notification delivery fails', async () => {
|
|
67
|
+
const reporter = (0, operation_reporter_js_1.createOperationReporter)({
|
|
68
|
+
mcpReq: {
|
|
69
|
+
_meta: { progressToken: 7 },
|
|
70
|
+
notify: vitest_1.vi.fn().mockRejectedValue(new Error('disconnected')),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
await (0, vitest_1.expect)(reporter.phase({
|
|
74
|
+
phase: 'waiting',
|
|
75
|
+
operation: 'run query',
|
|
76
|
+
message: 'Waiting for Lightdash',
|
|
77
|
+
})).resolves.toBeUndefined();
|
|
78
|
+
});
|
|
79
|
+
});
|
package/dist/tools/shared.d.ts
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Capability surface is the profile's tools array, not process safety mode.
|
|
11
11
|
*/
|
|
12
|
+
import type { OperationReporter } from '../notifications/operation-reporter.js';
|
|
12
13
|
import type { McpContextProvider } from '../server/request-context.js';
|
|
13
14
|
import type { LightdashClient } from '@lightdash-tools/client';
|
|
14
15
|
import type { AuditStatus, ToolAnnotations } from '@lightdash-tools/common';
|
|
@@ -86,6 +87,8 @@ export declare function withAuditStatus<T extends TextContent>(result: T, status
|
|
|
86
87
|
export declare function registerToolSafe(server: unknown, shortName: string, options: ToolOptions, handler: ToolHandler): void;
|
|
87
88
|
export type ToolExecutionContext = {
|
|
88
89
|
lightdashClient: LightdashClient;
|
|
90
|
+
/** Request-scoped reporter backed by MCP progress notifications when available. */
|
|
91
|
+
operationReporter: OperationReporter;
|
|
89
92
|
/** SDK ServerContext when the transport provides it (second registerTool arg). */
|
|
90
93
|
serverContext: ServerContext | undefined;
|
|
91
94
|
sessionId: string;
|
package/dist/tools/shared.js
CHANGED
|
@@ -28,6 +28,7 @@ const tool_audit_context_js_1 = require("../audit/tool-audit-context.js");
|
|
|
28
28
|
const available_projects_js_1 = require("../governance/available-projects.js");
|
|
29
29
|
const mcp_client_session_js_1 = require("../governance/mcp-client-session.js");
|
|
30
30
|
const project_pin_js_1 = require("../governance/project-pin.js");
|
|
31
|
+
const operation_reporter_js_1 = require("../notifications/operation-reporter.js");
|
|
31
32
|
const upstream_errors_js_1 = require("../server/upstream-errors.js");
|
|
32
33
|
/** Prefix for all MCP tool names (disambiguation when multiple servers are connected). */
|
|
33
34
|
exports.TOOL_PREFIX = 'lightdash_';
|
|
@@ -239,11 +240,13 @@ function wrapToolContextual(contextProvider, fn) {
|
|
|
239
240
|
return await (0, mcp_client_session_js_1.runWithMcpClientSessionAsync)(sessionId, async () => {
|
|
240
241
|
const context = await contextProvider.getContext(extra);
|
|
241
242
|
const auth = context.auth;
|
|
243
|
+
const serverContext = asServerContext(extra);
|
|
242
244
|
return await (0, tool_audit_context_js_1.runWithToolAuditAuthAsync)({ tokenHash: auth === null || auth === void 0 ? void 0 : auth.tokenHash, subject: auth === null || auth === void 0 ? void 0 : auth.subject }, async () => {
|
|
243
245
|
var _a;
|
|
244
246
|
const execution = {
|
|
245
247
|
lightdashClient: context.lightdashClient,
|
|
246
|
-
|
|
248
|
+
operationReporter: (0, operation_reporter_js_1.createOperationReporter)(serverContext),
|
|
249
|
+
serverContext,
|
|
247
250
|
sessionId,
|
|
248
251
|
subject: (_a = auth === null || auth === void 0 ? void 0 : auth.subject) !== null && _a !== void 0 ? _a : 'anonymous',
|
|
249
252
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightdash-tools/mcp",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.1",
|
|
4
4
|
"description": "MCP server for Lightdash semantic-layer, organization-audit, content-reader, content-developer, content-governance, and ai-agent-ops profiles.",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"repository": {
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"commander": "^15.0.0",
|
|
25
25
|
"hono": "^4.13.0",
|
|
26
26
|
"zod": "^4.4.3",
|
|
27
|
-
"@lightdash-tools/client": "0.13.
|
|
28
|
-
"@lightdash-tools/common": "0.13.
|
|
27
|
+
"@lightdash-tools/client": "0.13.1",
|
|
28
|
+
"@lightdash-tools/common": "0.13.1"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@modelcontextprotocol/client": "2.0.0",
|