{"record":{"id":"cfce28226706cd7f","repo":"mastra-ai/mastra","slug":"no-organizations-found-create-one-at-mastra-stu","errorCode":null,"errorMessage":"No organizations found. Create one at ${MASTRA_STUDIO_URL}","messagePattern":"No organizations found\\. Create one at (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/commands/server/deploy.ts","lineNumber":212,"sourceCode":"    }\n  }\n\n  const currentOrgId = await getCurrentOrgId();\n  const orgs = await fetchOrgs(token);\n\n  if (currentOrgId) {\n    const match = orgs.find(o => o.id === currentOrgId);\n    if (match) {\n      return { orgId: match.id, orgName: match.name };\n    }\n  }\n\n  if (orgs.length === 1) {\n    return { orgId: orgs[0]!.id, orgName: orgs[0]!.name };\n  }\n\n  if (orgs.length === 0) {\n    throw new Error(`No organizations found. Create one at ${MASTRA_STUDIO_URL}`);\n  }\n\n  const selected = await p.select({\n    message: 'Select an organization',\n    options: orgs.map(o => ({ value: o.id, label: `${o.name} (${o.id})` })),\n  });\n\n  if (p.isCancel(selected)) {\n    p.cancel('Deploy cancelled.');\n    process.exit(0);\n  }\n\n  const selectedOrg = orgs.find(o => o.id === selected)!;\n  return { orgId: selectedOrg.id, orgName: selectedOrg.name };\n}\n\n/* ------------------------------------------------------------------ */\n/*  Resolve project                                                   */","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/cli/src/commands/server/deploy.ts#L194-L230","documentation":"`resolveOrg` fetches the authenticated user's organizations from Mastra Cloud to determine which org the deploy targets. If the API returns zero organizations, the CLI throws this error directing the user to create an organization in Mastra Studio, since a deployment must belong to one.","triggerScenarios":"Running `mastra server deploy` while authenticated with a token/account that has no organizations, and no --org-id was supplied.","commonSituations":"Using a freshly created or personal access token with no org membership; wrong account logged in; org deleted or user removed from it; auth against a stale token for a different environment.","solutions":["Create an organization at the Mastra Studio URL, then re-authenticate and retry","Pass the org explicitly with --org-id if you have one","Run `mastra auth login` (or equivalent) to switch to an account that belongs to an organization"],"exampleFix":"// before\n# account has zero orgs\nmastra server deploy\n// after\n# create org in Studio, then\nmastra auth login && mastra server deploy","handlingStrategy":"try-catch","validationCode":"const orgs = await fetchOrganizations(token);\nif (!orgs.length) {\n  console.error('No organizations on this account — create one at ' + MASTRA_STUDIO_URL);\n  process.exit(1);\n}","typeGuard":"const hasOrg = (orgs: { id: string; name: string }[]): boolean => orgs.length > 0;","tryCatchPattern":"try {\n  await runServerDeploy(opts);\n} catch (e) {\n  if ((e as Error).message.startsWith('No organizations found')) {\n    console.error('Create an org in Mastra Studio, then re-authenticate.');\n  } else throw e;\n}","preventionTips":["Create an organization before first deploy","Verify the logged-in account has org membership","Pass --org-id explicitly in automation","Re-run login after account/org changes"],"tags":["auth","deploy","cli","organization"],"backgroundTag":"missing-organization","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}