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
- Ask an organization admin to run `create-factory` for you.
- Attach the database from the Mastra Platform dashboard, then rerun the CLI pointing at the existing database.
- Re-authenticate with an account that has the admin role in the target org.
- 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
- Check your org role before running provisioning commands.
- Keep at least one admin account available for infrastructure setup.
- Use the dashboard for database attach when the CLI account is member-scoped.
- Re-verify role after SSO or team changes.
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
- No access to organization ${orgId}. Run: mastra auth orgs
- You need the admin role in this organization to manage datab
- Admin access required
- You do not have permission to update this connection
- Permission denied
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/d9163dcf2d5787d4.
Report an issue: GitHub.