@cloudgrid-io/mcp 0.20.55 → 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/README.md +2 -1
- package/package.json +7 -3
- package/src/corpus/cli-reference.md +1 -1
- package/src/corpus/playbook.md +1 -1
- package/src/corpus/rules/publish-fallbacks.md +2 -2
- package/src/corpus/templates/semantic-search/services/backend/requirements.txt +1 -1
- package/src/corpus/templates/semantic-search/services/refresh/requirements.txt +1 -1
- package/src/corpus/troubleshooting/deploy-errors.md +1 -1
- package/src/tools/deploy.js +221 -11
- package/src/tools/register.js +47 -6
- package/src/tools.js +1 -0
package/README.md
CHANGED
|
@@ -84,7 +84,7 @@ posted). `CLOUDGRID_QA_IDLE_MS` overrides the abandoned-idle window (default
|
|
|
84
84
|
<!-- gen:tools -->
|
|
85
85
|
## Tools
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
37 tools registered (15 shared across both editions, 22 local-only). No deprecated aliases. MIN_CLI_VERSION: 0.15.26.
|
|
88
88
|
|
|
89
89
|
### Direct-API tools (both editions)
|
|
90
90
|
|
|
@@ -92,6 +92,7 @@ posted). `CLOUDGRID_QA_IDLE_MS` overrides the abandoned-idle window (default
|
|
|
92
92
|
|---|---|---|
|
|
93
93
|
| `grid_pickup` | API | Pick up an app: make your OWN COPY of any app you can see (like a git fork) into a grid you can build in. |
|
|
94
94
|
| `grid_pull` | API | Pull an app to continue/edit it IN PLACE — like `git clone` of the SAME entity: your next grid_plug (with its target_... |
|
|
95
|
+
| `grid_collab` | API | Collab: GET PUSH ACCESS to the SAME live entity that someone else owns — you become a collaborator on THAT entity, no... |
|
|
95
96
|
| `grid_create_grid` | API | Create a new grid (workspace) for the signed-in user — they become its admin. |
|
|
96
97
|
| `grid_note` | API | Optionally leave a one-paragraph summary of what you built this session and why. |
|
|
97
98
|
| `grid_plug` | API | Plug an app, website, game, or single HTML page into CloudGrid — the live runtime that runs it and provides its infra... |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudgrid-io/mcp",
|
|
3
|
-
"version": "0.
|
|
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": ">=
|
|
13
|
+
"node": ">=22.19"
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"start": "node src/index.js",
|
|
@@ -59,7 +59,11 @@
|
|
|
59
59
|
"test:system-ca": "node test/system-ca.test.mjs",
|
|
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
|
-
"test:verb-distinction": "node test/verb-distinction.test.mjs"
|
|
62
|
+
"test:verb-distinction": "node test/verb-distinction.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"
|
|
63
67
|
},
|
|
64
68
|
"dependencies": {
|
|
65
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
|
-
| `
|
|
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) |
|
package/src/corpus/playbook.md
CHANGED
|
@@ -39,7 +39,7 @@ Operating rules:
|
|
|
39
39
|
15. Editing an existing thing from just its URL (a fresh chat, no prior context — e.g. "change the background to green here <url>"): call grid_get_app_source(url) first. It resolves the entity_id and returns the current HTML plus its kind, single_html, capabilities, and replug_handle — read those to pick the branch:
|
|
40
40
|
- Single-HTML inspiration you can re-plug (single_html: true and capabilities.replug: true): edit the returned HTML and call grid_plug with target_entity_id (or grid+slug — the replug_handle) to update the SAME URL in place. This works on every edition, including hosted.
|
|
41
41
|
- Multi-file app or agent (kind is app or agent, or single_html: false): do NOT try to edit it as one inline HTML file. Tell the user it is a multi-file <kind>, give them the entity_id and the source (source_download_url), and explain that rebuilding it needs the local edition (Claude Desktop/Code) or the CLI — the hosted server cannot rebuild a multi-file app.
|
|
42
|
-
- Not yours (capabilities.replug: false, reason not_owner): do NOT attempt a re-plug.
|
|
42
|
+
- Not yours (capabilities.replug: false, reason not_owner): do NOT attempt a re-plug. If the user wants their OWN copy, offer to fork it into their grid with grid_pickup and edit the copy. If the user wants to COLLABORATE on the SAME entity, use grid_collab. Three distinct verbs, do not conflate them: grid_pickup = make your OWN COPY (a fork, a NEW entity); grid_pull = continue the SAME entity in place (needs push access — you own it or are a collaborator); grid_collab = GET push access to that same entity (grants permission only and fetches nothing — run grid_pull afterwards to get the code, and if the owner gates access grid_collab sends them a request to approve). So if the user asks to "collab", do NOT call grid_pickup; call grid_collab — distinct from pickup's fork.
|
|
43
43
|
16. Help CloudGrid QA. When you plug, fill BOTH of grid_plug's user_request (a brief version of the user's ask) AND session_note (one short paragraph on what you built and why) — include both by default; omit only if the user objects. A successful plug posts the QA log on that same call, so do NOT call grid_note after plugging — session_note is the narrative path. Use grid_note only BEFORE a plug, or in a session that ends without one. Everything here is recorded for quality review and never changes the plug.
|
|
44
44
|
17. Auth check before an owned plug, with a guest fallback — ALWAYS ask first. grid_start reports signed_in. If the user wants to publish and is NOT signed in (or the plug returns a create-time 401), do NOT silently fail, do NOT invent an auth flow, and NEVER pass anon: true on your own — ask them plainly: "Sign in and plug it to your grid, or plug it as a guest right now (live immediately at a guest link that expires in 7 days unless claimed)?" Only if they choose guest, re-call grid_plug with anon: true and surface the claim_url + owner_token. grid_plug enforces this server-side: the first unauthenticated create in a session returns needs_auth (the ask) even when anon: true was passed — relay it to the user and stop; do not answer it yourself. This is distinct from rule 7: rule 7 forbids the anon fallback on a SERVER error (5xx) for a signed-in user (it burns quota and downgrades ownership); THIS rule is about not being authenticated at all, where guest is a legitimate choice the USER makes.
|
|
45
45
|
18. Using the CLI (runtime apps, `grid dev`, or any shell step): the verb is `grid`, but ALWAYS invoke it as `npx -y @cloudgrid-io/cli@latest <command>` — never a bare `grid` or `cloudgrid`. A `grid` already on the machine is usually a stale global that the API rejects on its version floor, so a bare command fails with a version error and wastes turns; `npx …@latest` needs no install and is always current. In a local edition, prefer the MCP `grid_*` tools — they resolve a current CLI for you — and drop to `npx …@latest` only for shell-only steps like `grid dev`.
|
|
@@ -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
|
|
@@ -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. |
|
package/src/tools/deploy.js
CHANGED
|
@@ -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
|
|
@@ -635,10 +658,10 @@ export async function runReport(
|
|
|
635
658
|
// Like `git clone` of the SAME entity: your next grid_plug (target_entity_id)
|
|
636
659
|
// updates it. Needs push access — you must OWN it or be a COLLABORATOR. A
|
|
637
660
|
// view-only caller is told they can't edit/plug it (fork a copy with grid_pickup,
|
|
638
|
-
// or GET collaborator push access with
|
|
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
|
-
|
|
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,18 +750,47 @@ 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 {
|
|
730
779
|
text:
|
|
731
780
|
`You don't have push access to this entity, so you can't edit or plug it. Two options: ` +
|
|
732
781
|
`make your own separate copy (a fork) with grid_pickup, or GET collaborator push access to the SAME ` +
|
|
733
|
-
`entity with the CLI \`grid collab <entity>\` — that grants permission only and fetches nothing, so ` +
|
|
734
|
-
`pull again once it is granted (if the owner gates access,
|
|
782
|
+
`entity with grid_collab (the CLI equivalent is \`grid collab <entity>\`) — that grants permission only and fetches nothing, so ` +
|
|
783
|
+
`pull again once it is granted (if the owner gates access, grid_collab becomes a request they approve).`,
|
|
735
784
|
structured: { can_edit: false, owner_is_you: false, access: "view_only" },
|
|
736
785
|
};
|
|
737
786
|
}
|
|
738
|
-
|
|
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
|
|
|
@@ -758,7 +813,7 @@ export async function runPull(ctx, { claim_token, claim_url, entity_id }) {
|
|
|
758
813
|
head = `You have collaborator push access to ${slug}${where} — your next grid_plug (target_entity_id) updates the SHARED entity; the team sees the new version and can roll it back.`;
|
|
759
814
|
canEdit = true;
|
|
760
815
|
} else {
|
|
761
|
-
head = `You can view ${slug}${where} but do NOT have push access — you can't edit or plug it. Make your own separate copy (a fork) with grid_pickup, or GET collaborator push access to the SAME entity with
|
|
816
|
+
head = `You can view ${slug}${where} but do NOT have push access — you can't edit or plug it. Make your own separate copy (a fork) with grid_pickup, or GET collaborator push access to the SAME entity with grid_collab (CLI equivalent: \`grid collab ${slug}\`) — it grants permission only and fetches nothing, so pull again once granted.`;
|
|
762
817
|
canEdit = false;
|
|
763
818
|
}
|
|
764
819
|
const lines = [head];
|
|
@@ -780,6 +835,161 @@ export async function runPull(ctx, { claim_token, claim_url, entity_id }) {
|
|
|
780
835
|
}
|
|
781
836
|
|
|
782
837
|
|
|
838
|
+
// grid_collab — GET PUSH ACCESS to the SAME live entity you do NOT own (issue
|
|
839
|
+
// #253). This is the third adopt/access verb, distinct from the other two:
|
|
840
|
+
// grid_pickup = make your OWN COPY (a fork: new entity, forked_from lineage)
|
|
841
|
+
// grid_pull = continue an entity you ALREADY have access to (fetch the code)
|
|
842
|
+
// grid_collab = grant yourself push access to someone else's SAME entity
|
|
843
|
+
// (permission only — fetches nothing; run grid_pull afterwards)
|
|
844
|
+
//
|
|
845
|
+
// Mirrors the CLI reference (packages/cli/src/commands/collab.ts). It records the
|
|
846
|
+
// grant server-side via the CANONICAL join path POST /api/v2/entities/:id/collab
|
|
847
|
+
// — the SAME entity, NOT a fork. The fork route is POST /runtimes/:id/remix
|
|
848
|
+
// (runPickup); collab never touches it, so a collab can never silently become a
|
|
849
|
+
// pickup (the #242 defect). On a POLICY denial (NOT_ALLOWLISTED / PICKUP_DISABLED
|
|
850
|
+
// — the owner gated who may join) it does NOT dead-end on the 403: it turns the
|
|
851
|
+
// denial into a REQUEST the owner approves, via POST /:id/collab-requests, exactly
|
|
852
|
+
// as the CLI does (collab.ts:129). Other 403s (NOT_A_GRID_MEMBER / FORBIDDEN_ROLE)
|
|
853
|
+
// are grid-boundary problems, not policy denials, so they are surfaced, never
|
|
854
|
+
// converted to a request. Pure authenticated API calls, no CLI or filesystem —
|
|
855
|
+
// so, like grid_pickup / grid_pull, it ships on BOTH editions.
|
|
856
|
+
export async function runCollab(ctx, { entity_id, grid } = {}) {
|
|
857
|
+
const token = await ctx.getToken();
|
|
858
|
+
if (!token) {
|
|
859
|
+
throw new Error("You are not signed in. Run grid_login first, then collab.");
|
|
860
|
+
}
|
|
861
|
+
const target = entity_id;
|
|
862
|
+
if (!target) {
|
|
863
|
+
throw new Error("`entity_id` is required (a canonical UUID or <grid-slug>/<entity-slug>).");
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
const orgSlug = grid || (await ctx.getActiveGrid());
|
|
867
|
+
const headers = {
|
|
868
|
+
Authorization: `Bearer ${token}`,
|
|
869
|
+
"Content-Type": "application/json",
|
|
870
|
+
};
|
|
871
|
+
if (orgSlug) {
|
|
872
|
+
// Grid-native header + X-CloudGrid-Org alias (same slug) during the soak, so
|
|
873
|
+
// a bare-slug target resolves in the intended grid (mirrors runPull).
|
|
874
|
+
headers["X-CloudGrid-Grid"] = orgSlug;
|
|
875
|
+
headers["X-CloudGrid-Org"] = orgSlug;
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
const collabUrl = `${API_BASE}/api/v2/entities/${encodeURIComponent(target)}/collab`;
|
|
879
|
+
let res;
|
|
880
|
+
try {
|
|
881
|
+
res = await fetch(collabUrl, { method: "POST", headers, body: JSON.stringify({}) });
|
|
882
|
+
} catch (err) {
|
|
883
|
+
throw new Error(`Could not reach CloudGrid at ${API_BASE}: ${err.message}`);
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
const raw = await res.text();
|
|
887
|
+
let data = null;
|
|
888
|
+
try { data = JSON.parse(raw); } catch { /* handled below */ }
|
|
889
|
+
|
|
890
|
+
if (!res.ok) {
|
|
891
|
+
const code = data?.error?.code || null;
|
|
892
|
+
// ── Policy denial → REQUEST ACCESS (the whole point of the tool). Scoped to
|
|
893
|
+
// the two policy codes ONLY: a grid-boundary 403 (NOT_A_GRID_MEMBER /
|
|
894
|
+
// FORBIDDEN_ROLE) is a different problem and must NOT spam the owner. ──────
|
|
895
|
+
if (res.status === 403 && (code === "NOT_ALLOWLISTED" || code === "PICKUP_DISABLED")) {
|
|
896
|
+
return await requestCollabAccess(ctx, target, headers);
|
|
897
|
+
}
|
|
898
|
+
if (res.status === 404 || code === "RUNTIME_NOT_FOUND" || code === "NOT_FOUND" || (typeof code === "string" && code.endsWith("_NOT_FOUND"))) {
|
|
899
|
+
throw new Error(`No entity matched '${target}'. Check the id or grid/slug (a canonical UUID or <grid-slug>/<entity-slug>).`);
|
|
900
|
+
}
|
|
901
|
+
if (res.status === 403 && code === "NOT_A_GRID_MEMBER") {
|
|
902
|
+
throw new Error(data?.error?.message || `You're not a member of the grid that owns '${target}'. Ask its owner to invite you to the grid first, then collab.`);
|
|
903
|
+
}
|
|
904
|
+
if (res.status === 403 && code === "FORBIDDEN_ROLE") {
|
|
905
|
+
throw new Error(data?.error?.message || `Collaborating on '${target}' needs builder or admin role in its grid.`);
|
|
906
|
+
}
|
|
907
|
+
if (res.status === 400 && code === "NOT_A_RUNTIME") {
|
|
908
|
+
throw new Error(data?.error?.message || `'${target}' is an Inspiration, not an app or agent — it has no collaborators. Fork it with grid_pickup instead.`);
|
|
909
|
+
}
|
|
910
|
+
const msg = data?.error?.message || data?.message || raw || `HTTP ${res.status}`;
|
|
911
|
+
throw new Error(`Collab failed (HTTP ${res.status}): ${msg}`);
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// ── Grant recorded on the SAME entity (permission only — no code fetched) ────
|
|
915
|
+
// Interpret the unified §4 pickup contract, exactly as runPull does, but frame
|
|
916
|
+
// it as an access grant and point at grid_pull for the code (founder split
|
|
917
|
+
// 2026-07-23: collab = permission, pull = code).
|
|
918
|
+
const slug = data?.slug || target;
|
|
919
|
+
const where = data?.grid ? ` in ${data.grid}` : "";
|
|
920
|
+
const ownerIsYou = data?.owner?.is_you === true;
|
|
921
|
+
const canReplug = data?.capabilities?.replug === true;
|
|
922
|
+
let head, canEdit;
|
|
923
|
+
if (ownerIsYou) {
|
|
924
|
+
head = `${slug}${where} is yours — nothing to grant. Use grid_pull to get the code, then grid_plug (target_entity_id) to update it.`;
|
|
925
|
+
canEdit = true;
|
|
926
|
+
} else if (canReplug) {
|
|
927
|
+
head = `You're now a collaborator on ${slug}${where} — you have PUSH ACCESS to the SAME entity (not a copy). This granted permission only; use grid_pull to get the code, then grid_plug (target_entity_id) updates the shared entity — the team sees the new version and can roll it back.`;
|
|
928
|
+
canEdit = true;
|
|
929
|
+
} else {
|
|
930
|
+
head = `You can view ${slug}${where}, but the grant did not give you push access. Make your own separate copy (a fork) with grid_pickup instead.`;
|
|
931
|
+
canEdit = false;
|
|
932
|
+
}
|
|
933
|
+
const lines = [head];
|
|
934
|
+
if (data?.url) lines.push(`URL: ${data.url}`);
|
|
935
|
+
return {
|
|
936
|
+
text: lines.join("\n"),
|
|
937
|
+
structured: {
|
|
938
|
+
...(data?.entity_id ? { entity_id: data.entity_id } : {}),
|
|
939
|
+
...(slug ? { slug } : {}),
|
|
940
|
+
grid: data?.grid ?? null,
|
|
941
|
+
...(data?.url ? { url: data.url } : {}),
|
|
942
|
+
owner_is_you: ownerIsYou,
|
|
943
|
+
can_edit: canEdit,
|
|
944
|
+
access_requested: false,
|
|
945
|
+
request_pending: false,
|
|
946
|
+
},
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
// Turn a policy 403 into a request: POST /:id/collab-requests and tell the user
|
|
951
|
+
// what happens next (mirrors CLI collab-requests.ts requestCollabAccess). A
|
|
952
|
+
// request IS a success outcome, so this returns a normal result, never throws for
|
|
953
|
+
// the expected 409s (a pending ask, or an access race the owner just opened).
|
|
954
|
+
async function requestCollabAccess(ctx, target, headers) {
|
|
955
|
+
const url = `${API_BASE}/api/v2/entities/${encodeURIComponent(target)}/collab-requests`;
|
|
956
|
+
let res;
|
|
957
|
+
try {
|
|
958
|
+
res = await fetch(url, { method: "POST", headers, body: JSON.stringify({}) });
|
|
959
|
+
} catch (err) {
|
|
960
|
+
throw new Error(`Could not reach CloudGrid at ${API_BASE}: ${err.message}`);
|
|
961
|
+
}
|
|
962
|
+
const raw = await res.text();
|
|
963
|
+
let data = null;
|
|
964
|
+
try { data = JSON.parse(raw); } catch { /* handled below */ }
|
|
965
|
+
const code = data?.error?.code || null;
|
|
966
|
+
|
|
967
|
+
if (res.ok) {
|
|
968
|
+
return {
|
|
969
|
+
text:
|
|
970
|
+
`The owner gates who can collaborate on '${target}', so I asked them for push access on your behalf. ` +
|
|
971
|
+
`They've been notified — once they approve, run grid_collab again to join, then grid_pull to get the code.`,
|
|
972
|
+
structured: { access_requested: true, request_pending: true, owner_is_you: false, can_edit: false },
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
if (res.status === 409 && code === "COLLAB_REQUEST_EXISTS") {
|
|
976
|
+
return {
|
|
977
|
+
text: `You already asked for access to '${target}'. The owner hasn't decided yet — you'll be able to join once they approve.`,
|
|
978
|
+
structured: { access_requested: true, request_pending: true, owner_is_you: false, can_edit: false },
|
|
979
|
+
};
|
|
980
|
+
}
|
|
981
|
+
if (res.status === 409 && code === "COLLAB_ALREADY_ALLOWED") {
|
|
982
|
+
// Race: the owner opened access between the join 403 and this request.
|
|
983
|
+
return {
|
|
984
|
+
text: `You already have access to '${target}'. Run grid_collab again to join, then grid_pull to get the code.`,
|
|
985
|
+
structured: { access_requested: false, request_pending: false, owner_is_you: false, can_edit: false },
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
const msg = data?.error?.message || data?.message || raw || `HTTP ${res.status}`;
|
|
989
|
+
throw new Error(`Couldn't request access to '${target}' (HTTP ${res.status}): ${msg}`);
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
|
|
783
993
|
// ── grid_plug — the unified create/re-plug verb (spec v2 §3) ──────────────
|
|
784
994
|
|
|
785
995
|
// Total upload budget mirrors the server's multipart cap (100 MB).
|
|
@@ -1122,7 +1332,7 @@ export function errorGuidance({ status, code, edition, isEdit, isAnon, signedIn
|
|
|
1122
1332
|
// internally with a bounded budget; this guidance is the budget-exhausted tail,
|
|
1123
1333
|
// so the wording tells the agent to wait and re-call rather than surface a raw
|
|
1124
1334
|
// code. (Issue #235.)
|
|
1125
|
-
if (status === 409 && code
|
|
1335
|
+
if (status === 409 && isProvisioningCode(code)) {
|
|
1126
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.";
|
|
1127
1337
|
}
|
|
1128
1338
|
// 409 EDIT_REJECTED — an in-place re-plug the server won't take.
|
|
@@ -1142,7 +1352,7 @@ export function errorGuidance({ status, code, edition, isEdit, isAnon, signedIn
|
|
|
1142
1352
|
if (code === "NO_ACTIVE_ORG") {
|
|
1143
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>.";
|
|
1144
1354
|
}
|
|
1145
|
-
return "You lack the role to plug this target. To
|
|
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`.";
|
|
1146
1356
|
}
|
|
1147
1357
|
// ── Consent-gated report offer (Task 34) ──────────────────────────────────
|
|
1148
1358
|
// GENUINE bugs only: a build/deploy failure, any 5xx, INTERNAL_ERROR, or an
|
|
@@ -1599,7 +1809,7 @@ export async function runPlug(ctx, input, deps = {}) {
|
|
|
1599
1809
|
for (;;) {
|
|
1600
1810
|
({ res, raw, data } = await sendPlug());
|
|
1601
1811
|
if (res.ok) break;
|
|
1602
|
-
if (res.status === 409 && data?.error?.code
|
|
1812
|
+
if (res.status === 409 && isProvisioningCode(data?.error?.code)) {
|
|
1603
1813
|
const hint = data?.error?.details?.[0]?.hint || "";
|
|
1604
1814
|
// Terminal failure — provisioning did not complete; retrying is futile.
|
|
1605
1815
|
if (/did not (complete|finish)/i.test(hint)) {
|
package/src/tools/register.js
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
detectSourceManifest,
|
|
22
22
|
runReport,
|
|
23
23
|
runPull,
|
|
24
|
+
runCollab,
|
|
24
25
|
runPlug,
|
|
25
26
|
runPickup,
|
|
26
27
|
runCreateGrid,
|
|
@@ -132,7 +133,7 @@ export function registerTools(server, ctx) {
|
|
|
132
133
|
"grid_pickup",
|
|
133
134
|
{
|
|
134
135
|
title: "Copy an app into your grid",
|
|
135
|
-
description: "Pick up an app: make your OWN COPY of any app you can see (like a git fork) into a grid you can build in. It mints a NEW entity with lineage back to the source and WITHOUT the source's secrets (set your own before you plug). Plugging your copy creates/updates YOUR entity — the original is never touched. Requires sign-in. This is a FORK, not a \"collab\": it never grants you access to anyone else's live entity. Getting PUSH ACCESS to the SAME entity is a different operation — the CLI
|
|
136
|
+
description: "Pick up an app: make your OWN COPY of any app you can see (like a git fork) into a grid you can build in. It mints a NEW entity with lineage back to the source and WITHOUT the source's secrets (set your own before you plug). Plugging your copy creates/updates YOUR entity — the original is never touched. Requires sign-in. This is a FORK, not a \"collab\": it never grants you access to anyone else's live entity. Getting PUSH ACCESS to the SAME entity is a different operation — the grid_collab tool (or the CLI `grid collab <entity>`) — so do NOT reach for grid_pickup when the user asks to collab; reach for grid_collab. To edit the ORIGINAL entity in place (as its owner or a collaborator), use grid_pull instead.",
|
|
136
137
|
inputSchema: {
|
|
137
138
|
entity_id: z.string().describe("The source app to copy: a canonical UUID or <grid-slug>/<entity-slug>."),
|
|
138
139
|
grid: z.string().optional().describe("Grid to create your copy in. Required only when you belong to more than one grid."),
|
|
@@ -172,9 +173,10 @@ export function registerTools(server, ctx) {
|
|
|
172
173
|
"grid_pull",
|
|
173
174
|
{
|
|
174
175
|
title: "Pull an app to edit in place",
|
|
175
|
-
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 the CLI
|
|
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).",
|
|
176
177
|
inputSchema: {
|
|
177
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."),
|
|
178
180
|
claim_token: z.string().optional().describe("Anonymous drop only: its owner token — claims that drop into your account (ownership transfer)."),
|
|
179
181
|
claim_url: z.string().optional().describe("Alternative to claim_token for an anonymous drop — the claim_url; the token is read from it."),
|
|
180
182
|
},
|
|
@@ -185,6 +187,9 @@ export function registerTools(server, ctx) {
|
|
|
185
187
|
url: z.string().optional().describe("Its public URL."),
|
|
186
188
|
owner_is_you: z.boolean().optional().describe("True if you own it."),
|
|
187
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."),
|
|
188
193
|
},
|
|
189
194
|
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
|
|
190
195
|
},
|
|
@@ -197,6 +202,42 @@ export function registerTools(server, ctx) {
|
|
|
197
202
|
},
|
|
198
203
|
);
|
|
199
204
|
|
|
205
|
+
// grid_collab — GET PUSH ACCESS to the SAME live entity you do NOT own (#253).
|
|
206
|
+
// The THIRD adopt/access verb, distinct from grid_pickup (fork) and grid_pull
|
|
207
|
+
// (continue). Pure API (POST /entities/:id/collab; a policy 403 → a request via
|
|
208
|
+
// POST /:id/collab-requests), no CLI or filesystem — so it ships on BOTH
|
|
209
|
+
// editions, exactly like grid_pickup/grid_pull. Registered BEFORE the
|
|
210
|
+
// edition!=="local" gate for that reason.
|
|
211
|
+
reg(
|
|
212
|
+
"grid_collab",
|
|
213
|
+
{
|
|
214
|
+
title: "Get push access to an app you don't own",
|
|
215
|
+
description: "Collab: GET PUSH ACCESS to the SAME live entity that someone else owns — you become a collaborator on THAT entity, not a copy. This grants PERMISSION ONLY and fetches nothing: after it succeeds, run grid_pull to get the code, then grid_plug (with its target_entity_id) updates the SHARED entity in place (the team sees the new version and can roll it back). This is NOT a fork — it never mints a new entity and never carries forked_from lineage; if you want your OWN separate copy instead, that is grid_pickup. If the owner GATES who may join, this does NOT dead-end: it sends the owner a request for access on your behalf, and once they approve you run grid_collab again to join. Use this — not grid_pickup — whenever the user asks to \"collab\" on, \"join\", or \"get push/write access to\" an app they don't own. Requires sign-in. Calls the API directly (both editions).",
|
|
216
|
+
inputSchema: {
|
|
217
|
+
entity_id: z.string().describe("The app to get push access to: a canonical UUID or <grid-slug>/<entity-slug>."),
|
|
218
|
+
grid: z.string().optional().describe("Grid to resolve a bare slug in. Required only when a bare slug is ambiguous across grids you belong to."),
|
|
219
|
+
},
|
|
220
|
+
outputSchema: {
|
|
221
|
+
entity_id: z.string().optional().describe("The SAME entity you now collaborate on — pass it to grid_pull, then to grid_plug as target_entity_id. Never a new/forked entity."),
|
|
222
|
+
slug: z.string().optional().describe("Its slug."),
|
|
223
|
+
grid: z.string().nullable().optional().describe("Its grid."),
|
|
224
|
+
url: z.string().optional().describe("Its public URL."),
|
|
225
|
+
owner_is_you: z.boolean().optional().describe("True if you already own it (nothing to grant)."),
|
|
226
|
+
can_edit: z.boolean().optional().describe("True once you have push access (owner or collaborator). False = still view-only."),
|
|
227
|
+
access_requested: z.boolean().optional().describe("True when the owner gates access and a request was sent on your behalf."),
|
|
228
|
+
request_pending: z.boolean().optional().describe("True when a request is awaiting the owner's decision — join with grid_collab again once approved."),
|
|
229
|
+
},
|
|
230
|
+
annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: true },
|
|
231
|
+
},
|
|
232
|
+
async (input) => {
|
|
233
|
+
try {
|
|
234
|
+
return okResult(await runCollab(ctx, input || {}));
|
|
235
|
+
} catch (err) {
|
|
236
|
+
return fail(err.message);
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
);
|
|
240
|
+
|
|
200
241
|
// grid_create_grid — create a grid for the signed-in user (POST /api/v2/grids,
|
|
201
242
|
// the same call as the CLI `grid create grid <slug>`). Exists so a first-time
|
|
202
243
|
// user with NO grid is never sent to the console: grid_plug returns
|
|
@@ -411,6 +452,7 @@ export function registerTools(server, ctx) {
|
|
|
411
452
|
is_active: z.boolean(),
|
|
412
453
|
})).optional().describe("Alias of grids (legacy picker alias)."),
|
|
413
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>."),
|
|
414
456
|
},
|
|
415
457
|
// destructiveHint (M3): a re-plug with target_entity_id REPLACES what is
|
|
416
458
|
// live at a public URL in place. Versions + grid rollback exist, but the
|
|
@@ -1206,13 +1248,12 @@ export function registerTools(server, ctx) {
|
|
|
1206
1248
|
// source + cloudgrid.yaml and links the folder, so the next `grid plug` updates
|
|
1207
1249
|
// the SAME entity in place. Wraps `grid pull` (NOT `grid pickup` — pickup now
|
|
1208
1250
|
// makes a separate copy). Push access required; a view-only entity can't be
|
|
1209
|
-
// pulled — use grid_pickup to fork a copy, or
|
|
1210
|
-
//
|
|
1211
|
-
// granted). `grid collab` is CLI-only; there is no grid_collab MCP tool.
|
|
1251
|
+
// pulled — use grid_pickup to fork a copy, or grid_collab to GET push access
|
|
1252
|
+
// to the same entity (grants permission only — pull again once granted).
|
|
1212
1253
|
regTool(
|
|
1213
1254
|
"grid_edit_existing_app",
|
|
1214
1255
|
"Pull app source to edit locally",
|
|
1215
|
-
"Continue/edit an EXISTING entity locally: download its source + cloudgrid.yaml and link the folder so your next `grid plug` updates it IN PLACE. Requires push access (owner or collaborator). Wraps `grid pull`. To make your own separate copy (a fork) instead, use grid_pickup. To GET push access to an entity you can currently only view, that is a different operation —
|
|
1256
|
+
"Continue/edit an EXISTING entity locally: download its source + cloudgrid.yaml and link the folder so your next `grid plug` updates it IN PLACE. Requires push access (owner or collaborator). Wraps `grid pull`. To make your own separate copy (a fork) instead, use grid_pickup. To GET push access to an entity you can currently only view, that is a different operation — grid_collab (CLI equivalent: `grid collab <entity>`), which grants permission only; run the pull again once it is granted.",
|
|
1216
1257
|
{
|
|
1217
1258
|
name: z.string().describe("Entity slug or id to pull."),
|
|
1218
1259
|
target_dir: z.string().optional().describe("Directory to pull into (relative to cwd). Defaults to the entity name."),
|