mastra-ai/mastra · error · PlatformApiError

Attaching a database requires the admin role in your organiz

Error message

Attaching a database requires the admin role in your organization. Ask an org admin to run `create-factory`, or attach a database from the dashboard.

What it means

attachNeonDatabase attaches a Neon database to a server project via the platform API. A 403 response is mapped to this explicit, actionable PlatformApiError instead of the generic attach-failure message, because attaching a database requires the admin role in the organization.

Source

Thrown at mastracode/mastra-factory/src/platform.ts:145

  regionId,
}: {
  token: string;
  orgId: string;
  projectId: string;
  name: string;
  regionId: string;
}): Promise<AttachedDatabase> {
  const res = await platformFetch(
    `${MASTRA_PLATFORM_API_URL}/v1/server/projects/${encodeURIComponent(projectId)}/databases`,
    {
      method: 'POST',
      headers: { ...authHeaders(token, orgId), 'Content-Type': 'application/json' },
      body: JSON.stringify({ kind: 'neon', name, regionId }),
    },
  );
  if (!res.ok) {
    if (res.status === 403) {
      throw new PlatformApiError(
        403,
        `Attaching a database requires the admin role in your organization. Ask an org admin to run \`create-factory\`, or attach a database from the dashboard.`,
      );
    }
    throw new PlatformApiError(res.status, `Failed to attach Neon database — ${await extractError(res)}`);
  }
  const body = (await res.json()) as AttachDatabaseResponse;
  return body.database;
}

/** GET /v1/server/projects/:id/databases/:dbId — status poll target. */
export async function getDatabaseStatus({
  token,
  orgId,
  projectId,
  databaseId,
  signal,
}: {

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Ask an organization admin to run `create-factory` for you.
  2. Attach the database from the Mastra Platform dashboard, then rerun the CLI pointing at the existing database.
  3. Re-authenticate with an account that has the admin role in the target org.
  4. Verify with the org owner that your role hasn't changed recently.
Defensive patterns

Strategy: try-catch

Validate before calling

const me = await getOrgMember({ token, orgId, userId: currentUserId });
if (me.role !== 'admin' && me.role !== 'owner') {
  throw new Error('Requires org admin role — ask an admin to run create-factory or attach the DB via dashboard.');
}

Try / catch

try {
  await attachNeonDatabase(opts);
} catch (err) {
  if (err instanceof PlatformApiError && err.status === 403) {
    console.error('Your account lacks the org admin role. Ask an admin to run create-factory or attach the DB from the dashboard.');
    process.exit(1);
  }
  throw err;
}

Prevention

When it happens

Trigger: POST to attach a `{ kind: 'neon', name, regionId }` database returns HTTP 403 — i.e. the authenticated user is a member of the org but not an admin/owner.

Common situations: Developer on a team plan running create-factory with a non-admin account; role downgraded after SSO/invites changed; token minted for a member-scoped API key; using --attach mode instead of full provisioning that an admin would run.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/d9163dcf2d5787d4. Report an issue: GitHub.