@lightdash-tools/mcp 0.20.0 → 0.21.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 +5 -5
- package/dist/auth/request-state-key.d.ts +2 -2
- package/dist/auth/request-state-key.js +2 -2
- package/dist/config/enabled-profiles.d.ts +1 -1
- package/dist/config/enabled-profiles.js +3 -2
- package/dist/config/enabled-profiles.test.js +1 -0
- package/dist/policy/create-agent-preview.d.ts +65 -0
- package/dist/policy/create-agent-preview.js +126 -0
- package/dist/policy/create-agent-preview.test.d.ts +4 -0
- package/dist/policy/create-agent-preview.test.js +162 -0
- package/dist/profiles/ai-agent-ops/v1/index.js +10 -0
- package/dist/profiles/ai-agent-ops/v1/invariants.d.ts +6 -3
- package/dist/profiles/ai-agent-ops/v1/invariants.js +6 -2
- package/dist/profiles/ai-agent-ops/v1/prompts.js +24 -3
- package/dist/profiles/ai-agent-ops/v1/prompts.test.js +10 -1
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/core.md +34 -2
- package/dist/profiles/ai-agent-ops/v1/resources/playbooks/loop-engineering.md +9 -4
- package/dist/profiles/index.test.js +7 -2
- package/dist/server/server.js +16 -4
- package/dist/tools/ai-agents/agents.d.ts +8 -0
- package/dist/tools/ai-agents/agents.js +283 -1
- package/dist/tools/ai-agents/agents.test.js +25 -0
- package/dist/tools/ai-agents/create-elicitation.d.ts +52 -0
- package/dist/tools/ai-agents/create-elicitation.js +206 -0
- package/dist/tools/ai-agents/create-elicitation.test.d.ts +4 -0
- package/dist/tools/ai-agents/create-elicitation.test.js +363 -0
- package/dist/tools/ai-agents/create-request-state.d.ts +18 -0
- package/dist/tools/ai-agents/create-request-state.js +43 -0
- package/dist/tools/ai-agents/documents.d.ts +15 -0
- package/dist/tools/ai-agents/documents.js +212 -0
- package/dist/tools/ai-agents/documents.test.d.ts +1 -0
- package/dist/tools/ai-agents/documents.test.js +129 -0
- package/dist/tools/ai-agents/gate-create-project-agent.d.ts +28 -0
- package/dist/tools/ai-agents/gate-create-project-agent.js +71 -0
- package/dist/tools/ai-agents/helpers.d.ts +11 -0
- package/dist/tools/ai-agents/helpers.js +29 -1
- package/dist/tools/ai-agents/knowledge-warnings.d.ts +11 -0
- package/dist/tools/ai-agents/knowledge-warnings.js +21 -0
- package/dist/tools/ai-agents/space-warnings.d.ts +36 -0
- package/dist/tools/ai-agents/space-warnings.js +101 -0
- package/dist/tools/ai-agents/space-warnings.test.d.ts +1 -0
- package/dist/tools/ai-agents/space-warnings.test.js +78 -0
- package/dist/tools/ai-agents/tag-warnings.d.ts +31 -0
- package/dist/tools/ai-agents/tag-warnings.js +70 -0
- package/dist/tools/ai-agents/test-support.d.ts +4 -1
- package/dist/tools/ai-agents/test-support.js +7 -2
- package/package.json +3 -3
|
@@ -4,17 +4,49 @@ URI: `lightdash://playbooks/ai-agent-ops/core`
|
|
|
4
4
|
|
|
5
5
|
## Hard bans
|
|
6
6
|
|
|
7
|
-
Do not
|
|
7
|
+
Do not delete agents on this server, start or continue threads, mutate users/roles/semantic models/charts, run local offline scorers, write Git eval artifact stores via MCP, or claim a CLI promotion gate passed from MCP run results alone.
|
|
8
8
|
|
|
9
9
|
## Tool catalog (primitives only)
|
|
10
10
|
|
|
11
11
|
There are no `recommend_*`, `analyze_*`, or offline dataset MCP tools (no offline scorers). Chain:
|
|
12
12
|
|
|
13
|
-
- Inventory: `list_project_agents`, `get_project_agent`
|
|
13
|
+
- Inventory: `list_project_agents`, `get_project_agent`, `preview_create_agent`, `confirm_create_agent`, `create_project_agent` (form elicitation **or** preview-token path — human must accept), `update_project_agent`
|
|
14
14
|
- Readiness API: `evaluate_agent_readiness` (not an eval run)
|
|
15
15
|
- Scope helpers: `get_agent_suggestions`, `get_agent_models`, `get_explore_access_summary`
|
|
16
16
|
- Threads (read): `list_agent_threads`, `get_agent_thread` (`includeMessageText=true` to reveal bodies / firstMessage)
|
|
17
17
|
- Evaluations: `list_agent_evaluations`, `get_agent_evaluation`, `create_agent_evaluation`, `update_agent_evaluation`, `append_agent_evaluation_prompts`, `delete_agent_evaluation`, `run_agent_evaluation`, `list_agent_evaluation_runs`, `get_agent_eval_run_results` (`includePromptText=true` to reveal prompt text)
|
|
18
|
+
- Knowledge documents: `list_agent_documents`, `get_agent_document` (`includeDocumentContent=true` to reveal body), `create_agent_document`, `update_agent_document`, `delete_agent_document` (inline JSON, 20KB max; ADR-0035)
|
|
19
|
+
|
|
20
|
+
## Agent tags (explore allowlist)
|
|
21
|
+
|
|
22
|
+
Agent `tags` match dbt/Lightdash explore or field tags (OR). **Explore names are not tags.** Null/empty = all explores. Invented tags that match nothing → zero explores and `TAGS_MATCH_NO_EXPLORES` after create/update. Always call `get_explore_access_summary` with the same tag list before setting tags. Prefer `list_project_agents` and `update_project_agent` over create when an existing agent fits.
|
|
23
|
+
|
|
24
|
+
## Create confirmation (dual gate)
|
|
25
|
+
|
|
26
|
+
When the host supports MCP form elicitation, `create_project_agent` shows the permission matrix form (ADR-0033). When it does not (e.g. Cursor coding agents), use `preview_create_agent` → show `confirmationMessage` to the human → `confirm_create_agent` → `create_project_agent` with the same payload and `createConfirmToken` (ADR-0034). Do not skip confirm after preview.
|
|
27
|
+
|
|
28
|
+
## Secure agent defaults
|
|
29
|
+
|
|
30
|
+
MCP, CLI, and `agentops apply` create agents with **secure-by-default** permissions (more conservative than the Lightdash UI):
|
|
31
|
+
|
|
32
|
+
| Capability | Default |
|
|
33
|
+
| ------------------------------------------- | ----------------------------- |
|
|
34
|
+
| Read rows behind chart (`enableDataAccess`) | off |
|
|
35
|
+
| Create/edit content (`enableContentTools`) | off |
|
|
36
|
+
| SQL mode (`enableSqlMode`) | off |
|
|
37
|
+
| User context (`enableUserContext`) | off |
|
|
38
|
+
| Visibility (`adminOnly`) | on — admins & developers only |
|
|
39
|
+
|
|
40
|
+
Elevation is **explicit opt-in**. The create form shows the full permission matrix; responses may include `ELEVATED_*` warning codes when capabilities or visibility exceed the baseline.
|
|
41
|
+
|
|
42
|
+
**Presets for clients:**
|
|
43
|
+
|
|
44
|
+
| Preset | Flags | Use when |
|
|
45
|
+
| ---------------------- | ---------------------------------------------------------------------------------------- | ---------------------------------- |
|
|
46
|
+
| **Governed** (default) | all capabilities off, `adminOnly: true` | Setup, eval authoring, pre-release |
|
|
47
|
+
| **Analyst** | `enableDataAccess: true`, scoped `tags`; widen visibility only after CLI `evaluate-gate` | Production Q&A |
|
|
48
|
+
|
|
49
|
+
Do not enable data access, content tools, SQL mode, user context, or public visibility unless the user explicitly requested elevation.
|
|
18
50
|
|
|
19
51
|
## Project scope
|
|
20
52
|
|
|
@@ -10,7 +10,8 @@ URI: `lightdash://playbooks/ai-agent-ops/loop-engineering`
|
|
|
10
10
|
4. Intervene outside this profile:
|
|
11
11
|
- Semantic / AI hints → optional `semantic-layer` MCP or out-of-band
|
|
12
12
|
- Content → optional `content-reader` / developer workflows
|
|
13
|
-
- Agent
|
|
13
|
+
- Agent instruction/flags → prefer `update_project_agent`; create only after `list_project_agents`. **Form hosts:** `create_project_agent` (human form). **Non-form hosts:** `preview_create_agent` → human approves permission + space scope summary → `confirm_create_agent` → `create_project_agent` with `createConfirmToken` (verify tags via `get_explore_access_summary`; discover `spaceAccess` UUIDs via `content-reader` `list_spaces` first). Default create is governed (all capabilities off, adminOnly on) — enable `enableDataAccess` only when eval runs need warehouse rows
|
|
14
|
+
- Agent config bundles as Git → CLI `agentops plan|apply`
|
|
14
15
|
5. Regress with focused then full evaluation runs
|
|
15
16
|
6. Gate with CLI `agentops evaluate-gate`
|
|
16
17
|
7. Stop after gates pass, no safe intervention remains, or 3 iterations
|
|
@@ -20,9 +21,13 @@ URI: `lightdash://playbooks/ai-agent-ops/loop-engineering`
|
|
|
20
21
|
```text
|
|
21
22
|
correct semantic fact
|
|
22
23
|
→ improve metadata/AI hints
|
|
23
|
-
→ adjust tags/scope
|
|
24
|
-
→
|
|
25
|
-
→
|
|
24
|
+
→ adjust tags/scope (verify with get_explore_access_summary; heed TAGS_MATCH_NO_EXPLORES)
|
|
25
|
+
→ adjust spaceAccess (discover UUIDs with content-reader list_spaces; heed SPACES_NOT_IN_PROJECT)
|
|
26
|
+
→ curate knowledge via `list_agent_documents` / `create_agent_document` / `update_agent_document` (inline JSON, 20KB max; not warehouse data)
|
|
27
|
+
→ curate verified examples
|
|
28
|
+
→ revise instruction via update_project_agent / agentops/CLI
|
|
26
29
|
```
|
|
27
30
|
|
|
28
31
|
Do not recommend prompt patches when semantic metadata is demonstrably wrong.
|
|
32
|
+
Do not invent agent tags that are not present on explores — empty scope looks like “no explores configured” at eval time.
|
|
33
|
+
Do not invent space UUIDs — copy from `content-reader` `list_spaces` / `get_space` or an existing agent via `get_project_agent`.
|
|
@@ -84,8 +84,13 @@ const index_js_1 = require("./index.js");
|
|
|
84
84
|
(0, vitest_1.it)('ai-agent-ops membership and short server name', () => {
|
|
85
85
|
const profile = (0, index_js_1.getProfile)('ai-agent-ops');
|
|
86
86
|
const tools = (0, index_js_1.listToolIds)(profile);
|
|
87
|
-
(0, vitest_1.expect)(tools).toHaveLength(
|
|
88
|
-
(0, vitest_1.expect)(tools).
|
|
87
|
+
(0, vitest_1.expect)(tools).toHaveLength(26);
|
|
88
|
+
(0, vitest_1.expect)(tools).toContain('preview_create_agent');
|
|
89
|
+
(0, vitest_1.expect)(tools).toContain('confirm_create_agent');
|
|
90
|
+
(0, vitest_1.expect)(tools).toContain('create_project_agent');
|
|
91
|
+
(0, vitest_1.expect)(tools).toContain('update_project_agent');
|
|
92
|
+
(0, vitest_1.expect)(tools).toContain('create_agent_document');
|
|
93
|
+
(0, vitest_1.expect)(tools).not.toContain('delete_project_agent');
|
|
89
94
|
(0, vitest_1.expect)(tools).not.toContain('generate_agent_message');
|
|
90
95
|
(0, vitest_1.expect)(tools).not.toContain('generate_agent_response');
|
|
91
96
|
(0, vitest_1.expect)((0, index_js_1.getProfileServerName)(profile)).toBe('lightdash-mcp-aops');
|
package/dist/server/server.js
CHANGED
|
@@ -5,6 +5,7 @@ const server_1 = require("@modelcontextprotocol/server");
|
|
|
5
5
|
const request_state_key_js_1 = require("../auth/request-state-key.js");
|
|
6
6
|
const request_state_js_1 = require("../destructive/request-state.js");
|
|
7
7
|
const index_js_1 = require("../profiles/index.js");
|
|
8
|
+
const create_request_state_js_1 = require("../tools/ai-agents/create-request-state.js");
|
|
8
9
|
const capabilities_js_1 = require("./capabilities.js");
|
|
9
10
|
const version_js_1 = require("./version.js");
|
|
10
11
|
function createLightdashMcpServer(contextProvider, options) {
|
|
@@ -16,13 +17,24 @@ function createLightdashMcpServer(contextProvider, options) {
|
|
|
16
17
|
else if (profile.id === 'content-developer') {
|
|
17
18
|
(0, request_state_key_js_1.assertRequestStateKeyConfigured)(request_state_key_js_1.PREVIEW_TOKEN_KEY_PURPOSE);
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
else if (profile.id === 'ai-agent-ops') {
|
|
21
|
+
(0, request_state_key_js_1.assertRequestStateKeyConfigured)(create_request_state_js_1.CREATE_AGENT_REQUEST_STATE_KEY_PURPOSE);
|
|
22
|
+
}
|
|
23
|
+
let serverOptions;
|
|
24
|
+
if (profile.id === 'content-governance') {
|
|
25
|
+
serverOptions = {
|
|
21
26
|
requestState: {
|
|
22
27
|
verify: (state, ctx) => (0, request_state_js_1.getDestructiveRequestStateCodec)().verify(state, ctx),
|
|
23
28
|
},
|
|
24
|
-
}
|
|
25
|
-
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
else if (profile.id === 'ai-agent-ops') {
|
|
32
|
+
serverOptions = {
|
|
33
|
+
requestState: {
|
|
34
|
+
verify: (state, ctx) => (0, create_request_state_js_1.getCreateAgentRequestStateCodec)().verify(state, ctx),
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
26
38
|
const server = new server_1.McpServer({
|
|
27
39
|
name: (0, index_js_1.getProfileServerName)(profile),
|
|
28
40
|
version: version_js_1.PACKAGE_VERSION,
|
|
@@ -5,7 +5,15 @@ import type { McpContextProvider } from '../../server/request-context.js';
|
|
|
5
5
|
import type { McpServer } from '@modelcontextprotocol/server';
|
|
6
6
|
export declare function registerListProjectAgents(server: McpServer, contextProvider: McpContextProvider): void;
|
|
7
7
|
export declare function registerGetProjectAgent(server: McpServer, contextProvider: McpContextProvider): void;
|
|
8
|
+
export declare function registerPreviewCreateAgent(server: McpServer, contextProvider: McpContextProvider): void;
|
|
9
|
+
export declare function registerConfirmCreateAgent(server: McpServer, contextProvider: McpContextProvider): void;
|
|
10
|
+
export declare function registerCreateProjectAgent(server: McpServer, contextProvider: McpContextProvider): void;
|
|
11
|
+
export declare function registerUpdateProjectAgent(server: McpServer, contextProvider: McpContextProvider): void;
|
|
8
12
|
export declare function registerGetUserAgentPreferences(server: McpServer, contextProvider: McpContextProvider): void;
|
|
9
13
|
export declare const listProjectAgentsTool: import("../types.js").ToolModule;
|
|
10
14
|
export declare const getProjectAgentTool: import("../types.js").ToolModule;
|
|
15
|
+
export declare const previewCreateAgentTool: import("../types.js").ToolModule;
|
|
16
|
+
export declare const confirmCreateAgentTool: import("../types.js").ToolModule;
|
|
17
|
+
export declare const createProjectAgentTool: import("../types.js").ToolModule;
|
|
18
|
+
export declare const updateProjectAgentTool: import("../types.js").ToolModule;
|
|
11
19
|
export declare const getUserAgentPreferencesTool: import("../types.js").ToolModule;
|
|
@@ -2,14 +2,118 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Project AI agent inventory tools (ai-agent-ops and ai-agent-chat profiles).
|
|
4
4
|
*/
|
|
5
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
6
|
+
var t = {};
|
|
7
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
8
|
+
t[p] = s[p];
|
|
9
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
10
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
11
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
12
|
+
t[p[i]] = s[p[i]];
|
|
13
|
+
}
|
|
14
|
+
return t;
|
|
15
|
+
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getUserAgentPreferencesTool = exports.getProjectAgentTool = exports.listProjectAgentsTool = void 0;
|
|
17
|
+
exports.getUserAgentPreferencesTool = exports.updateProjectAgentTool = exports.createProjectAgentTool = exports.confirmCreateAgentTool = exports.previewCreateAgentTool = exports.getProjectAgentTool = exports.listProjectAgentsTool = void 0;
|
|
7
18
|
exports.registerListProjectAgents = registerListProjectAgents;
|
|
8
19
|
exports.registerGetProjectAgent = registerGetProjectAgent;
|
|
20
|
+
exports.registerPreviewCreateAgent = registerPreviewCreateAgent;
|
|
21
|
+
exports.registerConfirmCreateAgent = registerConfirmCreateAgent;
|
|
22
|
+
exports.registerCreateProjectAgent = registerCreateProjectAgent;
|
|
23
|
+
exports.registerUpdateProjectAgent = registerUpdateProjectAgent;
|
|
9
24
|
exports.registerGetUserAgentPreferences = registerGetUserAgentPreferences;
|
|
25
|
+
const common_1 = require("@lightdash-tools/common");
|
|
26
|
+
const zod_1 = require("zod");
|
|
27
|
+
const project_scope_js_1 = require("../../governance/project-scope.js");
|
|
28
|
+
const create_agent_preview_js_1 = require("../../policy/create-agent-preview.js");
|
|
29
|
+
const reader_tool_helpers_js_1 = require("../query/reader-tool-helpers.js");
|
|
10
30
|
const shared_js_1 = require("../shared.js");
|
|
11
31
|
const types_js_1 = require("../types.js");
|
|
32
|
+
const create_elicitation_js_1 = require("./create-elicitation.js");
|
|
33
|
+
const gate_create_project_agent_js_1 = require("./gate-create-project-agent.js");
|
|
12
34
|
const helpers_js_1 = require("./helpers.js");
|
|
35
|
+
const space_warnings_js_1 = require("./space-warnings.js");
|
|
36
|
+
const tag_warnings_js_1 = require("./tag-warnings.js");
|
|
37
|
+
const TAGS_FIELD_DESCRIPTION = 'Explore/field allowlist matching dbt model tags and/or Lightdash meta field tags (OR). ' +
|
|
38
|
+
'Null or empty = all project explores. Verify with get_explore_access_summary before setting; ' +
|
|
39
|
+
'invented tags that match nothing yield TAGS_MATCH_NO_EXPLORES.';
|
|
40
|
+
const projectAgentPatchFields = {
|
|
41
|
+
description: zod_1.z.string().nullable().optional().describe('Agent description'),
|
|
42
|
+
instruction: zod_1.z.string().nullable().optional().describe('System instruction for the agent'),
|
|
43
|
+
tags: zod_1.z.array(zod_1.z.string()).nullable().optional().describe(TAGS_FIELD_DESCRIPTION),
|
|
44
|
+
enableDataAccess: zod_1.z
|
|
45
|
+
.boolean()
|
|
46
|
+
.optional()
|
|
47
|
+
.describe('Read rows behind a chart (default: off). Requires explicit true to enable warehouse data access.'),
|
|
48
|
+
enableContentTools: zod_1.z
|
|
49
|
+
.boolean()
|
|
50
|
+
.optional()
|
|
51
|
+
.describe('Create and edit saved content (default: off). Requires data access when enabled upstream.'),
|
|
52
|
+
enableSqlMode: zod_1.z
|
|
53
|
+
.boolean()
|
|
54
|
+
.optional()
|
|
55
|
+
.describe('Run SQL against the warehouse (default: off). Subject to per-query user approval in Lightdash.'),
|
|
56
|
+
enableSelfImprovement: zod_1.z
|
|
57
|
+
.boolean()
|
|
58
|
+
.optional()
|
|
59
|
+
.describe('Allow self-improvement features (default: off)'),
|
|
60
|
+
enableUserContext: zod_1.z
|
|
61
|
+
.boolean()
|
|
62
|
+
.optional()
|
|
63
|
+
.describe('See user information — name, role, groups (default: off)'),
|
|
64
|
+
adminOnly: zod_1.z
|
|
65
|
+
.boolean()
|
|
66
|
+
.optional()
|
|
67
|
+
.describe('Restrict to admins & developers only (default: on). Set false for everyone or use userAccess/groupAccess.'),
|
|
68
|
+
groupAccess: zod_1.z.array(zod_1.z.string()).optional().describe('Group UUIDs with access'),
|
|
69
|
+
userAccess: zod_1.z.array(zod_1.z.string()).optional().describe('User UUIDs with access'),
|
|
70
|
+
spaceAccess: zod_1.z
|
|
71
|
+
.array(zod_1.z.string())
|
|
72
|
+
.optional()
|
|
73
|
+
.describe('Space UUIDs the agent may access for saved content (charts/dashboards). ' +
|
|
74
|
+
'Empty or omitted = all project spaces. Discover UUIDs via content-reader list_spaces — do not invent.'),
|
|
75
|
+
mcpServerUuids: zod_1.z.array(zod_1.z.string()).optional().describe('Nested MCP server UUIDs'),
|
|
76
|
+
};
|
|
77
|
+
function buildCreatePayload(args) {
|
|
78
|
+
const { name, projectUuid, createConfirmToken } = args, patch = __rest(args, ["name", "projectUuid", "createConfirmToken"]);
|
|
79
|
+
void projectUuid;
|
|
80
|
+
void createConfirmToken;
|
|
81
|
+
return Object.assign({ name }, patch);
|
|
82
|
+
}
|
|
83
|
+
async function resolveCreateProjectUuid(projectUuid) {
|
|
84
|
+
try {
|
|
85
|
+
return { ok: true, projectUuid: (0, project_scope_js_1.resolveProjectScope)({ projectUuid }).projectUuid };
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
return { ok: false, result: (0, reader_tool_helpers_js_1.projectScopeErrorResult)(err) };
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
function assignIfDefined(target, key, value) {
|
|
92
|
+
if (value !== undefined) {
|
|
93
|
+
// eslint-disable-next-line security/detect-object-injection -- key is a fixed literal at each call site
|
|
94
|
+
target[key] = value;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function buildUpdateProjectAgentBody(agentUuid, args) {
|
|
98
|
+
const patch = {};
|
|
99
|
+
assignIfDefined(patch, 'name', args.name);
|
|
100
|
+
assignIfDefined(patch, 'description', args.description);
|
|
101
|
+
assignIfDefined(patch, 'instruction', args.instruction);
|
|
102
|
+
if (args.tags !== undefined) {
|
|
103
|
+
assignIfDefined(patch, 'tags', (0, common_1.normalizeAgentTags)(args.tags));
|
|
104
|
+
}
|
|
105
|
+
assignIfDefined(patch, 'enableDataAccess', args.enableDataAccess);
|
|
106
|
+
assignIfDefined(patch, 'enableContentTools', args.enableContentTools);
|
|
107
|
+
assignIfDefined(patch, 'enableSqlMode', args.enableSqlMode);
|
|
108
|
+
assignIfDefined(patch, 'enableSelfImprovement', args.enableSelfImprovement);
|
|
109
|
+
assignIfDefined(patch, 'enableUserContext', args.enableUserContext);
|
|
110
|
+
assignIfDefined(patch, 'adminOnly', args.adminOnly);
|
|
111
|
+
assignIfDefined(patch, 'groupAccess', args.groupAccess);
|
|
112
|
+
assignIfDefined(patch, 'userAccess', args.userAccess);
|
|
113
|
+
assignIfDefined(patch, 'spaceAccess', args.spaceAccess);
|
|
114
|
+
assignIfDefined(patch, 'mcpServerUuids', args.mcpServerUuids);
|
|
115
|
+
return Object.assign({ uuid: agentUuid }, patch);
|
|
116
|
+
}
|
|
13
117
|
function registerListProjectAgents(server, contextProvider) {
|
|
14
118
|
(0, shared_js_1.registerToolSafe)(server, 'list_project_agents', {
|
|
15
119
|
title: 'List project AI agents',
|
|
@@ -33,6 +137,180 @@ function registerGetProjectAgent(server, contextProvider) {
|
|
|
33
137
|
data: await c.v1.aiAgents.getAgent(scope.projectUuid, agentUuid),
|
|
34
138
|
}))));
|
|
35
139
|
}
|
|
140
|
+
function registerPreviewCreateAgent(server, contextProvider) {
|
|
141
|
+
(0, shared_js_1.registerToolSafe)(server, 'preview_create_agent', {
|
|
142
|
+
title: 'Preview create project AI agent',
|
|
143
|
+
description: 'Preview a new Lightdash AI agent create (permission matrix + explore tag scope). ' +
|
|
144
|
+
'Returns createPreviewToken for confirm_create_agent. No upstream write.',
|
|
145
|
+
inputSchema: Object.assign({ projectUuid: (0, helpers_js_1.optionalProjectUuidField)(), name: zod_1.z.string().min(1).describe('Agent display name') }, projectAgentPatchFields),
|
|
146
|
+
annotations: shared_js_1.READ_ONLY_DEFAULT,
|
|
147
|
+
}, (0, shared_js_1.wrapToolContextual)(contextProvider, (ctx) => {
|
|
148
|
+
const aiAgents = ctx.lightdashClient.v1.aiAgents;
|
|
149
|
+
const spacesClient = ctx.lightdashClient.v1.spaces;
|
|
150
|
+
return async (rawArgs) => {
|
|
151
|
+
const scope = await resolveCreateProjectUuid(rawArgs.projectUuid);
|
|
152
|
+
if (!scope.ok) {
|
|
153
|
+
return scope.result;
|
|
154
|
+
}
|
|
155
|
+
const payload = buildCreatePayload(rawArgs);
|
|
156
|
+
const [exploreCount, spaceAccessValidation] = await Promise.all([
|
|
157
|
+
(0, create_elicitation_js_1.previewExploreCountForTags)(aiAgents, scope.projectUuid, payload.tags),
|
|
158
|
+
(0, space_warnings_js_1.fetchSpaceAccessValidation)(spacesClient, scope.projectUuid, payload.spaceAccess),
|
|
159
|
+
]);
|
|
160
|
+
const spacePreviewWarnings = (0, space_warnings_js_1.warningsFromSpaceAccessValidation)(spaceAccessValidation);
|
|
161
|
+
const payloadDigest = (0, common_1.digestCreateAgentPayload)(payload);
|
|
162
|
+
const { createPreviewToken, claims } = await (0, create_agent_preview_js_1.mintDraftCreateAgentPreviewToken)({
|
|
163
|
+
subject: ctx.subject,
|
|
164
|
+
projectUuid: scope.projectUuid,
|
|
165
|
+
agentName: payload.name,
|
|
166
|
+
payloadDigest,
|
|
167
|
+
serverContext: ctx.serverContext,
|
|
168
|
+
});
|
|
169
|
+
const permissionSummary = (0, common_1.formatAgentPermissionSummary)(payload, {
|
|
170
|
+
groupAccess: payload.groupAccess,
|
|
171
|
+
userAccess: payload.userAccess,
|
|
172
|
+
});
|
|
173
|
+
const confirmationMessage = (0, create_elicitation_js_1.buildCreateAgentConfirmationMessage)({
|
|
174
|
+
name: payload.name,
|
|
175
|
+
payload,
|
|
176
|
+
tags: payload.tags,
|
|
177
|
+
exploreCount,
|
|
178
|
+
spaceAccessValidation,
|
|
179
|
+
});
|
|
180
|
+
const elevationPreviewWarnings = (0, common_1.collectElevationWarnings)(payload);
|
|
181
|
+
return (0, helpers_js_1.withAiAgentProjectScope)(scope.projectUuid, async () => ({
|
|
182
|
+
data: {
|
|
183
|
+
createPreviewToken,
|
|
184
|
+
previewId: claims.previewId,
|
|
185
|
+
payloadDigest,
|
|
186
|
+
permissionSummary,
|
|
187
|
+
confirmationMessage,
|
|
188
|
+
exploreCount,
|
|
189
|
+
},
|
|
190
|
+
warnings: [...elevationPreviewWarnings, ...spacePreviewWarnings],
|
|
191
|
+
}));
|
|
192
|
+
};
|
|
193
|
+
}));
|
|
194
|
+
}
|
|
195
|
+
function registerConfirmCreateAgent(server, contextProvider) {
|
|
196
|
+
(0, shared_js_1.registerToolSafe)(server, 'confirm_create_agent', {
|
|
197
|
+
title: 'Confirm create project AI agent preview',
|
|
198
|
+
description: 'Confirm a preview_create_agent draft after human approval. Returns createConfirmToken ' +
|
|
199
|
+
'for create_project_agent. No upstream write.',
|
|
200
|
+
inputSchema: {
|
|
201
|
+
projectUuid: (0, helpers_js_1.optionalProjectUuidField)(),
|
|
202
|
+
name: zod_1.z.string().min(1).describe('Agent display name (must match preview)'),
|
|
203
|
+
createPreviewToken: zod_1.z.string().min(1).describe('Draft token from preview_create_agent'),
|
|
204
|
+
},
|
|
205
|
+
annotations: shared_js_1.READ_ONLY_DEFAULT,
|
|
206
|
+
}, (0, shared_js_1.wrapToolContextual)(contextProvider, (ctx) => async (rawArgs) => {
|
|
207
|
+
const scope = await resolveCreateProjectUuid(rawArgs.projectUuid);
|
|
208
|
+
if (!scope.ok) {
|
|
209
|
+
return scope.result;
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
const { createConfirmToken, claims } = await (0, create_agent_preview_js_1.confirmCreateAgentPreviewToken)({
|
|
213
|
+
createPreviewToken: rawArgs.createPreviewToken,
|
|
214
|
+
subject: ctx.subject,
|
|
215
|
+
projectUuid: scope.projectUuid,
|
|
216
|
+
agentName: rawArgs.name,
|
|
217
|
+
serverContext: ctx.serverContext,
|
|
218
|
+
});
|
|
219
|
+
return (0, helpers_js_1.withAiAgentProjectScope)(scope.projectUuid, async () => ({
|
|
220
|
+
data: {
|
|
221
|
+
createConfirmToken,
|
|
222
|
+
previewId: claims.previewId,
|
|
223
|
+
status: claims.status,
|
|
224
|
+
},
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
catch (err) {
|
|
228
|
+
if (err instanceof create_agent_preview_js_1.CreateAgentPreviewError) {
|
|
229
|
+
return (0, shared_js_1.withLightdashBlockedMarker)((0, shared_js_1.jsonToolResult)({
|
|
230
|
+
status: 'blocked',
|
|
231
|
+
code: err.code,
|
|
232
|
+
message: err.message,
|
|
233
|
+
created: false,
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
throw err;
|
|
237
|
+
}
|
|
238
|
+
}));
|
|
239
|
+
}
|
|
240
|
+
function registerCreateProjectAgent(server, contextProvider) {
|
|
241
|
+
(0, shared_js_1.registerToolSafe)(server, 'create_project_agent', {
|
|
242
|
+
title: 'Create project AI agent',
|
|
243
|
+
description: 'Create a Lightdash AI agent in the resolved project. Requires MCP form elicitation ' +
|
|
244
|
+
'(human confirm_create) or, when form elicitation is unavailable, a validated ' +
|
|
245
|
+
'createConfirmToken from preview_create_agent -> confirm_create_agent. After accept, ' +
|
|
246
|
+
'non-empty tags that match no explores yield TAGS_MATCH_NO_EXPLORES (agent is still created). ' +
|
|
247
|
+
'For integrations, imageUrl, or modelConfig use CLI agents create --file or agentops apply.',
|
|
248
|
+
inputSchema: Object.assign({ projectUuid: (0, helpers_js_1.optionalProjectUuidField)(), name: zod_1.z.string().min(1).describe('Agent display name'), createConfirmToken: zod_1.z
|
|
249
|
+
.string()
|
|
250
|
+
.optional()
|
|
251
|
+
.describe('Validated token from confirm_create_agent when the client lacks MCP form elicitation') }, projectAgentPatchFields),
|
|
252
|
+
annotations: common_1.WRITE_NONDESTRUCTIVE,
|
|
253
|
+
}, (0, shared_js_1.wrapToolContextual)(contextProvider, (ctx) => {
|
|
254
|
+
const aiAgents = ctx.lightdashClient.v1.aiAgents;
|
|
255
|
+
const spacesClient = ctx.lightdashClient.v1.spaces;
|
|
256
|
+
return async (rawArgs) => {
|
|
257
|
+
const scope = await resolveCreateProjectUuid(rawArgs.projectUuid);
|
|
258
|
+
if (!scope.ok) {
|
|
259
|
+
return scope.result;
|
|
260
|
+
}
|
|
261
|
+
const payload = buildCreatePayload(rawArgs);
|
|
262
|
+
const gate = await (0, gate_create_project_agent_js_1.gateCreateProjectAgent)({
|
|
263
|
+
server,
|
|
264
|
+
ctx,
|
|
265
|
+
projectUuid: scope.projectUuid,
|
|
266
|
+
payload,
|
|
267
|
+
exploreAccessClient: aiAgents,
|
|
268
|
+
spacesClient,
|
|
269
|
+
createConfirmToken: rawArgs.createConfirmToken,
|
|
270
|
+
});
|
|
271
|
+
if (!gate.proceed) {
|
|
272
|
+
return gate.result;
|
|
273
|
+
}
|
|
274
|
+
return (0, helpers_js_1.withAiAgentProjectScope)(scope.projectUuid, async (resolvedScope) => {
|
|
275
|
+
const data = await aiAgents.createAgent(resolvedScope.projectUuid, (0, common_1.buildSecureCreateAiAgentBody)(Object.assign(Object.assign({}, payload), { projectUuid: resolvedScope.projectUuid })));
|
|
276
|
+
const [tagWarnings, spaceWarnings] = await Promise.all([
|
|
277
|
+
(0, tag_warnings_js_1.warningsForAgentTags)(aiAgents, resolvedScope.projectUuid, payload.tags),
|
|
278
|
+
(0, space_warnings_js_1.warningsForAgentSpaceAccess)(spacesClient, resolvedScope.projectUuid, payload.spaceAccess),
|
|
279
|
+
]);
|
|
280
|
+
const permissionWarnings = (0, common_1.collectElevationWarnings)(payload);
|
|
281
|
+
return { data, warnings: [...tagWarnings, ...spaceWarnings, ...permissionWarnings] };
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
}));
|
|
285
|
+
}
|
|
286
|
+
function registerUpdateProjectAgent(server, contextProvider) {
|
|
287
|
+
(0, shared_js_1.registerToolSafe)(server, 'update_project_agent', {
|
|
288
|
+
title: 'Update project AI agent',
|
|
289
|
+
description: 'Patch a Lightdash AI agent in the resolved project. Omit fields to leave them unchanged. ' +
|
|
290
|
+
'No form elicitation. When tags are set and match no explores, returns TAGS_MATCH_NO_EXPLORES ' +
|
|
291
|
+
'(update still applied). Agent delete is not available on MCP — use CLI agents delete.',
|
|
292
|
+
inputSchema: Object.assign({ projectUuid: (0, helpers_js_1.optionalProjectUuidField)(), agentUuid: (0, helpers_js_1.agentUuidField)(), name: zod_1.z.string().min(1).optional().describe('Agent display name') }, projectAgentPatchFields),
|
|
293
|
+
annotations: common_1.WRITE_NONDESTRUCTIVE,
|
|
294
|
+
}, (0, shared_js_1.wrapTool)(contextProvider, (c) => async (_a) => {
|
|
295
|
+
var { projectUuid, agentUuid } = _a, patch = __rest(_a, ["projectUuid", "agentUuid"]);
|
|
296
|
+
return (0, helpers_js_1.withAiAgentProjectScope)(projectUuid, async (scope) => {
|
|
297
|
+
const data = await c.v1.aiAgents.updateAgent(scope.projectUuid, agentUuid, buildUpdateProjectAgentBody(agentUuid, patch));
|
|
298
|
+
const [tagWarnings, spaceWarnings] = await Promise.all([
|
|
299
|
+
patch.tags === undefined
|
|
300
|
+
? []
|
|
301
|
+
: (0, tag_warnings_js_1.warningsForAgentTags)(c.v1.aiAgents, scope.projectUuid, patch.tags),
|
|
302
|
+
patch.spaceAccess === undefined
|
|
303
|
+
? []
|
|
304
|
+
: (0, space_warnings_js_1.warningsForAgentSpaceAccess)(c.v1.spaces, scope.projectUuid, patch.spaceAccess),
|
|
305
|
+
]);
|
|
306
|
+
const permissionWarnings = (0, common_1.collectElevationWarningsFromPatch)(patch);
|
|
307
|
+
return {
|
|
308
|
+
data,
|
|
309
|
+
warnings: [...tagWarnings, ...spaceWarnings, ...permissionWarnings],
|
|
310
|
+
};
|
|
311
|
+
});
|
|
312
|
+
}));
|
|
313
|
+
}
|
|
36
314
|
function registerGetUserAgentPreferences(server, contextProvider) {
|
|
37
315
|
(0, shared_js_1.registerToolSafe)(server, 'get_user_agent_preferences', {
|
|
38
316
|
title: 'Get user agent preferences',
|
|
@@ -46,4 +324,8 @@ function registerGetUserAgentPreferences(server, contextProvider) {
|
|
|
46
324
|
// ToolModule exports (profile mounts)
|
|
47
325
|
exports.listProjectAgentsTool = (0, types_js_1.defineTool)('list_project_agents', registerListProjectAgents);
|
|
48
326
|
exports.getProjectAgentTool = (0, types_js_1.defineTool)('get_project_agent', registerGetProjectAgent);
|
|
327
|
+
exports.previewCreateAgentTool = (0, types_js_1.defineTool)('preview_create_agent', registerPreviewCreateAgent);
|
|
328
|
+
exports.confirmCreateAgentTool = (0, types_js_1.defineTool)('confirm_create_agent', registerConfirmCreateAgent);
|
|
329
|
+
exports.createProjectAgentTool = (0, types_js_1.defineTool)('create_project_agent', registerCreateProjectAgent);
|
|
330
|
+
exports.updateProjectAgentTool = (0, types_js_1.defineTool)('update_project_agent', registerUpdateProjectAgent);
|
|
49
331
|
exports.getUserAgentPreferencesTool = (0, types_js_1.defineTool)('get_user_agent_preferences', registerGetUserAgentPreferences);
|
|
@@ -161,6 +161,31 @@ const RUN = '44444444-4444-4444-4444-444444444444';
|
|
|
161
161
|
(0, vitest_1.expect)(getUserAgentPreferences).toHaveBeenCalledWith(PROJECT);
|
|
162
162
|
(0, vitest_1.expect)((0, test_support_js_1.parseAiAgentToolBody)(result).data).toEqual({ defaultAgentUuid: AGENT });
|
|
163
163
|
});
|
|
164
|
+
(0, vitest_1.it)('registers create_project_agent as WRITE_NONDESTRUCTIVE', () => {
|
|
165
|
+
const createAgent = vitest_1.vi.fn();
|
|
166
|
+
const { options } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerCreateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ createAgent }), 'create_project_agent');
|
|
167
|
+
(0, vitest_1.expect)(options).toMatchObject({
|
|
168
|
+
annotations: vitest_1.expect.objectContaining({
|
|
169
|
+
readOnlyHint: false,
|
|
170
|
+
destructiveHint: false,
|
|
171
|
+
}),
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
(0, vitest_1.it)('updates a project agent with partial patch body', async () => {
|
|
175
|
+
const updateAgent = vitest_1.vi.fn().mockResolvedValue({ uuid: AGENT, instruction: 'Updated' });
|
|
176
|
+
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerUpdateProjectAgent, (0, test_support_js_1.mockAiAgentsContext)({ updateAgent }), 'update_project_agent');
|
|
177
|
+
const result = await handler({
|
|
178
|
+
projectUuid: PROJECT,
|
|
179
|
+
agentUuid: AGENT,
|
|
180
|
+
instruction: 'Updated',
|
|
181
|
+
});
|
|
182
|
+
(0, vitest_1.expect)(result.isError).toBeUndefined();
|
|
183
|
+
(0, vitest_1.expect)(updateAgent).toHaveBeenCalledWith(PROJECT, AGENT, {
|
|
184
|
+
uuid: AGENT,
|
|
185
|
+
instruction: 'Updated',
|
|
186
|
+
});
|
|
187
|
+
(0, vitest_1.expect)((0, test_support_js_1.parseAiAgentToolBody)(result).data).toEqual({ uuid: AGENT, instruction: 'Updated' });
|
|
188
|
+
});
|
|
164
189
|
(0, vitest_1.it)('surfaces PROJECT_SCOPE_REQUIRED for get_user_agent_preferences when unresolved', async () => {
|
|
165
190
|
const getUserAgentPreferences = vitest_1.vi.fn();
|
|
166
191
|
const { handler } = (0, test_support_js_1.registeredAiAgentTool)(agents_js_1.registerGetUserAgentPreferences, (0, test_support_js_1.mockAiAgentsContext)({ getUserAgentPreferences }), 'get_user_agent_preferences');
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form elicitation gate for create_project_agent (ADR-0033 / ADR-0015 pattern).
|
|
3
|
+
*/
|
|
4
|
+
import { digestCreateAgentPayload, type AgentCreatePayloadFields } from '@lightdash-tools/common';
|
|
5
|
+
import { type ProjectSpacesClient, type SpaceAccessValidationResult } from './space-warnings.js';
|
|
6
|
+
import { previewExploreCountForTags, type ExploreAccessSummaryClient } from './tag-warnings.js';
|
|
7
|
+
import type { ToolExecutionContext, ToolResult } from '../shared.js';
|
|
8
|
+
import type { McpServer } from '@modelcontextprotocol/server';
|
|
9
|
+
export { digestCreateAgentPayload, previewExploreCountForTags };
|
|
10
|
+
export declare const CONFIRM_CREATE_AGENT_INPUT_KEY: "confirm_create_agent";
|
|
11
|
+
export type CreateAgentConfirmFormContent = {
|
|
12
|
+
decision: 'confirm_create' | 'do_not_create';
|
|
13
|
+
};
|
|
14
|
+
export declare const CREATE_AGENT_CONFIRM_FORM_SCHEMA: {
|
|
15
|
+
type: "object";
|
|
16
|
+
properties: {
|
|
17
|
+
decision: {
|
|
18
|
+
type: "string";
|
|
19
|
+
title: string;
|
|
20
|
+
description: string;
|
|
21
|
+
enum: string[];
|
|
22
|
+
enumNames: string[];
|
|
23
|
+
default: string;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
required: string[];
|
|
27
|
+
};
|
|
28
|
+
export declare function buildCreateAgentConfirmationMessage(input: {
|
|
29
|
+
name: string;
|
|
30
|
+
payload: AgentCreatePayloadFields;
|
|
31
|
+
tags: string[] | null | undefined;
|
|
32
|
+
exploreCount: number | null;
|
|
33
|
+
spaceAccessValidation: SpaceAccessValidationResult;
|
|
34
|
+
}): string;
|
|
35
|
+
/**
|
|
36
|
+
* Run the create elicitation gate. Returns:
|
|
37
|
+
* - ToolResult to return immediately (blocked / input required / declined), or
|
|
38
|
+
* - `{ proceed: true }` when the human accepted and the digest matches.
|
|
39
|
+
*/
|
|
40
|
+
export declare function gateCreateProjectAgentElicitation(input: {
|
|
41
|
+
server: McpServer;
|
|
42
|
+
ctx: ToolExecutionContext;
|
|
43
|
+
projectUuid: string;
|
|
44
|
+
payload: AgentCreatePayloadFields;
|
|
45
|
+
exploreAccessClient: ExploreAccessSummaryClient;
|
|
46
|
+
spacesClient: ProjectSpacesClient;
|
|
47
|
+
}): Promise<{
|
|
48
|
+
proceed: false;
|
|
49
|
+
result: ToolResult;
|
|
50
|
+
} | {
|
|
51
|
+
proceed: true;
|
|
52
|
+
}>;
|