MCP agent operating model
Purpose
Define how agents should use PlanetScale MCP safely. Agents should use production telemetry to generate useful work while avoiding autonomous production changes.
Default MCP choice
Use the PlanetScale MCP insights-only server when the task only needs Insights and Schema Recommendations.
Use the full PlanetScale MCP server only when the task explicitly requires database/schema access beyond Insights. Prefer read-only scopes.
The full MCP server has query execution tools. Treat write query tools as disabled unless the operator explicitly approves a specific non-production action or a carefully reviewed production action.
AGENTS.md guidance
Two different documents both named AGENTS.md serve different purposes:
CLI agent guide — shipped with pscale (AGENTS.md in the
planetscale/cli repo, or
pscale agent-guide --format json). Covers auth, --format json, flag
placement, and pscale sql. Load skill planetscale-pscale-cli-automation for the
same conventions inside this skills pack.
Project agent guide — your application repository's AGENTS.md (or
equivalent). Covers database targeting and approval policy for this app.
When working inside a repository, recommend adding a project database
targeting section to AGENTS.md or equivalent project instructions:
- PlanetScale organization.
- Database.
- Branch.
- Engine: Vitess or Postgres.
- Production branch name.
- Whether agents may use MCP insights-only or full MCP.
- Whether write queries are forbidden.
- Required approval protocol for schema, Traffic Control, webhooks, roles, and network changes.
Do not edit AGENTS.md without approval.
Safe autonomous tasks
Allowed by default:
- Read Insights.
- Read schema recommendations.
- Read schema metadata.
- Read existing webhooks and Traffic Control configuration.
- Read branch metadata.
- Inspect repository code.
- Correlate query patterns with code.
- File issues.
- Open pull requests.
- Create development branches.
- Apply DDL and migrations to non-production development branches.
- Open deploy requests into branches protected by a review workflow.
- Draft Traffic Control budget proposals.
- Draft webhook receiver requirements.
Where a PR + deploy-request workflow exists, the default deliverable for a
schema recommendation is the complete reviewable unit: development branch
with the DDL applied, PR with evidence (fingerprint, metrics, expected
effect), and an open deploy request. The human action is the merge/deploy
decision, not shepherding the proposal into existence.
Not allowed by default (the review-gate actions and non-reviewable mutations):
- Execute write SQL against production.
- Execute DDL directly against production branches.
- Deploy a deploy request / apply schema to production.
- Merge pull requests.
- Create webhooks.
- Create or enforce Traffic Control budgets.
- Rotate credentials.
- Change roles.
- Change IP restrictions or private connectivity.
- Restore or promote branches.
Agent loops
Daily recommendation loop
- Read open schema recommendations.
- Read top Insights regressions.
- Correlate with repository code.
- Generate ranked issues or PRs.
- Human reviews.
- Human approves any database-affecting action.
Anomaly loop
- Receive or inspect anomaly.
- Gather affected query patterns and tags.
- Identify source route/job/deploy.
- Produce incident note and proposed remediation.
- If code fix is obvious, open PR.
- If database change is needed, create a proposed change set only.
Traffic Control loop
- Identify unsafe traffic slice from Insights/tags.
- Draft
warn budget proposal.
- Human approves creation.
- Observe warnings.
- Human approves enforce mode only after validation.
Scheduled loops (cron / Automations)
The loops above run interactively. They can also run on a schedule with no
human in the loop, in two tiers. Tier 2 requires a standing authorization
per ../planetscale-autonomous-execution-mode/SKILL.md; Tier 1 requires none.
Every scheduled loop, both tiers: re-read authorization at run start,
stream status to a configured delivery channel, persist a run log, and
avoid filing duplicates (do not re-file an issue that is already open
for the same fingerprint/recommendation ID).
Tier 1 — propose through the review workflow (no authorization needed)
- Recommendation-to-PR loop (daily): list open schema recommendations
via MCP; for each new one matching the workflow (additive or destructive
— the PR review is the gate), create a development branch, apply the
DDL, open a PR with fingerprint, metrics, and expected effect, and open
the deploy request. The reviewable unit is complete when a human can
ship it with one merge/deploy action. Output: branch + PR + deploy
request per recommendation.
- Regression watch (hourly or per-deploy): compare top patterns
against a stored baseline (p50/p99, rows read, execution count); on
material regression, identify the deploy SHA from query tags and file
a report linking pattern to commit range. Output: report.
- Tag coverage audit (weekly): measure percentage of query time
carrying tags; list untagged high-cost patterns with likely code
paths; open or update a single tracking issue. Output: issue.
- Anomaly triage (webhook-triggered, not polled): on
branch.anomaly,
gather affected patterns, classify probable cause, post triage note to
the incident channel. Output: triage note.
- Posture drift check (daily): diff current safe-migrations flags,
webhook config, role list, and backup schedule against the last
assessment report; report any drift. Output: report.
Tier 2 — execute the review-gate action (standing authorization required)
- Recommendation deployer (daily, after the PR loop): deploy open
deploy requests that match the allowlist — typically "additive DDL,
PR approved or authored from an open recommendation, deploy with revert
window, max N per run" — then verify via schema read-back and an
Insights follow-up on the target fingerprint. Destructive DDL deploys
autonomously only when the authorization states a runtime-verifiable
bound (e.g. "drop only indexes with zero reads in 30 days, confirmed
via Insights at run time"). Where the org requires PR approval before
deploy, an approved PR satisfies the review gate and the authorization
covers only the mechanical deploy.
- Branch hygiene (weekly): delete development branches older than the
authorized age bound with no open deploy request; never touch
production or protected branches.
- Warn-budget gardener (weekly): create warn-mode Traffic Control
budgets for newly identified expensive slices matching the allowlist;
report warn counts on existing budgets. Enforce mode is never entered
autonomously unless the authorization names the specific budget.
- Credential expiry enforcement (daily): delete or flag passwords
past the authorized max age, only where the authorization lists the
affected roles and a rotation runbook exists.
Loop anti-patterns
- Polling MCP on a cron for events webhooks already deliver — use the
webhook as the trigger; use cron for baselines, sweeps, and audits.
- A Tier 2 loop whose allowlist is an intent ("keep things healthy")
rather than bounded operations.
- Loops that mutate without a delivery channel for status.
- Unbounded fan-out: one run applying every open recommendation at once
with no per-run cap.
Query execution safeguards
For read queries:
- Prefer replicas when available.
planetscale_execute_read_query routes reads to replicas by default when a
branch has replicas configured (use_replica: true). Set
use_replica: false only when the task needs primary-read semantics, such
as checking immediately-after-write state or primary-only behavior.
- Add source tags/comments for agent work.
- Avoid unbounded scans.
- Avoid
EXPLAIN ANALYZE on production unless explicitly approved.
- Limit result sizes.
- Avoid querying sensitive columns unless required and approved.
- For Postgres tables with row-level security, remember that the MCP read role
uses
pg_read_all_data and does not bypass RLS. If a read query returns zero
rows or a zero count and the MCP response warns that RLS may be filtering
results, treat the result as policy-filtered/unknown until confirmed through
an approved path; do not conclude the table is empty.
- When debugging high CPU on Postgres, use Insights data sorted by CPU
usage (via MCP where available, or
sort=cpuTime on the Insights API).
CPU time metrics are Postgres-only; do not ask for the same CPU-sorted
view on Vitess.
For write queries:
- Default is forbidden.
- If approved, prefer non-production branch.
- Require exact SQL review.
- Require rollback plan.
- Require branch and database name confirmation.
Output
Return:
- Recommended MCP server choice.
- Required scopes.
- AGENTS.md instructions to add.
- Allowed autonomous work.
- Disallowed work.
- Proposed agent loops.
- Approval gates.
End with:
“No MCP write tools or database mutations have been used.”
1---2name: planetscale-mcp-agent-operating-model3description: Configure safe agent behavior around PlanetScale MCP, Insights, schema recommendations, and repository work without autonomous production mutation.4---5
6# MCP agent operating model
7
8## Purpose
9
10Define how agents should use PlanetScale MCP safely. Agents should use production telemetry to generate useful work while avoiding autonomous production changes.
11
12## Default MCP choice
13
14Use the PlanetScale MCP insights-only server when the task only needs Insights and Schema Recommendations.
15
16Use the full PlanetScale MCP server only when the task explicitly requires database/schema access beyond Insights. Prefer read-only scopes.
17
18The full MCP server has query execution tools. Treat write query tools as disabled unless the operator explicitly approves a specific non-production action or a carefully reviewed production action.
19
20## AGENTS.md guidance
21
22Two different documents both named `AGENTS.md` serve different purposes:
23
241. **CLI agent guide** — shipped with `pscale` (`AGENTS.md` in the
25 [planetscale/cli](https://github.com/planetscale/cli) repo, or
26 `pscale agent-guide --format json`). Covers auth, `--format json`, flag
27 placement, and `pscale sql`. Load skill `planetscale-pscale-cli-automation` for the
28 same conventions inside this skills pack.
29
302. **Project agent guide** — your application repository's `AGENTS.md` (or
31 equivalent). Covers database targeting and approval policy for *this* app.
32
33When working inside a repository, recommend adding a **project** database
34targeting section to `AGENTS.md` or equivalent project instructions:
35
36- PlanetScale organization.
37- Database.
38- Branch.
39- Engine: Vitess or Postgres.
40- Production branch name.
41- Whether agents may use MCP insights-only or full MCP.
42- Whether write queries are forbidden.
43- Required approval protocol for schema, Traffic Control, webhooks, roles, and network changes.
44
45Do not edit `AGENTS.md` without approval.
46
47## Safe autonomous tasks
48
49Allowed by default:
50
51- Read Insights.
52- Read schema recommendations.
53- Read schema metadata.
54- Read existing webhooks and Traffic Control configuration.
55- Read branch metadata.
56- Inspect repository code.
57- Correlate query patterns with code.
58- File issues.
59- Open pull requests.
60- Create development branches.
61- Apply DDL and migrations to non-production development branches.
62- Open deploy requests into branches protected by a review workflow.
63- Draft Traffic Control budget proposals.
64- Draft webhook receiver requirements.
65
66Where a PR + deploy-request workflow exists, the default deliverable for a
67schema recommendation is the complete reviewable unit: development branch
68with the DDL applied, PR with evidence (fingerprint, metrics, expected
69effect), and an open deploy request. The human action is the merge/deploy
70decision, not shepherding the proposal into existence.
71
72Not allowed by default (the review-gate actions and non-reviewable mutations):
73
74- Execute write SQL against production.
75- Execute DDL directly against production branches.
76- Deploy a deploy request / apply schema to production.
77- Merge pull requests.
78- Create webhooks.
79- Create or enforce Traffic Control budgets.
80- Rotate credentials.
81- Change roles.
82- Change IP restrictions or private connectivity.
83- Restore or promote branches.
84
85## Agent loops
86
87### Daily recommendation loop
88
891. Read open schema recommendations.
902. Read top Insights regressions.
913. Correlate with repository code.
924. Generate ranked issues or PRs.
935. Human reviews.
946. Human approves any database-affecting action.
95
96### Anomaly loop
97
981. Receive or inspect anomaly.
992. Gather affected query patterns and tags.
1003. Identify source route/job/deploy.
1014. Produce incident note and proposed remediation.
1025. If code fix is obvious, open PR.
1036. If database change is needed, create a proposed change set only.
104
105### Traffic Control loop
106
1071. Identify unsafe traffic slice from Insights/tags.
1082. Draft `warn` budget proposal.
1093. Human approves creation.
1104. Observe warnings.
1115. Human approves enforce mode only after validation.
112
113## Scheduled loops (cron / Automations)
114
115The loops above run interactively. They can also run on a schedule with no
116human in the loop, in two tiers. Tier 2 requires a standing authorization
117per `../planetscale-autonomous-execution-mode/SKILL.md`; Tier 1 requires none.
118
119Every scheduled loop, both tiers: re-read authorization at run start,
120stream status to a configured delivery channel, persist a run log, and
121avoid filing duplicates (do not re-file an issue that is already open
122for the same fingerprint/recommendation ID).
123
124### Tier 1 — propose through the review workflow (no authorization needed)
125
126- **Recommendation-to-PR loop** (daily): list open schema recommendations
127 via MCP; for each new one matching the workflow (additive or destructive
128 — the PR review is the gate), create a development branch, apply the
129 DDL, open a PR with fingerprint, metrics, and expected effect, and open
130 the deploy request. The reviewable unit is complete when a human can
131 ship it with one merge/deploy action. Output: branch + PR + deploy
132 request per recommendation.
133- **Regression watch** (hourly or per-deploy): compare top patterns
134 against a stored baseline (p50/p99, rows read, execution count); on
135 material regression, identify the deploy SHA from query tags and file
136 a report linking pattern to commit range. Output: report.
137- **Tag coverage audit** (weekly): measure percentage of query time
138 carrying tags; list untagged high-cost patterns with likely code
139 paths; open or update a single tracking issue. Output: issue.
140- **Anomaly triage** (webhook-triggered, not polled): on `branch.anomaly`,
141 gather affected patterns, classify probable cause, post triage note to
142 the incident channel. Output: triage note.
143- **Posture drift check** (daily): diff current safe-migrations flags,
144 webhook config, role list, and backup schedule against the last
145 assessment report; report any drift. Output: report.
146
147### Tier 2 — execute the review-gate action (standing authorization required)
148
149- **Recommendation deployer** (daily, after the PR loop): deploy open
150 deploy requests that match the allowlist — typically "additive DDL,
151 PR approved or authored from an open recommendation, deploy with revert
152 window, max N per run" — then verify via schema read-back and an
153 Insights follow-up on the target fingerprint. Destructive DDL deploys
154 autonomously only when the authorization states a runtime-verifiable
155 bound (e.g. "drop only indexes with zero reads in 30 days, confirmed
156 via Insights at run time"). Where the org requires PR approval before
157 deploy, an approved PR satisfies the review gate and the authorization
158 covers only the mechanical deploy.
159- **Branch hygiene** (weekly): delete development branches older than the
160 authorized age bound with no open deploy request; never touch
161 production or protected branches.
162- **Warn-budget gardener** (weekly): create warn-mode Traffic Control
163 budgets for newly identified expensive slices matching the allowlist;
164 report warn counts on existing budgets. Enforce mode is never entered
165 autonomously unless the authorization names the specific budget.
166- **Credential expiry enforcement** (daily): delete or flag passwords
167 past the authorized max age, only where the authorization lists the
168 affected roles and a rotation runbook exists.
169
170### Loop anti-patterns
171
172- Polling MCP on a cron for events webhooks already deliver — use the
173 webhook as the trigger; use cron for baselines, sweeps, and audits.
174- A Tier 2 loop whose allowlist is an intent ("keep things healthy")
175 rather than bounded operations.
176- Loops that mutate without a delivery channel for status.
177- Unbounded fan-out: one run applying every open recommendation at once
178 with no per-run cap.
179
180## Query execution safeguards
181
182For read queries:
183
184- Prefer replicas when available.
185- `planetscale_execute_read_query` routes reads to replicas by default when a
186 branch has replicas configured (`use_replica: true`). Set
187 `use_replica: false` only when the task needs primary-read semantics, such
188 as checking immediately-after-write state or primary-only behavior.
189- Add source tags/comments for agent work.
190- Avoid unbounded scans.
191- Avoid `EXPLAIN ANALYZE` on production unless explicitly approved.
192- Limit result sizes.
193- Avoid querying sensitive columns unless required and approved.
194- For Postgres tables with row-level security, remember that the MCP read role
195 uses `pg_read_all_data` and does not bypass RLS. If a read query returns zero
196 rows or a zero count and the MCP response warns that RLS may be filtering
197 results, treat the result as policy-filtered/unknown until confirmed through
198 an approved path; do not conclude the table is empty.
199- When debugging high CPU on Postgres, use Insights data sorted by CPU
200 usage (via MCP where available, or `sort=cpuTime` on the Insights API).
201 CPU time metrics are Postgres-only; do not ask for the same CPU-sorted
202 view on Vitess.
203
204For write queries:
205
206- Default is forbidden.
207- If approved, prefer non-production branch.
208- Require exact SQL review.
209- Require rollback plan.
210- Require branch and database name confirmation.
211
212## Output
213
214Return:
215
216- Recommended MCP server choice.
217- Required scopes.
218- AGENTS.md instructions to add.
219- Allowed autonomous work.
220- Disallowed work.
221- Proposed agent loops.
222- Approval gates.
223
224End with:
225
226“No MCP write tools or database mutations have been used.”