1 # Set Up Medusa for AI Agents
2
3 You are an AI coding agent helping a user set up a Medusa commerce application from scratch. Follow this prompt end-to-end. Each section is a discrete step — finish it, verify it, then move to the next. Do not skip verification.
4
5 ## Operating Rules
6
7 - Run all commands in the user's shell from the project's parent directory unless a step says otherwise.
8 - Before running a command that changes system state (installing software, creating a database, pushing to GitHub, deploying), state what you are about to do in one sentence so the user can interrupt.
9 - Never invent values. If a step needs input from the user (account email, project name, GitHub URL), ask once and reuse the answer.
10 - After each command, check exit codes and command output. If a step fails, stop and surface the error with a concrete next action — do not silently continue.
11 - Prefer non-interactive flags. This document calls them out explicitly. Do not run commands that block on a TTY (browser prompts, confirmations) unless the step says to.
12 - Do not commit secrets, `.env` files, or admin credentials. Treat the admin password the user gives you as sensitive.
13
14 ---
15
16 ## Step 1: Verify Prerequisites
17
18 Check the three prerequisites in order. For each, run the check first; only install if the check fails. Do not upgrade existing tools without asking the user.
19
20 ### 1a. Node.js (v20.19.0+ or v22.12.0+, LTS only, but not v25+)
21
22 ```bash
23 node --version
24 ```
25
26 Required: Node.js `^20.19.0` or `>=22.12.0` (LTS versions only, `<= 24`). The Next.js Starter Storefront does not support Node.js v25+.
27
28 If Node is missing or out of range, ask the user how they want to install it. Recommend `nvm`:
29
30 ```bash
31 # macOS / Linux
32 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
33 # then, in a new shell:
34 nvm install 22
35 nvm use 22
36 ```
37
38 On Windows, point the user to https://nodejs.org/en/download and have them install Node 22 LTS, then re-run `node --version`.
39
40 ### 1b. Git CLI
41
42 ```bash
43 git --version
44 ```
45
46 If missing:
47 - macOS: `xcode-select --install` (or `brew install git`)
48 - Linux (Debian/Ubuntu): `sudo apt-get update && sudo apt-get install -y git`
49 - Windows: install from https://git-scm.com/downloads
50
51 ### 1c. PostgreSQL (installed and running)
52
53 ```bash
54 psql --version
55 pg_isready
56 ```
57
58 `pg_isready` should exit `0`. If PostgreSQL is missing:
59 - macOS: `brew install postgresql@16 && brew services start postgresql@16`
60 - Linux (Debian/Ubuntu): `sudo apt-get install -y postgresql && sudo systemctl enable --now postgresql`
61 - Windows: install from https://www.postgresql.org/download/windows/ and start the service
62
63 If `pg_isready` fails after install, ask the user to start the PostgreSQL service (`brew services start postgresql@16`, `sudo systemctl start postgresql`, or via the Windows Services panel) before continuing.
64
65 Do not proceed to Step 2 until all three checks pass.
66
67 ---
68
69 ## Step 2: Install Medusa
70
71 Pick the package manager in this priority order — use the **first one** that is already installed:
72
73 1. `pnpm` — check with `pnpm --version`
74 2. `yarn` — check with `yarn --version`
75 3. `npm` — always available with Node.js
76
77 Ask the user for a project name (default: `my-medusa-store`).
78
79 ### Check for an Existing Database
80
81 `create-medusa-app` creates a PostgreSQL database using the project name. Before running the install, check whether a database with that name already exists:
82
83 ```bash
84 psql -lqt | cut -d\| -f1 | grep -qw "<project-name>"
85 ```
86
87 - **Exit code `0`** (database exists) → generate a randomised project suffix to use with `create-medusa-app. For example:
88
89 ```bash
90 PROJECT_SUFFIX=$(LC_ALL=C tr -dc 'a-z0-9' < /dev/urandom | head -c6)
91 ```
92
93 Use this as the project name for the install command (`<project-name>-$PROJECT_SUFFIX`).
94
95 - **Exit code `1`** (database does not exist) → continue with the original project name.
96
97 ### Run the Installer
98
99 From the directory where the project should be created, run `create-medusa-app` with `CI=true` to skip interactive prompts and `--no-browser` to prevent the command from starting servers and opening a browser (which would hang).
100
101 **If didn't set a randomised project suffix** (no collision detected):
102
103 ```bash
104 # pnpm (preferred)
105 CI=true pnpm dlx create-medusa-app@latest <project-name> --with-nextjs-starter --no-browser
106
107 # yarn
108 CI=true yarn dlx create-medusa-app@latest <project-name> --with-nextjs-starter --no-browser
109
110 # npm
111 CI=true npx create-medusa-app@latest <project-name> --with-nextjs-starter --no-browser
112 ```
113
114 **If set a randomised project suffix** (collision detected):
115
116 ```bash
117 # pnpm (preferred)
118 CI=true pnpm dlx create-medusa-app@latest <project-name>-$PROJECT_SUFFIX --with-nextjs-starter --no-browser
119
120 # yarn
121 CI=true yarn dlx create-medusa-app@latest <project-name> --with-nextjs-starter --no-browser
122
123 # npm
124 CI=true npx create-medusa-app@latest <project-name> --with-nextjs-starter --no-browser
125 ```
126
127 The command:
128
129 - Creates a monorepo at `./<project-name>` with `apps/backend` (Medusa server + admin) and `apps/storefront` (Next.js Starter Storefront).
130 - Creates a PostgreSQL database named `$DB_NAME` and runs migrations.
131 - Does **not** start the dev servers and does **not** open a browser (because of `--no-browser`).
132
133 After the install completes, `cd` into `<project-name>` for all subsequent steps.
134
135 ---
136
137 ## Step 3: Create the Admin User
138
139 Because we used `--no-browser`, no admin user has been created yet. Create a local test user with preset credentials — these are for local development only and will not transfer to any deployed application.
140
141 From the backend directory (`apps/backend`), run:
142
143 ```bash
144 # pnpm
145 cd apps/backend && pnpm exec medusa user -e admin@example.com -p supersecret
146 # yarn
147 cd apps/backend && yarn medusa user -e admin@example.com -p supersecret
148 # npm
149 cd apps/backend && npx medusa user -e admin@example.com -p supersecret
150 ```
151
152 Verify the command exits `0` and prints a confirmation that the user was created. Then return to the project root: `cd ../..`.
153
154 ---
155
156 ## Step 4: Start the Local Development Servers
157
158 Start the Medusa backend and the Next.js storefront as background processes so the user can try the application immediately.
159
160 From the project root, open two background processes (or two terminal tabs):
161
162 > DO NOT run the `dev` command from the root directory — it must be run separately for the backend and storefront.
163
164 ```bash
165 # Terminal 1 — Medusa backend (from apps/backend)
166 cd apps/backend && npm run dev
167 # or: pnpm dev / yarn dev
168
169 # Terminal 2 — Next.js storefront (from apps/storefront)
170 cd apps/storefront && npm run dev
171 # or: pnpm dev / yarn dev
172 ```
173
174 DO NOT spend time on whether the servers are running. If the user has issues, they'll report them.
175
176 Once both are running, tell the user:
177
178 ```
179 **Here's what has been set up so far:**
180
181 - **Medusa backend** running at http://localhost:9000
182 - **Admin dashboard** at http://localhost:9000/app — log in with:
183 - Email: `admin@example.com`
184 - Password: `supersecret`
185 - **Next.js Storefront** running at http://localhost:8000
186
187 The backend has a PostgreSQL database, all migrations applied, and is ready for development. The storefront is pre-connected to the local Medusa backend.
188 ```
189
190 Then ask the user: **"Would you like to deploy your store to Medusa Cloud for seamless production hosting? (yes / no / later)"** Use your ask-question tool for this.
191
192 - **Yes** → continue to Step 5.
193 - **No / Later** → skip to Step 4a and finish local-only setup.
194
195 DO NOT show wrap up yet. Wait until user confirms deployment or skipping before showing the next steps.
196
197 ---
198
199 ## Step 4a: Local-Only Setup (skip Cloud)
200
201 If the user chose not to deploy to Cloud now, go directly to Step 5 (Install Agent Skills) and Step 8 (Docs MCP Server). After both are done, go to the Wrap Up step (Step 13).
202
203 Tell the user they can run `mcloud signup` at any time when they are ready to deploy.
204
205 ---
206
207 ## Step 5: Install Medusa Agent Skills
208
209 Install skills so the agent has the right context for building Medusa features and storefronts.
210
211 Run from the project root:
212
213 ### Claude Code
214
215 ```bash
216 npx -y skills add medusajs/medusa-agent-skills --skill '*' --yes --agent claude-code
217 ```
218
219 ### Cursor
220
221 ```bash
222 npx -y skills add medusajs/medusa-agent-skills --skill '*' --yes --agent cursor
223 ```
224
225 ### Codex
226
227 ```bash
228 npx -y skills add medusajs/medusa-agent-skills --skill '*' --yes --agent codex
229 ```
230
231 ### Gemini CLI
232
233 ```bash
234 npx -y skills add medusajs/medusa-agent-skills --skill '*' --yes --agent gemini-cli
235 ```
236
237 ### Other
238
239 ```bash
240 npx -y skills add medusajs/medusa-agent-skills --skill '*' --yes
241 ```
242
243 ---
244
245 ## Step 6: Install the Medusa Cloud CLI
246
247 Check whether `mcloud` is already installed:
248
249 ```bash
250 mcloud --version
251 ```
252
253 If it exits `0`, skip to Step 7. Otherwise install it globally with the same package manager priority:
254
255 ```bash
256 # pnpm
257 pnpm add -g @medusajs/mcloud
258 # yarn
259 yarn global add @medusajs/mcloud
260 # npm
261 npm install -g @medusajs/mcloud
262 ```
263
264 Re-run `mcloud --version` to confirm the binary is on `PATH`. If not, ask the user to add their global package bin directory to `PATH`.
265
266 For all `mcloud` commands in the rest of this prompt: pass `--json` whenever you need to parse output, and run `mcloud whoami --json` before any command that mutates state.
267
268 ---
269
270 ## Step 7: Sign Up or Log In to Medusa Cloud
271
272 Ask the user: **"Do you already have a Medusa Cloud account?"**
273
274 ### If no
275
276 Run:
277
278 ```bash
279 mcloud signup
280 ```
281
282 This opens a browser. Tell the user that sign-up starts a free trial and doesn't require payment details. Wait for the user to confirm they have completed sign-up before continuing.
283
284 Then run:
285
286 ```bash
287 mcloud login
288 ```
289
290 Wait for the browser flow to complete.
291
292 ### If yes
293
294 Run:
295
296 ```bash
297 mcloud login
298 ```
299
300 Wait for the browser flow to complete.
301
302 ### If the user wants to skip Cloud
303
304 Skip Steps 7-12. Tell them they can revisit Cloud deployment later and jump to Step 13.
305
306 ### Verify authentication
307
308 ```bash
309 mcloud whoami --json
310 ```
311
312 The `auth.kind` field must not be `"none"`. If it is, retry `mcloud login`.
313
314 ---
315
316 ## Step 8: Add the Docs MCP Server
317
318 The Docs MCP server gives the agent live access to the Medusa documentation. The connection method depends on the agent.
319
320 Add the MCP servers but do not authenticate yet or block next steps. In the wrap up, remind the user to authenticate so the agent can use the docs.
321
322 ### Claude Code
323
324 Run the following command to add the MCP server to the Claude Code agent:
325
326 ```bash
327 claude mcp add --transport http medusa https://docs.medusajs.com/mcp
328 ```
329
330 Then instruct the user to authenticate the agent with Medusa Cloud so it can access the MCP server:
331
332 ```bash
333 /mcp
334 ```
335
336 ### Cursor
337
338 Add the following to `.cursor/mcp.json` (project) or the user's Cursor settings:
339
340 ```json
341 {
342 "mcpServers": {
343 "medusa": {
344 "url": "https://docs.medusajs.com/mcp"
345 }
346 }
347 }
348 ```
349
350 Then ask user to authenticate with Medusa Cloud from the Cursor settings.
351
352 ### VS Code (with MCP support)
353
354 Add the following to `.vscode/mcp.json`:
355
356 ```json
357 {
358 "servers": {
359 "medusa": {
360 "type": "http",
361 "url": "https://docs.medusajs.com/mcp"
362 }
363 }
364 }
365 ```
366
367 Then ask user to authenticate with Medusa Cloud from the VS Code MCP extension.
368
369 ### Other agents
370
371 Configure the agent to connect to the Streamable HTTP MCP server at `https://docs.medusajs.com/mcp`. The MCP server requires an active Medusa Cloud subscription — the `mcloud login` from Step 7 covers this.
372
373 ---
374
375 ## Step 9: Create a GitHub Repository
376
377 Cloud deploys from a GitHub repository. The user must own the repository.
378
379 Ask the user to create an empty repository on GitHub for the project (no README, no .gitignore, no license — those would conflict with the existing project files). Have them paste the resulting `git@github.com:<user>/<repo>.git` or `https://github.com/<user>/<repo>.git` URL.
380
381 Then, from the project root:
382
383 ```bash
384 git init
385 git add .
386 git commit -m "Initial Medusa application"
387 git branch -M main
388 git remote add origin <repo-url>
389 git push -u origin main
390 ```
391
392 If `git init` reports the repo already exists (because `create-medusa-app` already initialized it), skip `git init` and continue from `git remote add origin`.
393
394 If the push fails because the user is not authenticated with GitHub, point them to `gh auth login` (https://cli.github.com/) or to set up an SSH key, then retry.
395
396 ---
397
398 ## Step 10: Create the Cloud Project
399
400 Open the Medusa Cloud project creation flow in the user's browser. The full UI flow is documented at https://docs.medusajs.com/cloud/projects.
401
402 Tell the user:
403
404 1. Go to https://cloud.medusajs.com and confirm the correct organization is selected.
405 2. Click **Create Project**.
406 3. Choose **Create from existing application** and authenticate GitHub if prompted.
407 4. Select the repository pushed in Step 9.
408 5. Configure the project:
409 - **Project name**: any name
410 - **Custom subdomain**: at least 5 characters, not one of the reserved names (`medusa`, `admin`, `staging`, `production`, `preview`, `development`, `proxy`)
411 - **Region**: closest to the target users (`us-east-1`, `eu-central-1`, or `ap-southeast-1`)
412 - **Project root directory**: `apps/backend`
413 - **Storefront root directory**: `apps/storefront`
414 - **Initial user**: set up a production admin user with a strong password (not the local test credentials from Step 3)
415 6. Click **Create**.
416
417 Wait for the user to confirm the project has been created in the Cloud dashboard before continuing.
418
419 ---
420
421 ## Step 11: Monitor the Deployment
422
423 After the project is created, set the active context for the CLI so subsequent commands don't need flags. Resolve the IDs from names:
424
425 ```bash
426 ORG_ID=$(mcloud organizations list --json | jq -r '.[0].id')
427 # If the user has multiple organizations, ask which one and filter by name instead:
428 # ORG_ID=$(mcloud organizations list --json | jq -r '.[] | select(.name == "<name>") | .id')
429
430 PROJECT_HANDLE=$(mcloud projects list --organization "$ORG_ID" --json | jq -r '.[] | select(.name == "<project-name>") | .handle')
431 ENV_HANDLE=$(mcloud environments list --organization "$ORG_ID" --project "$PROJECT_HANDLE" --json | jq -r '.[] | select(.name == "Production") | .handle')
432
433 mcloud use --organization "$ORG_ID" --project "$PROJECT_HANDLE" --environment "$ENV_HANDLE"
434 ```
435
436 Poll the latest deployment until it reaches a terminal state. A reasonable loop:
437
438 ```bash
439 while true; do
440 STATUS=$(mcloud deployments list --limit 1 --json | jq -r '.[0].backend_status')
441 echo "Backend status: $STATUS"
442 case "$STATUS" in
443 deployed|build-failed|deployment-failed|timed-out|canceled) break ;;
444 esac
445 sleep 20
446 done
447 ```
448
449 Report `backend_status` to the user as it changes. If the final status is anything other than `deployed`, debug per the [Cloud CLI agent guide](https://docs.medusajs.com/cloud/cli/agents):
450
451 - `build-failed` → `mcloud deployments build-logs <deployment-id>`
452 - `deployment-failed` → `mcloud logs --deployment <deployment-id> --limit 1000`
453 - `timed-out` → check both
454
455 Surface the relevant error to the user and stop. Do not retry blindly.
456
457 If a storefront was deployed too, repeat the polling using `storefront_status`.
458
459 ---
460
461 ## Step 12: Show the Live URLs
462
463 Once `backend_status` is `deployed`, fetch the URLs:
464
465 ```bash
466 mcloud environments get "$ENV_HANDLE" --json | jq '{backend_url, storefront_url}'
467 ```
468
469 Show the user:
470
471 - **Admin dashboard**: `<backend_url>/app` (login with Medusa Cloud account, button is on the dashboard)
472 - **Storefront**: `<storefront_url>` (if a storefront was deployed)
473 - **API base**: `<backend_url>`
474
475 If a custom domain has not been set, the URLs will be subdomains of `medusajs.app` (backend) and `medusajs.site` (storefront).
476
477 ---
478
479 ## Step 13: Wrap Up
480
481 Tell the user, in one short message:
482
483 - Their ecommerce store is live (or running locally, if they skipped Cloud).
484 - They can now build features by asking. The installed skills (`medusa-dev`, `ecommerce-storefront`) and the Docs MCP server (if installed) give the agent everything it needs to add modules, API routes, admin UI, storefront pages, and integrations.
485 - If MCP was installed, remind the user to authenticate with Medusa Cloud from the MCP settings so the agent can access the documentation.
486 - If any step was blocked due to execution mode or permissions, mention them in the message and tell the user how to re-run them.
487 - Suggest two or three concrete next prompts the user could try, e.g.:
488 - "Add a product reviews module with admin moderation and a customer-facing form on the storefront."
489 - "Build a wishlist feature with API routes and storefront UI."
490 - "Add a megamenu to the storefront header showing product categories."
491
492 Stop. Do not start building features unless the user asks.