@enhance-eng/enhance 0.1.25 → 0.1.37
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-DpON8As5.mjs → cli-output-identity.lib-i4KnVAYs.mjs} +3264 -1639
- package/dist/main.mjs +1083 -80
- package/dist/{mcp-invocation.adapter-FuxI6KsE.mjs → mcp-invocation.adapter-CBnzmPZl.mjs} +120 -70
- package/dist/mcp-main.mjs +12 -7
- package/dist/{mcp-server.adapter-D7XwVD-o.mjs → mcp-server.adapter-DC9gAePw.mjs} +110 -35
- package/dist/mcp.mjs +2 -2
- package/dist/{mutation-key.adapter-CXQ08HQY.mjs → mutation-key.adapter-Ck8nOqke.mjs} +385 -193
- package/dist/remote-mcp-main.mjs +28 -45
- package/package.json +6 -9
|
@@ -1,12 +1,81 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { Gn as getCanvasDocumentOutputSchema, K as canvasWriteHtmlCapabilityInputSchema,
|
|
2
|
+
import { $n as canvasRenderTargetSchema, Et as canvasReferenceRenderTarget, Gn as getCanvasDocumentOutputSchema, K as canvasWriteHtmlCapabilityInputSchema, Mn as agentClientMetadata, Ot as hasCanvasReferenceScope, Q as canvasRenderBatchResultSchema, St as canvasEditCapabilityInputSchema, Zn as canvasRenderSourceStateSchema, ar as canvasReadableSceneDocumentSchema, c as toPresentedCapabilities, f as createCapabilityCatalogAdapter, jt as CliError, kt as parseCanvasReference, n as withCommandName, o as toMcpFailurePayload, r as toCanvasAuthoringResult, rt as canvasRenderFileSchema, t as withCommandInFailure, u as createMcpCapabilityDiscoveryAdapter } from "./cli-output-identity.lib-i4KnVAYs.mjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { readFileSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { createHash, randomUUID } from "node:crypto";
|
|
7
7
|
import { readFile, rm } from "node:fs/promises";
|
|
8
|
-
import {
|
|
8
|
+
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
|
9
|
+
import { CLIENT_INFO_META_KEY, McpServer } from "@modelcontextprotocol/server";
|
|
10
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
11
|
|
|
12
|
+
//#region src/infrastructure/mcp-client-context.adapter.ts
|
|
13
|
+
const requests = new AsyncLocalStorage();
|
|
14
|
+
const initializeSchema = z.object({
|
|
15
|
+
method: z.literal("initialize"),
|
|
16
|
+
params: z.object({ clientInfo: z.object({
|
|
17
|
+
name: z.string(),
|
|
18
|
+
version: z.string()
|
|
19
|
+
}) })
|
|
20
|
+
});
|
|
21
|
+
const envelopeSchema = z.object({ [CLIENT_INFO_META_KEY]: z.object({
|
|
22
|
+
name: z.string(),
|
|
23
|
+
version: z.string()
|
|
24
|
+
}).optional() });
|
|
25
|
+
const currentMcpClientMetadata = () => requests.getStore();
|
|
26
|
+
const withMcpClientContext = (context, action) => {
|
|
27
|
+
const envelope = envelopeSchema.safeParse(context.mcpReq.envelope);
|
|
28
|
+
const client = envelope.success ? envelope.data[CLIENT_INFO_META_KEY] : void 0;
|
|
29
|
+
const metadata = context.mcpReq.envelope === void 0 ? void 0 : agentClientMetadata({
|
|
30
|
+
path: "local_mcp",
|
|
31
|
+
...client !== void 0 && {
|
|
32
|
+
name: client.name,
|
|
33
|
+
version: client.version
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return requests.run(metadata, action);
|
|
37
|
+
};
|
|
38
|
+
const createMcpStdioClientAdapter = (offered) => {
|
|
39
|
+
const native = offered ?? new StdioServerTransport();
|
|
40
|
+
const state = {
|
|
41
|
+
metadata: agentClientMetadata({ path: "local_mcp" }),
|
|
42
|
+
isInitialized: false
|
|
43
|
+
};
|
|
44
|
+
const onmessage = (message, extra) => {
|
|
45
|
+
const initialized = initializeSchema.safeParse(message);
|
|
46
|
+
if (!state.isInitialized && initialized.success) {
|
|
47
|
+
state.metadata = agentClientMetadata({
|
|
48
|
+
path: "local_mcp",
|
|
49
|
+
...initialized.data.params.clientInfo
|
|
50
|
+
});
|
|
51
|
+
state.isInitialized = true;
|
|
52
|
+
}
|
|
53
|
+
transport.onmessage?.(message, extra);
|
|
54
|
+
};
|
|
55
|
+
const transport = {
|
|
56
|
+
start: async () => {
|
|
57
|
+
Object.assign(native, {
|
|
58
|
+
onmessage,
|
|
59
|
+
onclose: () => transport.onclose?.(),
|
|
60
|
+
onerror: (error) => transport.onerror?.(error)
|
|
61
|
+
});
|
|
62
|
+
await native.start();
|
|
63
|
+
},
|
|
64
|
+
send: async (message, options) => native.send(message, options),
|
|
65
|
+
close: async () => native.close()
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
transport,
|
|
69
|
+
metadata: () => state.metadata
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
const createMcpClientContextAdapter = () => ({
|
|
73
|
+
current: currentMcpClientMetadata,
|
|
74
|
+
run: withMcpClientContext,
|
|
75
|
+
createStdio: createMcpStdioClientAdapter
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
10
79
|
//#region src/infrastructure/mcp-render-attachment.adapter.ts
|
|
11
80
|
const createMcpRenderAttachmentAdapter = async (server, result, delivery) => {
|
|
12
81
|
const body = await readFile(result.path);
|
|
@@ -79,6 +148,7 @@ const createMcpRenderBatchResultAdapter = async (server, presented, delivery) =>
|
|
|
79
148
|
pixelsDelivered: false,
|
|
80
149
|
outcome: {
|
|
81
150
|
state: "delivery_unavailable",
|
|
151
|
+
...render.data.source !== void 0 && { source: render.data.source },
|
|
82
152
|
operation: {
|
|
83
153
|
kind: "canvas-render",
|
|
84
154
|
canvasId: render.data.canvasId,
|
|
@@ -402,6 +472,16 @@ const mcpMutationInputSchema = z.object({
|
|
|
402
472
|
clientToken: z.uuid().optional().describe("Stable UUID reused only when retrying this exact mutation input.")
|
|
403
473
|
});
|
|
404
474
|
|
|
475
|
+
//#endregion
|
|
476
|
+
//#region src/infrastructure/mcp-client-invocation.adapter.ts
|
|
477
|
+
const clientContext$2 = createMcpClientContextAdapter();
|
|
478
|
+
const createMcpClientInvocationAdapter = (invocation, legacyClient) => ({ invoke: async (request) => {
|
|
479
|
+
return invocation.invoke({
|
|
480
|
+
...request,
|
|
481
|
+
clientMetadata: clientContext$2.current() ?? legacyClient?.() ?? agentClientMetadata({ path: "local_mcp" })
|
|
482
|
+
});
|
|
483
|
+
} });
|
|
484
|
+
|
|
405
485
|
//#endregion
|
|
406
486
|
//#region src/infrastructure/mcp-workflows.adapter.ts
|
|
407
487
|
const workflowNameSchema = z.enum([
|
|
@@ -458,8 +538,7 @@ const createMcpWorkflowsAdapter = (directory, authenticationInstructions) => {
|
|
|
458
538
|
|
|
459
539
|
//#endregion
|
|
460
540
|
//#region src/infrastructure/mcp-canvas-tools.adapter.ts
|
|
461
|
-
const
|
|
462
|
-
const MAX_RENDER_SCALE = 4;
|
|
541
|
+
const clientContext$1 = createMcpClientContextAdapter();
|
|
463
542
|
const clientToken = z.uuid().optional().describe("Reuse only when retrying this exact mutation.");
|
|
464
543
|
const writeSchema = canvasWriteHtmlCapabilityInputSchema.pick({
|
|
465
544
|
baseVersion: true,
|
|
@@ -478,7 +557,7 @@ const renderSchema = z.object({
|
|
|
478
557
|
expectedVersion: z.number().int().positive().describe("Version returned by the latest successful read or write."),
|
|
479
558
|
target: canvasRenderTargetSchema.default({ kind: "content" }),
|
|
480
559
|
sourceState: canvasRenderSourceStateSchema.nullable().default(null),
|
|
481
|
-
scale: z.number().
|
|
560
|
+
scale: z.number().positive().default(1)
|
|
482
561
|
});
|
|
483
562
|
const invoke = async (input, id, args, token = null) => {
|
|
484
563
|
const capability = input.catalog.find((candidate) => candidate.id === id);
|
|
@@ -523,7 +602,7 @@ const registerWrite = (server, input) => {
|
|
|
523
602
|
idempotentHint: false,
|
|
524
603
|
openWorldHint: false
|
|
525
604
|
}
|
|
526
|
-
}, async ({ canvas, clientToken: token, ...args }) => deliver(server, input, async () => {
|
|
605
|
+
}, async ({ canvas, clientToken: token, ...args }, context) => clientContext$1.run(context, async () => deliver(server, input, async () => {
|
|
527
606
|
const reference = parseCanvasReference(canvas);
|
|
528
607
|
return invoke(input, "canvas.writeHtml", {
|
|
529
608
|
...args,
|
|
@@ -536,7 +615,7 @@ const registerWrite = (server, input) => {
|
|
|
536
615
|
renderScale: 1,
|
|
537
616
|
renderTimeoutMs: 12e4
|
|
538
617
|
}, token ?? null);
|
|
539
|
-
}));
|
|
618
|
+
})));
|
|
540
619
|
};
|
|
541
620
|
const registerEdit = (server, input) => {
|
|
542
621
|
if (input.catalog.some((capability) => capability.id === "canvas.edit")) server.registerTool("canvas_edit", {
|
|
@@ -550,7 +629,7 @@ const registerEdit = (server, input) => {
|
|
|
550
629
|
idempotentHint: false,
|
|
551
630
|
openWorldHint: false
|
|
552
631
|
}
|
|
553
|
-
}, async ({ clientToken: token, ...args }) => deliver(server, input, async () => invoke(input, "canvas.edit", args, token ?? null)));
|
|
632
|
+
}, async ({ clientToken: token, ...args }, context) => clientContext$1.run(context, async () => deliver(server, input, async () => invoke(input, "canvas.edit", args, token ?? null))));
|
|
554
633
|
};
|
|
555
634
|
const registerRender = (server, input) => {
|
|
556
635
|
if (input.catalog.some((capability) => capability.id === "canvas.render")) server.registerTool("canvas_render", {
|
|
@@ -564,7 +643,7 @@ const registerRender = (server, input) => {
|
|
|
564
643
|
idempotentHint: false,
|
|
565
644
|
openWorldHint: false
|
|
566
645
|
}
|
|
567
|
-
}, async (args) => deliver(server, input, async () => invoke(input, "canvas.render", {
|
|
646
|
+
}, async (args, context) => clientContext$1.run(context, async () => deliver(server, input, async () => invoke(input, "canvas.render", {
|
|
568
647
|
...await renderTarget(input, args),
|
|
569
648
|
expectedVersion: args.expectedVersion,
|
|
570
649
|
sourceState: args.sourceState,
|
|
@@ -572,7 +651,7 @@ const registerRender = (server, input) => {
|
|
|
572
651
|
outputPath: null,
|
|
573
652
|
overwrite: false,
|
|
574
653
|
timeoutMs: 12e4
|
|
575
|
-
}, args.clientToken ?? null)));
|
|
654
|
+
}, args.clientToken ?? null))));
|
|
576
655
|
};
|
|
577
656
|
const createMcpCanvasToolsAdapter = (input) => ({ register: (server) => {
|
|
578
657
|
const selected = input.tools ?? [
|
|
@@ -664,6 +743,13 @@ const createMcpDescribeToolAdapter = (discovery, mcpResults) => ({ register: (se
|
|
|
664
743
|
|
|
665
744
|
//#endregion
|
|
666
745
|
//#region src/infrastructure/mcp-server.adapter.ts
|
|
746
|
+
const clientContext = createMcpClientContextAdapter();
|
|
747
|
+
const QUERY_ANNOTATIONS = {
|
|
748
|
+
readOnlyHint: true,
|
|
749
|
+
destructiveHint: false,
|
|
750
|
+
idempotentHint: true,
|
|
751
|
+
openWorldHint: false
|
|
752
|
+
};
|
|
667
753
|
const MAX_SEARCH_QUERY_CHARACTERS = 200;
|
|
668
754
|
const MAX_SEARCH_RESULTS = 10;
|
|
669
755
|
const DEFAULT_SEARCH_RESULTS = 5;
|
|
@@ -694,23 +780,18 @@ const registerSearch = (server, catalog, discovery, mcpResults) => {
|
|
|
694
780
|
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.",
|
|
695
781
|
inputSchema: searchInputSchema,
|
|
696
782
|
outputSchema: mcpSearchResultSchema,
|
|
697
|
-
annotations:
|
|
698
|
-
readOnlyHint: true,
|
|
699
|
-
destructiveHint: false,
|
|
700
|
-
idempotentHint: true,
|
|
701
|
-
openWorldHint: false
|
|
702
|
-
},
|
|
783
|
+
annotations: QUERY_ANNOTATIONS,
|
|
703
784
|
_meta: {
|
|
704
785
|
"ai.enhancelabs/disclosure": "progressive",
|
|
705
786
|
"ai.enhancelabs/catalogSize": catalog.length,
|
|
706
787
|
"enhance/disclosure": "progressive",
|
|
707
788
|
"enhance/catalogSize": catalog.length
|
|
708
789
|
}
|
|
709
|
-
}, async ({ query, operation, limit }) => mcpResults.inline(discovery.search({
|
|
790
|
+
}, async ({ query, operation, limit }, context) => clientContext.run(context, async () => mcpResults.inline(discovery.search({
|
|
710
791
|
query,
|
|
711
792
|
operation,
|
|
712
793
|
limit
|
|
713
|
-
})));
|
|
794
|
+
}))));
|
|
714
795
|
};
|
|
715
796
|
const registerQuery = (server, catalog, invocation, execution) => {
|
|
716
797
|
server.registerTool("capability_query", {
|
|
@@ -718,17 +799,12 @@ const registerQuery = (server, catalog, invocation, execution) => {
|
|
|
718
799
|
description: "Run one read-only capability using an available complete contract. Search or describe only when the contract is missing.",
|
|
719
800
|
inputSchema: mcpQueryInputSchema,
|
|
720
801
|
outputSchema: mcpDispatchedResultSchema,
|
|
721
|
-
annotations:
|
|
722
|
-
readOnlyHint: true,
|
|
723
|
-
destructiveHint: false,
|
|
724
|
-
idempotentHint: true,
|
|
725
|
-
openWorldHint: false
|
|
726
|
-
},
|
|
802
|
+
annotations: QUERY_ANNOTATIONS,
|
|
727
803
|
_meta: {
|
|
728
804
|
"ai.enhancelabs/disclosure": "progressive",
|
|
729
805
|
"enhance/disclosure": "progressive"
|
|
730
806
|
}
|
|
731
|
-
}, async ({ capability: id, input }) => {
|
|
807
|
+
}, async ({ capability: id, input }, context) => clientContext.run(context, async () => {
|
|
732
808
|
try {
|
|
733
809
|
return await execution.results.success(server, await invocation.invoke({
|
|
734
810
|
capability: capabilityFor(catalog, id, "query"),
|
|
@@ -738,7 +814,7 @@ const registerQuery = (server, catalog, invocation, execution) => {
|
|
|
738
814
|
} catch (error) {
|
|
739
815
|
return execution.results.failure(error);
|
|
740
816
|
}
|
|
741
|
-
});
|
|
817
|
+
}));
|
|
742
818
|
};
|
|
743
819
|
const registerMutation = (server, catalog, invocation, execution) => {
|
|
744
820
|
server.registerTool("capability_mutate", {
|
|
@@ -756,7 +832,7 @@ const registerMutation = (server, catalog, invocation, execution) => {
|
|
|
756
832
|
"ai.enhancelabs/disclosure": "progressive",
|
|
757
833
|
"enhance/disclosure": "progressive"
|
|
758
834
|
}
|
|
759
|
-
}, async ({ capability: id, input, clientToken }) => {
|
|
835
|
+
}, async ({ capability: id, input, clientToken }, context) => clientContext.run(context, async () => {
|
|
760
836
|
try {
|
|
761
837
|
return await execution.results.success(server, await invocation.invoke({
|
|
762
838
|
capability: capabilityFor(catalog, id, "mutation"),
|
|
@@ -766,7 +842,7 @@ const registerMutation = (server, catalog, invocation, execution) => {
|
|
|
766
842
|
} catch (error) {
|
|
767
843
|
return execution.results.failure(error);
|
|
768
844
|
}
|
|
769
|
-
});
|
|
845
|
+
}));
|
|
770
846
|
};
|
|
771
847
|
const createMcpServerAdapter = (input) => {
|
|
772
848
|
const authenticationInstructions = input.exposures?.includes("mcp-transport") === true ? AUTHENTICATION_INSTRUCTIONS : void 0;
|
|
@@ -784,20 +860,19 @@ const createMcpServerAdapter = (input) => {
|
|
|
784
860
|
});
|
|
785
861
|
const catalog = toPresentedCapabilities(input.catalog ?? createCapabilityCatalogAdapter(), input.exposures ?? ["shared"]);
|
|
786
862
|
const discovery = createMcpCapabilityDiscoveryAdapter(catalog);
|
|
787
|
-
const delivery = input.delivery ?? "linked";
|
|
788
863
|
const mcpResults = createMcpResultAdapter(input.exposures?.includes("mcp-transport") === true ? LOCAL_AUTHENTICATION_REMEDY : HOSTED_AUTHENTICATION_REMEDY, input.commandName);
|
|
789
864
|
createMcpCatalogueToolAdapter(catalog, input.version, input.commandName).register(server);
|
|
790
865
|
registerSearch(server, catalog, discovery, mcpResults);
|
|
791
866
|
createMcpDescribeToolAdapter(discovery, mcpResults).register(server);
|
|
792
867
|
const execution = {
|
|
793
|
-
delivery,
|
|
794
|
-
results: mcpResults
|
|
868
|
+
delivery: input.delivery ?? "linked",
|
|
869
|
+
results: mcpResults,
|
|
870
|
+
invocation: createMcpClientInvocationAdapter(input.invocation, input.clientMetadata)
|
|
795
871
|
};
|
|
796
|
-
registerQuery(server, catalog,
|
|
797
|
-
registerMutation(server, catalog,
|
|
872
|
+
registerQuery(server, catalog, execution.invocation, execution);
|
|
873
|
+
registerMutation(server, catalog, execution.invocation, execution);
|
|
798
874
|
createMcpCanvasToolsAdapter({
|
|
799
875
|
catalog,
|
|
800
|
-
invocation: input.invocation,
|
|
801
876
|
...execution
|
|
802
877
|
}).register(server);
|
|
803
878
|
workflows?.register(server);
|
|
@@ -805,4 +880,4 @@ const createMcpServerAdapter = (input) => {
|
|
|
805
880
|
};
|
|
806
881
|
|
|
807
882
|
//#endregion
|
|
808
|
-
export { createMcpResultAdapter as i, createMcpWorkflowsAdapter as n,
|
|
883
|
+
export { createMcpResultAdapter as a, mcpDispatchedResultSchema as i, createMcpWorkflowsAdapter as n, createMcpClientContextAdapter as o, createMcpClientInvocationAdapter as r, createMcpServerAdapter as t };
|
package/dist/mcp.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { f as createCapabilityCatalogAdapter, l as toSharedCapabilities } from "./cli-output-identity.lib-
|
|
2
|
+
import { f as createCapabilityCatalogAdapter, l as toSharedCapabilities } from "./cli-output-identity.lib-i4KnVAYs.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-DC9gAePw.mjs";
|
|
5
5
|
|
|
6
6
|
export { createCapabilityCatalogAdapter, createMcpServerAdapter as createEnhanceMcpServer, toCapabilityInventory, toSharedCapabilities };
|