latex-workspace-mcp
Provides tools for managing local LaTeX projects, including scanning project structure, reading and editing .tex files, compiling with latexmk, analyzing build logs, checking citations and labels, validating image assets, and verifying generated PDFs.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
LaTeX SafeFix — LaTeX Workspace MCP
Safe, precise LaTeX editing, compilation, and PDF verification through Model Context Protocol tools for local LaTeX projects. The server lets an AI assistant inspect a configured workspace, make narrow .tex edits, compile with a fixed latexmk command, and verify that the generated PDF and image assets are usable.
Features
Scan LaTeX projects and infer the main file, engine, bibliography mode, included files, figure references, citations, and labels.
Read
.texfiles, create or overwrite.texfiles only with explicit overwrite approval, and replace exactly one unique text occurrence. Preview an edit, confirm its application, and roll it back if needed.Compile a selected main file with
pdflatexorxelatexthroughlatexmkinto the document-localbuild/directory.Analyze build logs for errors, warnings, undefined references, and undefined citations.
Check citation keys, duplicate labels, undefined labels, and figure path existence.
Validate image assets before a build with
validate_latex_assets, including reachable\input/\includefiles, first-page PDF metadata, dimensions for PNG/JPEG/PDF assets, and similar-path suggestions.Verify generated PDFs with
verify_latex_pdf, including MIME type, page count, page sizes, and embedded image metadata frompdfimages. Render a page to PNG withrender_latex_pdf_pagefor visual inspection.Run the full asset-check, build, and PDF-verification flow with
build_and_verify_latex.Use either stdio MCP for local editors or Streamable HTTP MCP for ChatGPT-style clients.
Related MCP server: GoLatex MCP Server
Security Model
Every path is resolved under the configured
--rootdirectory. Paths outside the root are rejected.Write tools only accept project-relative
.texfiles. There is no delete, rename, arbitrary shell, or generic file-write API.write_tex_filerefuses to overwrite existing files unlessoverwrite: trueis supplied.replace_tex_textrequires one exact unique match. Empty, missing, or multiple matches are rejected.Compilation uses a fixed
latexmkcommand withshell: false, disabled shell escape, bounded output, and build artifacts underbuild/. By default it passes-norcsolatexmkdoes not load configuration files. SetLATEX_MCP_ALLOW_LATEXMKRC=1only for trusted projects to restore customized builds: latexmk configuration can execute commands.Workspace paths containing symbolic links are rejected. Writes use temporary files and atomic replacement; previewed edits also reject changes since the preview.
The server is not an OS sandbox. Compile only trusted TeX or use a separate OS-level sandbox: TeX and its toolchain run with the server user's permissions. Portable filesystem checks also cannot prevent a hostile local process from racing directory changes.
The HTTP server requires an API key from
LATEX_MCP_API_KEY_FILEand accepts eitherAuthorization: Bearer ...orX-API-Key.The HTTP server binds to
127.0.0.1by default and allows onlylocalhost,127.0.0.1host headers unlessLATEX_MCP_ALLOWED_HOSTSis set.
Requirements and installation
The MCP server and its external programs must run in the same environment, with
node, latexmk, pdflatex, file, pdfinfo, pdfimages, and pdftoppm on its PATH.
Node.js 20 or newer is required. Install xelatex as well if using the XeLaTeX
engine. Your document may require additional TeX packages and fonts.
Linux (Debian or Ubuntu)
sudo apt update
sudo apt install git nodejs npm latexmk texlive-latex-recommended texlive-xetex file poppler-utilsCheck node --version: if the distribution package is older than Node 20, install
an up-to-date Node release from nodejs.org first. Other
Linux distributions can install equivalent TeX Live, file, and Poppler packages
with their package manager.
macOS
Install Node.js 20 or newer, a TeX distribution containing latexmk and the
chosen engine (for example MacTeX), and Poppler.
For example, with Homebrew and MacTeX installed:
brew install node popplerAfter installing MacTeX, open a new terminal and check that /Library/TeX/texbin
is on PATH. macOS includes the file utility.
Windows
Use WSL 2 with an Ubuntu
installation. Run the Linux commands above inside the WSL terminal, and keep the
server, Node, TeX, Poppler, and project root in that same WSL environment. An
MCP client running in Windows must be able to launch wsl.exe; configure it to
invoke the Linux Node executable and Linux paths within WSL. Native Windows
installation requires compatible versions of all command-line dependencies on
PATH and is not currently documented or tested.
Install the server
In the environment that will run the server:
git clone https://github.com/Alexchen93/latex-workspace-mcp.git
cd latex-workspace-mcp
npm ci
node --version
latexmk -v
pdflatex --version
file -v
pdfinfo -v
pdfimages -v
pdftoppm -vUse an existing absolute project root when starting either server:
node server.mjs --root /path/to/latex/projectThe stdio process communicates with the MCP client over standard input/output; start it through the client configuration below. The project root should be the smallest directory containing the LaTeX files and assets the server needs.
Build limits
Set LATEX_MCP_TIMEOUT_MS to the maximum compilation time in milliseconds
(default 120000) and LATEX_MCP_MAX_OUTPUT_BYTES to the maximum captured
compilation output in bytes (default 12000). Set these environment variables
in the MCP client's server configuration or in the service environment before
starting either transport.
By default, latexmk configuration files are disabled with -norc. For a trusted
project that requires its latexmk configuration, set
LATEX_MCP_ALLOW_LATEXMKRC=1 in the server environment. Configuration files can
execute commands, so enabling this changes the security assumptions of a build.
Stdio MCP
Use stdio when the MCP client launches local commands directly.
{
"mcpServers": {
"latex-workspace": {
"command": "node",
"args": ["/path/to/latex-workspace-mcp/server.mjs", "--root", "/path/to/latex/project"]
}
}
}For a Windows client invoking a WSL installation, an example configuration is:
{
"mcpServers": {
"latex-workspace": {
"command": "wsl.exe",
"args": ["--", "node", "/home/YOUR_USER/latex-workspace-mcp/server.mjs", "--root", "/home/YOUR_USER/latex-project"]
}
}
}Replace both Linux paths and ensure node is on the WSL launch environment's
PATH; use its absolute path if necessary.
HTTP MCP
Create an API key file with permissions limited to the service user:
install -d -m 700 ~/.config/latex-workspace-mcp
openssl rand -base64 48 > ~/.config/latex-workspace-mcp/api-key
chmod 600 ~/.config/latex-workspace-mcp/api-keyStart the loopback HTTP server:
LATEX_MCP_API_KEY_FILE="$HOME/.config/latex-workspace-mcp/api-key" \
LATEX_MCP_HTTP_HOST=127.0.0.1 \
LATEX_MCP_HTTP_PORT=8787 \
LATEX_MCP_ALLOWED_HOSTS=localhost,127.0.0.1 \
node http-server.mjs --root /path/to/latex/projectThe MCP endpoint is http://127.0.0.1:8787/mcp. Unauthenticated calls should return 401.
If you put a trusted reverse proxy in front of the server, keep the origin private and set LATEX_MCP_ALLOWED_HOSTS to the exact host headers your proxy sends.
systemd
Copy examples/latex-mcp-http.service.example and replace YOUR_PROJECT_ROOT with the absolute LaTeX workspace root. Keep LATEX_MCP_HTTP_HOST=127.0.0.1 when the proxy runs on the same machine.
ChatGPT Prompt Pattern
Use a prompt that keeps edits precise and makes the verification flow explicit:
Use the LaTeX Workspace MCP for this project. Before changing figure paths, call validate_latex_assets with the project-relative main_file. For source edits, prefer replace_tex_text and only use write_tex_file with overwrite: true when I explicitly ask for a full-file replacement. After any document or image-path change, call build_and_verify_latex. If the build fails, use analyze_log and validate_latex_assets to make the smallest precise repair.For projects with multiple main.tex files, always pass a project-relative main_file, such as paper/main.tex.
Image And First-Page Validation Workflow
Put images under the configured project root and reference them with paths relative to the main file directory.
Call
validate_latex_assetsbefore compiling. Missing\includegraphicsassets stopbuild_and_verify_latexbefore LaTeX runs.For PNG and JPEG assets, the tool reports dimensions from the file header.
For PDF assets, the tool calls
pdfinfoand reports first-page page-size metadata without extracting binary content.After compilation, call
verify_latex_pdforbuild_and_verify_latexto confirm the expectedbuild/<stem>.pdfexists, has pages, and lists embedded images.
Preview, confirm, and roll back an edit
Call preview_tex_edit with file, search, and replacement to inspect an
exact, unique replacement as a diff. Once the change is approved, call
apply_tex_edit with the returned edit_id and confirmed: true. To undo it,
call rollback_tex_edit with the returned rollback_id and confirmed: true.
Application and rollback reject a file that changed since the associated preview
or edit, so review a fresh preview if that happens. IDs are scoped to the MCP
server session, are lost on restart, and can expire when the bounded history is
full; they are not a substitute for version control or backups. The existing
write_tex_file and replace_tex_text tools remain available for compatibility.
Call render_latex_pdf_page with main_file and a one-based page after a
successful build to obtain a PNG page for visual inspection. It requires
Poppler's pdftoppm; metadata verification by itself cannot establish that a
page looks correct.
Tool Summary
get_project_infoscan_projectanalyze_logcheck_citationscheck_labelscheck_figuresvalidate_latex_assetsverify_latex_pdfbuild_and_verify_latexlist_tex_filesread_tex_filewrite_tex_filereplace_tex_textcompile_latexpreview_tex_editapply_tex_editrollback_tex_editrender_latex_pdf_page
Agent skill
The reusable LaTeX SafeFix skill contains a client configuration example, task prompts, and troubleshooting guidance. The ZIP package includes the skill and MIT license. Extract it into a skill directory supported by your agent, configure the MCP server separately, and replace the example paths with your own.
License
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
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.
Your org's AI agents, tasks, runs, search, and brain files as MCP tools and resources.
Compile and check LaTeX to PDF from any AI agent: errors, fixes and quota via Octree.
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables ChatGPT to inspect and edit local projects through a secure MCP interface, offering workspace management, file operations, git integration, and safe command execution.6MIT
- 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.-
- AlicenseAqualityDmaintenanceEnables AI agents to read, write, compile, and manage Overleaf projects through MCP, including file operations, project administration, and LaTeX compilation diagnostics.16MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to read, edit, upload, compile, and manage projects in a self-hosted Overleaf Community Edition via MCP, while also providing a git remote for cloning and pushing changes.1MIT