arXiv LaTeX MCP Server for Precise Math Interpretation
Fetch and process arXiv LaTeX with an MCP server to extract and precisely interpret mathematical expressions from scientific papers.
npx -y @takashiishida/arxiv-latex-mcpOverview
This project provides an MCP (Model Context Protocol) server that fetches arXiv paper sources (LaTeX), processes them, and exposes structured representations of mathematical content for downstream models and tools. By combining arXiv source retrieval, LaTeX parsing, macro expansion, and math-specific normalization, the server enables precise interpretation and reliable provenance for equations, symbols, and expressions extracted from scientific papers.
The server is intended for developer workflows that need exact math semantics rather than raw rendered images. Typical consumers are LLM-driven agents, symbolic algebra interfaces, dataset creators, and search/indexing systems that require a machine-readable, disambiguated view of math expressions together with links back to the original arXiv source.
GitHub: https://github.com/takashiishida/arxiv-latex-mcp
Features
- Fetch arXiv source tarballs for papers via arXiv IDs
- Parse LaTeX to extract math environments (inline, display, aligned, arrays)
- Expand user-defined macros and common package macros where possible
- Produce structured math output (LaTeX AST and optional MathML)
- Maintain provenance: map expressions to file, line, surrounding context, and PDF coordinates (when available)
- HTTP/MCP-compatible API to stream content and serve tool-style endpoints
- Dockerized deployment and CLI utility for batch processing
- Configurable parser behavior (macro whitelist, package handling, strict/lenient parsing)
Installation / Configuration
Prerequisites: Docker or Python 3.10+ and Git.
Clone the repo:
Run with Docker:
# Build
# Run (exposes default MCP-compatible HTTP endpoints on 8080)
Run locally with Python:
# Example environment variables
# Start server
Configuration options (example):
# config.yml
http:
host: 0.0.0.0
port: 8080
arxiv:
cache_dir: ./cache
timeout_sec: 30
parser:
expand_macros: true
macro_whitelist:
- \\vec
- \\mathrm
output_formats:
- ast
- mathml
Available Tools / Resources
The server exposes MCP-style tool endpoints suitable for model-driven workflows. Common endpoints:
| Endpoint | Method | Description |
|---|---|---|
| /fetch/{arxiv_id} | GET | Download and unpack arXiv source tarball |
| /parse/{arxiv_id} | POST | Parse LaTeX sources and return structured math artifacts |
| /equation/{arxiv_id}/{eq_id} | GET | Retrieve a single equation with provenance |
| /status | GET | Health and queue status |
Example response (JSON snippet for an extracted equation):
Included utilities:
- CLI: fetch, parse, list equations
- Batch mode: parse lists of arXiv IDs to a local datastore
- Optional helper to locate equation bounding boxes in the compiled PDF (requires LaTeX toolchain)
Use Cases
LLM-assisted paper QA
- Use the server as a tool in an agent that needs to inspect formulas precisely. Example workflow: agent calls /parse/2101.00001, retrieves an AST for a suspect equation, converts it to canonical form, and uses a CAS to verify an identity.
Symbolic verification and reproducibility
- Extract expressions with macro expansion and send them to symbolic engines (SymPy, Sage). Because the server preserves provenance, you can report exactly which file and lines contributed to a given expression.
Mathematical search and indexing
- Index ASTs or MathML instead of raw text to enable formula-level search, similarity queries, or clustering across a corpus of arXiv papers.
Dataset creation for ML tasks
- Batch-parse arXiv IDs to generate labeled examples: (latex, AST, MathML, provenance). Useful for training models on math normalization, translation, or equation recognition.
Examples:
- Fetch and parse via curl:
- Retrieve a particular equation:
Notes and Best Practices
- The parser aims to expand common macros but cannot perfectly resolve arbitrary package logic; prefer papers with included macro definitions or provide macro overrides in config.
- For PDF-coordinate provenance, the server compiles LaTeX and requires a TeX toolchain in the environment.
- Use caching for large-scale processing; the server supports on-disk cache to avoid repeated downloads.
For code, issues, and contribution guidelines, see the GitHub repository: https://github.com/takashiishida/arxiv-latex-mcp