docs-translate-webhook — Wire an external translation pipeline via webhook
Workflow#
- Verify MCP transport — call
list_workspacesas a connectivity probe. If it fails, print the MCP connection command and exit gracefully. - Validate plan and inputs — read the workspace plan via
get_workspace. If the plan is below PRO+, stop and print an upgrade prompt. Validate that the webhook URL ishttps://(rejecthttp://and non-URLs). Confirm the runtime flavor (vercelorexpress; defaultvercel). - Switch translation mode — call
set_translation_modewithmode: external. This stops Docsbook's built-in translator and causes it to emittranslation.requestedevents instead. - Register the webhook — generate a fresh HMAC secret and call
register_webhook_translation_requestedwith the provided URL. Capture thecallback_urlfrom the response for use in the handler. Surface the HMAC secret to the user once. - Scaffold the handler — produce a handler file for the selected runtime that verifies the HMAC signature, invokes the user's translation logic (as a TODO placeholder), and POSTs results back to the callback URL.
- Write the handler file — place it at the configured output path (default
api/docsbook-translate.tsfor Vercel,src/routes/docsbook-translate.tsfor Express). Create parent directories if needed. Overwrite if the file already exists. - Report — print the webhook URL, HMAC secret, handler path, and the next steps the user must complete before the pipeline goes live.
Guardrails#
- Reject
http://webhook URLs — onlyhttps://is accepted. - Never hardcode the HMAC secret inside the generated handler file — always reference an environment variable (
DOCSBOOK_WEBHOOK_SECRET). - Never call
set_translation_modebefore plan validation passes — switching toexternalon a workspace without PRO+ disables translation entirely. - The generated handler must include HMAC signature verification as a non-optional step before processing any payload.
- If the MCP response does not include a
callback_url, default tohttps://docsbook.io/api/translations/callbackin the handler.
MCP Tools#
| Tool | Purpose |
|---|---|
list_workspaces |
Probe MCP transport liveness |
get_workspace |
Read workspace plan and settings |
set_translation_mode |
Switch mode to external |
register_webhook_translation_requested |
Register the outbound webhook and obtain callback URL |
Acceptance Criteria#
- MCP transport verified before any mutation
- PRO+ plan confirmed; execution halted cleanly if below PRO+
- Webhook URL validated as
https://before registration - Translation mode switched to
external - Webhook registered with a freshly generated HMAC secret
- HMAC secret surfaced to the user exactly once; never embedded in handler file
- Handler file scaffolded with HMAC verification and TODO translation logic
- Handler file written to the correct path for the selected runtime
- Output includes webhook URL, secret instructions, handler path, and next steps