All jobs

Which Queries Got Slower This Month? A Database Consultancy's PlanetScale Review for Each Client

A database consultancy makes one agent per client, signed into that client's PlanetScale, that drafts the monthly review of slow queries, errors and index advice.

Run this on RushOpens the console with this prompt ready to send. Connect PlanetScale there first.

What the agent does

This is for a database consultancy that keeps SaaS companies' PlanetScale databases healthy on a monthly retainer. Every month each client gets a written review: which queries cost the most time, which ones fail, which index changes PlanetScale suggests, and what the consultancy recommends. Gathering the numbers takes longer than writing the advice. The consultancy saves one agent as a template whose connections name planetscale, PlanetScale's MCP server at https://mcp.pscale.dev/mcp/planetscale, with instructions that set the review's layout and forbid every tool that changes anything. When a client signs a retainer, its backend calls POST /o/{org}/agents {"template": "<template id>", "name": "pscale-review-<client id>"} and stores the agent id on the client's record.

The client connects their own PlanetScale organization to that agent. The consultancy's client portal calls POST /o/{org}/agents/{agent}/connections {"type": "mcp", "name": "planetscale"} and opens the authorize_url for the client's admin. On PlanetScale's own page they choose no access, read-only or full access, for the whole organization or per database, and separately whether the server may touch the payment method; this job needs read-only on the databases in scope and nothing on payments. Because the review runs no SQL, the client can also set their organization's MCP query access to "No query access". The consultancy registers no OAuth app and never holds a service token for a client.

On a run the agent calls planetscale_list_databases and planetscale_list_branches to find each production branch. For each one it reads planetscale_get_insights for query performance, planetscale_list_query_error_patterns for failing queries grouped by error fingerprint with their message, occurrence count, last run and duration, planetscale_list_schema_recommendations for suggested indexes to add, redundant ones to drop and primary keys nearing exhaustion, and planetscale_get_branch_metrics with view set to series for CPU, memory, disk, replication lag and connections over time.

The consultancy's backend pastes last month's summary into the prompt, so the agent marks each of this month's heaviest query patterns as new, worse, better or unchanged. It writes review.md in the consultancy's layout and summary.json for next month's comparison. It does not call planetscale_execute_read_query, planetscale_execute_write_query or planetscale_update_payment_method, and applies no recommendation.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "<agent id>",
  "input": "Review this client's PlanetScale databases for October 2026. Call planetscale_list_databases, then planetscale_list_branches for each, and use each database's production branch. For each production branch call planetscale_get_insights, planetscale_list_query_error_patterns, planetscale_list_schema_recommendations, and planetscale_get_branch_metrics with view series. Take the 10 query patterns with the most total time and mark each new, worse, better or unchanged against last month's summary below. Write review.md with: those 10 patterns with the table each reads and what changed; every error pattern with its message, occurrence count and last run; every open schema recommendation with the table it touches; and any metric that stayed high through the month. Also write summary.json with the 10 patterns and the error fingerprints, for next month. Do not call planetscale_execute_read_query, planetscale_execute_write_query or planetscale_update_payment_method, and change nothing. Last month's summary: <summary.json from the previous review>"
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

review.md and summary.json come back as artifacts on the session, and the run.completed webhook carries a short result. The consultant who owns the client opens the review as a first draft: the facts are in place, and their job is the judgment, which recommendation is worth the client's engineering time this month and which can wait.

What the consultant checks before sending: a query marked worse because the client ran a one-off backfill; a schema recommendation that adds an index to a table the client writes to heavily, where the extra write cost may outweigh the faster read; and error patterns that come from the client's own retries rather than the database. The session's transcript shows every tool call and what it returned, so any number in the draft can be traced to PlanetScale's answer.

The consultancy stores summary.json against the client so next month's request carries it. A month with nothing new produces a short review saying so, which is itself worth sending.

Run it on every month, per client

On the first of the month the consultancy's scheduler sends one POST /o/{org}/sessions per client, with that client's agent id as agent, the month and last month's summary in input, and a request_id that is a UUID v5 of the client id and the month so a retried job starts no second run. Runs past the key's concurrent limit are created queued and start as earlier ones finish, so the whole client list goes out in one loop.

When a client reports that their app got slow, the consultant can send the same request mid-month with a shorter window. Each answer arrives on the key's webhook; the handler matches execution_id to the client it stored at start and downloads the two files from the session's artifact links.

The use case this job follows, with its automation and trigger: Run an agent per customer task.

Why run it on Rush?

Each client's PlanetScale access belongs to that client's own agent and was granted on PlanetScale's page at the level the client chose. The client can revoke it in PlanetScale at any time, and no run for one client can reach another client's databases. The consultancy keeps one template: a change to the review's layout or a new check is one PATCH to the template, which reaches every client's agent on its next run.

Every run has its own computer and a record of what it read and what it cost. GET /o/{org}/sessions?agent=<agent id> lists one client's reviews with their total_cost_usd, what each review's model calls cost, so the consultancy can see what a retainer's monthly review costs in model calls.

Frequently asked questions

Does the client have to give the consultancy write access?

No. Read-only access to the databases in scope is enough, with no payment method access. The prompt and the template's instructions forbid the query and payment tools, and the client can set MCP query access to none in PlanetScale as a second lock.

Can the agent add the indexes PlanetScale recommends?

Not in this setup: it has no write access and its instructions forbid writes. The consultant recommends the change in the review and the client's engineers make it, which keeps a schema change on a production database a decision people make.

Does it work for PlanetScale Postgres as well as Vitess?

PlanetScale's MCP server covers both. Some tools behave differently; planetscale_get_postgres_logs, for example, works only on Postgres branches. A consultancy with Postgres clients can add that call to the template's instructions for them.

What happens when a client disconnects PlanetScale?

The connection under their agent stops working, and GET /o/{org}/agents/{agent}/connections shows its status. The portal asks the client's admin to sign in again with the same connections call, and the next month's review runs as before.

More PlanetScale jobs

More jobs like this: Run an agent per customer task

Keep reading