$npx -y skills add medusajs/medusa-agent-skills --skill mcloud-authExecute mcloud authentication and context commands: login, logout, whoami, use, version, and signup. Use when setting up the CLI, switching accounts, verifying auth state, setting the active org/project/environment context, or checking the CLI version.
| 1 | # Cloud CLI: Auth and Context Commands |
| 2 | |
| 3 | Execute authentication and context commands for the Medusa Cloud CLI. |
| 4 | |
| 5 | ## Constraints |
| 6 | |
| 7 | - `mcloud login`, `mcloud signup`, and `mcloud use` (without flags) require a **TTY** — they fail in CI, Docker, or piped input. Use `MCLOUD_TOKEN` or pass flags explicitly instead. |
| 8 | - When `MCLOUD_TOKEN` is set, file-based credentials are ignored and `mcloud login` is rejected. Unset it to switch accounts. |
| 9 | - Always verify auth before any state-changing command: `mcloud whoami --json | jq -e '.auth.kind != "none"'` |
| 10 | |
| 11 | ## Commands |
| 12 | |
| 13 | ### whoami |
| 14 | |
| 15 | Show authenticated user, auth method, and active context (organization, project, environment). |
| 16 | |
| 17 | ```bash |
| 18 | mcloud whoami --json |
| 19 | ``` |
| 20 | |
| 21 | **Options:** |
| 22 | - `--json` — Output as JSON |
| 23 | |
| 24 | **Use to verify auth and scope:** |
| 25 | ```bash |
| 26 | mcloud whoami --json | jq -e '.auth.kind != "none" and .organization.id != null' |
| 27 | ``` |
| 28 | Exit code `0` = authenticated and scoped. Non-zero = stop and prompt the user. |
| 29 | |
| 30 | ### use |
| 31 | |
| 32 | Set the active organization, project, and/or environment so subsequent commands skip those flags. |
| 33 | |
| 34 | ```bash |
| 35 | mcloud use \ |
| 36 | --organization <org-id> \ |
| 37 | --project <project-id-or-handle> \ |
| 38 | --environment <environment-handle> |
| 39 | ``` |
| 40 | |
| 41 | **CRITICAL:** `mcloud use` without flags is interactive and fails in CI/Docker/piped input. Always pass flags explicitly. |
| 42 | |
| 43 | **Options:** |
| 44 | - `-o/--organization <id>` — Set active organization |
| 45 | - `-p/--project <id-or-handle>` — Set active project |
| 46 | - `-e/--environment <handle>` — Set active environment |
| 47 | - `--clear` — Clear all active context |
| 48 | - `--json` — Output as JSON |
| 49 | |
| 50 | **Clear context:** |
| 51 | ```bash |
| 52 | mcloud use --clear |
| 53 | ``` |
| 54 | |
| 55 | ### version |
| 56 | |
| 57 | Print CLI version and platform metadata. |
| 58 | |
| 59 | ```bash |
| 60 | mcloud version --json |
| 61 | ``` |
| 62 | |
| 63 | **Options:** |
| 64 | - `--json` — Output as JSON |
| 65 | |
| 66 | ### login |
| 67 | |
| 68 | Authenticate with Medusa Cloud. Opens a browser to complete auth. |
| 69 | |
| 70 | > **TTY required.** Cannot be run in CI, Docker, or non-interactive environments. Use `MCLOUD_TOKEN` instead for non-interactive auth. |
| 71 | |
| 72 | ```bash |
| 73 | mcloud login |
| 74 | ``` |
| 75 | |
| 76 | **Non-interactive alternative:** |
| 77 | ```bash |
| 78 | export MCLOUD_TOKEN=<access-key> |
| 79 | ``` |
| 80 | |
| 81 | **Options:** |
| 82 | - `-t/--token <token>` — Authenticate using an access key without browser (non-interactive) |
| 83 | - `--json` — Output as JSON |
| 84 | |
| 85 | ### logout |
| 86 | |
| 87 | Remove stored credentials. |
| 88 | |
| 89 | ```bash |
| 90 | mcloud logout --json |
| 91 | ``` |
| 92 | |
| 93 | **Options:** |
| 94 | - `--json` — Output as JSON |
| 95 | |
| 96 | ### signup |
| 97 | |
| 98 | Create a new Medusa Cloud account. Opens a browser. |
| 99 | |
| 100 | > **TTY required.** Cannot be run in non-interactive environments. |
| 101 | |
| 102 | ```bash |
| 103 | mcloud signup |
| 104 | ``` |
| 105 | |
| 106 | ## Auth Methods |
| 107 | |
| 108 | | Method | When to use | |
| 109 | |--------|-------------| |
| 110 | | `mcloud login` (browser) | Interactive setup; requires TTY | |
| 111 | | `mcloud login --token <key>` | Non-interactive login with access key | |
| 112 | | `MCLOUD_TOKEN=<key>` env var | CI/CD, Docker, scripted environments | |
| 113 | |
| 114 | ## Examples |
| 115 | |
| 116 | ```bash |
| 117 | # Check authentication and active context |
| 118 | mcloud whoami --json |
| 119 | |
| 120 | # Verify auth before running commands |
| 121 | mcloud whoami --json | jq -e '.auth.kind != "none" and .organization.id != null' |
| 122 | |
| 123 | # Set full context (org + project + environment) |
| 124 | mcloud use \ |
| 125 | --organization org_123 \ |
| 126 | --project my-store \ |
| 127 | --environment production |
| 128 | |
| 129 | # Set context by resolving names |
| 130 | ORGANIZATION_ID=$(mcloud organizations list --json | jq -r '.[] | select(.name == "My Org") | .id') |
| 131 | PROJECT_HANDLE=$(mcloud projects list --organization "$ORGANIZATION_ID" --json | jq -r '.[] | select(.name == "My Store") | .handle') |
| 132 | ENVIRONMENT_HANDLE=$(mcloud environments list --organization "$ORGANIZATION_ID" --project "$PROJECT_HANDLE" --json | jq -r '.[] | select(.name == "Production") | .handle') |
| 133 | |
| 134 | mcloud use \ |
| 135 | --organization "$ORGANIZATION_ID" \ |
| 136 | --project "$PROJECT_HANDLE" \ |
| 137 | --environment "$ENVIRONMENT_HANDLE" |
| 138 | |
| 139 | # Clear context |
| 140 | mcloud use --clear |
| 141 | |
| 142 | # Check CLI version |
| 143 | mcloud version --json |
| 144 | |
| 145 | # Non-interactive login with token |
| 146 | mcloud login --token <access-key> |
| 147 | |
| 148 | # Logout |
| 149 | mcloud logout |
| 150 | ``` |