constructor-research-mcp 0.5.0 → 0.6.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 +3 -1
- package/dist/api.d.ts +2 -0
- package/dist/api.js +13 -3
- package/dist/deployment.d.ts +16 -0
- package/dist/deployment.js +68 -2
- package/dist/schemas.js +1 -1
- package/dist/server.js +44 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Constructor Research MCP
|
|
2
2
|
|
|
3
|
+
> **0.6:** a registry `image` the project does not have is added to it as an external image, with no desk and no build; Constructor refuses a bad one at once, with its reason.
|
|
4
|
+
>
|
|
3
5
|
> **0.5:** one command sets it up: `npx -y constructor-research-mcp@latest install` finds your coding agents, saves your access key and adds the MCP to each of them.
|
|
4
6
|
>
|
|
5
7
|
> **0.4:** works with Constructor's public API and a personal access key (`rk-…`); browser sign-in is gone. On a Constructor without the public API yet, pin the previous version: `constructor-research-mcp@0.3.3`.
|
|
@@ -191,7 +193,7 @@ Private DNS works between containers; browser JavaScript needs a public backend
|
|
|
191
193
|
|
|
192
194
|
Replace a service's `build` with `"image_id":"IMAGE_ID"` to skip building, or with `"image":"registry/repo:tag"` to run a registry image unchanged, such as `jgraph/drawio:latest` from Docker Hub. Which of `build`, `image` and `image_id` fits is the agent's choice; the tool descriptions say what each one does. `list_images` returns compact records with `source` (`desk_build` or `external`), `reference` and `build_status` (`not_started`, `snapshot_creation`, `in_progress`, `done` or `error`); `detailed:true` returns full records.
|
|
193
195
|
|
|
194
|
-
With `image`, the MCP first looks for it in the project (by `reference` or name). External images there (`source: external`) are pulled, not built, so they are used whatever their build status, unless it is `error`. An image the project does not have is
|
|
196
|
+
With `image`, the MCP first looks for it in the project (by `reference` or name). External images there (`source: external`) are pulled, not built, so they are used whatever their build status, unless it is `error`. An image the project does not have is added to the project as an external image (`POST /projects/{id}/images/external`): no desk, no upload, no build. Constructor reads the image manifest at once and refuses a missing tag, a private image, an image without a `linux/amd64` variant or a malformed reference; the MCP then returns `image_refused` with Constructor's reason and creates nothing else. Docker Hub references are sent in the short form (`docker.io/library/nginx:1.27` becomes `nginx:1.27`), which Constructor requires for now. A reference without a tag means `latest`, which moves: the result then carries `image_warnings`. On a Constructor without this endpoint, the MCP falls back to building the image on the desk from a one-line `FROM <image>` Dockerfile in `.constructor/images/<name>/`.
|
|
195
197
|
|
|
196
198
|
- Build storage is omitted by default, using the API's documented **50 GB** default. Explicit `ephemeral_build_disk_size_gb` overrides must be **10–1000 GB**.
|
|
197
199
|
- Each service can have multiple ports (1–65535), with at most **one public port**. That port must match where the container listens.
|
package/dist/api.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare class ToolError extends Error {
|
|
|
8
8
|
constructor(code: string, message: string, status?: number | undefined, apiCode?: number | undefined,
|
|
9
9
|
/** Extra fields returned to the agent next to status and message. */
|
|
10
10
|
details?: Record<string, unknown> | undefined);
|
|
11
|
+
/** Constructor's own reason (detail.info.details); never put into messages by default. */
|
|
12
|
+
reason?: string;
|
|
11
13
|
}
|
|
12
14
|
export declare const segment: (s: string) => string;
|
|
13
15
|
/** A key as Constructor shows it, with or without the "Bearer " the header adds. */
|
package/dist/api.js
CHANGED
|
@@ -16,6 +16,8 @@ export class ToolError extends Error {
|
|
|
16
16
|
this.apiCode = apiCode;
|
|
17
17
|
this.details = details;
|
|
18
18
|
}
|
|
19
|
+
/** Constructor's own reason (detail.info.details); never put into messages by default. */
|
|
20
|
+
reason;
|
|
19
21
|
}
|
|
20
22
|
export const segment = (s) => encodeURIComponent(s);
|
|
21
23
|
/** A key as Constructor shows it, with or without the "Bearer " the header adds. */
|
|
@@ -185,15 +187,23 @@ export class PlatformApi {
|
|
|
185
187
|
if (method !== "GET" && response.status >= 500)
|
|
186
188
|
throw new ToolError("uncertain_outcome", `Constructor API returned HTTP ${response.status}. The mutation may have been applied; inspect resources before retrying.`, response.status);
|
|
187
189
|
let apiCode;
|
|
190
|
+
let reason;
|
|
188
191
|
try {
|
|
189
192
|
const d = (await response.json());
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
// Constructor answers {"detail": {...}}; older specs show {"details": {...}}.
|
|
194
|
+
const body = d?.detail ?? d?.details;
|
|
195
|
+
if (typeof body?.error_code === "number")
|
|
196
|
+
apiCode = body.error_code;
|
|
197
|
+
if (typeof body?.info?.details === "string")
|
|
198
|
+
reason = body.info.details;
|
|
192
199
|
}
|
|
193
200
|
catch {
|
|
194
201
|
/* Error bodies can contain secrets; never echo them. */
|
|
195
202
|
}
|
|
196
|
-
|
|
203
|
+
const err = new ToolError("api_error", `Constructor API returned HTTP ${response.status}${apiCode ? ` (error ${apiCode})` : ""}.`, response.status, apiCode);
|
|
204
|
+
// Kept off the message: only callers that know the reason is safe to show use it.
|
|
205
|
+
err.reason = reason;
|
|
206
|
+
throw err;
|
|
197
207
|
}
|
|
198
208
|
if (response.status === 204)
|
|
199
209
|
return undefined;
|
package/dist/deployment.d.ts
CHANGED
|
@@ -59,6 +59,13 @@ export declare class DeploymentEngine {
|
|
|
59
59
|
deskFor(project: string, create?: string): Promise<string>;
|
|
60
60
|
/** Turn each service's `image` into the project's image_id when the project has it (by reference or name); others are left as `image`. */
|
|
61
61
|
resolveImages(project: string, services: any[]): Promise<any[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Add a public registry image to the project as an external image: no desk, no
|
|
64
|
+
* build. Constructor reads the manifest at once and refuses a missing, private,
|
|
65
|
+
* non-amd64 or malformed image with its reason. Undefined when this Constructor
|
|
66
|
+
* has no such endpoint yet (the caller then builds it from FROM).
|
|
67
|
+
*/
|
|
68
|
+
registerExternal(project: string, service: string, reference: string): Promise<any>;
|
|
62
69
|
listImages(raw: unknown): Promise<{
|
|
63
70
|
results: any[];
|
|
64
71
|
total: number;
|
|
@@ -103,3 +110,12 @@ export declare class DeploymentEngine {
|
|
|
103
110
|
};
|
|
104
111
|
private view;
|
|
105
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Docker Hub references in the short form Constructor accepts: docker.io/library/nginx:1.27
|
|
115
|
+
* is refused (HYP-3189), nginx:1.27 works. Other registries are left as given.
|
|
116
|
+
*/
|
|
117
|
+
export declare function shortReference(reference: string): string;
|
|
118
|
+
/** True when the reference pins a tag or digest; without one it means latest, which moves. */
|
|
119
|
+
export declare function hasTag(reference: string): boolean;
|
|
120
|
+
/** Image name for a reference (Constructor allows 30 characters): repository and tag. */
|
|
121
|
+
export declare function externalName(reference: string): string;
|
package/dist/deployment.js
CHANGED
|
@@ -409,18 +409,47 @@ export class DeploymentEngine {
|
|
|
409
409
|
if (!s.image)
|
|
410
410
|
return s;
|
|
411
411
|
const want = s.image.trim();
|
|
412
|
-
const
|
|
412
|
+
const ref = shortReference(want);
|
|
413
|
+
const same = (im) => typeof im.reference === "string" &&
|
|
414
|
+
shortReference(im.reference) === ref;
|
|
415
|
+
const hits = images.filter((im) => im.reference === want ||
|
|
416
|
+
same(im) ||
|
|
417
|
+
im.name === want ||
|
|
418
|
+
im.id === want);
|
|
413
419
|
const im = hits.length > 1
|
|
414
420
|
? (hits.find((x) => x.reference === want) ??
|
|
421
|
+
hits.find((x) => same(x) && DeploymentEngine.usable(x)) ??
|
|
415
422
|
bad(`Image "${want}" for ${s.name} matches several images: ${hits.map((x) => x.id).join(", ")}. Pass image_id.`))
|
|
416
423
|
: hits[0];
|
|
417
|
-
// Not in the project: the caller
|
|
424
|
+
// Not in the project: the caller registers it (registerExternal).
|
|
418
425
|
if (!im)
|
|
419
426
|
return s;
|
|
420
427
|
const { image: _i, ...rest } = s;
|
|
421
428
|
return { ...rest, image_id: im.id };
|
|
422
429
|
});
|
|
423
430
|
}
|
|
431
|
+
/**
|
|
432
|
+
* Add a public registry image to the project as an external image: no desk, no
|
|
433
|
+
* build. Constructor reads the manifest at once and refuses a missing, private,
|
|
434
|
+
* non-amd64 or malformed image with its reason. Undefined when this Constructor
|
|
435
|
+
* has no such endpoint yet (the caller then builds it from FROM).
|
|
436
|
+
*/
|
|
437
|
+
async registerExternal(project, service, reference) {
|
|
438
|
+
try {
|
|
439
|
+
return await this.api.request("POST", this.root(project) + "/images/external", { name: externalName(reference), reference });
|
|
440
|
+
}
|
|
441
|
+
catch (err) {
|
|
442
|
+
if (!(err instanceof ToolError) || err.code !== "api_error")
|
|
443
|
+
throw err;
|
|
444
|
+
if (err.status === 404 || err.status === 405)
|
|
445
|
+
return undefined;
|
|
446
|
+
if ([400, 421, 422].includes(err.status ?? 0)) {
|
|
447
|
+
const why = cleanReason(err.reason);
|
|
448
|
+
throw new ToolError("image_refused", `Service ${service}: Constructor refused image ${reference}${why ? `: ${why}` : ""}. Nothing was deployed. Only public images with a linux/amd64 variant can be used; check the name and tag (Docker Hub images as name:tag or user/name:tag). Tell the user, or use build with a Dockerfile instead.`, err.status, err.apiCode, { stage: "register", service, image: reference });
|
|
449
|
+
}
|
|
450
|
+
throw err;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
424
453
|
async listImages(raw) {
|
|
425
454
|
const input = listInput.parse(raw);
|
|
426
455
|
await this.project(input.project_id);
|
|
@@ -1303,3 +1332,40 @@ export class DeploymentEngine {
|
|
|
1303
1332
|
return result;
|
|
1304
1333
|
}
|
|
1305
1334
|
}
|
|
1335
|
+
/**
|
|
1336
|
+
* Docker Hub references in the short form Constructor accepts: docker.io/library/nginx:1.27
|
|
1337
|
+
* is refused (HYP-3189), nginx:1.27 works. Other registries are left as given.
|
|
1338
|
+
*/
|
|
1339
|
+
export function shortReference(reference) {
|
|
1340
|
+
const r = reference.trim();
|
|
1341
|
+
const m = /^(?:docker\.io|index\.docker\.io|registry-1\.docker\.io)\/(.+)$/i.exec(r);
|
|
1342
|
+
return m ? m[1].replace(/^library\/(?=[^/]+$)/, "") : r;
|
|
1343
|
+
}
|
|
1344
|
+
/** True when the reference pins a tag or digest; without one it means latest, which moves. */
|
|
1345
|
+
export function hasTag(reference) {
|
|
1346
|
+
return reference.includes("@") || reference.split("/").at(-1).includes(":");
|
|
1347
|
+
}
|
|
1348
|
+
/** Image name for a reference (Constructor allows 30 characters): repository and tag. */
|
|
1349
|
+
export function externalName(reference) {
|
|
1350
|
+
const name = reference
|
|
1351
|
+
.split("/")
|
|
1352
|
+
.at(-1)
|
|
1353
|
+
.split("@")[0]
|
|
1354
|
+
.toLowerCase()
|
|
1355
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
1356
|
+
.slice(0, 30)
|
|
1357
|
+
.replace(/^-+|-+$/g, "");
|
|
1358
|
+
return name || "image";
|
|
1359
|
+
}
|
|
1360
|
+
/** Constructor's refusal reason as one short line, never anything that looks like a key. */
|
|
1361
|
+
function cleanReason(reason) {
|
|
1362
|
+
if (!reason)
|
|
1363
|
+
return undefined;
|
|
1364
|
+
const line = reason
|
|
1365
|
+
.replace(/rk-[A-Za-z0-9_-]+/g, "rk-…")
|
|
1366
|
+
.replace(/\s+/g, " ")
|
|
1367
|
+
.trim()
|
|
1368
|
+
.slice(0, 300)
|
|
1369
|
+
.replace(/[.\s]+$/, "");
|
|
1370
|
+
return line || undefined;
|
|
1371
|
+
}
|
package/dist/schemas.js
CHANGED
|
@@ -117,7 +117,7 @@ export const serviceInput = z
|
|
|
117
117
|
.max(256)
|
|
118
118
|
.regex(/^[a-z0-9][a-z0-9._\/:@-]*$/i, "image is a registry reference such as jgraph/drawio:latest or ghcr.io/org/app:1.2.")
|
|
119
119
|
.optional()
|
|
120
|
-
.describe("A registry image reference (
|
|
120
|
+
.describe("A public registry image reference (jgraph/drawio:24.7.17, ghcr.io/org/app:1.2) or the name of an image already in the project; the alternative to build and image_id. If the project has it, it is used as is. Otherwise the MCP adds it to the project as an external image: no desk and no build, it runs unchanged. Constructor checks it at once (public, linux/amd64, tag exists) and a refusal comes back as image_refused with the reason; then tell the user. Prefer a fixed tag over latest. To add files or change it, use build with your own Dockerfile. The service's ports must match the port the image listens on."),
|
|
121
121
|
build: build.optional(),
|
|
122
122
|
hardware: z
|
|
123
123
|
.strictObject({
|
package/dist/server.js
CHANGED
|
@@ -4,7 +4,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
4
4
|
import { configFromEnv, VERSION } from "./config.js";
|
|
5
5
|
import { PlatformApi, ToolError } from "./api.js";
|
|
6
6
|
import { StateStore } from "./store.js";
|
|
7
|
-
import { DeploymentEngine } from "./deployment.js";
|
|
7
|
+
import { DeploymentEngine, hasTag, shortReference } from "./deployment.js";
|
|
8
8
|
import { DeploymentRuntime } from "./runtime.js";
|
|
9
9
|
import { FileManager, dockerignore } from "./files.js";
|
|
10
10
|
import { basename, join } from "node:path";
|
|
@@ -41,10 +41,47 @@ async function main() {
|
|
|
41
41
|
engine.logs = logs;
|
|
42
42
|
/** Verify Dockerfiles on their disks before any build; surface lint warnings to the agent. */
|
|
43
43
|
const checked = (fn, single = false) => async (a) => {
|
|
44
|
+
const notes = [];
|
|
45
|
+
const result = await prepared(fn, single, a, notes);
|
|
46
|
+
return notes.length
|
|
47
|
+
? {
|
|
48
|
+
...result,
|
|
49
|
+
message: `${result.message ?? ""} ${notes.join(" ")}`.trim(),
|
|
50
|
+
image_warnings: notes,
|
|
51
|
+
}
|
|
52
|
+
: result;
|
|
53
|
+
};
|
|
54
|
+
const prepared = async (fn, single, a, notes) => {
|
|
44
55
|
const begun = Date.now();
|
|
45
56
|
if (!single && a.project_id && a.services) {
|
|
46
|
-
// Images the project has by reference or name
|
|
47
|
-
|
|
57
|
+
// Images the project has (by reference or name) are used as they are. Any other
|
|
58
|
+
// registry image is added to the project as an external image: no desk, no build.
|
|
59
|
+
const added = new Map();
|
|
60
|
+
let services = [];
|
|
61
|
+
for (const x of await engine.resolveImages(a.project_id, a.services)) {
|
|
62
|
+
if (!x.image) {
|
|
63
|
+
services.push(x);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (!/^[a-z0-9][a-z0-9._/:@-]*$/i.test(x.image))
|
|
67
|
+
throw new ToolError("invalid_input", `Service ${x.name}: invalid image reference.`);
|
|
68
|
+
const ref = shortReference(x.image);
|
|
69
|
+
let im = added.get(ref);
|
|
70
|
+
if (!im) {
|
|
71
|
+
im = await engine.registerExternal(a.project_id, x.name, ref);
|
|
72
|
+
// This Constructor cannot add external images: build it from FROM below.
|
|
73
|
+
if (!im?.id) {
|
|
74
|
+
services.push(x);
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
added.set(ref, im);
|
|
78
|
+
if (!hasTag(ref))
|
|
79
|
+
notes.push(`Image ${ref} (${x.name}) has no tag, so it means latest, which moves; Constructor keeps the version it found now (${im.digest ?? "digest not shown"}). Suggest a tag to the user.`);
|
|
80
|
+
}
|
|
81
|
+
const { image: _i, ...rest } = x;
|
|
82
|
+
services.push({ ...rest, image_id: im.id });
|
|
83
|
+
}
|
|
84
|
+
// Builds without a desk go to the project's desk.
|
|
48
85
|
if (services.some((x) => x.image || (x.build && !x.build.desk_id))) {
|
|
49
86
|
const here = config.localDesk;
|
|
50
87
|
const desk = here && a.project_id === here.projectId
|
|
@@ -55,9 +92,7 @@ async function main() {
|
|
|
55
92
|
return { ...x, build: { ...x.build, desk_id: desk } };
|
|
56
93
|
if (!x.image)
|
|
57
94
|
return x;
|
|
58
|
-
// A
|
|
59
|
-
if (!/^[a-z0-9][a-z0-9._/:@-]*$/i.test(x.image))
|
|
60
|
-
throw new ToolError("invalid_input", `Service ${x.name}: invalid image reference.`);
|
|
95
|
+
// A Constructor without external images: build it from a one-line Dockerfile.
|
|
61
96
|
const slug = x.image
|
|
62
97
|
.toLowerCase()
|
|
63
98
|
.replace(/[^a-z0-9]+/g, "-")
|
|
@@ -100,10 +135,7 @@ async function main() {
|
|
|
100
135
|
build: {
|
|
101
136
|
...rest,
|
|
102
137
|
dockerfile: "/" +
|
|
103
|
-
[
|
|
104
|
-
...at.split("/"),
|
|
105
|
-
...(b.dockerfile ?? "Dockerfile").split("/"),
|
|
106
|
-
]
|
|
138
|
+
[...at.split("/"), ...(b.dockerfile ?? "Dockerfile").split("/")]
|
|
107
139
|
.filter(Boolean)
|
|
108
140
|
.join("/"),
|
|
109
141
|
},
|
|
@@ -145,8 +177,7 @@ async function main() {
|
|
|
145
177
|
build: {
|
|
146
178
|
...b,
|
|
147
179
|
remote_path: remote,
|
|
148
|
-
dockerfile: "/" +
|
|
149
|
-
[...remote.split("/").filter(Boolean), ...inside].join("/"),
|
|
180
|
+
dockerfile: "/" + [...remote.split("/").filter(Boolean), ...inside].join("/"),
|
|
150
181
|
},
|
|
151
182
|
});
|
|
152
183
|
}
|
|
@@ -194,7 +225,7 @@ async function main() {
|
|
|
194
225
|
? text.replace(/Where to act: ask the user for the Constructor desk link.*?if the user has not said where to deploy or where files live, ask\. /, deskInstructions(config.localDesk) + " ")
|
|
195
226
|
: text;
|
|
196
227
|
const server = new McpServer({ name: "constructor-research", version: VERSION }, {
|
|
197
|
-
instructions: withDesk(`Access: the MCP works with one Constructor and the user's personal access key for it, set up outside the chat. When a tool returns needs_key, pass its instructions on to the user; never ask for the key in the chat. Where to act: ask the user for the Constructor desk link (they open the desk in the browser and copy the address; it contains /projects/<project>/desks/<desk>) and pass it as desk_url. Do not pick a project yourself; if the user has not said where to deploy or where files live, ask. Given a project only (project_id), the MCP uses its only desk, or creates one for a deploy when there is none; when the project has several desks it returns desk_choice_required with their names and links: ask the user which one. Ask the user only before replacing, renaming or deleting files on a disk, once per request for the whole list (the tools return confirm_required); creating folders and uploading new files need no question. ${RULES} For a local app, pass build.local_path (the folder with the Dockerfile) and deploy_app uploads it first. A service can also take image: a registry reference (repo:tag) that runs unchanged. The MCP uses the copy in the project when there is one (list_images shows source and reference), otherwise
|
|
228
|
+
instructions: withDesk(`Access: the MCP works with one Constructor and the user's personal access key for it, set up outside the chat. When a tool returns needs_key, pass its instructions on to the user; never ask for the key in the chat. Where to act: ask the user for the Constructor desk link (they open the desk in the browser and copy the address; it contains /projects/<project>/desks/<desk>) and pass it as desk_url. Do not pick a project yourself; if the user has not said where to deploy or where files live, ask. Given a project only (project_id), the MCP uses its only desk, or creates one for a deploy when there is none; when the project has several desks it returns desk_choice_required with their names and links: ask the user which one. Ask the user only before replacing, renaming or deleting files on a disk, once per request for the whole list (the tools return confirm_required); creating folders and uploading new files need no question. ${RULES} For a local app, pass build.local_path (the folder with the Dockerfile) and deploy_app uploads it first. A service can also take image: a public registry reference (repo:tag) that runs unchanged. The MCP uses the copy in the project when there is one (list_images shows source and reference), otherwise adds it to the project as an external image, with no desk and no build; if Constructor refuses it (image_refused), tell the user the reason. Hardware: leave it out; the default is used. Set hardware minimums only when the app cannot run without a GPU or a lot of RAM. Use deploy_app/update_app once for the WHOLE application. The MCP builds, resolves service URLs, configures and starts services in the background. IDs are automatic. To wait, run the wait command that next_action names (with a shell), or call get_deployment(wait_seconds=45) again until it is finished; never perform the deployment steps yourself. Never end the turn while a deployment the user asked for is still running. When the user asks to deploy or build, wait until the deployment is finished before answering, then give the public URL or what failed. On failure, tell the user the failed stage/service; failure.log_tail and get_logs show the last build or service log lines. Do not use browser or debugging tools. For source files: sync_files to the desk before building (the MCP checks each Dockerfile on the disk and reports warnings); after a needs_upload pause, sync and call get_deployment with files_uploaded=true. Started is not readiness.`),
|
|
198
229
|
});
|
|
199
230
|
const register = (name, description, schema, fn, readOnly = false, budget = 20000, scope) => {
|
|
200
231
|
const here = config.localDesk && DESK_DEFAULT.has(name) ? config.localDesk : undefined;
|