Skip to content

cloudflare/polystella

Astro integration for localization and automated AI translation of content

https://skillcdn.ai/gh/cloudflare/polystella

Connect this address to your AI to use this skill. How to connect

  • Unverified
  • Default branchmain
  • Commit452fda3
  • LicenseMIT
  • Searchwords
View on GitHub

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.

Path
skills/polystella-emdash-agent/SKILL.md
License
MIT

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 areUseToken scope
An AI agent with an MCP clientMCP tools at /_emdash/api/mcpmcp:tools:polystella
A CI job, script or WorkerREST, the typed client, or the OpenAPI docadmin

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)

  1. Create a token in the EmDash admin with the scope from the table above.

  2. 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}'
    
  3. 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"
    
  4. 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.

ToolInputUse it to
collection_policycollectionCheck a collection is enabled; get its fields and locales.
batch_checkcollection, entryIds[] (50 at most)Before a job: bad ids, untranslated blocks, #… links.
batch_startcollection, locales[], entryIds[]?Create missing translations as drafts.
batch_start_publish_or_updatesame + publish?, updateExisting?, confirm?Publish and/or replace. Destructive; see below.
batch_jobs—The ten latest jobs: status, counts, usage.
batch_resultsjobId, outcome?, cursor?Per-entry rows of one job, paged by nextCursor.
batch_canceljobIdStop a running job. Saved translations stay. 409 if done.
batch_retryjobIdNew job for the failed or never-run rows of a stopped job.
catalog_statuslocale, only?, group?, limit?, cursor?One page of UI strings, with untranslated/override counts.
catalog_exportlocaleThe catalog JSON file to commit.
translate_texttext, 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)
  1. collection_policy {collection}. If enabled is false, stop: an administrator must enable it under Collections. Use targetLocales[].code for the locales.
  2. Optional, when you have entryIds: batch_check {collection, entryIds}. It calls no model. Report any problem (unknown id, not a source entry), unlistedBlockTypes (copied untranslated) and notice (same-page links to review after translating) before going on.
  3. Tell the user it spends model tokens, then batch_start {collection, locales}. Add entryIds to limit it to some entries. entryIds × locales may be at most 5,000.
  4. The reply is {started: true, job}. Keep job.id.
  5. Poll batch_jobs until that job's status is finished or cancelled. Wait at least 10 seconds between polls; big collections take minutes.
  6. Report counts (created, updated, skipped, failed) and usage.estimatedCostUsd when present. If truncated is true, the job stopped at 5,000 translations: run batch_start again, and the done ones are skipped.
  7. If failed > 0: batch_results {jobId, outcome: "failed"} for the message of each row, then batch_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:

  1. Ask the user explicitly and say which of the two they want.
  2. Call batch_start_publish_or_update without confirm. You get {started: false, summary, confirm}. Nothing has started.
  3. Show the user the summary word for word and wait for a yes.
  4. Repeat the same call with confirm set to the returned value.

Rules:

  • Change any argument and you need a new plan. A confirm from another call is ignored and you get a new plan back.
  • Never compute confirm yourself, 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_retry on a job that published or replaced needs the same switches, but runs without a plan or confirm: 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.

  1. catalog_status {locale, only: "overridden"} to see what differs: entries with override set, or with state: "missing". Use only: "untranslated" for keys with no translation yet. Follow nextCursor while it isn't null; counts covers every page.
  2. catalog_export {locale} returns {filePath, filename, json}.
  3. Write json byte for byte to filePath in the repository. Don't reformat it; it's already deterministic.
  4. 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" } }.

RouteSame as MCP tool
batch/jobsbatch_jobs
batch/resultsbatch_results
batch/startbatch_start*
batch/checkbatch_check
batch/cancelbatch_cancel
batch/retrybatch_retry
catalogcatalog_status¹
catalog/exportcatalog_export
policycollection_policy
translation-sandboxtranslate_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, or import doc from "@cloudflare/polystella-emdash/openapi.json" with { type: "json" }.
  • GET /_emdash/api/plugins/polystella/openapi on the site (admin token), with servers set to the site's origin.

Errors

MCP errors arrive as isError: true with text [CODE] message.

Code / statusUsually meansDo
FORBIDDEN 403Collection 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_SCOPEThe token lacks mcp:tools:polystella (MCP) or admin (REST)Ask the user for a token with that scope. Don't retry.
INSUFFICIENT_PERMISSIONSThe token's user has too low a roleAsk the user to use an Administrator's token. Don't retry.
BAD_REQUEST 400 batchQueueBindingThe site has no batch queue configuredBatch jobs can't run here. Tell the user; don't retry.
BAD_REQUEST 400Wrong locale, empty collection, over 5,000 translations, nothing to retryFix the arguments.
CONFLICT 409The job is still running, already stopped, or it changed while you actedRead the message: wait, batch_cancel first, or do nothing.
NOT_FOUND 404Unknown jobId, collection or localeGet ids from batch_jobs, slugs from the user.
401Bad or expired tokenAsk the user for a new token.
No polystella__* toolsTools not enabled, or re-enable needed after an upgradeAsk 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/updateExisting to batch_start: it rejects them. Use the guarded tool.
  • Don't use a REST admin token 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.

Browse all supporting files