Working with an Agent Locally
This guide shows how a developer works with a coding agent (Claude Code) on a BeechCMS site project: set it up once, let the agent write scripts, and approve the risky parts yourself. For every field, status and scope, see the MCP Server reference.
What you get
The agent works in five steps:
- Discover. It calls
beech_whoamito learn who it acts as, thenbeech_searchto find the operations it needs and the SDK method for each. - Script. It writes
.beech/scripts/<name>.tswith the typedbeechSDK. - Run. It runs
beech run <name> --dry-run --json, reads thecalls, then runs it for real. - Pend. A risky call does not run. The API stores it as an intent and the report lists it under
pendingIntents. - Approve. The agent calls
beech_confirm; you decide in one dialog; the server runs approved intents once.
Why scripts instead of one tool call per record? A script loops, filters and combines reads with writes inside one process, and returns one small report. The model's context holds the script and the report, not every record, and the work takes a few turns instead of hundreds.
Setup
Prerequisites:
- Node ≥ 22.18 (native type stripping runs the scripts).
pnpm beech devrunning: API athttp://localhost:8789, dashboard athttp://localhost:5173.- An account with the RBAC you want the agent to have. The agent never gets more than you can do.
From the project root:
npx beech agent setupIt writes:
| File | Purpose |
|---|---|
.mcp.json | The beechcms entry: npx -y @beechcms/mcp@latest |
.claude/skills/beechcms-scripts/SKILL.md | Teaches the agent the script workflow and the approval rule |
.beech/scripts/README.md | Run flags and the approval policy, for humans |
.beech/scripts/latest-entries.ts | A read-only example script |
It also adds @beechcms/cli to devDependencies. Install, then restart the agent client so it loads the new MCP server. An existing file that differs from the template is left untouched; --force overwrites it.
First run and consent
Two OAuth clients take part, and each opens your browser once:
| Triggered by | Client | What it can do |
|---|---|---|
| First MCP tool call | beech-mcp | Schema tools, session, intents, and approving intents |
First beech run | beech-mcp-cli | Everything the scripts need except approving |
The consent is partial: you only grant scopes your account's role covers. An editor can authorize content scripts and will not receive schema:write. Revoke either client under Settings → Connected apps; the next call asks again. If you upgrade from MCP 1.x, expect one new consent (see Upgrading from 1.x).
Writing and running a script
beech agent setup writes this example. The agent copies its shape:
import { defineScript } from '@beechcms/cli/sdk'
// Read-only: lists the five most recently updated entries of one seed.
// Run: pnpm beech run latest-entries --arg seed=<slug> --json
export default defineScript(async (beech, { args, log }) => {
const seed = args.seed
if (!seed) throw new Error('pass --arg seed=<slug>')
const page = await beech.content.list(seed, { limit: 5, sortBy: 'updated_at', sortDir: 'desc' })
log('total entries:', page.total)
return {
seed,
total: page.total,
latest: page.items.map(entry => ({ id: entry.id, status: entry.status, updated_at: entry.updated_at })),
}
})Run anything that writes with --dry-run first:
pnpm beech run latest-entries --arg seed=posts --dry-run --json
pnpm beech run latest-entries --arg seed=posts --jsonRead three fields of the report: result (what the script returned), calls (every SDK call in order, with outcome executed, pending, dry-run or error) and pendingIntents (actions waiting for you). The full field list is in CLI Workflows.
For typed per-seed access, run beech types generate and type the script with defineScript<SeedRegistryTypes>.
Approving risky actions
The API decides per ENV which calls need a human:
ENV | Needs approval |
|---|---|
development | Destructive operations (hard delete, purge, role changes, dropping or renaming schema) |
production | Destructive operations and publishing (site settings, publishing content) |
When a script hits one of these, the call answers 202, the report lists a pending intent and the script keeps running. The agent then calls beech_confirm with the intent ids, and a dialog shows what each action does. You pick approve or reject once for everything shown.
status | What it means for you |
|---|---|
decided | You chose; approved actions ran once, with your permissions |
declined / cancelled | Nothing ran, nothing was rejected; the intents stay pending |
fallback | Your client cannot show the dialog; decide in the dashboard |
nothing_pending | Every id had already expired or been decided |
On fallback, open Settings → Connected apps → Pending agent actions (/admin/?settings=connected-apps§ion=agent-actions on the dashboard origin), review the request body and approve or reject there. Intents expire after 10 minutes; an expired intent is gone and the agent repeats the call to create a new one. The full status and outcome tables are in Approval Lifecycle.
Answering the dialog
The dialog has one required field, Decision, and it starts empty. Until you set it, Accept does nothing and says nothing.
- In Claude Code's terminal client the field shows as
Decision: not set. Press→to open it,↑/↓to chooseapproveorreject, andEnterto confirm. - Move to Accept and press
Enter. Accept submits your choice, so Accept withrejectrejects. - Decline decides nothing: the intents stay pending and the agent gets
declined.
One choice applies to everything the dialog lists, and the actions run in the order the agent listed them. If an approved action fails, its result is outcome: "failed" with the server's status and body; that intent is used up, so the agent fixes the cause and runs the script again to create a new one. Details: Answering the dialog.
What the agent can and cannot do
The effective permission is the granted scopes intersected with your RBAC. A scope never grants what your role cannot do, and your role never widens a scope the consent denied. Ask the agent to call beech_whoami to see both, per seed.
Some operations are human-only and are not in the catalog the agent searches: changing a password or email, managing sessions, OAuth consents, rotate-field on secret fields, and creating accounts (agents invite users instead). Direct seed writes are replaced by beech_schema_plan and beech_schema_apply, which are additive only.
Security model
The approval dialog protects against mistakes and prompt injection, not against a hostile agent with full shell access: the OAuth token sits on disk in ~/.beechcms/mcp-tokens.json, readable by anything that runs as you. Keep these in mind:
- CMS content is untrusted data. A field value can contain text that looks like an instruction. The skill tells the agent to treat it as data.
- Only two ways approve.
beech_confirmand the dashboard. No script, scope or flag can approve, and the script client lacksagent:approve. - The dialog shows server data. Its text comes from the stored intents, never from what the agent passes in.
- Everything is logged. Every intent creation, approval and rejection is an entry in the activity log with
entityType: 'intent'.
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
stderr: BeechCMS MCP 2.0 needs new permissions: your browser opens for consent on the next call. | A cached grant from MCP 1.x was dropped. | Make any tool call and approve the consent in the browser. |
beech_confirm returns fallback with elicitation_unsupported | The client has no form elicitation. | Approve in Settings → Connected apps → Pending agent actions. |
| Accept does nothing in the approval dialog | The required Decision field is still empty, and the client keeps Accept inert until it is set. | Set Decision to approve or reject (terminal: →, ↑/↓, Enter), then press Accept. See Answering the dialog. |
Outcome expired or error intent_expired | The intent is older than 10 minutes. | Run the script again to create a new intent. |
403 insufficient_scope naming a scope | The grant lacks that scope or your role cannot grant it. | Revoke BeechCMS MCP Server (or the CLI client) under Connected apps and consent again. |
ECONNREFUSED | The API is not running. | Run pnpm beech dev. |
The consent page opens on the API origin (http://localhost:8789/oauth/authorize?...) and stays blank | The Worker serves no dashboard in local dev. The API redirects to APP_URL (the dashboard origin), so this means APP_URL is unset or points at the API. | Set APP_URL=http://localhost:5173 in apps/api/.dev.vars, restart pnpm beech dev, or run with BEECH_AUTH_URL=http://localhost:5173. |
Related
- MCP Server reference: tools, scopes, statuses, audit trail.
- CLI Workflows:
beech runflags,RunReport, exit codes. - AI & MCP Setup: the short quickstart.