@cloudgrid-io/mcp 0.11.0 → 0.12.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 +3 -1
- package/src/corpus/capability-map.md +46 -28
- package/src/corpus/cloudgrid-yaml.md +569 -0
- package/src/corpus/examples/ai-app/index.md +237 -0
- package/src/corpus/examples/api-service/index.md +190 -0
- package/src/corpus/examples/app-with-data/index.md +24 -19
- package/src/corpus/templates/ai-app/README.md +95 -0
- package/src/corpus/templates/ai-app/cloudgrid.yaml +20 -0
- package/src/corpus/templates/ai-app/index.md +269 -0
- package/src/corpus/templates/ai-app/services/web/app/api/chat/route.js +51 -0
- package/src/corpus/templates/ai-app/services/web/app/chat.js +60 -0
- package/src/corpus/templates/ai-app/services/web/app/layout.js +36 -0
- package/src/corpus/templates/ai-app/services/web/app/page.js +25 -0
- package/src/corpus/templates/ai-app/services/web/lib/db.js +32 -0
- package/src/corpus/templates/ai-app/services/web/package.json +17 -0
- package/src/corpus/templates/api-service/README.md +87 -0
- package/src/corpus/templates/api-service/cloudgrid.yaml +18 -0
- package/src/corpus/templates/api-service/index.md +225 -0
- package/src/corpus/templates/api-service/services/api/package.json +13 -0
- package/src/corpus/templates/api-service/services/api/src/index.js +132 -0
- package/src/corpus/templates/app-with-data/README.md +22 -19
- package/src/corpus/templates/app-with-data/cloudgrid.yaml +9 -13
- package/src/corpus/templates/app-with-data/index.md +37 -38
- package/src/corpus/templates/app-with-data/services/web/lib/db.js +10 -9
- package/src/corpus/troubleshooting/persistent-apps.md +6 -6
- package/src/corpus/workflows/ai-app.md +136 -0
- package/src/corpus/workflows/api-service.md +118 -0
- package/src/corpus/workflows/app-with-data.md +21 -18
- package/src/tools.js +1 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: persistent-apps
|
|
3
|
-
when: A persistent (Mongo-backed) app misbehaves — data doesn't survive refresh,
|
|
4
|
-
summary: Symptom, cause, and fix for the common app-with-data (runtime Mongo app) problems — in-memory vs persistent, injected MONGODB_URL, async deploys, and the hosted-edition gate.
|
|
3
|
+
when: A persistent (Mongo-backed) app misbehaves — data doesn't survive refresh, DATABASE_MONGODB_URL is undefined, a runtime deploy seems stuck, or it won't build on hosted.
|
|
4
|
+
summary: Symptom, cause, and fix for the common app-with-data (runtime Mongo app) problems — in-memory vs persistent, injected DATABASE_MONGODB_URL (+legacy MONGODB_URL), async deploys, and the hosted-edition gate.
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# Troubleshooting: persistent apps (app-with-data)
|
|
@@ -12,11 +12,11 @@ Match the symptom to the row, apply the fix, and stop.
|
|
|
12
12
|
| --- | --- | --- |
|
|
13
13
|
| Data doesn't persist / resets on refresh | You built a static inspiration (in-memory / localStorage), not a runtime app | Use the `app-with-data` workflow: a real Next.js + Mongo runtime that reads `process.env.MONGODB_URL`. Static templates keep state only in memory. |
|
|
14
14
|
| `Error: Service directory not found: …/services/web` | App code lives at the repo/template root, not under the service folder | App code must live under `services/<name>/` (e.g. `services/web/`). `path:` in `cloudgrid.yaml` is the URL mount, NOT the filesystem path — the service name is the folder the CLI looks for. |
|
|
15
|
-
| `next build` fails /
|
|
16
|
-
| App builds + deploys but every request 500s with `
|
|
17
|
-
| `
|
|
15
|
+
| `next build` fails / DB connection error at build time | The DB env var is read at module top level; `next build` imports the module for route analysis before the grid injects the var | Read `process.env.DATABASE_MONGODB_URL` (with a legacy `MONGODB_URL` fallback) LAZILY inside the getter (e.g. inside `getDb`), never at module load. Moving the check into the function lets the build pass. |
|
|
16
|
+
| App builds + deploys but every request 500s with `DATABASE_MONGODB_URL not set` | The datastore isn't declared, or you declared the deprecated `requires:` instead of `needs:` | Declare `needs: { database: true }` in `cloudgrid.yaml`. The deployer provisions Mongo and injects `DATABASE_MONGODB_URL` (plus the legacy `MONGODB_URL` alias). Never set `needs:` and `requires:` together (the validator rejects it). |
|
|
17
|
+
| `DATABASE_MONGODB_URL is undefined` (or the db.js guard throws) | The env var isn't present because you're not running under the grid | Run locally with `grid dev`, or deploy with `grid plug` — the grid injects `DATABASE_MONGODB_URL` (+legacy `MONGODB_URL`) at dev-time and runtime. Do NOT set it yourself and never hardcode a connection string. |
|
|
18
18
|
| Deploy seems stuck / no URL returned | Runtime deploys are asynchronous | `plug` returns `status: building`, not a URL. Poll `gridctl_status` (or the poll_url) until the app is live, then return the live URL. Don't treat the build/log link as the deliverable. |
|
|
19
19
|
| It won't build on the hosted edition | Hosted MCP is inline-only — it can't run the CLI or folder-plug | Runtime apps need the LOCAL edition (Claude Desktop/Code) or the CLI. On hosted, tell the user persistence isn't available there and offer a static version instead. |
|
|
20
|
-
| Redis not available | `
|
|
20
|
+
| Redis not available | `cache` wasn't declared | Add `cache: true` to `needs:` in `cloudgrid.yaml`; the grid then injects `CACHE_REDIS_URL` (plus the legacy `REDIS_URL` alias). Only add it if the app actually needs Redis. |
|
|
21
21
|
|
|
22
22
|
See the `app-with-data` workflow for the full recipe.
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ai-app
|
|
3
|
+
when: chatbot, AI assistant, Q&A bot, conversational app, support bot, ask-me-anything, an app that talks to an LLM / generates text with AI. Needs AI + a database → runtime → local edition.
|
|
4
|
+
needs: ai, database
|
|
5
|
+
deploy: runtime
|
|
6
|
+
editions: local
|
|
7
|
+
capabilities_note: AI chatbot — needs ai (the grid AI gateway) + a database (Mongo) for chat history. Next.js App Router app. Uses @cloudgrid-io/ai createClient().chat() with zero-config in-grid identity auth (no API key). Runtime app, async build, local edition only. Declare `needs: { ai: true, database: true }`. (RAG over your own docs needs `needs: { vector: pgvector }` — not yet available, platform issue #1545.)
|
|
8
|
+
summary: Build an AI chatbot on the grid — a Next.js app that calls @cloudgrid-io/ai createClient().chat({messages}) (zero-config in-grid auth, no key) and persists the conversation to grid-shared Mongo. Edition-gate first, scaffold, put the app under services/web/, declare needs:{ai:true,database:true}, read DATABASE_MONGODB_URL lazily, deploy async, poll to a live URL.
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Workflow: ai-app
|
|
12
|
+
|
|
13
|
+
The user wants an app that **talks to an LLM** — a chatbot, an AI assistant, a
|
|
14
|
+
Q&A/support bot, an ask-me-anything. It calls the grid's AI gateway to generate
|
|
15
|
+
replies and **remembers the conversation** in the grid-shared Mongo. So it needs
|
|
16
|
+
two capabilities: `ai` (the gateway) and `database` (chat history). That makes it
|
|
17
|
+
a **runtime app**, not a static page.
|
|
18
|
+
|
|
19
|
+
Follow this recipe. Be honest that a runtime deploy is async and needs the local
|
|
20
|
+
edition.
|
|
21
|
+
|
|
22
|
+
## 1. Edition check FIRST (hard gate)
|
|
23
|
+
|
|
24
|
+
An AI chatbot is a built + deployed container. It requires the **local edition**
|
|
25
|
+
(Claude Desktop / Claude Code) or the CLI, because the grid must run the CLI and
|
|
26
|
+
folder-plug your project.
|
|
27
|
+
|
|
28
|
+
- **Hosted edition (Claude Web / hosted MCP):** you CANNOT build a runtime app —
|
|
29
|
+
hosted is inline-only and can only publish static pages. Tell the user plainly:
|
|
30
|
+
"An AI chatbot needs the local edition (Claude Desktop/Code) or the CloudGrid
|
|
31
|
+
CLI; the hosted edition can only publish static pages." STOP the runtime path
|
|
32
|
+
here.
|
|
33
|
+
- **Local edition:** continue.
|
|
34
|
+
|
|
35
|
+
## 2. Auth + grid
|
|
36
|
+
|
|
37
|
+
Persistent apps are owned entities.
|
|
38
|
+
1. Ensure signed in: `gridctl_login_status`; if not, `gridctl_login`.
|
|
39
|
+
2. A grid is required. Respect the grid picker: if the user has more than one
|
|
40
|
+
grid, ask which to use; do not assume a target.
|
|
41
|
+
|
|
42
|
+
## 3. Scaffold
|
|
43
|
+
|
|
44
|
+
`gridctl_init` an app `<name>`. `init` creates the entity + `.cloudgrid/link.json`
|
|
45
|
+
and writes a `cloudgrid.yaml` with an EMPTY `services: {}`. `plug` needs a linked
|
|
46
|
+
directory, so run `init` FIRST.
|
|
47
|
+
|
|
48
|
+
You then do two things: (a) write the app under **`services/web/`**, and (b) fill
|
|
49
|
+
in `cloudgrid.yaml` to the shape below (`services.web` type `nextjs` + `needs: {
|
|
50
|
+
ai: true, database: true }`).
|
|
51
|
+
|
|
52
|
+
## 4. Wire the AI gateway + Mongo
|
|
53
|
+
|
|
54
|
+
1. Set `cloudgrid.yaml` to declare the `web` service and the capabilities it
|
|
55
|
+
needs. **App code MUST live under `services/<name>/`** — `path:` is the URL
|
|
56
|
+
mount, NOT the filesystem path. A service named `web` → the CLI looks for
|
|
57
|
+
`services/web/`; files at the repo root fail with
|
|
58
|
+
`Error: Service directory not found: …/services/web`.
|
|
59
|
+
```yaml
|
|
60
|
+
name: my-chatbot
|
|
61
|
+
services:
|
|
62
|
+
web:
|
|
63
|
+
type: nextjs
|
|
64
|
+
path: /
|
|
65
|
+
needs:
|
|
66
|
+
ai: true
|
|
67
|
+
database: true
|
|
68
|
+
# For retrieval-augmented (RAG) over your own docs, add `needs: { vector:
|
|
69
|
+
# pgvector }` once platform issue #1545 ships — not yet available.
|
|
70
|
+
```
|
|
71
|
+
**Declare `needs: { ai: true, database: true }`** — the canonical shape. The
|
|
72
|
+
deployer wires the AI gateway (in-grid identity) and provisions Mongo,
|
|
73
|
+
injecting `DATABASE_MONGODB_URL` (plus the legacy `MONGODB_URL` alias) at
|
|
74
|
+
dev-time and runtime. `requires:` is the deprecated v1 alias; don't author new
|
|
75
|
+
yaml with it, and never set `needs:` and `requires:` together (the validator
|
|
76
|
+
rejects it).
|
|
77
|
+
2. Fetch the template for the chat wiring:
|
|
78
|
+
`gridctl_fetch("template", "ai-app")`. It is a minimal Next.js App Router chat
|
|
79
|
+
app under `services/web/`: a chat page, an API route
|
|
80
|
+
(`app/api/chat/route.js`, `export const dynamic = "force-dynamic"`) that reads
|
|
81
|
+
the user message, calls the AI gateway, persists the exchange to Mongo, and
|
|
82
|
+
returns the reply.
|
|
83
|
+
3. **Call the AI gateway with `@cloudgrid-io/ai`** — zero config, no API key:
|
|
84
|
+
```js
|
|
85
|
+
import { createClient } from "@cloudgrid-io/ai";
|
|
86
|
+
const client = createClient(); // zero-arg, no key
|
|
87
|
+
const r = await client.chat({ messages: [{ role: "user", content: text }] });
|
|
88
|
+
const reply = r.text ?? r.content; // reply text
|
|
89
|
+
```
|
|
90
|
+
The SDK auto-detects the in-grid identity — **do NOT set an API key.** It only
|
|
91
|
+
works inside a deployed grid app (or under `grid dev`).
|
|
92
|
+
4. **Persist the exchange to Mongo** — read `process.env.DATABASE_MONGODB_URL`
|
|
93
|
+
(falling back to the legacy `process.env.MONGODB_URL`) **lazily inside the
|
|
94
|
+
getter, never at module top level**, or `next build` fails (the module is
|
|
95
|
+
imported for route analysis before the grid injects the var). Store the user
|
|
96
|
+
message and the assistant reply so the conversation survives refresh. Never
|
|
97
|
+
hardcode a connection string; never commit a secret.
|
|
98
|
+
- (Optional) fetch `gridctl_fetch("example", "ai-app")` for a richer filled
|
|
99
|
+
reference (a themed assistant) to imitate.
|
|
100
|
+
|
|
101
|
+
## 5. (Optional) Run locally
|
|
102
|
+
|
|
103
|
+
Mention that the user can `grid dev` to run locally — the AI gateway and Mongo
|
|
104
|
+
are wired in dev too — and send a test message before deploying. Don't require it.
|
|
105
|
+
|
|
106
|
+
## 6. Config
|
|
107
|
+
|
|
108
|
+
- Extra API keys / secrets (only if the app needs its own) → `gridctl_secrets`.
|
|
109
|
+
- Non-secret config → `gridctl_env`.
|
|
110
|
+
- Do **NOT** set the DB connection var yourself (`DATABASE_MONGODB_URL` / legacy
|
|
111
|
+
`MONGODB_URL`) and do **NOT** set an AI key — the grid injects the DB var and
|
|
112
|
+
the AI SDK auto-detects the in-grid identity.
|
|
113
|
+
|
|
114
|
+
## 7. Deploy (async)
|
|
115
|
+
|
|
116
|
+
Deploy the folder with `gridctl_plug`. A **runtime deploy is ASYNC**: the first
|
|
117
|
+
response is `status: "building"` with a `poll_url` / entity, NOT a live URL yet.
|
|
118
|
+
- Poll `gridctl_status` (or the returned poll_url) until the entity is live.
|
|
119
|
+
- Surface a liveness signal while it builds — never a bare silent wait.
|
|
120
|
+
- Only once it is live, return the deployed URL (the app URL, NOT the build/log
|
|
121
|
+
link).
|
|
122
|
+
|
|
123
|
+
## 8. Return the live URL + iterate
|
|
124
|
+
|
|
125
|
+
Give the user the live chatbot URL — that is the deliverable. To iterate, re-plug
|
|
126
|
+
the SAME entity (`target_entity_id`) so it updates the same URL.
|
|
127
|
+
|
|
128
|
+
## Note on RAG / retrieval
|
|
129
|
+
|
|
130
|
+
If the user wants the bot to answer over **their own documents** (retrieval-
|
|
131
|
+
augmented generation), that needs a vector store (`needs: { vector: pgvector }`).
|
|
132
|
+
That path is **not yet available** — platform issue #1545. Ship the plain
|
|
133
|
+
chatbot now; add retrieval once the vector need is unblocked.
|
|
134
|
+
|
|
135
|
+
Keep it honest: async build, local-edition only, AI auth and DB credentials
|
|
136
|
+
provided by the grid.
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: api-service
|
|
3
|
+
when: REST API, backend for X, API endpoint(s), CRUD API, JSON API, webhook receiver, a backend/service that stores data and isn't a full web UI. Needs a database → runtime → local edition.
|
|
4
|
+
needs: database
|
|
5
|
+
deploy: runtime
|
|
6
|
+
editions: local
|
|
7
|
+
capabilities_note: persistent backend service — needs a database (Mongo). A plain Node HTTP service (type: node), not a web UI. Runtime app, async build, local edition only. Declare the canonical `needs: { database: true }`; the deployer injects DATABASE_MONGODB_URL (+legacy MONGODB_URL).
|
|
8
|
+
summary: Build a real REST/JSON API on the grid — a Node HTTP service backed by grid-shared Mongo. Edition-gate first, scaffold, put the service under services/api/, read process.env.DATABASE_MONGODB_URL (legacy MONGODB_URL fallback) lazily, declare needs:{database:true} (not requires:), deploy async, poll to a live URL.
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Workflow: api-service
|
|
12
|
+
|
|
13
|
+
The user wants a **backend API**, not a full web UI — a REST/JSON service with
|
|
14
|
+
endpoints, a resource it stores and returns (a `/items` CRUD API, a webhook
|
|
15
|
+
receiver, a small backend for another app). It **saves data**, so it is a
|
|
16
|
+
**runtime app** backed by the grid's shared Mongo. This is the plain-service
|
|
17
|
+
sibling of `app-with-data`: no Next.js, no pages — just a Node HTTP server
|
|
18
|
+
speaking JSON.
|
|
19
|
+
|
|
20
|
+
Follow this recipe. Be honest that a runtime deploy is async (not instant like a
|
|
21
|
+
static drop) and that it needs the local edition.
|
|
22
|
+
|
|
23
|
+
## 1. Edition check FIRST (hard gate)
|
|
24
|
+
|
|
25
|
+
An API service is a built + deployed container. It requires the **local
|
|
26
|
+
edition** (Claude Desktop / Claude Code) or the CLI, because the grid must run
|
|
27
|
+
the CLI and folder-plug your project.
|
|
28
|
+
|
|
29
|
+
- **Hosted edition (Claude Web / hosted MCP):** you CANNOT build a runtime
|
|
30
|
+
service — hosted is inline-only and can only publish static pages. Tell the
|
|
31
|
+
user plainly: "An API service needs the local edition (Claude Desktop/Code) or
|
|
32
|
+
the CloudGrid CLI; the hosted edition can only publish static pages." STOP the
|
|
33
|
+
runtime path here (there is no useful static fallback for a backend API).
|
|
34
|
+
- **Local edition:** continue.
|
|
35
|
+
|
|
36
|
+
## 2. Auth + grid
|
|
37
|
+
|
|
38
|
+
Persistent services are owned entities.
|
|
39
|
+
1. Ensure signed in: `gridctl_login_status`; if not, `gridctl_login`.
|
|
40
|
+
2. A grid is required. Respect the grid picker: if the user has more than one
|
|
41
|
+
grid, ask which to use; do not assume a target.
|
|
42
|
+
|
|
43
|
+
## 3. Scaffold
|
|
44
|
+
|
|
45
|
+
`gridctl_init` an app `<name>`. `init` creates the entity + `.cloudgrid/link.json`
|
|
46
|
+
and writes a `cloudgrid.yaml` with an EMPTY `services: {}`. `plug` needs a linked
|
|
47
|
+
directory, so run `init` FIRST.
|
|
48
|
+
|
|
49
|
+
You then do two things: (a) write the service under **`services/api/`**, and (b)
|
|
50
|
+
fill in `cloudgrid.yaml` to the shape below (`services.api` type `node` + `needs:
|
|
51
|
+
{ database: true }`).
|
|
52
|
+
|
|
53
|
+
## 4. Add the datastore + wire Mongo
|
|
54
|
+
|
|
55
|
+
1. Set `cloudgrid.yaml` to declare the `api` service and the store it needs.
|
|
56
|
+
**Service code MUST live under `services/<name>/`** — `path:` is the URL
|
|
57
|
+
mount, NOT the filesystem path. A service named `api` → the CLI looks for
|
|
58
|
+
`services/api/`; files at the repo root fail with
|
|
59
|
+
`Error: Service directory not found: …/services/api`.
|
|
60
|
+
```yaml
|
|
61
|
+
name: my-api
|
|
62
|
+
services:
|
|
63
|
+
api:
|
|
64
|
+
type: node
|
|
65
|
+
path: /
|
|
66
|
+
needs:
|
|
67
|
+
database: true
|
|
68
|
+
```
|
|
69
|
+
**Declare the datastore with `needs: { database: true }`** — this is the
|
|
70
|
+
canonical shape. The deployer provisions Mongo and injects
|
|
71
|
+
`DATABASE_MONGODB_URL` (plus the legacy `MONGODB_URL` alias) at dev-time and
|
|
72
|
+
runtime. `requires:` is the deprecated v1 alias; don't author new yaml with
|
|
73
|
+
it, and never set `needs:` and `requires:` together (the validator rejects it).
|
|
74
|
+
2. Fetch the template for the server + Mongo shape:
|
|
75
|
+
`gridctl_fetch("template", "api-service")`. It is a minimal Node `http`
|
|
76
|
+
server under `services/api/`: it listens on `process.env.PORT || 8080` and
|
|
77
|
+
serves a small REST resource (`/items` GET list / POST create / DELETE by id)
|
|
78
|
+
backed by Mongo.
|
|
79
|
+
3. Adapt it to the user's API (rename the resource, change the fields, add
|
|
80
|
+
routes). **Read the database from `process.env.DATABASE_MONGODB_URL`** (falling
|
|
81
|
+
back to the legacy `process.env.MONGODB_URL`) — the grid injects those env
|
|
82
|
+
vars at dev-time and runtime. Never hardcode a connection string; never commit
|
|
83
|
+
a secret.
|
|
84
|
+
- **Read the connection string LAZILY inside the request handler / a getter —
|
|
85
|
+
never at module top level, or node startup crashes** before the grid has
|
|
86
|
+
injected the var.
|
|
87
|
+
- Return clear JSON errors (`{ "error": "…" }`) with the right status codes.
|
|
88
|
+
- (Optional) fetch `gridctl_fetch("example", "api-service")` for a slightly
|
|
89
|
+
richer filled reference to imitate.
|
|
90
|
+
|
|
91
|
+
## 5. (Optional) Run locally
|
|
92
|
+
|
|
93
|
+
Mention that the user can `grid dev` to run locally against the injected Mongo
|
|
94
|
+
and hit the endpoints before deploying. Don't require it.
|
|
95
|
+
|
|
96
|
+
## 6. Config
|
|
97
|
+
|
|
98
|
+
- API keys / secrets → `gridctl_secrets`.
|
|
99
|
+
- Non-secret config → `gridctl_env`.
|
|
100
|
+
- Do **NOT** set the DB connection vars yourself (`DATABASE_MONGODB_URL`, or the
|
|
101
|
+
legacy `MONGODB_URL` alias) — the grid injects them.
|
|
102
|
+
|
|
103
|
+
## 7. Deploy (async)
|
|
104
|
+
|
|
105
|
+
Deploy the folder with `gridctl_plug`. A **runtime deploy is ASYNC**: the first
|
|
106
|
+
response is `status: "building"` with a `poll_url` / entity, NOT a live URL yet.
|
|
107
|
+
- Poll `gridctl_status` (or the returned poll_url) until the entity is live.
|
|
108
|
+
- Surface a liveness signal while it builds — never a bare silent wait.
|
|
109
|
+
- Only once it is live, return the deployed URL (the API base URL, NOT the
|
|
110
|
+
build/log link).
|
|
111
|
+
|
|
112
|
+
## 8. Return the live URL + iterate
|
|
113
|
+
|
|
114
|
+
Give the user the live API URL — that is the deliverable. Point out the endpoints
|
|
115
|
+
(e.g. `GET /items`, `POST /items`). To iterate, re-plug the SAME entity
|
|
116
|
+
(`target_entity_id`) so it updates the same URL.
|
|
117
|
+
|
|
118
|
+
Keep it honest: async build, local-edition only, credentials injected by the grid.
|
|
@@ -4,8 +4,8 @@ when: to-do, task list, notes app, guestbook, CRUD app, form that SAVES/STORES s
|
|
|
4
4
|
needs: database
|
|
5
5
|
deploy: runtime
|
|
6
6
|
editions: local
|
|
7
|
-
capabilities_note: persistent — needs a database (Mongo). Runtime app, async build, local edition only.
|
|
8
|
-
summary: Build a real persistent Next.js + Mongo runtime app on the grid — edition-gate first, scaffold, put the app under services/web/, wire process.env.MONGODB_URL lazily, declare
|
|
7
|
+
capabilities_note: persistent — needs a database (Mongo). Runtime app, async build, local edition only. Declare the canonical `needs: { database: true }`; the deployer injects DATABASE_MONGODB_URL (+legacy MONGODB_URL).
|
|
8
|
+
summary: Build a real persistent Next.js + Mongo runtime app on the grid — edition-gate first, scaffold, put the app under services/web/, wire process.env.DATABASE_MONGODB_URL (legacy MONGODB_URL fallback) lazily, declare needs:{database:true} (not requires:), deploy async, poll to a live URL.
|
|
9
9
|
---
|
|
10
10
|
|
|
11
11
|
# Workflow: app-with-data
|
|
@@ -48,7 +48,7 @@ the entity + `.cloudgrid/link.json` and writes a `cloudgrid.yaml` with an EMPTY
|
|
|
48
48
|
`services: {}`. `plug` needs a linked directory, so run `init` FIRST.
|
|
49
49
|
|
|
50
50
|
You then do two things: (a) write the app under **`services/web/`**, and (b) fill
|
|
51
|
-
in `cloudgrid.yaml` to the shape below (`services.web` + `
|
|
51
|
+
in `cloudgrid.yaml` to the shape below (`services.web` + `needs: { database: true }`).
|
|
52
52
|
|
|
53
53
|
## 4. Add the datastore + wire Mongo
|
|
54
54
|
|
|
@@ -63,27 +63,28 @@ in `cloudgrid.yaml` to the shape below (`services.web` + `requires: [mongodb]`).
|
|
|
63
63
|
web:
|
|
64
64
|
type: nextjs
|
|
65
65
|
path: /
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
#
|
|
66
|
+
needs:
|
|
67
|
+
database: true
|
|
68
|
+
# cache: true # OPTIONAL — add only if the app needs Redis
|
|
69
69
|
```
|
|
70
|
-
**Declare the datastore with `
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
**Declare the datastore with `needs: { database: true }`** — this is the
|
|
71
|
+
canonical shape. The deployer provisions Mongo and injects
|
|
72
|
+
`DATABASE_MONGODB_URL` (plus the legacy `MONGODB_URL` alias) at dev-time and
|
|
73
|
+
runtime. `requires:` is the deprecated v1 alias; don't author new yaml with it,
|
|
74
|
+
and never set `needs:` and `requires:` together (the validator rejects it).
|
|
75
75
|
2. Fetch the template for the Mongo wiring + CRUD shape:
|
|
76
76
|
`gridctl_fetch("template", "app-with-data")`. It is a minimal, real
|
|
77
77
|
Next.js + `mongodb`-driver to-do app under `services/web/`: a lazy client in
|
|
78
78
|
`services/web/lib/db.js`, an App-Router GET/POST/DELETE route on a `todos`
|
|
79
79
|
collection, and a page.
|
|
80
80
|
3. Adapt it to the user's app (rename the collection, change the fields, adjust
|
|
81
|
-
the UI). **Read the database from `process.env.
|
|
82
|
-
|
|
83
|
-
string; never commit a
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
module
|
|
81
|
+
the UI). **Read the database from `process.env.DATABASE_MONGODB_URL`** (falling
|
|
82
|
+
back to the legacy `process.env.MONGODB_URL`) — the grid injects those env vars
|
|
83
|
+
at dev-time and runtime. Never hardcode a connection string; never commit a
|
|
84
|
+
secret.
|
|
85
|
+
- **Put the DB connection behind a lazy getter — never read the connection
|
|
86
|
+
string at module top level, or `next build` fails** (the module is imported
|
|
87
|
+
for route analysis before the grid injects the var).
|
|
87
88
|
- (Optional) fetch `gridctl_fetch("example", "app-with-data")` for a slightly
|
|
88
89
|
richer filled reference to imitate.
|
|
89
90
|
|
|
@@ -96,7 +97,9 @@ and sanity-check before deploying. Don't require it.
|
|
|
96
97
|
|
|
97
98
|
- API keys / secrets → `gridctl_secrets`.
|
|
98
99
|
- Non-secret config → `gridctl_env`.
|
|
99
|
-
- Do **NOT** set
|
|
100
|
+
- Do **NOT** set the DB/cache connection vars yourself (`DATABASE_MONGODB_URL`,
|
|
101
|
+
`CACHE_REDIS_URL`, or their legacy `MONGODB_URL` / `REDIS_URL` aliases) — the
|
|
102
|
+
grid injects them.
|
|
100
103
|
|
|
101
104
|
## 7. Deploy (async)
|
|
102
105
|
|
package/src/tools.js
CHANGED
|
@@ -90,6 +90,7 @@ Operating rules:
|
|
|
90
90
|
10. Publishing a heavy or local file: in the local edition use the path parameter so it is read from disk (no inline size limit); never base64-encode HTML and never pass a file path (or an @-prefixed path) as html. If a drop looks empty, use gridctl_source to check what was actually published, then re-plug with the real HTML/path and target_entity_id.
|
|
91
91
|
11. Persistence check: if the user needs to SAVE data, share state across users/sessions, log in, or store submissions, that's a runtime app-with-data (Mongo-backed), NOT a static page — static templates keep state only in memory and lose it on refresh. Use the app-with-data workflow. This requires the LOCAL edition (Claude Desktop/Code or the CLI); on the hosted edition, tell the user persistence isn't available there and offer a static version.
|
|
92
92
|
12. To choose what to build: match the request against the workflow when: triggers and the capability-map (gridctl_fetch({kind:"doc", name:"capability-map"})). Pick the template whose needs: matches what the app requires (persistence → database; scheduled → cron; etc.). Static (needs: none) deploys as an inspiration (instant, any edition); anything needing needs: is a runtime (async, local edition).
|
|
93
|
+
13. Before writing a cloudgrid.yaml, fetch the reference: gridctl_fetch({kind:"doc", name:"cloudgrid-yaml"}) — it has the full schema, the needs: vocabulary, and the requires-vs-needs caveat (the deployer does not inject from needs: yet, so a database/cache today uses requires: [mongodb] / requires: [redis]).
|
|
93
94
|
|
|
94
95
|
Deploy is edition-dependent: on the hosted MCP call the drop tool with the HTML; on local MCP / CLI write the file and run the plug tool. An HTML page deploys synchronously, so you get a URL right away.`;
|
|
95
96
|
|