@enhance-eng/enhance 0.1.14 → 0.1.16
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/{cli-output-identity.lib-bX6NwZjd.mjs → cli-output-identity.lib-F9-nlguI.mjs} +504 -84
- package/dist/main.mjs +133 -512
- package/dist/{mcp-invocation.adapter-BdZ-LpPW.mjs → mcp-invocation.adapter-fYfIiCYu.mjs} +2 -2
- package/dist/mcp-main.mjs +7 -7
- package/dist/{mcp-server.adapter-DBlOw4BM.mjs → mcp-server.adapter-C8plL5bs.mjs} +317 -147
- package/dist/mcp.mjs +2 -2
- package/dist/{mutation-key.adapter-p1odGHfg.mjs → mutation-key.adapter-Bc4p5ff4.mjs} +720 -24
- package/dist/remote-mcp-main.mjs +5 -5
- package/package.json +2 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { a as createOauthLoopbackAdapter,
|
|
2
|
+
import { o as toFailurePayload } from "./cli-output-identity.lib-F9-nlguI.mjs";
|
|
3
|
+
import { a as createOauthLoopbackAdapter, m as createAuthUseCase, n as createHttpRemoteAdapter, o as createCapabilityInvocationAdapter, t as createMutationKeyAdapter } from "./mutation-key.adapter-Bc4p5ff4.mjs";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
|
|
6
6
|
//#region src/infrastructure/mcp-auth.adapter.ts
|
package/dist/mcp-main.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import { r as CLI_CONFIG } from "./mutation-key.adapter-
|
|
2
|
+
import { d as createCapabilityCatalogAdapter, m as toCapabilityDefinition } from "./cli-output-identity.lib-F9-nlguI.mjs";
|
|
3
|
+
import { r as CLI_CONFIG } from "./mutation-key.adapter-Bc4p5ff4.mjs";
|
|
4
4
|
import { t as createFileCredentialAdapter } from "./file-credential.adapter-rI5HpMEo.mjs";
|
|
5
|
-
import { t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-
|
|
6
|
-
import { t as createMcpServerAdapter } from "./mcp-server.adapter-
|
|
5
|
+
import { t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-fYfIiCYu.mjs";
|
|
6
|
+
import { t as createMcpServerAdapter } from "./mcp-server.adapter-C8plL5bs.mjs";
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import process from "node:process";
|
|
9
9
|
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
@@ -152,7 +152,7 @@ const capabilities = [
|
|
|
152
152
|
exampleInput: {},
|
|
153
153
|
exampleOutput: {
|
|
154
154
|
status: "ok",
|
|
155
|
-
runtimeVersion: "0.1.
|
|
155
|
+
runtimeVersion: "0.1.16",
|
|
156
156
|
api: {
|
|
157
157
|
reachable: true,
|
|
158
158
|
status: 200
|
|
@@ -167,10 +167,10 @@ const createMcpTransportCapabilityAdapter = () => capabilities;
|
|
|
167
167
|
//#endregion
|
|
168
168
|
//#region src/mcp-main.ts
|
|
169
169
|
const credentials = createFileCredentialAdapter(CLI_CONFIG.configDirectory);
|
|
170
|
-
const invocation = createMcpInvocationAdapter(CLI_CONFIG.apiUrl, credentials, CLI_CONFIG.configDirectory, "0.1.
|
|
170
|
+
const invocation = createMcpInvocationAdapter(CLI_CONFIG.apiUrl, credentials, CLI_CONFIG.configDirectory, "0.1.16");
|
|
171
171
|
const catalog = [...createCapabilityCatalogAdapter(), ...createMcpTransportCapabilityAdapter()];
|
|
172
172
|
serveStdio(() => createMcpServerAdapter({
|
|
173
|
-
version: "0.1.
|
|
173
|
+
version: "0.1.16",
|
|
174
174
|
name: CLI_CONFIG.mcpServiceName,
|
|
175
175
|
commandName: CLI_CONFIG.commandName,
|
|
176
176
|
invocation,
|
|
@@ -1,61 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { A as parseCanvasReference, E as assertCanvasReferenceNodes, M as CliError, St as canvasReadableSceneDocumentSchema, d as createCapabilityCatalogAdapter, gt as canvasRenderTargetSchema, ht as canvasRenderSourceStateSchema, i as toCanvasAuthoringResult, l as createMcpCapabilityDiscoveryAdapter, n as withCommandName, o as toFailurePayload, r as canvasRenderResultSchema, s as toPresentedCapabilities, t as withCommandInFailure, ut as getCanvasDocumentOutputSchema, w as canvasEditCapabilityInputSchema, y as canvasWriteHtmlCapabilityInputSchema } from "./cli-output-identity.lib-F9-nlguI.mjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { createHash, randomUUID } from "node:crypto";
|
|
5
5
|
import { readFile, rm } from "node:fs/promises";
|
|
6
6
|
import { McpServer } from "@modelcontextprotocol/server";
|
|
7
7
|
|
|
8
|
-
//#region src/infrastructure/capability-catalogue-text.mapper.ts
|
|
9
|
-
const MAX_LINE_CHARACTERS = 180;
|
|
10
|
-
const MAX_CATALOGUE_BYTES = 24 * 1024;
|
|
11
|
-
const oneLine = (value) => value.replaceAll(/\s+/gu, " ").trim();
|
|
12
|
-
const lineFor = (capability) => {
|
|
13
|
-
const prefix = `${capability.id} [${capability.effect}] — `;
|
|
14
|
-
const summary = oneLine(capability.guide.summary);
|
|
15
|
-
const available = MAX_LINE_CHARACTERS - prefix.length;
|
|
16
|
-
return `${prefix}${summary.slice(0, available)}`;
|
|
17
|
-
};
|
|
18
|
-
const toCapabilityCatalogueText = (catalog, serverVersion) => {
|
|
19
|
-
const lines = catalog.toSorted((left, right) => left.id.localeCompare(right.id)).map((capability) => lineFor(capability));
|
|
20
|
-
const digest = createHash("sha256").update(lines.join("\n")).digest("hex");
|
|
21
|
-
const text = [`Enhance MCP ${serverVersion} — ${String(lines.length)} capabilities — sha256:${digest}`, ...lines].join("\n");
|
|
22
|
-
if (Buffer.byteLength(text) > MAX_CATALOGUE_BYTES) throw new RangeError("the complete capability catalogue exceeds 24 KiB");
|
|
23
|
-
return {
|
|
24
|
-
digest,
|
|
25
|
-
text
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
//#endregion
|
|
30
|
-
//#region src/infrastructure/mcp-catalogue-tool.adapter.ts
|
|
31
|
-
const createMcpCatalogueToolAdapter = (catalog, version, commandName = "enhance") => {
|
|
32
|
-
const catalogue = toCapabilityCatalogueText(catalog, version);
|
|
33
|
-
const presented = String(withCommandName(catalogue.text, commandName));
|
|
34
|
-
return { register: (server) => {
|
|
35
|
-
server.registerTool("capability_catalogue", {
|
|
36
|
-
title: "Scan every Enhance capability",
|
|
37
|
-
description: "Return the complete bounded capability inventory when the task is broad, uncertain, or capability_search does not find the right words. Call capability_describe with one exact id before invoking it.",
|
|
38
|
-
inputSchema: z.strictObject({}),
|
|
39
|
-
annotations: {
|
|
40
|
-
readOnlyHint: true,
|
|
41
|
-
destructiveHint: false,
|
|
42
|
-
idempotentHint: true,
|
|
43
|
-
openWorldHint: false
|
|
44
|
-
},
|
|
45
|
-
_meta: {
|
|
46
|
-
"ai.enhancelabs/disclosure": "progressive",
|
|
47
|
-
"ai.enhancelabs/catalogSize": catalog.length,
|
|
48
|
-
"enhance/disclosure": "progressive",
|
|
49
|
-
"enhance/catalogSize": catalog.length
|
|
50
|
-
}
|
|
51
|
-
}, () => ({ content: [{
|
|
52
|
-
type: "text",
|
|
53
|
-
text: presented
|
|
54
|
-
}] }));
|
|
55
|
-
} };
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
//#endregion
|
|
59
8
|
//#region src/infrastructure/mcp-progressive.schema.ts
|
|
60
9
|
const failureSchema = z.object({
|
|
61
10
|
ok: z.literal(false),
|
|
@@ -69,13 +18,14 @@ const failureSchema = z.object({
|
|
|
69
18
|
})).optional()
|
|
70
19
|
})
|
|
71
20
|
});
|
|
21
|
+
const artifactReferenceSchema = z.object({
|
|
22
|
+
uri: z.string(),
|
|
23
|
+
mimeType: z.string(),
|
|
24
|
+
bytes: z.number().int().nonnegative()
|
|
25
|
+
});
|
|
72
26
|
const artifactSchema = z.object({
|
|
73
27
|
ok: z.literal(true),
|
|
74
|
-
artifact:
|
|
75
|
-
uri: z.string(),
|
|
76
|
-
mimeType: z.string(),
|
|
77
|
-
bytes: z.number().int().nonnegative()
|
|
78
|
-
})
|
|
28
|
+
artifact: artifactReferenceSchema
|
|
79
29
|
});
|
|
80
30
|
const capabilityContractSchema = z.object({
|
|
81
31
|
id: z.string(),
|
|
@@ -118,7 +68,9 @@ const capabilityBriefSchema = capabilityContractSchema.pick({
|
|
|
118
68
|
const mcpDispatchedResultSchema = z.union([
|
|
119
69
|
z.object({
|
|
120
70
|
ok: z.literal(true),
|
|
121
|
-
result: z.unknown()
|
|
71
|
+
result: z.unknown(),
|
|
72
|
+
artifact: artifactReferenceSchema.optional(),
|
|
73
|
+
detail: artifactReferenceSchema.optional()
|
|
122
74
|
}),
|
|
123
75
|
artifactSchema,
|
|
124
76
|
failureSchema
|
|
@@ -128,7 +80,9 @@ const mcpSearchResultSchema = z.union([z.object({
|
|
|
128
80
|
result: z.object({
|
|
129
81
|
matches: z.array(capabilityBriefSchema),
|
|
130
82
|
totalMatches: z.number().int().nonnegative(),
|
|
131
|
-
truncated: z.boolean()
|
|
83
|
+
truncated: z.boolean(),
|
|
84
|
+
bestContract: capabilityContractSchema.optional(),
|
|
85
|
+
detailRequired: z.object({ capability: z.string() }).optional()
|
|
132
86
|
})
|
|
133
87
|
}), failureSchema]);
|
|
134
88
|
const mcpDescribeResultSchema = z.union([z.object({
|
|
@@ -136,6 +90,183 @@ const mcpDescribeResultSchema = z.union([z.object({
|
|
|
136
90
|
result: capabilityContractSchema
|
|
137
91
|
}), failureSchema]);
|
|
138
92
|
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/infrastructure/mcp-canvas-tools.adapter.ts
|
|
95
|
+
const MIN_RENDER_SCALE = .1;
|
|
96
|
+
const MAX_RENDER_SCALE = 4;
|
|
97
|
+
const clientToken = z.uuid().optional().describe("Reuse only when retrying this exact mutation.");
|
|
98
|
+
const writeSchema = canvasWriteHtmlCapabilityInputSchema.pick({
|
|
99
|
+
baseVersion: true,
|
|
100
|
+
targetNodeId: true,
|
|
101
|
+
html: true,
|
|
102
|
+
idPrefix: true
|
|
103
|
+
}).extend({
|
|
104
|
+
canvas: z.string().min(1).describe("Canvas UUID or complete canvas/selection URL. Preserve a supplied selection URL."),
|
|
105
|
+
mode: z.enum(["insert-children", "replace"]).default("insert-children"),
|
|
106
|
+
clientToken
|
|
107
|
+
});
|
|
108
|
+
const editSchema = canvasEditCapabilityInputSchema.extend({ clientToken });
|
|
109
|
+
const renderSchema = z.object({
|
|
110
|
+
canvas: z.string().min(1),
|
|
111
|
+
expectedVersion: z.number().int().positive().describe("Version returned by the latest successful read or write."),
|
|
112
|
+
target: canvasRenderTargetSchema.default({ kind: "content" }),
|
|
113
|
+
sourceState: canvasRenderSourceStateSchema.nullable().default(null),
|
|
114
|
+
scale: z.number().min(MIN_RENDER_SCALE).max(MAX_RENDER_SCALE).default(1)
|
|
115
|
+
});
|
|
116
|
+
const invoke = async (input, id, args, token = null) => {
|
|
117
|
+
const capability = input.catalog.find((candidate) => candidate.id === id);
|
|
118
|
+
if (capability === void 0) throw new TypeError(`Missing canvas capability ${id}`);
|
|
119
|
+
return input.invocation.invoke({
|
|
120
|
+
capability,
|
|
121
|
+
arguments: args,
|
|
122
|
+
clientToken: token
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
const renderTarget = async (input, args) => {
|
|
126
|
+
const reference = parseCanvasReference(args.canvas);
|
|
127
|
+
if (reference.nodeIds.length === 0) return {
|
|
128
|
+
canvasId: reference.canvasId,
|
|
129
|
+
target: args.target
|
|
130
|
+
};
|
|
131
|
+
const nodeId = args.target.kind === "node" ? args.target.nodeId : args.target.kind === "content" && reference.nodeIds.length === 1 ? reference.nodeIds[0] : void 0;
|
|
132
|
+
if (nodeId === void 0) throw new CliError("BAD_REQUEST", "A selection link requires one selected node to render.", "Choose a node target inside the selection; bounds or whole-canvas renders can include unrelated content.");
|
|
133
|
+
const held = getCanvasDocumentOutputSchema.parse(await invoke(input, "canvas.document.get", { canvasId: reference.canvasId }));
|
|
134
|
+
if (held.version !== args.expectedVersion) throw new CliError("CONFLICT", "The canvas changed before rendering.", "Read the selected subtree and render its current version.");
|
|
135
|
+
assertCanvasReferenceNodes(reference, canvasReadableSceneDocumentSchema.parse(held.document), [nodeId]);
|
|
136
|
+
return {
|
|
137
|
+
canvasId: reference.canvasId,
|
|
138
|
+
target: {
|
|
139
|
+
kind: "node",
|
|
140
|
+
nodeId
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
const deliver = async (server, input, action) => {
|
|
145
|
+
try {
|
|
146
|
+
return await input.results.success(server, await action(), input.delivery);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
return input.results.failure(error);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const registerWrite = (server, input) => {
|
|
152
|
+
if (input.catalog.some((capability) => capability.id === "canvas.writeHtml")) server.registerTool("canvas_write_html", {
|
|
153
|
+
title: "Design editable canvas content",
|
|
154
|
+
description: "Create a populated screen or visual group from safe HTML/CSS. For multiple screens, publish the first populated screen before authoring the next, then publish each subsequent screen separately so the user can see and steer progress. Prepare only what that screen needs; do not prepare the whole set before the first write. Returns the committed version and root node without an extra read or render. If starting state is unknown, call capability_query with {\"capability\":\"canvas.inspect\",\"input\":{\"canvasId\":\"<UUID from canvas URL>\"}}. When nodeCount is 0, use targetNodeId \"root\" and the returned version. Use flex, padding, gap, concrete inline CSS and layer-name. Give important rows/cards/buttons explicit dimensions; avoid implicit stretch, margins, grid, tables and inline badge backgrounds. Include real content, not an empty shell. Reuse a returned version for subsequent edits; read a targeted subtree only when its ids or structure are unknown. Use canvas_edit for small changes, then canvas_render once at a useful review point. The schema here is executable; no search or describe is required.",
|
|
155
|
+
inputSchema: writeSchema,
|
|
156
|
+
outputSchema: mcpDispatchedResultSchema,
|
|
157
|
+
annotations: {
|
|
158
|
+
readOnlyHint: false,
|
|
159
|
+
destructiveHint: true,
|
|
160
|
+
idempotentHint: false,
|
|
161
|
+
openWorldHint: false
|
|
162
|
+
}
|
|
163
|
+
}, async ({ canvas, clientToken: token, ...args }) => deliver(server, input, async () => {
|
|
164
|
+
const reference = parseCanvasReference(canvas);
|
|
165
|
+
return invoke(input, "canvas.writeHtml", {
|
|
166
|
+
...args,
|
|
167
|
+
canvasId: reference.canvasId,
|
|
168
|
+
...reference.nodeIds.length > 0 && { selectionNodeIds: reference.nodeIds },
|
|
169
|
+
review: "none",
|
|
170
|
+
renderOutputPath: null,
|
|
171
|
+
overwriteRender: false,
|
|
172
|
+
renderScale: 1,
|
|
173
|
+
renderTimeoutMs: 12e4
|
|
174
|
+
}, token ?? null);
|
|
175
|
+
}));
|
|
176
|
+
};
|
|
177
|
+
const registerEdit = (server, input) => {
|
|
178
|
+
if (input.catalog.some((capability) => capability.id === "canvas.edit")) server.registerTool("canvas_edit", {
|
|
179
|
+
title: "Edit existing canvas content",
|
|
180
|
+
description: "Apply text, styles, rename, duplicate or move edits together in one atomic mutation. Use ids from the input version and the latest successful read or write version; no intermediate read is required just to advance a version. Keep the complete selection URL. Read only the missing subtree when ids are unknown. Returns a compact committed receipt; render after the requested changes are complete.",
|
|
181
|
+
inputSchema: editSchema,
|
|
182
|
+
outputSchema: mcpDispatchedResultSchema,
|
|
183
|
+
annotations: {
|
|
184
|
+
readOnlyHint: false,
|
|
185
|
+
destructiveHint: true,
|
|
186
|
+
idempotentHint: false,
|
|
187
|
+
openWorldHint: false
|
|
188
|
+
}
|
|
189
|
+
}, async ({ clientToken: token, ...args }) => deliver(server, input, async () => invoke(input, "canvas.edit", args, token ?? null)));
|
|
190
|
+
};
|
|
191
|
+
const registerRender = (server, input) => {
|
|
192
|
+
if (input.catalog.some((capability) => capability.id === "canvas.render")) server.registerTool("canvas_render", {
|
|
193
|
+
title: "Review canvas pixels",
|
|
194
|
+
description: "Render the version returned by a successful read or write and inspect its native PNG. Target the affected screen/node; a blank canvas does not need a pre-render. For a selection link use one node inside the selection. Review after a meaningful visual change, and repeat only after further changes or a real discrepancy.",
|
|
195
|
+
inputSchema: renderSchema,
|
|
196
|
+
outputSchema: mcpDispatchedResultSchema,
|
|
197
|
+
annotations: {
|
|
198
|
+
readOnlyHint: true,
|
|
199
|
+
destructiveHint: false,
|
|
200
|
+
idempotentHint: true,
|
|
201
|
+
openWorldHint: false
|
|
202
|
+
}
|
|
203
|
+
}, async (args) => deliver(server, input, async () => invoke(input, "canvas.render", {
|
|
204
|
+
...await renderTarget(input, args),
|
|
205
|
+
expectedVersion: args.expectedVersion,
|
|
206
|
+
sourceState: args.sourceState,
|
|
207
|
+
scale: args.scale,
|
|
208
|
+
outputPath: null,
|
|
209
|
+
overwrite: false,
|
|
210
|
+
timeoutMs: 12e4
|
|
211
|
+
})));
|
|
212
|
+
};
|
|
213
|
+
const createMcpCanvasToolsAdapter = (input) => ({ register: (server) => {
|
|
214
|
+
registerWrite(server, input);
|
|
215
|
+
registerEdit(server, input);
|
|
216
|
+
registerRender(server, input);
|
|
217
|
+
} });
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
//#region src/infrastructure/capability-catalogue-text.mapper.ts
|
|
221
|
+
const MAX_LINE_CHARACTERS = 180;
|
|
222
|
+
const MAX_CATALOGUE_BYTES = 24 * 1024;
|
|
223
|
+
const oneLine = (value) => value.replaceAll(/\s+/gu, " ").trim();
|
|
224
|
+
const lineFor = (capability) => {
|
|
225
|
+
const prefix = `${capability.id} [${capability.effect}] — `;
|
|
226
|
+
const summary = oneLine(capability.guide.summary);
|
|
227
|
+
const available = MAX_LINE_CHARACTERS - prefix.length;
|
|
228
|
+
return `${prefix}${summary.slice(0, available)}`;
|
|
229
|
+
};
|
|
230
|
+
const toCapabilityCatalogueText = (catalog, serverVersion) => {
|
|
231
|
+
const lines = catalog.toSorted((left, right) => left.id.localeCompare(right.id)).map((capability) => lineFor(capability));
|
|
232
|
+
const digest = createHash("sha256").update(lines.join("\n")).digest("hex");
|
|
233
|
+
const text = [`Enhance MCP ${serverVersion} — ${String(lines.length)} capabilities — sha256:${digest}`, ...lines].join("\n");
|
|
234
|
+
if (Buffer.byteLength(text) > MAX_CATALOGUE_BYTES) throw new RangeError("the complete capability catalogue exceeds 24 KiB");
|
|
235
|
+
return {
|
|
236
|
+
digest,
|
|
237
|
+
text
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/infrastructure/mcp-catalogue-tool.adapter.ts
|
|
243
|
+
const createMcpCatalogueToolAdapter = (catalog, version, commandName = "enhance") => {
|
|
244
|
+
const catalogue = toCapabilityCatalogueText(catalog, version);
|
|
245
|
+
const presented = String(withCommandName(catalogue.text, commandName));
|
|
246
|
+
return { register: (server) => {
|
|
247
|
+
server.registerTool("capability_catalogue", {
|
|
248
|
+
title: "Scan every Enhance capability",
|
|
249
|
+
description: "Return the complete bounded capability inventory when the task is broad, uncertain, or capability_search does not find the right words. Call capability_describe with one exact id before invoking it.",
|
|
250
|
+
inputSchema: z.strictObject({}),
|
|
251
|
+
annotations: {
|
|
252
|
+
readOnlyHint: true,
|
|
253
|
+
destructiveHint: false,
|
|
254
|
+
idempotentHint: true,
|
|
255
|
+
openWorldHint: false
|
|
256
|
+
},
|
|
257
|
+
_meta: {
|
|
258
|
+
"ai.enhancelabs/disclosure": "progressive",
|
|
259
|
+
"ai.enhancelabs/catalogSize": catalog.length,
|
|
260
|
+
"enhance/disclosure": "progressive",
|
|
261
|
+
"enhance/catalogSize": catalog.length
|
|
262
|
+
}
|
|
263
|
+
}, () => ({ content: [{
|
|
264
|
+
type: "text",
|
|
265
|
+
text: presented
|
|
266
|
+
}] }));
|
|
267
|
+
} };
|
|
268
|
+
};
|
|
269
|
+
|
|
139
270
|
//#endregion
|
|
140
271
|
//#region src/infrastructure/mcp-describe-tool.adapter.ts
|
|
141
272
|
const describeInputSchema = z.object({ capability: z.string().min(1).describe("Exact capability id returned by capability_search or capability_catalogue.") });
|
|
@@ -175,77 +306,39 @@ const hasProtectedMaterial = (value, key = "") => {
|
|
|
175
306
|
if (Reflect.get(value, "sensitive") === true) return true;
|
|
176
307
|
return Object.entries(value).some(([childKey, child]) => hasProtectedMaterial(child, childKey));
|
|
177
308
|
};
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
const path = Reflect.get(result, "path");
|
|
181
|
-
if (typeof path !== "string") return null;
|
|
182
|
-
const mimeType = Reflect.get(result, "contentType");
|
|
183
|
-
if (typeof mimeType !== "string" || !mimeType.startsWith("image/")) return null;
|
|
184
|
-
if (Reflect.get(result, "sensitive") !== true) return null;
|
|
185
|
-
const body = await readFile(path);
|
|
309
|
+
const renderAttachment = async (server, result, delivery) => {
|
|
310
|
+
const body = await readFile(result.path);
|
|
186
311
|
const id = randomUUID();
|
|
187
312
|
const uri = `enhance://artifact/${id}`;
|
|
188
|
-
if (delivery === "embedded") {
|
|
189
|
-
await rm(path, { force: true });
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
artifact: {
|
|
193
|
-
uri,
|
|
194
|
-
mimeType,
|
|
195
|
-
bytes: body.byteLength
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
return {
|
|
199
|
-
content: [
|
|
200
|
-
{
|
|
201
|
-
type: "text",
|
|
202
|
-
text: textFor(structuredContent)
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
type: "image",
|
|
206
|
-
data: body.toString("base64"),
|
|
207
|
-
mimeType
|
|
208
|
-
},
|
|
209
|
-
{
|
|
210
|
-
type: "resource",
|
|
211
|
-
resource: {
|
|
212
|
-
uri,
|
|
213
|
-
mimeType,
|
|
214
|
-
blob: body.toString("base64")
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
],
|
|
218
|
-
structuredContent
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
server.registerResource(`artifact-${id}`, uri, {
|
|
313
|
+
if (delivery === "embedded" && result.cleanup === "unlink-after-use") try {
|
|
314
|
+
await rm(result.path, { force: true });
|
|
315
|
+
} catch {}
|
|
316
|
+
if (delivery === "linked") server.registerResource(`artifact-${id}`, uri, {
|
|
222
317
|
title: "Enhance artifact",
|
|
223
|
-
mimeType
|
|
318
|
+
mimeType: result.contentType
|
|
224
319
|
}, (requested) => ({ contents: [{
|
|
225
320
|
uri: requested.href,
|
|
226
|
-
mimeType,
|
|
321
|
+
mimeType: result.contentType,
|
|
227
322
|
blob: body.toString("base64")
|
|
228
323
|
}] }));
|
|
229
|
-
|
|
230
|
-
|
|
324
|
+
return {
|
|
325
|
+
metadata: canvasRenderResultSchema.omit({
|
|
326
|
+
path: true,
|
|
327
|
+
sensitive: true,
|
|
328
|
+
cleanup: true,
|
|
329
|
+
deleteAfter: true
|
|
330
|
+
}).parse(result),
|
|
231
331
|
artifact: {
|
|
232
332
|
uri,
|
|
233
|
-
mimeType,
|
|
333
|
+
mimeType: result.contentType,
|
|
234
334
|
bytes: body.byteLength
|
|
335
|
+
},
|
|
336
|
+
image: {
|
|
337
|
+
type: "image",
|
|
338
|
+
data: body.toString("base64"),
|
|
339
|
+
mimeType: result.contentType
|
|
235
340
|
}
|
|
236
341
|
};
|
|
237
|
-
return {
|
|
238
|
-
content: [{
|
|
239
|
-
type: "text",
|
|
240
|
-
text: textFor(structuredContent)
|
|
241
|
-
}, {
|
|
242
|
-
type: "resource_link",
|
|
243
|
-
name: "Enhance artifact",
|
|
244
|
-
uri,
|
|
245
|
-
mimeType
|
|
246
|
-
}],
|
|
247
|
-
structuredContent
|
|
248
|
-
};
|
|
249
342
|
};
|
|
250
343
|
const artifactResult = (server, serialized, delivery) => {
|
|
251
344
|
const id = randomUUID();
|
|
@@ -304,39 +397,111 @@ const artifactResult = (server, serialized, delivery) => {
|
|
|
304
397
|
structuredContent
|
|
305
398
|
};
|
|
306
399
|
};
|
|
307
|
-
const validationError = (error) => new CliError("BAD_REQUEST", "Input validation error.", "
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
ok: true,
|
|
317
|
-
result: presented
|
|
400
|
+
const validationError = (error) => new CliError("BAD_REQUEST", "Input validation error.", "Correct the rejected fields using this tool’s schema, then retry. Describe the exact capability only if its contract is unknown.", Object.fromEntries(error.issues.map((issue) => [issue.path.length === 0 ? "input" : issue.path.join("."), issue.message])));
|
|
401
|
+
const prepareCanvasResult = async (server, presented, delivery) => {
|
|
402
|
+
const render = canvasRenderResultSchema.safeParse(presented);
|
|
403
|
+
if (render.success) {
|
|
404
|
+
const attachment = await renderAttachment(server, render.data, delivery);
|
|
405
|
+
return {
|
|
406
|
+
value: attachment.metadata,
|
|
407
|
+
detail: null,
|
|
408
|
+
attachment
|
|
318
409
|
};
|
|
410
|
+
}
|
|
411
|
+
const originalAuthoring = toCanvasAuthoringResult(presented);
|
|
412
|
+
if (originalAuthoring === null) return {
|
|
413
|
+
value: presented,
|
|
414
|
+
detail: null,
|
|
415
|
+
attachment: null
|
|
416
|
+
};
|
|
417
|
+
const original = originalAuthoring.detail ?? originalAuthoring.value;
|
|
418
|
+
const review = canvasRenderResultSchema.safeParse(original["review"]);
|
|
419
|
+
if (!review.success) return {
|
|
420
|
+
...originalAuthoring,
|
|
421
|
+
attachment: null
|
|
422
|
+
};
|
|
423
|
+
try {
|
|
424
|
+
const attachment = await renderAttachment(server, review.data, delivery);
|
|
425
|
+
const safeResult = {
|
|
426
|
+
...original,
|
|
427
|
+
review: {
|
|
428
|
+
...attachment.metadata,
|
|
429
|
+
artifact: attachment.artifact
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
const authoring = toCanvasAuthoringResult(safeResult);
|
|
319
433
|
return {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
}],
|
|
324
|
-
structuredContent
|
|
434
|
+
value: authoring?.value ?? safeResult,
|
|
435
|
+
detail: authoring?.detail ?? null,
|
|
436
|
+
attachment
|
|
325
437
|
};
|
|
326
|
-
}
|
|
327
|
-
|
|
438
|
+
} catch {
|
|
439
|
+
const safeResult = {
|
|
440
|
+
...original,
|
|
441
|
+
review: {
|
|
442
|
+
state: "unavailable",
|
|
443
|
+
mutationCommitted: true,
|
|
444
|
+
requestedVersion: original["version"],
|
|
445
|
+
retry: {
|
|
446
|
+
tool: "canvas_render",
|
|
447
|
+
arguments: {
|
|
448
|
+
canvas: original["canvasId"],
|
|
449
|
+
expectedVersion: original["version"],
|
|
450
|
+
target: review.data.target
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
},
|
|
454
|
+
next: ["Retry the render of the committed version; do not replay the write."]
|
|
455
|
+
};
|
|
456
|
+
const authoring = toCanvasAuthoringResult(safeResult);
|
|
457
|
+
return {
|
|
458
|
+
value: authoring?.value ?? safeResult,
|
|
459
|
+
detail: authoring?.detail ?? null,
|
|
460
|
+
attachment: null
|
|
461
|
+
};
|
|
462
|
+
}
|
|
463
|
+
};
|
|
464
|
+
const inlineResult = (result, commandName) => {
|
|
465
|
+
const structuredContent = {
|
|
466
|
+
ok: true,
|
|
467
|
+
result: withCommandName(result, commandName)
|
|
468
|
+
};
|
|
469
|
+
return {
|
|
470
|
+
content: [{
|
|
471
|
+
type: "text",
|
|
472
|
+
text: textFor(structuredContent)
|
|
473
|
+
}],
|
|
474
|
+
structuredContent
|
|
475
|
+
};
|
|
476
|
+
};
|
|
477
|
+
const createMcpResultAdapter = (authenticationRemediation, commandName = "enhance") => ({
|
|
478
|
+
success: async (server, result, delivery) => {
|
|
479
|
+
const presented = withCommandName(result, commandName);
|
|
480
|
+
const prepared = await prepareCanvasResult(server, presented, delivery);
|
|
481
|
+
const attachment = prepared.attachment;
|
|
482
|
+
const serialized = textFor(prepared.value);
|
|
483
|
+
if (hasProtectedMaterial(prepared.value)) return artifactResult(server, serialized, delivery);
|
|
484
|
+
if (attachment === null && prepared.detail === null && Buffer.byteLength(serialized) > PROTECTED_RESULT_BYTES) return artifactResult(server, serialized, delivery);
|
|
485
|
+
const detail = prepared.detail === null ? null : artifactResult(server, textFor(prepared.detail), delivery);
|
|
328
486
|
const structuredContent = {
|
|
329
487
|
ok: true,
|
|
330
|
-
result:
|
|
488
|
+
result: prepared.value,
|
|
489
|
+
...attachment !== null && { artifact: attachment.artifact },
|
|
490
|
+
...detail !== null && { detail: detail.structuredContent.artifact }
|
|
331
491
|
};
|
|
332
492
|
return {
|
|
333
|
-
content: [
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
493
|
+
content: [
|
|
494
|
+
{
|
|
495
|
+
type: "text",
|
|
496
|
+
text: textFor(structuredContent)
|
|
497
|
+
},
|
|
498
|
+
...attachment === null ? [] : [attachment.image],
|
|
499
|
+
...detail?.content.filter((entry) => entry.type !== "text") ?? []
|
|
500
|
+
],
|
|
337
501
|
structuredContent
|
|
338
502
|
};
|
|
339
503
|
},
|
|
504
|
+
inline: (result) => inlineResult(result, commandName),
|
|
340
505
|
failure: (error) => {
|
|
341
506
|
const failure = withCommandInFailure(toFailurePayload(error instanceof z.ZodError ? validationError(error) : error, null), commandName);
|
|
342
507
|
const structuredContent = {
|
|
@@ -371,15 +536,15 @@ const searchInputSchema = z.object({
|
|
|
371
536
|
"any",
|
|
372
537
|
"query",
|
|
373
538
|
"mutation"
|
|
374
|
-
]).default("any").describe("
|
|
539
|
+
]).default("any").describe("Filter dispatch, not effect. Omit if unknown; render uses mutation."),
|
|
375
540
|
limit: z.number().int().min(1).max(MAX_SEARCH_RESULTS).default(DEFAULT_SEARCH_RESULTS).describe("Maximum contracts to return.")
|
|
376
541
|
});
|
|
377
542
|
const queryInputSchema = z.object({
|
|
378
|
-
capability: z.string().min(1).describe("Exact query id
|
|
543
|
+
capability: z.string().min(1).describe("Exact query id from an available complete contract."),
|
|
379
544
|
input: z.record(z.string(), z.unknown()).default({}).describe("Input matching the discovered capability inputSchema.")
|
|
380
545
|
});
|
|
381
546
|
const mutationInputSchema = z.object({
|
|
382
|
-
capability: z.string().min(1).describe("Exact mutation id
|
|
547
|
+
capability: z.string().min(1).describe("Exact mutation id from an available complete contract."),
|
|
383
548
|
input: z.record(z.string(), z.unknown()).default({}).describe("Input matching the discovered capability inputSchema."),
|
|
384
549
|
clientToken: z.uuid().optional().describe("Stable UUID reused only when retrying this exact mutation input.")
|
|
385
550
|
});
|
|
@@ -395,7 +560,7 @@ const capabilityFor = (catalog, id, operation) => {
|
|
|
395
560
|
const registerSearch = (server, catalog, discovery, mcpResults) => {
|
|
396
561
|
server.registerTool("capability_search", {
|
|
397
562
|
title: "Discover Enhance capabilities",
|
|
398
|
-
description: "Search the Enhance capability catalogue for a specific likely action. Returns
|
|
563
|
+
description: "Search the Enhance capability catalogue for a specific likely action. Returns relevant summaries and a complete bestContract when it fits. Invoke from that contract directly; call capability_describe only when detailRequired is returned or a different match is needed.",
|
|
399
564
|
inputSchema: searchInputSchema,
|
|
400
565
|
outputSchema: mcpSearchResultSchema,
|
|
401
566
|
annotations: {
|
|
@@ -419,7 +584,7 @@ const registerSearch = (server, catalog, discovery, mcpResults) => {
|
|
|
419
584
|
const registerQuery = (server, catalog, invocation, execution) => {
|
|
420
585
|
server.registerTool("capability_query", {
|
|
421
586
|
title: "Run a discovered Enhance query",
|
|
422
|
-
description: "Run one read-only capability using
|
|
587
|
+
description: "Run one read-only capability using an available complete contract. Search or describe only when the contract is missing.",
|
|
423
588
|
inputSchema: queryInputSchema,
|
|
424
589
|
outputSchema: mcpDispatchedResultSchema,
|
|
425
590
|
annotations: {
|
|
@@ -447,7 +612,7 @@ const registerQuery = (server, catalog, invocation, execution) => {
|
|
|
447
612
|
const registerMutation = (server, catalog, invocation, execution) => {
|
|
448
613
|
server.registerTool("capability_mutate", {
|
|
449
614
|
title: "Run a discovered Enhance mutation",
|
|
450
|
-
description: "Run one state-changing capability using
|
|
615
|
+
description: "Run one state-changing capability using an available complete contract. Respect its preconditions and reuse clientToken only when retrying the identical mutation.",
|
|
451
616
|
inputSchema: mutationInputSchema,
|
|
452
617
|
outputSchema: mcpDispatchedResultSchema,
|
|
453
618
|
annotations: {
|
|
@@ -496,6 +661,11 @@ const createMcpServerAdapter = (input) => {
|
|
|
496
661
|
};
|
|
497
662
|
registerQuery(server, catalog, input.invocation, execution);
|
|
498
663
|
registerMutation(server, catalog, input.invocation, execution);
|
|
664
|
+
createMcpCanvasToolsAdapter({
|
|
665
|
+
catalog,
|
|
666
|
+
invocation: input.invocation,
|
|
667
|
+
...execution
|
|
668
|
+
}).register(server);
|
|
499
669
|
return server;
|
|
500
670
|
};
|
|
501
671
|
|
package/dist/mcp.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { c as toSharedCapabilities, d as createCapabilityCatalogAdapter } from "./cli-output-identity.lib-F9-nlguI.mjs";
|
|
3
3
|
import { t as toCapabilityInventory } from "./capability-inventory.mapper-DyYXyVBJ.mjs";
|
|
4
|
-
import { t as createMcpServerAdapter } from "./mcp-server.adapter-
|
|
4
|
+
import { t as createMcpServerAdapter } from "./mcp-server.adapter-C8plL5bs.mjs";
|
|
5
5
|
|
|
6
6
|
export { createCapabilityCatalogAdapter, createMcpServerAdapter as createEnhanceMcpServer, toCapabilityInventory, toSharedCapabilities };
|