How it works
- The agent connects to PlanetScale through the MCP server and pulls Insights data or open Schema Recommendations.
- Identifies the highest-impact queries or schema issues.
- Searches your codebase to find where those queries originate.
- Makes the change in the codebase.
- Benchmarks the change in a development environment to validate the improvement.
- Opens a pull request with the fix and an explanation of the expected impact.
Prerequisites
- PlanetScale MCP server installed and authenticated in your AI coding tool
- Cursor Automations (recommended) or another MCP-compatible coding agent such as Claude Code
- A PlanetScale database with Insights data
- An
AGENTS.mdfile in your repository with your PlanetScale org, database, and branch (see Help your agent target your project’s database)
Getting started
For best results, take an iterative approach:- Run the prompt manually first. Use one of the example prompts below in your AI coding tool and review the pull request it produces.
- Refine with guardrails. Based on the results, add rules specific to your codebase — which directories to touch, which ORM patterns to follow, linter and test requirements, migration commands, etc.
- Repeat a few times. Run it again with your refined prompt. Nudge the agent where needed. Each iteration helps you build a prompt that consistently produces high-quality PRs.
- Graduate to a schedule. Once the agent reliably produces good results, set it up as a Cursor Automation on a daily or weekly schedule.
Always review pull requests before merging. Automated agents can surface valuable optimizations, but a human should verify that the changes are safe for your workload.
Example prompt: Insights optimization
This prompt instructs the agent to review your Insights data, find the highest-impact queries, and optimize them. Customize the rules section for your framework, ORM, and linter.Adapt the rules to your stack. For example, a Rails project might add: “Run migrations with
rails db:migrate to generate the schema.rb file” and “Run rubocop and fix any lint errors.”Example prompt: Schema Recommendations
This prompt instructs the agent to evaluate open Schema Recommendations and implement them. Customize the rules section for your framework and workflow.Tips for effective automations
- One fix at a time. Each run should address a single query or recommendation. This keeps pull requests small, reviewable, and easy to revert.
- Benchmark in development. Instruct the agent to run
EXPLAINor time queries on a development branch before and after the change. This validates the optimization and gives reviewers concrete data. - Use
AGENTS.mdto provide context. Include your PlanetScale org, database, and branch so the agent doesn’t have to scan through all your organizations. - Adapt prompts to your stack. Add rules for your specific framework, ORM, migration tool, and linter. The more specific the guardrails, the better the output.
- Review every PR. Automated agents surface real improvements, but schema and query changes require human judgment before hitting production.

