typeset-mcp
v0.2.1MCP server that typesets Markdown documents to PDF with the Typst engine (CJK-first)
A Model Context Protocol server that typesets Markdown documents into production-quality PDFs. Powered by the Typst engine, with first-class CJK (Chinese, Japanese, Korean) support. LLM agents can write Markdown, but \"make it look professional\" is where they fail: fonts don't embed, tables split awkwardly, math breaks, page numbers vanish. typeset-mcp gives agents (and you) a structured pipeline instead of a one-shot converter: Add to your MCP client config (Claude Code, Cursor, Codex, etc.):
Summary extracted from the README.
typeset-mcp
A Model Context Protocol server that typesets Markdown documents into production-quality PDFs. Powered by the Typst engine, with first-class CJK (Chinese, Japanese, Korean) support.
Markdown → validate → measure → typeset → audit → render → publish → PDF
Why
LLM agents can write Markdown, but "make it look professional" is where they fail: fonts don't embed, tables split awkwardly, math breaks, page numbers vanish. typeset-mcp gives agents (and you) a structured pipeline instead of a one-shot converter:
- Validate before compiling — catch broken links, unbalanced code fences, oversized images, and setext heading traps before wasting a compile
- Measure before writing — table widths, code line lengths, and image sizes compared against the text area, with a rough page count
- Audit after building — read the actual PDF content stream: embedded fonts (error), text layer (error), WCAG AA contrast, orphan headings, split tables, page-edge text
- Render for visual review — page PNGs returned inline so the agent (or a vision model) can inspect the output
- Publish with fingerprint verification — sha256-checked copy that fails loudly if the draft changed
Quick Start
pip install typeset-mcp
Add to your MCP client config (Claude Code, Cursor, Codex, etc.):
{
"mcpServers": {
"typeset": {
"command": "typeset-mcp",
"args": ["--root", "/path/to/your/workspace"]
}
}
}
Or with uv:
{
"mcpServers": {
"typeset": {
"command": "uv",
"args": ["run", "--with", "typeset-mcp", "typeset-mcp", "--root", "."]
}
}
}
Tools
| Tool | What it does |
|---|---|
validate_document |
Lint Markdown: frontmatter, headings, code fences, tables, images, links |
measure_document |
Pre-compile estimates: table/code/image widths vs text area |
typeset_document |
Compile one .md to a draft PDF (.build.pdf) |
typeset_project |
Build multi-chapter projects from a YAML manifest |
audit_document |
Read the built PDF's content stream for typography defects |
render_pages |
Render page PNGs for visual review |
publish_document |
Copy draft to final destination with fingerprint check |
inspect_document |
Report pages, fonts, metadata |
convert_figures |
Batch-convert PDF vector figures to PNG |
create_project |
Scaffold a project from a template (report / homework / slides) |
list_guides / read_guide |
Methodology guides for agents |
Themes
Four themes × six accent colors:
| Theme | Use case | Layout |
|---|---|---|
minimal |
Simple documents | A4, no cover |
report |
Reports, papers | Cover + outline + body |
homework |
Problem sets | Compact info header, no cover |
beamer |
Presentations | 16:9 slides, one ## per slide |
---
title: My Document
author: Your Name
theme: report
lang: zh
accent: blue
footer: Internal Draft
---
Features
- CJK-first: Chinese/Japanese/Korean text renders correctly out of the box (Microsoft YaHei + Times fallback)
- Math: LaTeX math via mitex —
$\sum_{i=1}^n x_i$,$$E = mc^2$$, \boxed, align, matrices - Images: PNG/JPG/GIF/WebP, absolute or relative paths, remote URLs (with SSRF sandbox), auto-constrained to page, auto-optimized (downsampled + JPEG when oversized)
- Footnotes:
[^label]renders as page-bottom notes - Author notes:
authorNotesfrontmatter key renders \thanks-style footnotes on the cover - Mermaid diagrams: rendered via the mmdr package
- Multi-chapter books:
typeset_projectjoins chapters with one cover and outline - Stylesheets: custom
.typfiles injected after the theme - Project config:
typeset.yamlfor workspace-wide defaults - SSRF protection: remote image fetching runs through a network sandbox (scheme allowlist, private IP blocking, connection pinning, redirect validation)
Guides
The server ships two methodology guides that MCP agents read before typesetting:
- workflow — the calibration philosophy: validate → measure → typeset → audit → render → publish, when to fix vs accept advisories
- authoring — writing habits: frontmatter keys, footnote syntax, image path rules, heading numbering, common pitfalls
Requirements
- Python ≥ 3.12
- Windows / macOS / Linux
- Fonts: Microsoft YaHei or any CJK font (for Chinese), Times New Roman (Latin)
- First compile downloads Typst packages (mitex for math, mmdr for mermaid) — subsequent compiles are offline
Development
git clone https://github.com/lhh010/typeset-mcp
cd typeset-mcp
uv sync
uv run python -X utf8 -m unittest discover -s tests
93 tests, no network required (except first-time package downloads).
License
MIT — see LICENSE.