@enhance-eng/enhance 0.1.161 → 0.1.165
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-BfvrkZX5.mjs → cli-output-identity.lib-Z9ISwnoo.mjs} +4140 -2574
- package/dist/enhance-mcp.cjs +4 -0
- package/dist/enhance.cjs +4 -0
- package/dist/file-credential.adapter-CShGZcd5.mjs +63 -0
- package/dist/launch.cjs +36 -0
- package/dist/main.mjs +1559 -261
- package/dist/{mcp-invocation.adapter-DtgErzi9.mjs → mcp-invocation.adapter-Cn7Cr0UH.mjs} +25 -5
- package/dist/mcp-main.mjs +10 -9
- package/dist/{mcp-server.adapter-DJeyBKo7.mjs → mcp-server.adapter-DJ2BZrIw.mjs} +14 -8
- package/dist/mcp.mjs +2 -2
- package/dist/older-node.mjs +7320 -0
- package/dist/remote-mcp-main.mjs +117 -28
- package/dist/rolldown-runtime-b6G8-vqI.mjs +6 -0
- package/dist/{mutation-key.adapter-TMLqYILu.mjs → zod-messages.lib-BrqCGdLn.mjs} +1655 -465
- package/package.json +6 -4
- package/dist/file-credential.adapter-C78gc9OK.mjs +0 -51
package/dist/remote-mcp-main.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { $ as canvasAssetImportInputSchema, L as canvasPrototypeIntentSchema, R as canvasPrototypeOutputSchema, S as PROTOTYPE_UPDATE_GUIDANCE, Sn as prototypeArtifactPathSchema, Tn as MCP_AUTH_SCOPE, an as CliError, ci as signedDownloadSchema, et as canvasAssetImportOutputSchema, vn as foldPrototypeArtifactPath, wn as getMeOutputSchema } from "./cli-output-identity.lib-Z9ISwnoo.mjs";
|
|
3
|
+
import { h as createImportCanvasAssetComposite, m as createPublishCanvasPrototypeComposite, n as createMutationKeyAdapter, o as readRemoteMcpEnvironment, p as createPrototypeArtifactAdapter, r as createHttpRemoteAdapter, t as installZodMessages } from "./zod-messages.lib-BrqCGdLn.mjs";
|
|
4
|
+
import { a as createMcpResultAdapter, o as createMcpClientContextAdapter, s as createCapabilityCatalogAdapter, t as createMcpServerAdapter } from "./mcp-server.adapter-DJ2BZrIw.mjs";
|
|
5
|
+
import { n as createMcpCanvasProfileAdapter, t as createMcpInvocationAdapter } from "./mcp-invocation.adapter-Cn7Cr0UH.mjs";
|
|
6
6
|
import process from "node:process";
|
|
7
7
|
import { z } from "zod";
|
|
8
|
-
import
|
|
9
|
-
import { createWriteStream } from "node:fs";
|
|
8
|
+
import { mkdir, mkdtemp, readFile, rm } from "node:fs/promises";
|
|
10
9
|
import path from "node:path";
|
|
10
|
+
import os, { tmpdir } from "node:os";
|
|
11
11
|
import { createHash } from "node:crypto";
|
|
12
|
-
import {
|
|
12
|
+
import { createWriteStream } from "node:fs";
|
|
13
13
|
import { Transform, Writable } from "node:stream";
|
|
14
14
|
import { pipeline } from "node:stream/promises";
|
|
15
15
|
import { createServer, request } from "node:http";
|
|
@@ -19,7 +19,6 @@ import { toNodeHandler } from "@modelcontextprotocol/node";
|
|
|
19
19
|
import { request as request$1 } from "node:https";
|
|
20
20
|
import { lookup } from "node:dns/promises";
|
|
21
21
|
import { BlockList, isIP } from "node:net";
|
|
22
|
-
import { crc32 } from "node:zlib";
|
|
23
22
|
import { open as open$1 } from "yauzl";
|
|
24
23
|
|
|
25
24
|
//#region src/infrastructure/mcp-canvas-ui.adapter.ts
|
|
@@ -264,12 +263,13 @@ const createMcpHostedCapabilitiesAdapter = (offered, invocation) => {
|
|
|
264
263
|
invocation: { invoke: async (request) => {
|
|
265
264
|
const capability = catalog.find((candidate) => candidate.id === request.capability.id);
|
|
266
265
|
if (capability === void 0) throw new CliError("FORBIDDEN", "This capability is unavailable through hosted MCP.", "Use a listed tool. Local file imports require the local CLI or MCP connection.");
|
|
267
|
-
const
|
|
266
|
+
const given = request.arguments;
|
|
268
267
|
const outputFields = capability.policy.localOutputFields ?? [];
|
|
269
268
|
for (const field of outputFields) {
|
|
270
|
-
const value = typeof
|
|
269
|
+
const value = typeof given === "object" && given !== null ? Reflect.get(given, field) : void 0;
|
|
271
270
|
if (value !== null && value !== void 0) throw new CliError("BAD_REQUEST", "Hosted MCP cannot write to a caller-selected server path.", `Set ${field} to null to receive the artifact through the host, or use the local CLI.`);
|
|
272
271
|
}
|
|
272
|
+
const input = capability.inputSchema.parse(request.arguments);
|
|
273
273
|
return invocation.invoke({
|
|
274
274
|
...request,
|
|
275
275
|
capability,
|
|
@@ -360,6 +360,28 @@ const mcpFileSchema = z.strictObject({
|
|
|
360
360
|
file_name: z.string().min(1).max(NAME_LIMIT).optional()
|
|
361
361
|
});
|
|
362
362
|
|
|
363
|
+
//#endregion
|
|
364
|
+
//#region src/infrastructure/crc32.lib.ts
|
|
365
|
+
const POLYNOMIAL = 3988292384;
|
|
366
|
+
const BYTE_VALUES = 256;
|
|
367
|
+
const BITS = 8;
|
|
368
|
+
const LOW_BYTE = 255;
|
|
369
|
+
const ALL_BITS = 4294967295;
|
|
370
|
+
const TABLE = Uint32Array.from({ length: BYTE_VALUES }, (_, index) => {
|
|
371
|
+
let value = index;
|
|
372
|
+
for (let bit = 0; bit < BITS; bit += 1) value = (value & 1) === 1 ? value >>> 1 ^ POLYNOMIAL : value >>> 1;
|
|
373
|
+
return value >>> 0;
|
|
374
|
+
});
|
|
375
|
+
/**
|
|
376
|
+
* The CRC-32 checksum a zip entry carries, continued from an earlier part's checksum. Node has its
|
|
377
|
+
* own in `node:zlib`, but only from 20.15 and 22.2, and the tool runs on every Node 20.
|
|
378
|
+
*/
|
|
379
|
+
const crc32 = (bytes, earlier = 0) => {
|
|
380
|
+
let value = (earlier ^ ALL_BITS) >>> 0;
|
|
381
|
+
for (const byte of bytes) value = (TABLE[(value ^ byte) & LOW_BYTE] ?? 0) ^ value >>> BITS;
|
|
382
|
+
return (value ^ ALL_BITS) >>> 0;
|
|
383
|
+
};
|
|
384
|
+
|
|
363
385
|
//#endregion
|
|
364
386
|
//#region src/infrastructure/hosted-prototype-zip.adapter.ts
|
|
365
387
|
const ATTRIBUTE_BITS = 16;
|
|
@@ -484,8 +506,37 @@ const createMcpPrototypeArtifactAdapter = (files, file) => ({ package: async (in
|
|
|
484
506
|
//#endregion
|
|
485
507
|
//#region src/infrastructure/mcp-hosted-files.adapter.ts
|
|
486
508
|
const clientContext$1 = createMcpClientContextAdapter();
|
|
487
|
-
const
|
|
488
|
-
const
|
|
509
|
+
const stagedUploadIdSchema = z.uuid().optional().describe("Set by the Enhance plugin for a file it staged. Leave unset.");
|
|
510
|
+
const assetInputSchema = canvasAssetImportInputSchema.omit({ source: true }).extend({
|
|
511
|
+
file: mcpFileSchema.optional(),
|
|
512
|
+
stagedUploadId: stagedUploadIdSchema
|
|
513
|
+
});
|
|
514
|
+
const prototypeInputSchema = canvasPrototypeIntentSchema.extend({
|
|
515
|
+
file: mcpFileSchema.optional(),
|
|
516
|
+
stagedUploadId: stagedUploadIdSchema
|
|
517
|
+
});
|
|
518
|
+
/** Why the plugin can stage the file again; anything else about the failure is the real answer. */
|
|
519
|
+
const STAGED_UPLOAD_EXPIRED = "STAGED_UPLOAD_EXPIRED";
|
|
520
|
+
/**
|
|
521
|
+
* A staged file is named only by its id, and the API answers only for the person who staged it,
|
|
522
|
+
* so a caller can neither reach another person's file nor point the server at an address.
|
|
523
|
+
*/
|
|
524
|
+
const stagedFile = async (remote, id) => {
|
|
525
|
+
try {
|
|
526
|
+
return {
|
|
527
|
+
download_url: signedDownloadSchema.parse(await remote.query("stagedUpload.read", { id })).url,
|
|
528
|
+
file_id: id
|
|
529
|
+
};
|
|
530
|
+
} catch (error) {
|
|
531
|
+
if (error instanceof CliError && error.code === "NOT_FOUND") throw new CliError("NOT_FOUND", "The staged file does not exist or has expired.", "Publish the same folder again with the same clientToken.", { reason: STAGED_UPLOAD_EXPIRED });
|
|
532
|
+
throw error;
|
|
533
|
+
}
|
|
534
|
+
};
|
|
535
|
+
/** Exactly one source, resolved to something the existing file handling already understands. */
|
|
536
|
+
const selectedFile = async (remote, source) => {
|
|
537
|
+
if (source.file !== void 0 && source.stagedUploadId !== void 0) throw new CliError("BAD_REQUEST", "Supply either a file or a staged upload, not both.", "Select one file and retry with the same clientToken.");
|
|
538
|
+
return source.stagedUploadId === void 0 ? source.file : stagedFile(remote, source.stagedUploadId);
|
|
539
|
+
};
|
|
489
540
|
const transfer = async (action) => {
|
|
490
541
|
const result = createMcpResultAdapter("Select the same host file with a fresh download URL and reuse the original clientToken after uncertainty.");
|
|
491
542
|
try {
|
|
@@ -508,7 +559,10 @@ const registerAsset = (server, input) => {
|
|
|
508
559
|
},
|
|
509
560
|
_meta: { "openai/fileParams": ["file"] }
|
|
510
561
|
}, async (args, context) => clientContext$1.run(context, async () => transfer(async () => {
|
|
511
|
-
const
|
|
562
|
+
const remote = input.remoteFor(args.clientToken);
|
|
563
|
+
const file = await selectedFile(remote, args);
|
|
564
|
+
if (file === void 0) throw new CliError("BAD_REQUEST", "No file was selected.", "Select the file to import and retry with the same clientToken.");
|
|
565
|
+
const result = canvasAssetImportOutputSchema.parse(await createImportCanvasAssetComposite(remote, createMcpAssetFileAdapter(input.files, file)).execute(args));
|
|
512
566
|
return createMcpResultAdapter("Reconnect Enhance and retry the same intent.").structured(result);
|
|
513
567
|
})));
|
|
514
568
|
};
|
|
@@ -525,9 +579,14 @@ const registerPrototype = (server, input) => {
|
|
|
525
579
|
openWorldHint: true
|
|
526
580
|
},
|
|
527
581
|
_meta: { "openai/fileParams": ["file"] }
|
|
528
|
-
}, async ({ file, ...args }, context) => clientContext$1.run(context, async () => transfer(async () => {
|
|
582
|
+
}, async ({ file: selected, stagedUploadId, ...args }, context) => clientContext$1.run(context, async () => transfer(async () => {
|
|
583
|
+
const remote = input.remoteFor(args.clientToken);
|
|
584
|
+
const file = await selectedFile(remote, {
|
|
585
|
+
file: selected,
|
|
586
|
+
stagedUploadId
|
|
587
|
+
});
|
|
529
588
|
if (args.source.kind === "build" !== (file !== void 0)) throw new CliError("BAD_REQUEST", "Supply a file only when publishing a new build.", "For a new build select its ZIP. To resume an existing deployment, omit file.");
|
|
530
|
-
const result = canvasPrototypeOutputSchema.parse(await createPublishCanvasPrototypeComposite(
|
|
589
|
+
const result = canvasPrototypeOutputSchema.parse(await createPublishCanvasPrototypeComposite(remote, createMcpPrototypeArtifactAdapter(input.files, file)).execute(args));
|
|
531
590
|
return createMcpResultAdapter("Reconnect Enhance and retry the same intent.").structured(result);
|
|
532
591
|
})));
|
|
533
592
|
};
|
|
@@ -539,12 +598,26 @@ const createMcpHostedFilesAdapter = (input) => ({ register: (server) => {
|
|
|
539
598
|
//#endregion
|
|
540
599
|
//#region src/infrastructure/mcp-http-profile.adapter.ts
|
|
541
600
|
const clientContext = createMcpClientContextAdapter();
|
|
601
|
+
/** The tools that import a file, fetching only from the origins `files` allows. */
|
|
602
|
+
const hostedFilesFor = (files, apiUrl, credentials) => createMcpHostedFilesAdapter({
|
|
603
|
+
files,
|
|
604
|
+
remoteFor: (clientToken) => {
|
|
605
|
+
const mutationKey = createMutationKeyAdapter();
|
|
606
|
+
mutationKey.select(clientToken, true);
|
|
607
|
+
return createHttpRemoteAdapter(apiUrl, credentials, mutationKey, {
|
|
608
|
+
...clientContext.current(),
|
|
609
|
+
path: "hosted_mcp"
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
});
|
|
542
613
|
const createMcpHttpProfileAdapter = (config, catalog, credentialFor, profile) => {
|
|
543
|
-
const
|
|
614
|
+
const hostFiles = config.fileOrigins !== void 0 && config.fileOrigins.length > 0 ? createMcpFileDownloadAdapter(config.fileOrigins) : void 0;
|
|
615
|
+
const stagedFiles = config.stagedUploadOrigin === void 0 ? void 0 : createMcpFileDownloadAdapter([config.stagedUploadOrigin]);
|
|
544
616
|
const ui = config.uiUrl === void 0 ? void 0 : createMcpCanvasUiAdapter(config.uiUrl);
|
|
545
617
|
return createMcpHandler(({ authInfo }) => {
|
|
546
618
|
if (authInfo === void 0) throw new Error("authenticated MCP request held no identity");
|
|
547
619
|
const credentials = credentialFor(authInfo.token);
|
|
620
|
+
const files = authInfo.extra?.["savedLogin"] === true ? stagedFiles : hostFiles;
|
|
548
621
|
const hosted = createMcpHostedCapabilitiesAdapter(catalog, createMcpInvocationAdapter(config.apiUrl, credentials, config.configDirectory, {
|
|
549
622
|
version: config.version,
|
|
550
623
|
connectionPath: "hosted_mcp"
|
|
@@ -555,17 +628,7 @@ const createMcpHttpProfileAdapter = (config, catalog, credentialFor, profile) =>
|
|
|
555
628
|
delivery: "embedded",
|
|
556
629
|
authentication: "oauth",
|
|
557
630
|
...ui !== void 0 && { ui },
|
|
558
|
-
...files !== void 0 && { hostedFiles:
|
|
559
|
-
files,
|
|
560
|
-
remoteFor: (clientToken) => {
|
|
561
|
-
const mutationKey = createMutationKeyAdapter();
|
|
562
|
-
mutationKey.select(clientToken, true);
|
|
563
|
-
return createHttpRemoteAdapter(config.apiUrl, credentials, mutationKey, {
|
|
564
|
-
...clientContext.current(),
|
|
565
|
-
path: "hosted_mcp"
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
}) },
|
|
631
|
+
...files !== void 0 && { hostedFiles: hostedFilesFor(files, config.apiUrl, credentials) },
|
|
569
632
|
readOnly: profile.readOnly
|
|
570
633
|
}) : createMcpServerAdapter({
|
|
571
634
|
version: config.version,
|
|
@@ -583,6 +646,10 @@ const createMcpHttpProfileAdapter = (config, catalog, credentialFor, profile) =>
|
|
|
583
646
|
//#region src/infrastructure/remote-mcp-http.adapter.ts
|
|
584
647
|
const SECOND_MS = 1e3;
|
|
585
648
|
const BAD_REQUEST = 400;
|
|
649
|
+
const SAVED_LOGIN = {
|
|
650
|
+
clientId: "enhance-saved-agent-login",
|
|
651
|
+
checkSeconds: 3600
|
|
652
|
+
};
|
|
586
653
|
const credentialFor = (token, configDirectory) => ({
|
|
587
654
|
read: async () => token,
|
|
588
655
|
write: async () => {
|
|
@@ -595,10 +662,30 @@ const metadataFrom = async (config) => {
|
|
|
595
662
|
const remote = createHttpRemoteAdapter(config.apiUrl, credentialFor("", config.configDirectory), createMutationKeyAdapter());
|
|
596
663
|
return OAuthMetadataSchema.parse(await remote.oauthMetadata(config.issuer));
|
|
597
664
|
};
|
|
665
|
+
/**
|
|
666
|
+
* The login the plugin and command-line tool save. The API already accepts it for everything, so
|
|
667
|
+
* this grants nothing new. It carries no scopes or resource of its own; each request re-checks it.
|
|
668
|
+
*/
|
|
669
|
+
const savedAgentLogin = (config, token, login, personId) => {
|
|
670
|
+
const expiresAt = login.expiresAt === null ? Math.floor(Date.now() / SECOND_MS) + SAVED_LOGIN.checkSeconds : Math.floor(new Date(login.expiresAt).getTime() / SECOND_MS);
|
|
671
|
+
return {
|
|
672
|
+
token,
|
|
673
|
+
clientId: SAVED_LOGIN.clientId,
|
|
674
|
+
scopes: [MCP_AUTH_SCOPE],
|
|
675
|
+
expiresAt,
|
|
676
|
+
resource: new URL(config.resourceUrl),
|
|
677
|
+
extra: {
|
|
678
|
+
personId,
|
|
679
|
+
tokenId: login.tokenId,
|
|
680
|
+
savedLogin: true
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
};
|
|
598
684
|
const authVerifier = (config) => ({ verifyAccessToken: async (token) => {
|
|
599
685
|
try {
|
|
600
686
|
const remote = createHttpRemoteAdapter(config.apiUrl, credentialFor(token, config.configDirectory), createMutationKeyAdapter(), { path: "hosted_mcp" });
|
|
601
687
|
const me = getMeOutputSchema.parse(await remote.queryWithToken("person.me", {}, token));
|
|
688
|
+
if (me.authentication.kind === "agent") return savedAgentLogin(config, token, me.authentication, me.person?.id);
|
|
602
689
|
if (me.authentication.kind !== "oauth-agent" || me.authentication.resource !== config.resourceUrl) throw new OAuthError(OAuthErrorCode.InvalidToken, "token is not valid for Enhance MCP");
|
|
603
690
|
return {
|
|
604
691
|
token,
|
|
@@ -713,6 +800,7 @@ const createRemoteMcpHttpAdapter = async (config) => {
|
|
|
713
800
|
|
|
714
801
|
//#endregion
|
|
715
802
|
//#region src/remote-mcp-main.ts
|
|
803
|
+
installZodMessages();
|
|
716
804
|
const config = readRemoteMcpEnvironment();
|
|
717
805
|
const server = await createRemoteMcpHttpAdapter({
|
|
718
806
|
...config.MCP_CANVAS_PATH !== void 0 && { canvasProfile: {
|
|
@@ -727,9 +815,10 @@ const server = await createRemoteMcpHttpAdapter({
|
|
|
727
815
|
serviceDocumentationUrl: config.MCP_SERVICE_DOCUMENTATION_URL,
|
|
728
816
|
configDirectory: path.join(os.tmpdir(), "enhance-remote-mcp"),
|
|
729
817
|
fileOrigins: config.MCP_FILE_ORIGINS.split(",").map((value) => value.trim()).filter(Boolean),
|
|
818
|
+
...config.MCP_STAGED_UPLOAD_ORIGIN !== void 0 && { stagedUploadOrigin: config.MCP_STAGED_UPLOAD_ORIGIN },
|
|
730
819
|
allowedHosts: config.MCP_ALLOWED_HOSTS.split(",").map((value) => value.trim()),
|
|
731
820
|
allowedOrigins: config.MCP_ALLOWED_ORIGINS.split(",").map((value) => value.trim()),
|
|
732
|
-
version: "0.1.
|
|
821
|
+
version: "0.1.165",
|
|
733
822
|
...config.MCP_UI_URL !== void 0 && { uiUrl: config.MCP_UI_URL },
|
|
734
823
|
onerror: (error) => process.stderr.write(`${error.message}\n`)
|
|
735
824
|
});
|