@cloudgrid-io/mcp 0.20.56 → 0.21.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudgrid-io/mcp",
3
- "version": "0.20.56",
3
+ "version": "0.21.0",
4
4
  "description": "MCP access to CloudGrid — the live runtime environment where the user's apps run WITH the infrastructure they need out of the box: managed MongoDB, Redis (cache/queues/pub-sub), a pgvector store, persistent disk, and built-in AI with no API keys, in any language or stack, no Docker or Kubernetes to manage. Brainstorm, build, plug, and improve apps, games, dashboards, and tools; instant single-page publishes and full runtime-app deploys with a live URL — for developers and non-technical users. Three editions: local stdio (full toolset), hosted web (light, CLI-free), and a public docs-search server.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -10,7 +10,7 @@
10
10
  "src"
11
11
  ],
12
12
  "engines": {
13
- "node": ">=18"
13
+ "node": ">=22.19"
14
14
  },
15
15
  "scripts": {
16
16
  "start": "node src/index.js",
@@ -60,7 +60,10 @@
60
60
  "test:tool-titles-and-vocab": "node test/tool-titles-and-vocab.test.mjs",
61
61
  "test:visibility-mapping": "node test/visibility-mapping.test.mjs",
62
62
  "test:verb-distinction": "node test/verb-distinction.test.mjs",
63
- "test:collab": "node test/collab.test.mjs"
63
+ "test:collab": "node test/collab.test.mjs",
64
+ "test:url-shape": "node test/url-shape-guard.test.mjs",
65
+ "test:pull-grid": "node test/pull-grid-param.test.mjs",
66
+ "test:pull-output-schema": "node test/pull-output-schema.test.mjs"
64
67
  },
65
68
  "dependencies": {
66
69
  "@modelcontextprotocol/sdk": "^1.30.0",
@@ -95,7 +95,7 @@ grid grid
95
95
  | `env` / `secrets` | Manage runtime env vars and secrets (secret values are never printed) |
96
96
  | `grid` / `list` | List what's on your hub / org |
97
97
  | `rename` / `delete` / `unplug` | Rename, archive, take off the grid |
98
- | `pull` / `clone` / `fork` | Download source; clone or fork an entity |
98
+ | `collab` / `pull` / `pickup` | Grant push access (`collab`), continue in place (`pull`), or fork a copy (`pickup`) |
99
99
  | `feedback [message]` | Send feedback to the CloudGrid team |
100
100
  | `brain refresh <name>` | Re-run Grid Brain metadata (description, tags, diagram) |
101
101
  | `doctor` | Diagnostic checks (Node, Docker, API reachability, auth) |
@@ -14,8 +14,8 @@ loops forever.
14
14
 
15
15
  This is a known platform issue, not a mistake in your request. Do not retry with
16
16
  different flag or path permutations — they will all fail the same way. If a
17
- terminal is available, deploy from the CLI instead (`grid plug <path>`).
18
- If no terminal is available, stop and tell the user
17
+ terminal is available, deploy from the CLI instead (`grid plug <path>` or
18
+ `grid plug <url>`). If no terminal is available, stop and tell the user
19
19
  this is a known issue and needs the CLI.
20
20
 
21
21
  ## 429 anonymous cap
@@ -3,5 +3,5 @@ uvicorn[standard]==0.30.1
3
3
  pymongo==4.8.0
4
4
  numpy==1.26.4
5
5
  httpx==0.27.0
6
- pypdf==6.14.2
6
+ pypdf==6.15.0
7
7
  python-docx==1.1.2
@@ -5,5 +5,5 @@
5
5
  # pypdf / python-docx are imported lazily by source.extract_text for pdf/docx.
6
6
  pymongo==4.8.0
7
7
  httpx==0.27.0
8
- pypdf==6.14.2
8
+ pypdf==6.15.0
9
9
  python-docx==1.1.2
@@ -10,7 +10,7 @@ Match the symptom to the row, apply the fix, and stop. Do not retry permutations
10
10
 
11
11
  | Symptom | Cause | Fix |
12
12
  | --- | --- | --- |
13
- | `SCOPE_INVALID` on deploy | Known platform issue, not your request | Deploy from a terminal with `grid plug <path>`. Do not retry flag or path permutations. If no terminal is available, tell the user it is a known issue that needs the CLI. |
13
+ | `SCOPE_INVALID` on deploy | Known platform issue, not your request | Deploy from a terminal with `grid plug <path>` or `grid plug <url>`. Do not retry flag or path permutations. If no terminal is available, tell the user it is a known issue that needs the CLI. |
14
14
  | `429` anonymous cap reached | Anonymous deploy quota is exhausted | Stop. Do not log in to work around it and do not retry today. Tell the user the cap is reached; they can try later or sign in for a higher limit as a deliberate choice. |
15
15
  | `409 EDIT_REJECTED` on re-plug | The target entity is archived or expired | Do not silently create a new entity — that mints a new URL and orphans the shared one. Ask the user before creating a fresh entity. |
16
16
  | `401` on an anonymous edit | Missing or stale `owner_token` | Re-plug with the `owner_token` from the last deploy of that entity. Each anonymous edit returns a fresh token — store the new one and use it next time. |
@@ -21,6 +21,29 @@ import {
21
21
  import { okResult } from "./util.js";
22
22
  import { runCloudgrid } from "./cli.js";
23
23
 
24
+ /**
25
+ * The API refuses an infra-dependent write while a grid is still provisioning.
26
+ *
27
+ * The code is being renamed ORG_PROVISIONING -> GRID_PROVISIONING
28
+ * (cloudgrid-io/cloudgrid#2673, the org->grid retirement). This accepts BOTH,
29
+ * which is what makes the API-side rename safe: an mcp that understands both is
30
+ * version-independent from the API's side, so the rename can land the moment
31
+ * this ships rather than waiting for adoption.
32
+ *
33
+ * Keep both until the API no longer emits the old name AND the floor of
34
+ * installed mcp versions understands the new one. mcp is published to npm, so
35
+ * installed copies keep matching whatever they shipped with — dropping the old
36
+ * name early breaks plugs into brand-new grids, silently, by turning a
37
+ * retryable 409 into a hard failure.
38
+ *
39
+ * One predicate, two call sites, so they cannot drift.
40
+ */
41
+ const PROVISIONING_CODES = new Set(["GRID_PROVISIONING", "ORG_PROVISIONING"]);
42
+ function isProvisioningCode(code) {
43
+ return PROVISIONING_CODES.has(code);
44
+ }
45
+
46
+
24
47
  // ── Org listing (bearer-authed, web edition) ──────────────────────────────────
25
48
  // Fetches the signed-in user's orgs via GET /api/v2/orgs. The JWT does not
26
49
  // carry orgs (claims: sub, email, name, iat, exp), so the API is the canonical
@@ -638,7 +661,7 @@ export async function runReport(
638
661
  // or GET collaborator push access with grid_collab — grants permission
639
662
  // only, pull again once granted). A claim_token also
640
663
  // claims an anonymous drop into your account (ownership transfer).
641
- export async function runPull(ctx, { claim_token, claim_url, entity_id }) {
664
+ export async function runPull(ctx, { claim_token, claim_url, entity_id, grid } = {}) {
642
665
  const token = await ctx.getToken();
643
666
  if (!token) {
644
667
  throw new Error("You are not signed in. Run grid_login first, then claim.");
@@ -685,8 +708,11 @@ export async function runPull(ctx, { claim_token, claim_url, entity_id }) {
685
708
  };
686
709
  // The claim re-homes the inspiration into the caller's grid; the platform
687
710
  // resolves the destination from the active-org context, so send the org
688
- // header (the same header every other authed write uses).
689
- const orgSlug = await ctx.getActiveGrid();
711
+ // header (the same header every other authed write uses). The `grid`
712
+ // parameter (added for #247: the hosted transport cannot set HTTP headers,
713
+ // so multi-grid users must pass the grid explicitly) takes precedence, then
714
+ // the session's active grid.
715
+ const orgSlug = grid || (await ctx.getActiveGrid());
690
716
  // Grid-native header + X-CloudGrid-Org alias (same slug) during the soak.
691
717
  if (orgSlug) {
692
718
  headers["X-CloudGrid-Grid"] = orgSlug;
@@ -724,6 +750,29 @@ export async function runPull(ctx, { claim_token, claim_url, entity_id }) {
724
750
  };
725
751
  }
726
752
  const code = data?.error?.code || null;
753
+ // ORG_NOT_ACCESSIBLE: the `grid` param has a typo or the user isn't a
754
+ // member of that grid. The server message already contains an "Available:"
755
+ // hint listing valid grid slugs — surface it so the agent can self-correct.
756
+ if (code === "ORG_NOT_ACCESSIBLE") {
757
+ const serverMsg = data?.error?.message || "The specified grid is not accessible.";
758
+ const hint = data?.error?.details?.[0]?.hint || "";
759
+ return {
760
+ text:
761
+ `${serverMsg}${hint ? ` ${hint}` : ""} ` +
762
+ `Check the grid slug for typos and retry grid_pull with the correct \`grid\` parameter.`,
763
+ structured: { error: { code: "ORG_NOT_ACCESSIBLE" } },
764
+ };
765
+ }
766
+ // NO_ACTIVE_ORG: the account has no grid at all — route to in-flow grid
767
+ // creation instead of the misleading "no push access" advice.
768
+ if (code === "NO_ACTIVE_ORG") {
769
+ return {
770
+ text:
771
+ "The account has no grid yet. Do not send the user to the console — create one from here: " +
772
+ "suggest a short slug, confirm it with the user, call grid_create_grid, then re-call grid_pull.",
773
+ structured: { needs_grid_create: true },
774
+ };
775
+ }
727
776
  // No push access → not an error to throw; tell the user their options.
728
777
  if (res.status === 403 || code === "NOT_ALLOWLISTED" || code === "PICKUP_DISABLED" || code === "FORBIDDEN_ROLE") {
729
778
  return {
@@ -735,7 +784,13 @@ export async function runPull(ctx, { claim_token, claim_url, entity_id }) {
735
784
  structured: { can_edit: false, owner_is_you: false, access: "view_only" },
736
785
  };
737
786
  }
738
- const msg = data?.error?.message || data?.message || raw || `HTTP ${res.status}`;
787
+ let msg = data?.error?.message || data?.message || raw || `HTTP ${res.status}`;
788
+ // The API's "Set the X-CloudGrid-Grid header" error is unactionable for an
789
+ // MCP client (no client can set HTTP headers on a tool call). Rewrite it to
790
+ // name the tool parameter the caller CAN set (#247).
791
+ if (res.status === 400 && /X-CloudGrid-Grid/i.test(msg)) {
792
+ msg = "You belong to more than one grid. Pass the `grid` parameter to specify which grid to use.";
793
+ }
739
794
  throw new Error(`Pull failed (HTTP ${res.status}): ${msg}`);
740
795
  }
741
796
 
@@ -1277,7 +1332,7 @@ export function errorGuidance({ status, code, edition, isEdit, isAnon, signedIn
1277
1332
  // internally with a bounded budget; this guidance is the budget-exhausted tail,
1278
1333
  // so the wording tells the agent to wait and re-call rather than surface a raw
1279
1334
  // code. (Issue #235.)
1280
- if (status === 409 && code === "ORG_PROVISIONING") {
1335
+ if (status === 409 && isProvisioningCode(code)) {
1281
1336
  return "The grid is still finishing setup — a brand-new grid provisions its infrastructure in the background (usually within ~30s). Wait ~15s and call grid_plug again with the SAME parameters; it deploys once the grid is ready. Do not switch to anonymous and do not send the user to the console.";
1282
1337
  }
1283
1338
  // 409 EDIT_REJECTED — an in-place re-plug the server won't take.
@@ -1297,7 +1352,7 @@ export function errorGuidance({ status, code, edition, isEdit, isAnon, signedIn
1297
1352
  if (code === "NO_ACTIVE_ORG") {
1298
1353
  return "The account has no grid yet. Do not send the user to the console — create one from here: suggest a short slug, confirm it with the user, call grid_create_grid, then re-call grid_plug with grid: <slug>.";
1299
1354
  }
1300
- return "You lack the role to plug this target. To re-plug someone else's entity, pull it first (grid_pull), or make your own copy (grid_pickup).";
1355
+ return "You lack the role to plug this target. To get push access to the SAME entity, use `grid_collab` — it grants permission only and fetches nothing, so run `grid_pull` again once it is granted (if the owner gates access, it becomes a request they approve). To make your own separate copy (a fork), use `grid_pickup`.";
1301
1356
  }
1302
1357
  // ── Consent-gated report offer (Task 34) ──────────────────────────────────
1303
1358
  // GENUINE bugs only: a build/deploy failure, any 5xx, INTERNAL_ERROR, or an
@@ -1754,7 +1809,7 @@ export async function runPlug(ctx, input, deps = {}) {
1754
1809
  for (;;) {
1755
1810
  ({ res, raw, data } = await sendPlug());
1756
1811
  if (res.ok) break;
1757
- if (res.status === 409 && data?.error?.code === "ORG_PROVISIONING") {
1812
+ if (res.status === 409 && isProvisioningCode(data?.error?.code)) {
1758
1813
  const hint = data?.error?.details?.[0]?.hint || "";
1759
1814
  // Terminal failure — provisioning did not complete; retrying is futile.
1760
1815
  if (/did not (complete|finish)/i.test(hint)) {
@@ -176,6 +176,7 @@ export function registerTools(server, ctx) {
176
176
  description: "Pull an app to continue/edit it IN PLACE — like `git clone` of the SAME entity: your next grid_plug (with its target_entity_id) updates that entity, and the team sees the new version. Requires PUSH ACCESS: you must own it or be a collaborator. If you can only view it, you CANNOT edit or plug it — say so, and offer the two real options: (1) make your own separate copy (a fork) with grid_pickup, or (2) GET push access to the SAME entity with grid_collab (or the CLI `grid collab <entity>`) — \"collab\" is a distinct access-control operation that grants permission only and fetches nothing, so once it is granted you run grid_pull again to get the code (and if the owner gates access, grid_collab becomes a request they approve). Passing an anonymous drop's `claim_token` claims it into your account. Requires sign-in. Calls the API directly (both editions).",
177
177
  inputSchema: {
178
178
  entity_id: z.string().optional().describe("The entity id to pull. Defaults to this session's last anonymous drop."),
179
+ grid: z.string().optional().describe("Grid to resolve a bare slug in. Required only when you belong to more than one grid."),
179
180
  claim_token: z.string().optional().describe("Anonymous drop only: its owner token — claims that drop into your account (ownership transfer)."),
180
181
  claim_url: z.string().optional().describe("Alternative to claim_token for an anonymous drop — the claim_url; the token is read from it."),
181
182
  },
@@ -186,6 +187,9 @@ export function registerTools(server, ctx) {
186
187
  url: z.string().optional().describe("Its public URL."),
187
188
  owner_is_you: z.boolean().optional().describe("True if you own it."),
188
189
  can_edit: z.boolean().optional().describe("True if you can plug/update it (owner or collaborator). False = view-only."),
190
+ access: z.string().optional().describe("Access level when can_edit is false (e.g. 'view_only')."),
191
+ error: z.object({ code: z.string() }).optional().describe("Error envelope when the grid slug is wrong or inaccessible. code is the server error code (e.g. ORG_NOT_ACCESSIBLE)."),
192
+ needs_grid_create: z.boolean().optional().describe("True when the account has no grid yet — route to grid_create_grid before retrying."),
189
193
  },
190
194
  annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
191
195
  },
@@ -448,6 +452,7 @@ export function registerTools(server, ctx) {
448
452
  is_active: z.boolean(),
449
453
  })).optional().describe("Alias of grids (legacy picker alias)."),
450
454
  via: z.string().optional().describe("Recovery marker: 'cli-fallback' when a signed-in create was published through the bundled CloudGrid CLI."),
455
+ needs_grid_create: z.boolean().optional().describe("Zero-grid ask: the account has no grid yet — suggest a slug, confirm with the user, call grid_create_grid, then re-call grid_plug with grid: <slug>."),
451
456
  },
452
457
  // destructiveHint (M3): a re-plug with target_entity_id REPLACES what is
453
458
  // live at a public URL in place. Versions + grid rollback exist, but the