polystella-emdash-agent
Drive PolyStella translation on a running EmDash site through its MCP tools (polystella__*) or its REST API, typed client and OpenAPI. Use when asked to translate a collection, check or retry batch jobs, publish or replace translations, export UI-string catalogs for a pull request, or script PolyStella from CI or another service.
polystella-emdash-agent
You are talking to a running EmDash site that has the PolyStella plugin
(@cloudflare/polystella-emdash). This skill covers the MCP tools and the
REST API: setup, workflows, the publish/replace guard, and errors.
Load a different skill when:
- You are editing an Astro project's PolyStella config:
polystella-consumer. - You are changing the PolyStella source code:
polystella-contributor.
Pick a surface
| You are | Use | Token scope |
|---|---|---|
| An AI agent with an MCP client | MCP tools at /_emdash/api/mcp | mcp:tools:polystella |
| A CI job, script or Worker | REST, the typed client, or the OpenAPI doc | admin |
Both use an EmDash personal access token (ec_pat_…). The token's user needs
the Administrator role for everything except collection_policy
(Editor). Never print a token, paste it into chat, or commit it.
Setup (once per site, done by a human administrator)
-
Create a token in the EmDash admin with the scope from the table above.
-
Enable the plugin's MCP tools (they are off until enabled): in the admin, Plugins → PolyStella → Enable plugin MCP tools. Scripted:
curl -X PUT https://example.com/_emdash/api/admin/plugins/polystella/mcp \ -H "Content-Type: application/json" -H "X-EmDash-Request: 1" --cookie "…admin session…" \ -d '{"enabled": true}' -
Connect the MCP client, for example Claude Code:
claude mcp add --transport http emdash https://example.com/_emdash/api/mcp \ --header "Authorization: Bearer $EMDASH_TOKEN" -
Optional: in PolyStella's Translation settings, turn on Let agents publish translations and/or Let agents update existing translations. Both are off by default. Without them you can only create drafts.
If tools/list shows no polystella__* tools, step 2 hasn't been done, or
PolyStella was upgraded since: EmDash hides plugin tools whose definitions
changed until an administrator enables them again. Ask the user; you cannot
enable them yourself.
The tools
Names are prefixed polystella__. Inputs are strict: unknown keys are rejected.
| Tool | Input | Use it to |
|---|---|---|
collection_policy | collection | Check a collection is enabled; get its fields and locales. |
batch_check | collection, entryIds[] (50 at most) | Before a job: bad ids, untranslated blocks, #… links. |
batch_start | collection, locales[], entryIds[]? | Create missing translations as drafts. |
batch_start_publish_or_update | same + publish?, updateExisting?, confirm? | Publish and/or replace. Destructive; see below. |
batch_jobs | — | The ten latest jobs: status, counts, usage. |
batch_results | jobId, outcome?, cursor? | Per-entry rows of one job, paged by nextCursor. |
batch_cancel | jobId | Stop a running job. Saved translations stay. 409 if done. |
batch_retry | jobId | New job for the failed or never-run rows of a stopped job. |
catalog_status | locale, only?, group?, limit?, cursor? | One page of UI strings, with untranslated/override counts. |
catalog_export | locale | The catalog JSON file to commit. |
translate_text | text, targetLocale, model?, instructions? | Try a translation. Nothing is saved. |
Locales are catalog codes such as fr-FR, never the source locale. You cannot
change settings, collection policy, providers or locales. If the user wants
that, tell them where to do it in the admin.
Workflows
Translate a collection (drafts)
collection_policy {collection}. Ifenabledis false, stop: an administrator must enable it under Collections. UsetargetLocales[].codefor the locales.- Optional, when you have
entryIds:batch_check {collection, entryIds}. It calls no model. Report anyproblem(unknown id, not a source entry),unlistedBlockTypes(copied untranslated) andnotice(same-page links to review after translating) before going on. - Tell the user it spends model tokens, then
batch_start {collection, locales}. AddentryIdsto limit it to some entries.entryIds × localesmay be at most 5,000. - The reply is
{started: true, job}. Keepjob.id. - Poll
batch_jobsuntil that job'sstatusisfinishedorcancelled. Wait at least 10 seconds between polls; big collections take minutes. - Report
counts(created,updated,skipped,failed) andusage.estimatedCostUsdwhen present. Iftruncatedis true, the job stopped at 5,000 translations: runbatch_startagain, and the done ones are skipped. - If
failed > 0:batch_results {jobId, outcome: "failed"}for themessageof each row, thenbatch_retry {jobId}once the cause is fixed.
Existing translations are skipped, not replaced. That's the safe default.
Publish or replace translations (guarded)
publish: true makes each translation live without review.
updateExisting: true overwrites existing translation text. Before calling:
- Ask the user explicitly and say which of the two they want.
- Call
batch_start_publish_or_updatewithoutconfirm. You get{started: false, summary, confirm}. Nothing has started. - Show the user the
summaryword for word and wait for a yes. - Repeat the same call with
confirmset to the returned value.
Rules:
- Change any argument and you need a new plan. A
confirmfrom another call is ignored and you get a new plan back. - Never compute
confirmyourself, and never reuse one across tasks: it never expires, so reusing one skips showing the user the plan. FORBIDDEN … has not allowed agents to publish/update: the admin switch is off. Tell the user where it is (Translation settings). Do not work around it through REST or another token.batch_retryon a job that published or replaced needs the same switches, but runs without a plan orconfirm: it publishes or replaces again straight away. Ask the user first.
Export UI strings for a pull request
Catalogs live in Git; the site's overrides are edits waiting to be committed.
catalog_status {locale, only: "overridden"}to see what differs: entries withoverrideset, or withstate: "missing". Useonly: "untranslated"for keys with no translation yet. FollownextCursorwhile it isn'tnull;countscovers every page.catalog_export {locale}returns{filePath, filename, json}.- Write
jsonbyte for byte tofilePathin the repository. Don't reformat it; it's already deterministic. - Commit and open a pull request only if the user asked you to.
Check a translation quickly
translate_text {text, targetLocale} uses the site's glossary, instructions
and configured model. Use it to test wording or a glossary term before a batch.
It still spends tokens. Text is capped at 30,000 characters. Check
translation: if it is null, report error.
REST, client and OpenAPI
Every operation is POST /_emdash/api/plugins/polystella/<route> with a JSON
body. Read-only routes (batch/jobs, batch/results, catalog,
catalog/export, policy) also answer GET with a query string. Replies use
EmDash's envelope: { "success": true, "data": … } or
{ "success": false, "error": { "code", "message" } }.
| Route | Same as MCP tool |
|---|---|
batch/jobs | batch_jobs |
batch/results | batch_results |
batch/start | batch_start* |
batch/check | batch_check |
batch/cancel | batch_cancel |
batch/retry | batch_retry |
catalog | catalog_status¹ |
catalog/export | catalog_export |
policy | collection_policy |
translation-sandbox | translate_text |
¹ catalog returns every key at once; catalog_status filters and pages it.
REST is admin-equivalent. batch/start takes publish, updateExisting
and job settings directly, with no switch or confirmation. A script holding
an admin token is trusted like an administrator. An agent should still ask
before publishing or replacing over REST.
In TypeScript, use the client. It only needs fetch, so it runs in Node, CI
and Workers:
import { createPolystellaClient, PolystellaApiError } from "@cloudflare/polystella-emdash/api";
const polystella = createPolystellaClient({ baseUrl: "https://example.com", token: process.env.EMDASH_TOKEN ?? "" });
const job = await polystella.startBatchJob({ collection: "posts", locales: ["fr-FR"] });
const { jobs } = await polystella.listBatchJobs({ signal: AbortSignal.timeout(30_000) });
const { json, filePath } = await polystella.exportCatalog("fr-FR");
A refused call throws PolystellaApiError with status and code.
For other languages, generate a client from the OpenAPI 3.1 document:
node_modules/@cloudflare/polystella-emdash/dist/openapi.json, orimport doc from "@cloudflare/polystella-emdash/openapi.json" with { type: "json" }.GET /_emdash/api/plugins/polystella/openapion the site (admintoken), withserversset to the site's origin.
Errors
MCP errors arrive as isError: true with text [CODE] message.
| Code / status | Usually means | Do |
|---|---|---|
FORBIDDEN 403 | Collection not enabled or admin switch off (over REST also: role too low) | Read the message; tell the user what to change. Don't retry. |
INSUFFICIENT_SCOPE | The token lacks mcp:tools:polystella (MCP) or admin (REST) | Ask the user for a token with that scope. Don't retry. |
INSUFFICIENT_PERMISSIONS | The token's user has too low a role | Ask the user to use an Administrator's token. Don't retry. |
BAD_REQUEST 400 batchQueueBinding | The site has no batch queue configured | Batch jobs can't run here. Tell the user; don't retry. |
BAD_REQUEST 400 | Wrong locale, empty collection, over 5,000 translations, nothing to retry | Fix the arguments. |
CONFLICT 409 | The job is still running, already stopped, or it changed while you acted | Read the message: wait, batch_cancel first, or do nothing. |
NOT_FOUND 404 | Unknown jobId, collection or locale | Get ids from batch_jobs, slugs from the user. |
| 401 | Bad or expired token | Ask the user for a new token. |
No polystella__* tools | Tools not enabled, or re-enable needed after an upgrade | Ask an administrator to enable them (Setup step 2). |
Don'ts
- Don't start a job, publish, or replace without saying what it does and what it costs.
- Don't poll faster than every 10 seconds, or forever: stop and report if a job runs over 30 minutes.
- Don't pass
publish/updateExistingtobatch_start: it rejects them. Use the guarded tool. - Don't use a REST
admintoken to get around a refused MCP call. - Don't edit exported catalog JSON before committing it.
Files of this skill
This skill has no supporting files.