Metadata-Version: 2.5
Name: typeset-mcp
Version: 0.2.0
Summary: MCP server that typesets Markdown documents to PDF with the Typst engine (CJK-first)
Project-URL: Homepage, https://github.com/lhh010/typeset-mcp
Project-URL: Repository, https://github.com/lhh010/typeset-mcp
Project-URL: Issues, https://github.com/lhh010/typeset-mcp/issues
Project-URL: Changelog, https://github.com/lhh010/typeset-mcp/releases
License-Expression: MIT
License-File: LICENSE
Keywords: chinese,cjk,markdown,mcp,model-context-protocol,pdf,typesetting,typst
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Education
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Text Processing :: Markup
Classifier: Topic :: Text Processing :: Markup :: Markdown
Requires-Python: >=3.12
Requires-Dist: mcp<3,>=2.3
Requires-Dist: md2typst>=0.3.7
Requires-Dist: pillow>=13.0.0
Requires-Dist: pypdf>=7.2.0
Requires-Dist: pypdfium2>=5.15.2
Requires-Dist: pyyaml>=6
Requires-Dist: typst>=0.15.2
Description-Content-Type: text/markdown

# typeset-mcp

A [Model Context Protocol](https://modelcontextprotocol.io) server that typesets Markdown documents into production-quality PDFs. Powered by the [Typst](https://typst.app) 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

```bash
pip install typeset-mcp
```

Add to your MCP client config (Claude Code, Cursor, Codex, etc.):

```json
{
  "mcpServers": {
    "typeset": {
      "command": "typeset-mcp",
      "args": ["--root", "/path/to/your/workspace"]
    }
  }
}
```

Or with uv:

```json
{
  "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 |

```yaml
---
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**: `authorNotes` frontmatter key renders \\thanks-style footnotes on the cover
- **Mermaid diagrams**: rendered via the mmdr package
- **Multi-chapter books**: `typeset_project` joins chapters with one cover and outline
- **Stylesheets**: custom `.typ` files injected after the theme
- **Project config**: `typeset.yaml` for 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

```bash
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](LICENSE).
