MCP LaTeX Server
An MCP server for authoring, validating, compiling, and inspecting LaTeX documents and multi‑file projects.
Create article, report, book, letter, beamer, or minimal documents with a title, author, packages, and geometry settings.
Scaffold from templates, including bundled ones and custom YAML‑metadata templates with
{{variable}}placeholders.Read, list, and edit
.texfiles — replace, insert before/after, append, or prepend by search text or line number.Validate braces, environments, and references, and extract structure (class, title, author, packages, sections).
Compile to PDF with pdflatex, xelatex, or lualatex, and get parsed errors, warnings, and log output.
Additionally (per the README): analyze multi‑file projects (includes, labels, bibliographies, duplicates), run transactional multi‑edits, snapshot/restore, edit named sections, insert tables/figures/citations.
Also: count words, find TODOs, lint (chktex), format (latexindent), spell check, analyze logs, and inspect PDFs (metadata, text, page renders, embedded PDF).
Provides comprehensive tools for creating, editing, and managing LaTeX documents, including document class customization, package management, and basic syntax validation.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP LaTeX Server Create a new article template for a research paper on machine learning."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP LaTeX Server
A Model Context Protocol (MCP) server for LaTeX authoring: create and edit documents, analyze multi-file projects, validate structure and references, run quality checks, inspect PDFs, and compile to PDF. Built with FastMCP/MCPServer and Pydantic for structured tool output.
Highlights
Author article, report, book, letter, beamer, and minimal documents.
Transact multiple edits atomically, snapshot and restore files, and edit named sections.
Build custom templates with YAML metadata and double-brace variables.
Analyze multi-file projects: includes, labels, references, bibliographies, and duplicate labels.
Compile single files or whole projects with bibtex/biber sequencing, conditional reruns, timeouts, and optional latexmk.
Check braces, environments, references, word counts, TODOs, chktex, latexindent, and spelling.
Inspect PDF metadata, page counts, text, and optional page renders.
Support MCP Python SDK 1.x and 2.x.
Related MCP server: GoLatex MCP Server
Requirements
Python 3.11.9+
MCP Python SDK 1.x or 2.x: mcp[cli]>=1.9.4
LaTeX distribution for compilation only:
Windows: MiKTeX or TeX Live
macOS: MacTeX
Linux: texlive-full or texlive-scheme-full
Optional external tools, detected at runtime:
chktex, latexindent, hunspell or aspell
latexmk, bibtex, biber
poppler utilities (pdftoppm) for PDF page rendering
Python dependencies: pydantic, pyyaml, pypdf.
Editing, reading, listing, validation, project analysis, word counts, and PDF reading do not require LaTeX to be installed. Tools that need an external binary report available=false or a clear install hint instead of failing the server.
Installation
Using uv
git clone https://github.com/RobertoDure/mcp-latex-server
cd mcp-latex-server
uv venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
uv pip install -e ".[dev]"Using pip
git clone https://github.com/RobertoDure/mcp-latex-server
cd mcp-latex-server
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate
pip install -e ".[dev]"Quick setup
python scripts/quick_setup.pyThe setup script checks Python, installs dependencies, verifies the server, and optionally writes a Claude Desktop configuration. Existing configs are backed up and malformed JSON is left untouched.
Entry points
After installation, launch the server with any of:
mcp-latex-server
python -m mcp_latex_server
python latex_server.py # compatibility shimThe canonical packaged entry point is mcp-latex-server. The root latex_server.py stays as a compatibility shim for existing MCP client configurations.
Docker
A container image is included for the server runtime. It does not include a TeX distribution; extend the image or mount a TeX installation if you need compilation inside the container.
docker build -t mcp-latex-server .
docker run --rm -i \
-e LATEX_SERVER_BASE_PATH=/workspace \
-v "$PWD/documents:/workspace" \
mcp-latex-serverThe container communicates over stdio, so keep the interactive stdin flag
(-i) when connecting it to an MCP client.
Configuration
Variable | Description | Default |
| Root directory for all file operations | . (current directory) |
| Maximum file size a read tool may load | 5000000 |
| Maximum PDF size returned by | 50000000 |
| Logging level used by the entry point | INFO |
| os.pathsep-separated custom template directories | empty |
| Snapshot directory inside the base path | .latex-mcp/snapshots |
All tool paths resolve relative to the base directory. Paths that escape it, including symlinks that resolve outside, are denied. A templates directory inside the base path is treated as a custom template directory automatically.
MCP client configuration
Claude Desktop
Config locations:
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonmacOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"latex-server": {
"command": "uv",
"args": [
"--directory",
"/path/to/mcp-latex-server",
"run",
"mcp-latex-server"
],
"env": {
"LATEX_SERVER_BASE_PATH": "/path/to/your/latex/files"
}
}
}
}VS Code (GitHub Copilot)
Add to .vscode/mcp.json:
{
"servers": {
"latex-server": {
"command": "uv",
"args": [
"--directory",
"/path/to/mcp-latex-server",
"run",
"mcp-latex-server"
],
"env": {
"LATEX_SERVER_BASE_PATH": "${workspaceFolder}"
}
}
}
}Core tools
create_latex_file
Parameter | Type | Default | Description |
|
| required | Path for the new .tex file |
|
|
| Document class |
|
|
| Title (recipient for letters) |
|
|
| Author (signature for letters) |
|
|
| Date; empty string writes |
|
|
| Body content (raw LaTeX) |
|
|
| Extra packages; comma-separated names accepted |
|
|
| Geometry options, e.g. |
|
|
| Replace an existing file |
Generation is class-aware: beamer uses title frames, letter uses a letter environment, and minimal builds its own title block.
create_from_template
Parameter | Type | Default | Description |
|
| required | Path for the new .tex file |
|
|
| Bundled or custom template name |
|
|
| Values for |
|
|
| Replace an existing file |
Custom templates may use YAML front matter:
---
name: paper
description: Article scaffold
variables:
title: Untitled
author: Anonymous
required: [title]
---
\documentclass{article}
\title{{{title}}}
\author{{{author}}}
\begin{document}
{{content}}
\end{document}Placeholders without defaults raise an error instead of silently producing broken LaTeX.
edit_latex_file
Parameter | Type | Default | Description |
|
| required | Path to the file |
|
| required | Edit operation |
|
| required | Replacement or inserted text |
|
|
| Text to find |
|
|
| 1-based line alternative |
|
|
| Replace every occurrence |
replace changes the first match by default. append inserts before \end{document} and prepend inserts after \begin{document}. Empty non-replace edits are no-ops.
read_latex_file and list_latex_files
Read UTF-8 files within the base path. Listing supports recursive and max_results and returns total and truncated fields. Symlinks that escape the base are skipped.
validate_latex
Checks declarations, braces, environment nesting, content after \end{document}, and references. Validation ignores comments and verbatim-like content, including verbatim, Verbatim, lstlisting, minted, comment, filecontents, \verb, and \lstinline. Set check_references=false for labels that live in other files.
get_latex_structure
Returns document class, title, author, date, packages, and headings in document order. Starred headings, nested title braces, and comma-separated package lists are supported.
compile_latex
Parameter | Type | Default | Description |
|
| required | Path to the file |
|
|
| LaTeX engine |
|
|
| Per-pass timeout, 1-600 |
|
|
| Remove auxiliary files |
|
|
| Enable |
A second pass runs only when the first pass produced auxiliary files. Errors are parsed from the .log with line numbers; warnings are returned separately. Timeouts kill the compiler process group on POSIX.
Project tools
analyze_project
Analyzes a main file and recursively resolves \input, \include, \subfile, \import, \subimport, \inputfrom, and \includefrom. Returns:
project files and include relationships,
missing include targets,
labels and references with file:line locations,
undefined references and duplicate labels,
bibliography files and whether
bibtexorbiberis needed,validation issues for the main and included files.
validate_project
Validates the whole project. Set check_references=false to ignore unresolved references when labels are supplied by external sources. Missing includes are errors; missing bibliography files and some project problems are warnings.
compile_project
Parameter | Type | Default | Description |
|
| required | Main .tex file |
|
|
| Engine |
|
|
| Timeout per compiler or bibliography step |
|
|
| Remove auxiliary files |
|
|
| Enable shell escape for trusted documents |
|
|
| Run bibtex/biber and recompile |
|
|
| Use latexmk when available |
If a bibliography is detected, the server compiles, runs the appropriate bibliography tool, and recompiles. If latexmk is requested but unavailable, it falls back to direct engine passes and reports a warning.
Authoring tools
apply_edits
Applies an ordered list of edit specifications transactionally. All edits are applied in memory first; the file is written only if every edit succeeds. snapshot defaults to true, and validate_after can reject a batch that produces invalid LaTeX.
Each edit has operation, new_text, optional search_text/line_number, and replace_all.
edit_section
Edits a named section body while preserving its heading. Operations: replace, append, prepend, delete. Section bodies include subsections. Use section_level to disambiguate duplicate titles.
Snapshots
create_snapshotstores a content snapshot with an optional label.list_snapshotslists snapshots for a file, newest first.restore_snapshotrestores a snapshot and, by default, snapshots the current content first.
Snapshots are stored under .latex-mcp/snapshots inside the base path (or LATEX_SERVER_SNAPSHOT_DIR). Snapshot files use .tex.snap so they are not listed as documents.
Builders
insert_tableinserts a table environment with headers and rows.insert_figureinserts a figure with\includegraphics.insert_citationinserts\cite,\citep,\citet,\parencite,\textcite, or\autocite.
Builders accept an optional section and section_level and can snapshot before writing.
Quality and PDF tools
Tool | Purpose |
| Visible word, line, character, and section counts |
| TODO, FIXME, XXX, HACK, and NOTE markers with line numbers |
| chktex plus built-in validation issues |
| latexindent output, optionally written back with a snapshot |
| hunspell or aspell misspelling list |
| Errors, warnings, overfull and underfull box reports |
| Page count, metadata, size, and first-page preview |
| Text extraction for a page range |
| PNG render of one page via pdftoppm |
| Return a PDF directly as an MCP embedded |
External-tool results include available and a message explaining how to enable the feature. read_pdf_file returns the PDF bytes in an embedded resource, so a client can save or display the document without reading a path.
Resources
URI | Description |
| List bundled and custom templates with origin and description |
| Get a template body without rendering placeholders |
The list_template_details tool returns structured template metadata, variables, defaults, origins, and discovery errors.
Safety notes
Every path is resolved and checked against
LATEX_SERVER_BASE_PATH.Creation and template copies refuse to overwrite by default.
Writes use a temporary file plus atomic replace.
Transactions are all-or-nothing.
Compilation disables shell escape unless explicitly requested.
Compiler and helper processes have timeouts and process-group cleanup on POSIX.
Snapshot and template names are validated; custom template directories can be configured but are read-only inputs.
Architecture
See docs/ARCHITECTURE.md for module responsibilities, request flow, trust boundaries, and extension points.
Development
Install the editable development environment:
uv pip install -e ".[dev]"Run the standard checks:
ruff check src tests scripts examples latex_server.py
python -m pytestThe package follows a src layout. The importable namespace is mcp_latex_server, tests live under tests, maintenance scripts under scripts, and bundled template data under src/mcp_latex_server/resources/templates.
Testing
pip install -e ".[dev]"
python -m pytest -qThe suite covers all document classes, validation edge cases, path containment, project graphs, bibliography sequencing, transactions, snapshots, section editing, builders, optional quality tools, PDF metadata/text, and fake-engine compilation. Compilation tests are skipped on Windows because the fake engines are POSIX shell scripts. CI runs the suite against MCP 1.x and 2.x on Python 3.11-3.13.
Troubleshooting
Server won't start - Verify Python 3.11.9+ and the MCP SDK:
python -c "import mcp; print(mcp.__file__)"MCP 1.x or 2.x - Both are supported. If an older environment fails on MCP internals, upgrade the SDK and pydantic together.
Compilation fails - Ensure an engine is on PATH (pdflatex --version). Check analyze_log for line-numbered errors.
Compilation timed out - Increase timeout_seconds or simplify the document.
chktex/latexindent/spell checking unavailable - Install the corresponding binary. The tool reports available=false rather than failing.
PDF rendering unavailable - Install poppler-utils for pdftoppm. PDF metadata and text extraction use pypdf and do not require poppler.
Access denied - The requested path resolves outside LATEX_SERVER_BASE_PATH. Use relative paths or adjust the environment variable.
File already exists - Pass overwrite=true or choose another path.
Project layout
pyproject.toml Packaging, dependencies, tools, and test settings
src/mcp_latex_server/
__init__.py Package metadata
__main__.py python -m mcp_latex_server
server.py MCP tools, resources, models, and entry point
templates.py Template discovery, metadata, and rendering
project.py Multi-file graph, validation, and compilation
authoring.py Transactions, snapshots, sections, and builders
quality.py Quality, logs, spelling, and PDF helpers
resources/templates/ Bundled article, beamer, and report templates
tests/
conftest.py Shared pytest fixtures
test_core.py Core test suite
test_features.py Expanded feature test suite
examples/ Client demo and example MCP configuration
scripts/quick_setup.py Cross-platform setup helper
docs/reports/ Generated LaTeX report and PDF
latex_server.py Backward-compatible entry-point shim
.github/workflows/ CI matrix for MCP 1.x/2.x and Python 3.11-3.13
CHANGELOG.md Release notes
CONTRIBUTING.md Development workflow
SECURITY.md Vulnerability reporting
CODE_OF_CONDUCT.md Community expectations
Dockerfile Container build without a TeX distribution
LICENSE MIT licenseLicense
Available Tools
8 toolscompile_latexB
Compile a LaTeX file to PDF using the specified engine.
Inputs: file_path (required), engine. Returns: Result of LaTeX compilation.
create_from_templateB
Create a LaTeX document from a bundled template file.
Inputs: file_path (required), template. Returns: Result of a file operation.
create_latex_fileC
Create a new LaTeX document with specified content and structure.
Inputs: file_path (required), document_type, title, author, +4 more. Returns: Result of a file operation.
edit_latex_fileB
Edit an existing LaTeX file by replacing, inserting, or appending content.
Inputs: file_path (required), operation (required), new_text (required), search_text, +1 more. Returns: Result of a file operation.
get_latex_structureA
Extract document structure: class, title, author, packages, and section hierarchy.
Inputs: file_path (required). Returns: Extracted structure of a LaTeX document.
list_latex_filesB
List all .tex files in a directory.
Inputs: directory_path, recursive. Returns: Result of listing LaTeX files.
read_latex_fileB
Read and return the contents of a LaTeX file.
Inputs: file_path (required). Returns: Result of a file operation.
validate_latexB
Perform LaTeX syntax validation (structure, braces, environments, references).
Inputs: file_path (required). Returns: Result of LaTeX validation.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 8 tools
Each tool has a clearly distinct purpose with no ambiguity: compile, create from template, create new file, edit file, get structure, list files, read file, and validate syntax. The descriptions reinforce unique functions, preventing misselection.
All tool names follow a consistent verb_noun pattern using snake_case (e.g., compile_latex, edit_latex_file). This predictability makes the set easy to navigate and understand.
With 8 tools, the server is well-scoped for LaTeX document management. Each tool earns its place by covering essential operations like creation, editing, reading, validation, and compilation without bloat.
The toolset provides strong coverage for core LaTeX workflows, including CRUD operations and validation. A minor gap is the lack of tools for managing bibliographies or handling complex LaTeX errors, but agents can work around this with existing tools.
Maintenance
Related MCP Connectors
Create and revise structured scientific papers in real LaTeX. Compatible with Overleaf.
Persistent AI LaTeX workspace: edit and compile multi-file projects, export publication-ready PDFs.
A hosted LaTeX editor your assistant can actually use. Search 1,019 free templates, create and edit projects, and compile them to PDF on a real TeX Live farm, getting back the PDF or the compile log when a build fails. Thirteen tools behind OAuth 2.1, with nothing to install and nothing to run locally.
Overleaf alternative online LaTeX editor. AI agents edit, comment, and chat. Keep or revert edits.
Related MCP Servers
- AlicenseBqualityCmaintenanceEnables AI assistants to convert LaTeX source code into professionally formatted PDF documents with comprehensive error handling and local file generation capabilities.12MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to read, write, and compile LaTeX projects locally, view PDF pages as images, and manage project files, with live updates reflected in a web-based editor.-
- AlicenseAqualityBmaintenanceEnables AI agents to edit LaTeX documents with live PDF preview, commenting, and visual editing via the Model Context Protocol.798 npmAGPL 3.0
- FlicenseNot gradedqualityAmaintenanceEnables AI models to work with a markup-based typesetting system by converting LaTeX snippets, validating syntax, browsing the documentation, and rendering code as PNG images. This lets assistants produce and verify typeset documents and illustrations before sharing them with users.-