Guide
Rolling outMCP server
Layerbase runs a hosted Model Context Protocol server, so an AI agent such as Claude Code, Codex, Cursor or Grok can work with your Layerbase Cloud databases directly: list them, create one, fetch its connection string, run a query, branch it, and tidy up afterwards. The agent connects with a token you create in account settings, and that token acts as your account with exactly your permissions.
The MCP server is rolling out. If you do not see MCP tokens in your account settings yet, it is not on your account yet.
The endpoint
One URL for every client. It speaks MCP over Streamable HTTP and authenticates with a bearer token in the Authorization header:
https://layerbase.com/api/mcpAuthorization: Bearer lbm_YOUR_TOKENAny client that can reach a remote MCP server over HTTP and send a custom header works. The MCP server is available on every plan, Free included; each tool applies the same plan limits the dashboard does.
Create a token
- Open account settings and find the MCP tokens section.
- Choose New token, give it a label (up to 80 characters) that says where it will live, such as "Claude Code on my laptop", and pick an expiry: 30 days, 90 days, 1 year, never.
- Copy the token. It is shown exactly once, together with ready-made setup for the clients below. Layerbase stores only a hash, so a lost token cannot be shown again: revoke it and create a new one.
Tokens start with lbm_. The settings list shows each active token by its label and its first 8 characters after the prefix, with when it was last used and when it expires. Create one token per agent or machine, so you can revoke one without touching the others.
Revoke a token
Select the trash icon next to a token in MCP tokens and confirm. Any agent using it loses access on its next request; revoking cannot be undone. An expired token stops working the same way. Nothing about a token is cached between requests, so a revoke, an expiry or a change to your account takes effect on the very next call.
Connect your client
Replace lbm_YOUR_TOKEN with your token. The new-token dialog in settings fills it in for you.
Claude Code
claude mcp add --transport http layerbase https://layerbase.com/api/mcp --header "Authorization: Bearer lbm_YOUR_TOKEN"Codex CLI
[mcp_servers.layerbase]
url = "https://layerbase.com/api/mcp"
http_headers = { "Authorization" = "Bearer lbm_YOUR_TOKEN" }Grok
grok mcp add --transport http layerbase https://layerbase.com/api/mcp --header "Authorization: Bearer lbm_YOUR_TOKEN"OpenCode
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"layerbase": {
"type": "remote",
"url": "https://layerbase.com/api/mcp",
"enabled": true,
"headers": {
"Authorization": "Bearer lbm_YOUR_TOKEN"
}
}
}
}Cursor
{
"mcpServers": {
"layerbase": {
"url": "https://layerbase.com/api/mcp",
"headers": {
"Authorization": "Bearer lbm_YOUR_TOKEN"
}
}
}
}Claude Desktop
{
"mcpServers": {
"layerbase": {
"command": "npx",
"args": [
"mcp-remote",
"https://layerbase.com/api/mcp",
"--header",
"Authorization:${AUTH_HEADER}"
],
"env": {
"AUTH_HEADER": "Bearer lbm_YOUR_TOKEN"
}
}
}
}Claude Desktop reaches remote servers through the mcp-remote bridge, which needs Node.js. The file is in ~/Library/Application Support/Claude on macOS and %APPDATA%\Claude on Windows. Restart Claude Desktop after saving.
Other clients (JSON)
{
"mcpServers": {
"layerbase": {
"url": "https://layerbase.com/api/mcp",
"headers": {
"Authorization": "Bearer lbm_YOUR_TOKEN"
}
}
}
}The common shape for clients that speak streamable HTTP. Check your client docs for the exact file and key names.
Then ask the agent to call whoami. If it answers with your email and plan, the connection works.
Tools
The server offers 21 tools. Each one calls the same code path as the matching dashboard action, so plan limits, quotas, ownership rules and maintenance pauses apply exactly as they do in the browser. Slow operations (create, start, wake, branch) return at once; the agent polls get_database until the status is running. Team-scoped tools take an optional team slug from list_teams and otherwise use your own default team.
Account and teams
The account the token acts as: email, role and plan. A good first call to confirm the connection works.
Teams the account belongs to, which one is the default, and which ones it owns.
The resource pool (RAM, vCPU, storage) and how much each database draws from it.
Databases
Engines and versions the account can create, and which ones need a paid plan.
Every database the account can reach, its own and its teams', with branches included.
Status, engine, version and settings of one database. Never includes credentials.
The connection string and credentials for one database. The agent receives a secret.
Storage and memory use of one database.
Create a database with the same plan, quota and placement checks as the dashboard. Only a team owner can create on a team.
Start a stopped database.
Stop a running database. Open connections drop.
Wake a hibernated database.
Queries
Run one statement, exactly like the dashboard query console: SQL, a mongosh or Redis command, a REST request for HTTP engines, or a TigerBeetle operation. Writes are allowed.
Branches
Branches of one database (database owner only).
Fork a database into a copy-on-write branch (database owner only). Can reuse an existing branch of the same name.
Discard every change on a branch and re-fork it from its parent. Requires confirmName.
Delete one branch and its data. Refuses a primary database. Requires confirmName.
Permanently delete a database (database owner only). Requires confirmName and confirm: true; a database with branches also needs cascade: true.
Integrations
Whether the team has Vercel and GitHub connected. Connecting an integration stays in the dashboard.
The rules that wire git branches to databases: which branch reads production, which gets a staging branch, and the env var name.
Change a preview mapping rule. Only the fields sent change.
Some things are deliberately not tools: billing and plan changes, team membership, API keys, backups and restores, and connecting or replacing an integration. Do those in the dashboard.
Permissions and security
- A token is your account. It can do anything the tools allow that you could do yourself, and nothing more. On a team you do not own, the agent gets the same refusals you would: a team member can query and start a shared database, but only the database owner can delete or branch it, and only the team owner can create databases on the team. See Teams.
- Destructive tools ask for proof.
reset_branch,delete_branchanddelete_databaserefuse unlessconfirmNamematches the database name exactly aslist_databasesshows it.delete_databasealso needsconfirm: true, and refuses a database with branches unlesscascade: trueis sent. Deleting through MCP takes the same final backup as deleting from the dashboard, and can take a few minutes for that reason. - Queries can write.
run_queryruns with your own database access, so an agent can change or drop data. It shares the query console's rate limit and result-size limit (see Query console). For bulk work, give the agent a connection string instead. - Credentials reach the agent.
get_connection_stringreturns the database password into the agent's context. Treat that conversation like any other place a secret lives. - Account standing is checked on every call. MCP access pauses entirely while an account is past due, suspended or frozen, and stops for a deleted account. This is stricter than the REST API and CLI, because an agent runs unattended.
- Calls are logged without their contents. Each tool call is logged with the tool name, the account and the token it used, and whether it succeeded. Arguments and results are not logged.
- Treat tool results as data. Query results can contain text anyone wrote into your database. Use an agent that asks before running destructive tools, and give production tokens only to agents you trust.
Troubleshooting
Authorization: Bearer lbm_YOUR_TOKEN as a header, with the word Bearer and a space before the token.lbm_ followed by 40 characters with no spaces or quotes. Create a new one in account settings if in doubt.confirmName did not match. The error names the database as Layerbase shows it; ask the agent to use that exact name.run_query hit the query console's per-account limit. Wait a minute, or connect to the database directly for heavy work.list_teams), or the database id is not one this account can reach (check list_databases).list_databases to see whether the delete finished before retrying.