Typst MCP 服务器是一个 MCP(模型上下文协议) 实现,旨在助力 AI 模型与 Typst 进行交互。Typst 是一个基于标记的排版系统。该服务器提供了一系列工具,可实现将 LaTeX 转换为 Typst、验证 Typst 语法以及根据 Typst 代码生成图像等功能。
git clone https://github.com/johannesbrandenburger/typst-mcp.git
git clone https://github.com/typst/typst.git
在 Typst 仓库中运行文档生成:
cargo run --package typst-docs -- --assets-dir ../typst-mcp/typst-docs --out-file ../typst-mcp/typst-docs/main.json
main.json 和 typst-docs 文件夹中的资产。安装所需的依赖项:uv sync(如果尚未安装,请先安装 uv)。
请安装 Typst。
python server.py
mcp install server.py
⚠️ 重要提示
当前所有功能都以
tools的形式实现,因为 Cursor 和 VS Code 尚未支持其他类型的原语。
服务器提供的工具如下:
list_docs_chapters():列出 Typst 文档中的所有章节。
get_docs_chapter(route):获取特定章节的 Typst 文档内容。
get_docs_chapters(routes: 列表) 用于一次性获取多个章节的内容。latex_snippet_to_typst(latex_snippet):使用 Pandoc 将 LaTeX 代码转换为 Typst。
latex_snippets_to_typst(latex_snippets: 列表) 用于批量转换多个 LaTeX 片段。check_if_snippet_is_valid_typst_syntax(typst_snippet):验证 Typst 代码的语法是否正确。
check_if_snippets_are_valid_typst_syntax(typst_snippets: 列表) 用于批量验证多个 Typst 片段。typst_to_image(typst_snippet):将 Typst 代码渲染为 PNG 图像。
⚠️ 重要提示
Typst 文档的模式是不稳定的,可能会随时更改。此模式是从 Typst 源代码生成的,并不能保证完整或正确。如果模式发生变化,此仓库需要相应更新,以确保文档功能继续正常工作。