constructor-research-mcp 0.4.2 → 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/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; builds without a desk go to the project's desk.
47
- let services = await engine.resolveImages(a.project_id, a.services);
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 registry image the project does not have: build it from a one-line Dockerfile.
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 builds it from FROM <image>. 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.`),
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;
@@ -350,7 +381,17 @@ async function main() {
350
381
  };
351
382
  await server.connect(new StdioServerTransport());
352
383
  }
353
- main().catch(() => {
354
- console.error("Constructor Research MCP could not start. Check environment configuration.");
355
- process.exitCode = 1;
356
- });
384
+ // `constructor-research-mcp install` (or setup) runs the interactive setup instead of the server.
385
+ if (["install", "setup"].includes(process.argv[2] ?? "")) {
386
+ import("./install.js")
387
+ .then(({ runInstall }) => runInstall(process.argv.slice(3)))
388
+ .then((code) => (process.exitCode = code), (err) => {
389
+ console.error(`Setup failed: ${err?.message ?? err}`);
390
+ process.exitCode = 1;
391
+ });
392
+ }
393
+ else
394
+ main().catch(() => {
395
+ console.error("Constructor Research MCP could not start. Check environment configuration.");
396
+ process.exitCode = 1;
397
+ });
package/dist/set-key.js CHANGED
@@ -4,7 +4,7 @@
4
4
  // Usage: npx -y -p constructor-research-mcp constructor-research-set-key <Constructor link>
5
5
  import { configFromEnv, originOf } from "./config.js";
6
6
  import { cleanKey } from "./api.js";
7
- import { saveKeyFile } from "./key.js";
7
+ import { checkKey, saveKeyFile } from "./key.js";
8
8
  const USAGE = "Usage: npx -y -p constructor-research-mcp constructor-research-set-key <Constructor link, e.g. https://acme.constructor.app>\nThen paste the access key (rk-…) when asked, or pipe it in on stdin.";
9
9
  /** One line from the terminal without echoing it, or all of stdin when piped. */
10
10
  async function readSecret(prompt) {
@@ -72,28 +72,16 @@ async function main() {
72
72
  return 1;
73
73
  }
74
74
  // Check the key with Constructor before saving it.
75
- let status;
76
- try {
77
- const response = await fetch(`${url}${config.apiPath}/auth/session`, {
78
- headers: {
79
- "X-Research-AccessKey": `Bearer ${key}`,
80
- Accept: "application/json",
81
- },
82
- redirect: "manual",
83
- signal: AbortSignal.timeout(15000),
84
- });
85
- status = response.status;
86
- await response.body?.cancel();
87
- }
88
- catch {
75
+ const { result, status } = await checkKey(url, config.apiPath, key);
76
+ if (result === "unreachable") {
89
77
  console.error(`Could not reach ${url} (VPN?); nothing saved.`);
90
78
  return 1;
91
79
  }
92
- if (status === 401) {
80
+ if (result === "rejected") {
93
81
  console.error(`${url} rejected this key; nothing saved.`);
94
82
  return 1;
95
83
  }
96
- if (status !== 200) {
84
+ if (result !== "ok") {
97
85
  console.error(`${url} answered HTTP ${status}: it may not have the public API yet; nothing saved.`);
98
86
  return 1;
99
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "constructor-research-mcp",
3
- "version": "0.4.2",
3
+ "version": "0.6.0",
4
4
  "type": "module",
5
5
  "description": "Local deployment MCP for Constructor Research",
6
6
  "license": "MIT",
@@ -48,7 +48,9 @@
48
48
  "set-key": "node dist/set-key.js"
49
49
  },
50
50
  "dependencies": {
51
+ "@clack/prompts": "1.8.1",
51
52
  "@modelcontextprotocol/sdk": "1.32.2",
53
+ "smol-toml": "1.9.1",
52
54
  "zod": "4.6.7"
53
55
  },
54
56
  "devDependencies": {