Skip to content
Browse guides

MCP server

Connect AI assistants to Publisle through a stateless MCP endpoint that edits documents, previews HTML, and exports PDF with the Rust compiler.

Guide ·Markdown source ·View on GitHub

MCP server

Publisle exposes its document model to AI assistants through the Model Context Protocol (MCP). An assistant can draft a document, add and rearrange typed blocks, validate it, preview the compiled HTML and export a PDF. Nothing is stored on the server: every call receives the whole document and returns the new one.

Watch it run on the MCP demo page or call the hosted endpoint directly:

TextPOST https://api.publisle.xyz/mcp

Feasibility

The server is feasible at low risk because Publisle already has the pieces:

  • Editing. Every block operation in the playground (add, remove, move, duplicate, update, metadata, JSON import) lives in the framework-free DocumentEditor. Each MCP tool wraps one of those operations, so the assistant and the playground cannot drift apart.

  • Validation and preview. prepare validates, and compilePublicationAsync produces the same HTML the playground previews. Markdown conversion comes from @publisle/markdown.

  • PDF. The PDF service already compiles with the prebuilt Rust compiler (publisle-pdf, built in publisle-rs) inside a rootless Docker worker. The compile_pdf tool sends the document through that same queue, quota and image-fetch protections and always selects the Rust engine. Nothing is re-implemented.

The main risks, and how the design contains them:

RiskContainment
The API runs with a 48 MB heap and no JITThe MCP bundle loads lazily on the first /mcp call. A test runs every tool under those exact flags.
A broken MCP bundle could take PDF export down with it/mcp answers 503 if the bundle will not load. /health and /pdf/compile are untouched.
Abuse of a public endpointThe 256 KiB request cap, an in-flight cap, a per-call deadline and the per-IP PDF quota all apply.
Cross-site use from a browserThe existing origin allow-list applies. Requests without an Origin header (desktop clients) pass.
Specification driftStreamable HTTP with JSON responses only. The server negotiates the protocol version with the client.
Server state leaking between usersThere is none. The server has no sessions and never reads files or the network, except for PDF images.

Out of scope: sessions, SSE streaming, server-initiated messages and OAuth. The endpoint is public. PDF exports through MCP also use the PDF service's quota.

Architecture

TextMCP client --POST /mcp (JSON-RPC)--> publisle-api (server.mjs)
                                        |  lazy import
                                        v
                                     mcp.mjs  --> DocumentEditor, markdown, core, adapter-core
                                        |
                                        +-- compile_pdf --> queue + quota --> publisle-pdf (Rust)

The handler is a transport-agnostic function, handleRpc(message, host). The API route is a thin wrapper around it. The demo page runs the same handler in the browser when the API is unreachable.

Connect a client

Clients that accept a remote URL need only:

JSON{
  "mcpServers": {
    "publisle": { "url": "https://api.publisle.xyz/mcp" }
  }
}

Clients that only speak stdio can bridge with npx mcp-remote https://api.publisle.xyz/mcp.

Tools

Tools take a document (the Publisle JSON document) where one is needed and return the updated document in structuredContent.

ToolWhat it does
list_blocksBlock types with label, description, category and default data
list_templatesPDF templates, engines and required metadata
new_documentStart an empty document, optionally with metadata
set_metadataReplace the document metadata
add_blockInsert a block of a type at an index, with default or supplied data
update_blockReplace a block's data
remove_blockDelete a block
move_blockMove a block up or down
duplicate_blockCopy a block with a fresh id
import_markdownConvert Markdown to a document, reporting diagnostics
export_markdownConvert a document to Markdown
import_jsonParse and normalize a JSON document string
validatePrepare the document and return diagnostics
outlineHeadings in order
referencesLabelled targets such as figures, equations and headings
render_htmlThe compiled static HTML preview
compile_pdfExport a PDF with the Rust compiler; returns a base64 application/pdf resource

Failures return a normal tool result with isError: true and a message the assistant can act on, such as the diagnostics from validate. Protocol faults use standard JSON-RPC error codes.

The server also offers the block catalog and a sample document as resources, and a draft_article prompt.

Limits

LimitValue
Request body256 KiB
MCP call rate90 calls per client IP in any 60-second window
Concurrent MCP callsSix in-flight requests across the API
Tool time budgetFive seconds for editing tools and the PDF deadline for compile_pdf
PDF compilations15 attempts per IP per 10 minutes, with cached PDFs exempt

The API returns HTTP 429 with Retry-After: 60 when an MCP request exceeds either admission limit. Each message in a JSON-RPC batch counts toward the call quota. Cache hits still count toward MCP admission.

Run it locally

Bashpnpm --filter @publisle/mcp test
pnpm --filter @publisle/mcp build

The first release keeps @publisle/mcp private. It is bundled into the PDF API rather than published to npm, because publication is irreversible and the interface may still change.