@batadata/mcp
A Model Context Protocol stdio server that
exposes BataDB, a serverless Postgres platform with
instant branching, scale-to-zero, time travel, query insights and cost-truth
billing, as tools for AI agents (Claude Code, Claude Desktop, Cursor and any MCP
client).
With one API key an agent can provision a database, fork an ephemeral branch
for a task, run SQL, browse tables, read performance recommendations with their
evidence, prove an index on a throwaway branch, set up client telemetry, manage
keys, members and spend, and read an honest bill. Every agent-relevant API route
has a tool here. The one step that needs a person is adding a card to a new Free
team, once, before its first database starts (see Errors).
Install
Run it straight from npm with npx (no global install needed):
npx -y @batadata/mcp
Requires Node.js 20 or newer.
Authenticate
The server is headless. It uses BATA_API_KEY when that is set. Otherwise it uses
the machine's bata login (0.5.0 and later): the API key saved by the
@batadata/cli in the profile named by
BATA_PROFILE (the default profile, ~/.batarc, when unset), and that profile's API
URL when BATA_API_URL is unset. Only a bata_ API key is used, never an old password
session token. On a 401 the server re-reads the profile once, so a fresh bata login
is picked up without restarting the client. With neither, it exits at startup: run
bata login, or set BATA_API_KEY.
A person runs bata login once per machine; the key renews itself on use (it expires
after 90 days unused) and survives a password change.
Or a scoped key
Mint a key with the CLI and give the agent the narrowest key that does the job:
# Read-only agent: can inspect everything, change nothing
bata keys create --name "agent (read)" --scope read
# Agent that can also run SQL, but only in one project
bata keys create --name "agent (sql, one project)" --scope read --scope sql --project <project-id>
# Full agent: can create and delete projects, branches, keys
bata keys create --name "agent (admin)" --scope admin
| Scope |
What it allows |
read |
Every read tool (lists, insights, recommendations, schema, usage). |
sql |
read, plus running SQL, writing table rows and reading connection strings (which carry the password). |
admin |
Everything, including creating, changing and deleting resources, keys, members and billing. |
telemetry:write |
Only posting client telemetry. Meant for an application's environment, not for an agent (see telemetry_setup). |
A key restricted with --project can only reach those projects. It cannot call
team-level tools (teams_*, billing_*, api_keys_*, audit_log,
notifications_*). Each tool's description ends with the scope it needs, and a
key that lacks it gets a KEY_SCOPE_DENIED error that names the missing scope.
Scopes never add privilege: your team role (owner, admin, member, viewer) still
applies on top.
App keys (api_keys_create with kind: "app") are for deployed apps, not
agents. They never expire, are bound to one project and branch, and can only run
SQL through POST /v1/sql as their own Postgres role holding exactly their table
grants (or only post telemetry). An agent holding one can call no tool here.
Manage them with api_keys_grant and api_keys_rotate (the old secret keeps
working for the overlap).
| Env var |
Purpose |
Default |
BATA_API_KEY |
API key |
the CLI login |
BATA_PROFILE |
CLI profile to read the login from when BATA_API_KEY is unset |
default (~/.batarc) |
BATA_API_URL |
Control-plane base URL |
the profile's, else https://api.batadata.com |
BATA_MCP_READONLY |
1 or true hides every mutating tool |
off |
BATA_MCP_TOOLSETS |
Comma list of toolsets to expose (see below) |
all |
Configure your client
Claude Code
# On a machine that ran `bata login`:
claude mcp add batadata -- npx -y @batadata/mcp
# Or with a scoped key:
claude mcp add batadata --env BATA_API_KEY=bata_xxx -- npx -y @batadata/mcp
Or add it to the project's .mcp.json:
{
"mcpServers": {
"batadata": {
"command": "npx",
"args": ["-y", "@batadata/mcp"],
"env": { "BATA_API_KEY": "bata_xxx" }
}
}
}
Claude Desktop
Edit claude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"batadata": {
"command": "npx",
"args": ["-y", "@batadata/mcp"],
"env": { "BATA_API_KEY": "bata_xxx" }
}
}
}
Restart Claude Desktop after saving.
Cursor
Add .cursor/mcp.json in the project (or ~/.cursor/mcp.json for every
project). Cursor limits how many tools it loads, so pick the toolsets you need:
{
"mcpServers": {
"batadata": {
"command": "npx",
"args": ["-y", "@batadata/mcp"],
"env": {
"BATA_API_KEY": "bata_xxx",
"BATA_MCP_TOOLSETS": "core,insights,index"
}
}
}
}
Any other MCP client that speaks stdio uses the same command, args and env.
Toolsets and read-only mode
Tools are grouped into toolsets. BATA_MCP_TOOLSETS=core,insights exposes only
those groups; unset (or all) exposes everything. core alone is enough for the
basic loop: projects, branches, SQL, connection strings, usage and whoami.
BATA_MCP_READONLY=1 hides every tool that changes anything (including sql,
which can write). The issue-report tools stay: filing a report changes none of
your resources. Combine it with a read key for an agent you do not trust with
writes. The two filters stack.
| Toolset |
What is in it |
core |
Projects, branches, SQL, connection strings, usage, identity, issue reports |
projects |
Project details, rename, storage quota, restore window, operations |
branches |
Branch detail, TTL, reset, rollback, restore, databases, roles |
computes |
Compute status, start, suspend, resize, always-on, logs, read replicas |
sql |
Table browsing with filters, row writes, time travel, connection test |
schema |
Schema dump and diff, migration checks, EXPLAIN, copying a database in |
insights |
Performance series, top queries, recommendations, regressions, live activity |
index |
Index advice and index trials |
telemetry |
One-step client telemetry setup |
keys |
API keys |
team |
Teams and members |
billing |
Plans, invoices, card on file, spend cap, stop at the free limit, reservations, portal links |
account |
Audit log, notifications, health checks |
powdb |
The PowDB engine lane (PowQL) |
Tools
Tools marked (confirm) are destructive and refuse to run unless called with
confirm: true.
core (15)
| Tool |
What it does |
Scope |
projects_list |
List projects |
read |
projects_create |
Create a project |
admin |
projects_delete (confirm) |
Delete a project |
admin; owner or admin role |
branches_list |
List branches |
read |
branches_create |
Create a branch |
admin |
branches_delete (confirm) |
Delete a branch |
admin |
sql |
Run a SQL query |
sql |
usage |
Current usage and cost |
read |
whoami |
Who am I |
read |
platform_config |
Platform limits |
read |
connection_info |
Connection strings |
sql |
report_create |
Report a problem to BataDB (the project's state is attached) |
read |
report_list |
List issue reports |
read |
report_get |
Get an issue report and its thread |
read |
report_comment |
Add to an issue report |
read |
branches (15)
| Tool |
What it does |
Scope |
branches_protect |
Protect or unprotect a branch |
admin |
recovery_points |
List recovery points (PITR window) |
read |
restore_create |
Restore a branch to a point in time |
admin |
branches_get |
Get a branch |
read |
branches_set_ttl |
Set or clear a branch TTL |
admin |
branches_reset (confirm) |
Reset a branch to its parent |
admin |
branches_rollback (confirm) |
Roll a branch back to a point in time |
admin |
branches_set_primary |
Make a branch the primary |
admin |
databases_list |
List databases |
read |
databases_create |
Create a database |
admin |
databases_delete (confirm) |
Delete a database |
admin |
roles_list |
List roles |
read |
roles_create |
Create a role |
admin |
roles_delete (confirm) |
Delete a role |
admin |
roles_reset_password (confirm) |
Reset a role password |
admin |
owner_password_reset (confirm) |
Reset the project owner (bata_owner) password: every branch's connection string changes |
admin |
sql (7)
| Tool |
What it does |
Scope |
time_travel_query |
Query the database AS OF a past point |
sql |
sql_test_connection |
Test a branch connection |
read |
tables_list |
List tables |
read |
table_rows |
Browse table rows |
read |
table_rows_insert |
Insert a row |
sql |
table_rows_update |
Update a row |
sql |
table_rows_delete (confirm) |
Delete rows |
sql |
schema (7)
| Tool |
What it does |
Scope |
schema_dump |
Dump a branch's schema |
read |
schema_diff |
Diff two branches' schemas |
read |
schema_check |
Check a migration against live traffic |
sql |
explain |
EXPLAIN a query |
sql |
migrate_test_connection |
Test a source database |
admin |
migrate_estimate |
Estimate a migration |
admin |
migrate_start |
Copy a database in (server-side) |
admin |
insights (17)
| Tool |
What it does |
Scope |
cost_by_query |
Per-query compute cost attribution |
read |
insights_overview |
Insights overview |
read |
insights_queries |
Query statistics |
read |
insights_query |
One query's detail |
read |
insights_top_queries |
Top queries (attributed) |
read |
insights_performance |
Performance series |
read |
insights_timeseries |
Server time series |
read |
insights_size |
Database size |
read |
insights_live |
Live activity |
read |
insights_cold_start |
Cold start timings |
read |
insights_trends |
Query trend |
read |
insights_regressions |
Query regressions |
read |
insights_turbine_overview |
Telemetry overview |
read |
insights_health |
Telemetry health |
read |
recommendations_list |
List recommendations |
read |
recommendations_refresh |
Re-evaluate recommendations |
admin |
recommendations_set_status |
Dismiss or reopen a recommendation |
admin |
projects (9)