@enhance-eng/enhance 0.1.25 → 0.1.33
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-CWNAXho4.mjs} +2402 -1306
- package/dist/main.mjs +719 -58
- package/dist/{mcp-invocation.adapter-FuxI6KsE.mjs → mcp-invocation.adapter-DHdF8-MP.mjs} +115 -69
- package/dist/mcp-main.mjs +12 -7
- package/dist/{mcp-server.adapter-D7XwVD-o.mjs → mcp-server.adapter-B0Kn0e7m.mjs} +109 -35
- package/dist/mcp.mjs +2 -2
- package/dist/{mutation-key.adapter-CXQ08HQY.mjs → mutation-key.adapter-A1d27TVY.mjs} +333 -176
- package/dist/remote-mcp-main.mjs +28 -45
- package/package.json +4 -3
|
@@ -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, Fn as agentClientMetadata, Gn as getCanvasDocumentOutputSchema, K as canvasWriteHtmlCapabilityInputSchema, 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-CWNAXho4.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);
|
|
@@ -402,6 +471,16 @@ const mcpMutationInputSchema = z.object({
|
|
|
402
471
|
clientToken: z.uuid().optional().describe("Stable UUID reused only when retrying this exact mutation input.")
|
|
403
472
|
});
|
|
404
473
|
|
|
474
|
+
//#endregion
|
|
475
|
+
//#region src/infrastructure/mcp-client-invocation.adapter.ts
|
|
476
|
+
const clientContext$2 = createMcpClientContextAdapter();
|
|
477
|
+
const createMcpClientInvocationAdapter = (invocation, legacyClient) => ({ invoke: async (request) => {
|
|
478
|
+
return invocation.invoke({
|
|
479
|
+
...request,
|
|
480
|
+
clientMetadata: clientContext$2.current() ?? legacyClient?.() ?? agentClientMetadata({ path: "local_mcp" })
|
|
481
|
+
});
|
|
482
|
+
} });
|
|
483
|
+
|
|
405
484
|
//#endregion
|
|
406
485
|
//#region src/infrastructure/mcp-workflows.adapter.ts
|
|
407
486
|
const workflowNameSchema = z.enum([
|
|
@@ -458,8 +537,7 @@ const createMcpWorkflowsAdapter = (directory, authenticationInstructions) => {
|
|
|
458
537
|
|
|
459
538
|
//#endregion
|
|
460
539
|
//#region src/infrastructure/mcp-canvas-tools.adapter.ts
|
|
461
|
-
const
|
|
462
|
-
const MAX_RENDER_SCALE = 4;
|
|
540
|
+
const clientContext$1 = createMcpClientContextAdapter();
|
|
463
541
|
const clientToken = z.uuid().optional().describe("Reuse only when retrying this exact mutation.");
|
|
464
542
|
const writeSchema = canvasWriteHtmlCapabilityInputSchema.pick({
|
|
465
543
|
baseVersion: true,
|
|
@@ -478,7 +556,7 @@ const renderSchema = z.object({
|
|
|
478
556
|
expectedVersion: z.number().int().positive().describe("Version returned by the latest successful read or write."),
|
|
479
557
|
target: canvasRenderTargetSchema.default({ kind: "content" }),
|
|
480
558
|
sourceState: canvasRenderSourceStateSchema.nullable().default(null),
|
|
481
|
-
scale: z.number().
|
|
559
|
+
scale: z.number().positive().default(1)
|
|
482
560
|
});
|
|
483
561
|
const invoke = async (input, id, args, token = null) => {
|
|
484
562
|
const capability = input.catalog.find((candidate) => candidate.id === id);
|
|
@@ -523,7 +601,7 @@ const registerWrite = (server, input) => {
|
|
|
523
601
|
idempotentHint: false,
|
|
524
602
|
openWorldHint: false
|
|
525
603
|
}
|
|
526
|
-
}, async ({ canvas, clientToken: token, ...args }) => deliver(server, input, async () => {
|
|
604
|
+
}, async ({ canvas, clientToken: token, ...args }, context) => clientContext$1.run(context, async () => deliver(server, input, async () => {
|
|
527
605
|
const reference = parseCanvasReference(canvas);
|
|
528
606
|
return invoke(input, "canvas.writeHtml", {
|
|
529
607
|
...args,
|
|
@@ -536,7 +614,7 @@ const registerWrite = (server, input) => {
|
|
|
536
614
|
renderScale: 1,
|
|
537
615
|
renderTimeoutMs: 12e4
|
|
538
616
|
}, token ?? null);
|
|
539
|
-
}));
|
|
617
|
+
})));
|
|
540
618
|
};
|
|
541
619
|
const registerEdit = (server, input) => {
|
|
542
620
|
if (input.catalog.some((capability) => capability.id === "canvas.edit")) server.registerTool("canvas_edit", {
|
|
@@ -550,7 +628,7 @@ const registerEdit = (server, input) => {
|
|
|
550
628
|
idempotentHint: false,
|
|
551
629
|
openWorldHint: false
|
|
552
630
|
}
|
|
553
|
-
}, async ({ clientToken: token, ...args }) => deliver(server, input, async () => invoke(input, "canvas.edit", args, token ?? null)));
|
|
631
|
+
}, async ({ clientToken: token, ...args }, context) => clientContext$1.run(context, async () => deliver(server, input, async () => invoke(input, "canvas.edit", args, token ?? null))));
|
|
554
632
|
};
|
|
555
633
|
const registerRender = (server, input) => {
|
|
556
634
|
if (input.catalog.some((capability) => capability.id === "canvas.render")) server.registerTool("canvas_render", {
|
|
@@ -564,7 +642,7 @@ const registerRender = (server, input) => {
|
|
|
564
642
|
idempotentHint: false,
|
|
565
643
|
openWorldHint: false
|
|
566
644
|
}
|
|
567
|
-
}, async (args) => deliver(server, input, async () => invoke(input, "canvas.render", {
|
|
645
|
+
}, async (args, context) => clientContext$1.run(context, async () => deliver(server, input, async () => invoke(input, "canvas.render", {
|
|
568
646
|
...await renderTarget(input, args),
|
|
569
647
|
expectedVersion: args.expectedVersion,
|
|
570
648
|
sourceState: args.sourceState,
|
|
@@ -572,7 +650,7 @@ const registerRender = (server, input) => {
|
|
|
572
650
|
outputPath: null,
|
|
573
651
|
overwrite: false,
|
|
574
652
|
timeoutMs: 12e4
|
|
575
|
-
}, args.clientToken ?? null)));
|
|
653
|
+
}, args.clientToken ?? null))));
|
|
576
654
|
};
|
|
577
655
|
const createMcpCanvasToolsAdapter = (input) => ({ register: (server) => {
|
|
578
656
|
const selected = input.tools ?? [
|
|
@@ -664,6 +742,13 @@ const createMcpDescribeToolAdapter = (discovery, mcpResults) => ({ register: (se
|
|
|
664
742
|
|
|
665
743
|
//#endregion
|
|
666
744
|
//#region src/infrastructure/mcp-server.adapter.ts
|
|
745
|
+
const clientContext = createMcpClientContextAdapter();
|
|
746
|
+
const QUERY_ANNOTATIONS = {
|
|
747
|
+
readOnlyHint: true,
|
|
748
|
+
destructiveHint: false,
|
|
749
|
+
idempotentHint: true,
|
|
750
|
+
openWorldHint: false
|
|
751
|
+
};
|
|
667
752
|
const MAX_SEARCH_QUERY_CHARACTERS = 200;
|
|
668
753
|
const MAX_SEARCH_RESULTS = 10;
|
|
669
754
|
const DEFAULT_SEARCH_RESULTS = 5;
|
|
@@ -694,23 +779,18 @@ const registerSearch = (server, catalog, discovery, mcpResults) => {
|
|
|
694
779
|
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
780
|
inputSchema: searchInputSchema,
|
|
696
781
|
outputSchema: mcpSearchResultSchema,
|
|
697
|
-
annotations:
|
|
698
|
-
readOnlyHint: true,
|
|
699
|
-
destructiveHint: false,
|
|
700
|
-
idempotentHint: true,
|
|
701
|
-
openWorldHint: false
|
|
702
|
-
},
|
|
782
|
+
annotations: QUERY_ANNOTATIONS,
|
|
703
783
|
_meta: {
|
|
704
784
|
"ai.enhancelabs/disclosure": "progressive",
|
|
705
785
|
"ai.enhancelabs/catalogSize": catalog.length,
|
|
706
786
|
"enhance/disclosure": "progressive",
|
|
707
787
|
"enhance/catalogSize": catalog.length
|
|
708
788
|
}
|
|
709
|
-
}, async ({ query, operation, limit }) => mcpResults.inline(discovery.search({
|
|
789
|
+
}, async ({ query, operation, limit }, context) => clientContext.run(context, async () => mcpResults.inline(discovery.search({
|
|
710
790
|
query,
|
|
711
791
|
operation,
|
|
712
792
|
limit
|
|
713
|
-
})));
|
|
793
|
+
}))));
|
|
714
794
|
};
|
|
715
795
|
const registerQuery = (server, catalog, invocation, execution) => {
|
|
716
796
|
server.registerTool("capability_query", {
|
|
@@ -718,17 +798,12 @@ const registerQuery = (server, catalog, invocation, execution) => {
|
|
|
718
798
|
description: "Run one read-only capability using an available complete contract. Search or describe only when the contract is missing.",
|
|
719
799
|
inputSchema: mcpQueryInputSchema,
|
|
720
800
|
outputSchema: mcpDispatchedResultSchema,
|
|
721
|
-
annotations:
|
|
722
|
-
readOnlyHint: true,
|
|
723
|
-
destructiveHint: false,
|
|
724
|
-
idempotentHint: true,
|
|
725
|
-
openWorldHint: false
|
|
726
|
-
},
|
|
801
|
+
annotations: QUERY_ANNOTATIONS,
|
|
727
802
|
_meta: {
|
|
728
803
|
"ai.enhancelabs/disclosure": "progressive",
|
|
729
804
|
"enhance/disclosure": "progressive"
|
|
730
805
|
}
|
|
731
|
-
}, async ({ capability: id, input }) => {
|
|
806
|
+
}, async ({ capability: id, input }, context) => clientContext.run(context, async () => {
|
|
732
807
|
try {
|
|
733
808
|
return await execution.results.success(server, await invocation.invoke({
|
|
734
809
|
capability: capabilityFor(catalog, id, "query"),
|
|
@@ -738,7 +813,7 @@ const registerQuery = (server, catalog, invocation, execution) => {
|
|
|
738
813
|
} catch (error) {
|
|
739
814
|
return execution.results.failure(error);
|
|
740
815
|
}
|
|
741
|
-
});
|
|
816
|
+
}));
|
|
742
817
|
};
|
|
743
818
|
const registerMutation = (server, catalog, invocation, execution) => {
|
|
744
819
|
server.registerTool("capability_mutate", {
|
|
@@ -756,7 +831,7 @@ const registerMutation = (server, catalog, invocation, execution) => {
|
|
|
756
831
|
"ai.enhancelabs/disclosure": "progressive",
|
|
757
832
|
"enhance/disclosure": "progressive"
|
|
758
833
|
}
|
|
759
|
-
}, async ({ capability: id, input, clientToken }) => {
|
|
834
|
+
}, async ({ capability: id, input, clientToken }, context) => clientContext.run(context, async () => {
|
|
760
835
|
try {
|
|
761
836
|
return await execution.results.success(server, await invocation.invoke({
|
|
762
837
|
capability: capabilityFor(catalog, id, "mutation"),
|
|
@@ -766,7 +841,7 @@ const registerMutation = (server, catalog, invocation, execution) => {
|
|
|
766
841
|
} catch (error) {
|
|
767
842
|
return execution.results.failure(error);
|
|
768
843
|
}
|
|
769
|
-
});
|
|
844
|
+
}));
|
|
770
845
|
};
|
|
771
846
|
const createMcpServerAdapter = (input) => {
|
|
772
847
|
const authenticationInstructions = input.exposures?.includes("mcp-transport") === true ? AUTHENTICATION_INSTRUCTIONS : void 0;
|
|
@@ -784,20 +859,19 @@ const createMcpServerAdapter = (input) => {
|
|
|
784
859
|
});
|
|
785
860
|
const catalog = toPresentedCapabilities(input.catalog ?? createCapabilityCatalogAdapter(), input.exposures ?? ["shared"]);
|
|
786
861
|
const discovery = createMcpCapabilityDiscoveryAdapter(catalog);
|
|
787
|
-
const delivery = input.delivery ?? "linked";
|
|
788
862
|
const mcpResults = createMcpResultAdapter(input.exposures?.includes("mcp-transport") === true ? LOCAL_AUTHENTICATION_REMEDY : HOSTED_AUTHENTICATION_REMEDY, input.commandName);
|
|
789
863
|
createMcpCatalogueToolAdapter(catalog, input.version, input.commandName).register(server);
|
|
790
864
|
registerSearch(server, catalog, discovery, mcpResults);
|
|
791
865
|
createMcpDescribeToolAdapter(discovery, mcpResults).register(server);
|
|
792
866
|
const execution = {
|
|
793
|
-
delivery,
|
|
794
|
-
results: mcpResults
|
|
867
|
+
delivery: input.delivery ?? "linked",
|
|
868
|
+
results: mcpResults,
|
|
869
|
+
invocation: createMcpClientInvocationAdapter(input.invocation, input.clientMetadata)
|
|
795
870
|
};
|
|
796
|
-
registerQuery(server, catalog,
|
|
797
|
-
registerMutation(server, catalog,
|
|
871
|
+
registerQuery(server, catalog, execution.invocation, execution);
|
|
872
|
+
registerMutation(server, catalog, execution.invocation, execution);
|
|
798
873
|
createMcpCanvasToolsAdapter({
|
|
799
874
|
catalog,
|
|
800
|
-
invocation: input.invocation,
|
|
801
875
|
...execution
|
|
802
876
|
}).register(server);
|
|
803
877
|
workflows?.register(server);
|
|
@@ -805,4 +879,4 @@ const createMcpServerAdapter = (input) => {
|
|
|
805
879
|
};
|
|
806
880
|
|
|
807
881
|
//#endregion
|
|
808
|
-
export { createMcpResultAdapter as i, createMcpWorkflowsAdapter as n,
|
|
882
|
+
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-CWNAXho4.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-B0Kn0e7m.mjs";
|
|
5
5
|
|
|
6
6
|
export { createCapabilityCatalogAdapter, createMcpServerAdapter as createEnhanceMcpServer, toCapabilityInventory, toSharedCapabilities };
|