mastra-ai/mastra · error · PlatformApiError

Platform connection response missing DATABASE_URL.

Error message

Platform connection response missing DATABASE_URL.

What it means

Thrown by runPlatformProvisioning after provisioning a Neon database via the Mastra Platform. The platform connection response's `envVars` array is expected to always contain a `DATABASE_URL` entry with a non-empty value; if it is missing or blank, the provisioning flow cannot proceed and this PlatformApiError (HTTP 500) is thrown so the user gets a clear failure instead of a broken DATABASE_URL downstream.

Source

Thrown at mastracode/mastra-factory/src/create.ts:358

      });
      const ready = await waitForDatabaseReady({
        token,
        orgId,
        projectId: project.id,
        databaseId: attached.id,
      });
      const connection = await getDatabaseConnection({
        token,
        orgId,
        projectId: project.id,
        databaseId: ready.id,
      });
      // `envVars` is an array of `{ name, value, secret }` — Neon rows always
      // include a single `DATABASE_URL` entry (see services/project-databases
      // renderConnectionInstructions).
      const dbEnv = connection.envVars.find(v => v.name === 'DATABASE_URL');
      if (!dbEnv?.value) {
        throw new PlatformApiError(500, 'Platform connection response missing DATABASE_URL.');
      }
      databaseUrl = dbEnv.value;
      neonSpinner.stop('Neon database ready.');
    } catch (err) {
      neonSpinner.stop('Database provisioning failed.');
      throw err;
    }
    envAccumulator.DATABASE_URL = databaseUrl;

    // 8. Write .env (idempotent — replaces existing keys, appends missing).
    flush();

    return { orgId, orgName, project, secretKey, databaseUrl };
  } finally {
    // Best-effort partial write on failure so a successful `sk_` mint or
    // project-id isn't thrown away when a later step blows up.
    flush();
  }

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Retry the create-factory run — the provisioning may have been mid-flight and a fresh connection fetch will include DATABASE_URL.
  2. Check the Neon project dashboard and confirm the connection string exists; attach the database manually if needed.
  3. Verify the platform API version the CLI targets matches the server (no renamed env vars); update the CLI or pin a compatible platform version.
  4. If it persists, file/inspect the raw connection response (services/project-databases renderConnectionInstructions) to confirm the contract.

Example fix

// before
const dbEnv = connection.envVars.find(v => v.name === 'DATABASE_URL');
if (!dbEnv?.value) {
  throw new PlatformApiError(500, 'Platform connection response missing DATABASE_URL.');
}
// after
const dbEnv = connection.envVars.find(v => v.name === 'DATABASE_URL')
  ?? connection.envVars.find(v => /DATABASE_URL/i.test(v.name));
if (!dbEnv?.value) {
  throw new PlatformApiError(500, `Platform connection response missing DATABASE_URL. Got: ${connection.envVars.map(v => v.name).join(', ') || '(none)'}`);
}
Defensive patterns

Strategy: validation

Validate before calling

function hasDatabaseUrl(conn) {
  return Array.isArray(conn?.envVars) &&
    conn.envVars.some(v => v?.name === 'DATABASE_URL' && typeof v.value === 'string' && v.value.length > 0);
}
if (!hasDatabaseUrl(connection)) throw new Error('Connection response lacks DATABASE_URL; retry provisioning.');

Type guard

function hasDbEnv(v) { return typeof v === 'object' && v !== null && v.name === 'DATABASE_URL' && typeof v.value === 'string' && v.value.length > 0; }

Try / catch

try {
  databaseUrl = await provisionAndGetDatabaseUrl(opts);
} catch (err) {
  if (err instanceof PlatformApiError && err.message.includes('DATABASE_URL')) {
    console.error('Platform did not return DATABASE_URL. Retry, or attach a DB from the dashboard.');
  }
  throw err;
}

Prevention

When it happens

Trigger: The Neon connection API call succeeds but returns `connection.envVars` with no entry named 'DATABASE_URL', or the entry's `value` is empty/undefined.

Common situations: A platform API contract change where the env var is renamed (e.g. to POOLING_DATABASE_URL or a pooled variant); a partially provisioned database that reports connected but hasn't emitted credentials yet; a mocked/stubbed API response missing the field; a permissions-restricted connection response that redacts secrets.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


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