LaTeX数学文档语义搜索服务

一款本地MCP服务器,将LaTeX数学文档转换为可搜索的语义数据库,支持自然语言和LaTeX混合查询,适用于数学研究和文档管理。

  • by iwaokimura
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 iwaokimura/mcp-latex-docs

使用说明

mcp乳胶文档

本地人 主控程序 服务器 困惑Mac应用程序 这将把你的LaTeX数学文档变成一个可搜索的语义数据库。

它做什么

用LaTeX编写的数学文档是围绕命名环境构建的-- theorem, lemma, definition, proof该服务器解析这些文档,识别其结构,使用一对神经模型(一个用于多语言散文,一个用于数学符号)嵌入每个块,并将所有内容存储在本地 色度数据库 矢量数据库。

一旦被索引,你可以问困惑问题,比如:

  • “读取文件夹中的所有数学文档 /Users/me/papers"
  • “搜索均匀连续性的定义”
  • “找到关于紧致集$K\subiteq\mathbb{R}^n$的定理”
  • “获取带有标签的区块 thm:heine-borel"

查询可以是纯英语、原始LaTeX或两者的混合。支持日语文档。

建筑

.tex files
    │
    ▼
pylatexenc parser
    └── extracts theorem / lemma / definition / proof / ...  blocks
    └── captures \label{}, section title, source file
    └── resolves \input{} / \include{} recursively
    └── detects file encoding (UTF-8, EUC-JP, Shift-JIS)
    │
    ▼
Two embedding models (Apple Silicon / MPS)
    ├── intfloat/multilingual-e5-large-instruct  → prose + Japanese
    └── witiko/mathberta                          → LaTeX math notation
    │
    ▼
ChromaDB (local persistent store)
    ├── text_view   — e5 embeddings
    └── math_view   — mathberta embeddings

Query routing (automatic)
    ├── plain text query  → text_view only
    ├── LaTeX-only query  → math_view only
    └── mixed query       → both views, results merged and ranked

需求

安装

git clone git@github.com:iwaokimura/mcp-latex-docs.git
cd mcp-latex-docs
uv pip install -e .

这两个嵌入模型(总共约1GB)是从第一个Hugging Face下载的 index_folder 调用并缓存在 ~/.cache/huggingface/hub/.

连接到困惑

在困惑Mac应用程序中,打开 设置→ MCP服务器 并添加一个新的本地服务器:

{
  "command": "/path/to/mcp-latex-docs/.venv/bin/mcp-latex-docs"
}

替换 /path/to/mcp-latex-docs 带有克隆的绝对路径。然后授予困惑 全磁盘访问 在 系统设置→ 隐私和安全→ 全磁盘访问 这样服务器就可以读取您的文档文件夹。

可用工具

工具 说明
index_folder(folder_path) 解析并嵌入所有 .tex 文件夹中的文件。重新运行会更新现有条目。
search(query, folder_path?, env_type?, n_results?) 语义搜索。查询可以是自然语言、LaTeX或混合语言。
get_by_label(label, folder_path?) 通过以下方式进行精确查找 \label{...} 价值。
list_folders() 列出所有带有文件和块计数的索引文件夹。
remove_folder(folder_path) 删除文件夹的所有索引块。

支持的环境

theorem, lemma, proposition, corollary, definition, proof, remark, example, conjecture, claim, notation, observation (以及他们的常用别名: thm, lem, prop, cor, defn, dfn, rem, ex, conj)

发展

uv run pytest          # run all tests (52 tests, no GPU required)
uv run python smoke_test.py   # end-to-end test with real models

该项目遵循四个模块的布局:

src/mcp_latex_docs/
├── parser.py    — LaTeX block extractor
├── embedder.py  — dual-model embedder and query routing
├── store.py     — ChromaDB upsert, search, and ranking
└── server.py    — MCP stdio server

矢量数据存储在 ~/.mcp-latex-docs/chroma/ 并在服务器重新启动时持续存在。

许可证

麻省理工学院