使用说明
Typst MCP服务器
Typst MCP服务器是 MCP(模型上下文协议) 帮助AI模型与 类型,一个基于标记的排版系统。服务器提供用于在LaTeX和Typst之间进行转换、验证Typst语法以及从Typst代码生成图像的工具。
可用工具
⚠️ 目前,所有功能均已实现
tools,因为Cursor和VS Code还不能处理其他原语。
服务器提供以下工具:
-
list_docs_chapters():列出Typst文档中的所有章节。- 让LLM对文档进行概述,并选择要阅读的章节。
- 法学硕士应根据手头的任务选择要阅读的相关章节。
-
get_docs_chapter(route):从Typst文档中检索特定章节。- 根据LLM选择的章节,此工具检索章节的内容。
- 也可用作
get_docs_chapters(routes: list)用于一次检索多个章节。
-
latex_snippet_to_typst(latex_snippet):使用Pandoc将LaTeX代码转换为Typst。- LLM比Typst更擅长编写LaTeX,因此此工具有助于将LaTeX代码转换为Typst。
- 也可用作
latex_snippets_to_typst(latex_snippets: list)用于一次转换多个LaTeX代码段。
-
check_if_snippet_is_valid_typst_syntax(typst_snippet):验证Typst代码。- 在将Typst代码发送给用户之前,LLM应检查代码是否有效。
- 也可用作
check_if_snippets_are_valid_typst_syntax(typst_snippets: list)用于一次验证多个Typst代码段。
-
typst_to_image(typst_snippet):将Typst代码渲染为PNG图像。- 在向用户发送复杂的Typst插图之前,LLM应将代码渲染为图像,并检查其是否正确。
- 仅适用于多模态模型。
入门指南
-
克隆此存储库
git clone https://github.com/johannesbrandenburger/typst-mcp.git
-
克隆 typst存储库
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- 确保调整到typst-mcp存储库的本地克隆的路径
- 这将生成
main.json以及资产typst-docs文件夹
-
安装所需的依赖项:
uv sync(安装 紫外线 如果尚未安装) -
安装Typst
运行服务器
本地安装
执行服务器脚本:
python server.py
或者使用MCP将其安装在Claude Desktop中:
mcp install server.py
或者在VS Code中使用新的代理模式:
码头工人
有关Docker的安装和使用,请参阅 医生.md 获取详细的构建信息和说明。
平台配置
该MCP服务器可以与各种AI编码平台集成。以下是流行平台的配置说明:
克劳德桌面版
将以下内容添加到您的Claude Desktop配置文件中(claude_desktop_config.json):
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
视窗: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"typst": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"ghcr.io/johannesbrandenburger/typst-mcp:latest"
]
}
}
}
或用于本地安装:
{
"mcpServers": {
"typst": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"ghcr.io/johannesbrandenburger/typst-mcp:latest"
]
}
}
}
光标
创建 .cursor/mcp.json 在项目根目录中进行项目特定配置:
{
"mcpServers": {
"typst": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"ghcr.io/johannesbrandenburger/typst-mcp:latest"
]
}
}
}
或创建 ~/.cursor/mcp.json 用于全局配置。对于本地安装:
{
"mcpServers": {
"typst": {
"command": "python",
"args": ["/path/to/typst-mcp/server.py"]
}
}
}
Roo代码
创建 .roo/mcp.json 在项目根目录中进行项目特定配置:
{
"mcpServers": {
"typst": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"ghcr.io/johannesbrandenburger/typst-mcp:latest"
]
}
}
}
或者通过Roo Code MCP设置视图编辑全局设置。对于本地安装:
{
"mcpServers": {
"typst": {
"command": "python",
"args": ["/path/to/typst-mcp/server.py"]
}
}
}
OpenCode
创建或编辑 opencode.json 项目根目录中的文件:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"typst": {
"type": "local",
"command": ["docker", "run", "--rm", "-i",
"ghcr.io/johannesbrandenburger/typst-mcp:latest"
],
"enabled": true
}
}
}
对于本地安装:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"typst": {
"type": "local",
"command": ["python", "/path/to/typst-mcp/server.py"],
"enabled": true
}
}
}
克劳德代码
在Claude Code设置文件中配置MCP服务器(~/.claude/settings.json):
{
"mcpServers": {
"typst": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"ghcr.io/johannesbrandenburger/typst-mcp:latest"
]
}
}
}
或用于本地安装:
{
"mcpServers": {
"typst": {
"command": "python",
"args": ["/path/to/typst-mcp/server.py"]
}
}
}
具有代理模式的VS代码
VS Code的代理模式具有本机MCP支持(无需扩展):
- 在VS代码设置中启用代理模式(
chat.agent.enabled) - 创建
.vscode/mcp.json在您的工作空间中:
{
"servers": {
"typst": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"ghcr.io/johannesbrandenburger/typst-mcp:latest"
]
}
}
}
对于全局配置,请通过以下方式添加到您的用户配置文件中 MCP:打开用户配置 命令。
Typst文档的JSON模式
⚠️ 打字员文档的模式不稳定,可能随时更改。该模式是根据打字源代码生成的,不能保证其完整性或正确性。如果模式更改,则需要相应地更新此存储库,以便文档功能再次工作。