pranavgnn/latex-pdf-mcp
If you are the rightful owner of latex-pdf-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
A Model Context Protocol (MCP) server that compiles LaTeX source code to PDF documents.
LaTeX to PDF MCP Server
A Model Context Protocol (MCP) server that compiles LaTeX source code to PDF documents. This server provides a simple API for converting LaTeX strings into PDF files, with optional bibliography support.
Features
- LaTeX Compilation: Compile LaTeX source code to PDF using Tectonic
- Bibliography Support: Automatically handle BibTeX references and citations
- Error Checking: Integrated ChkTeX for LaTeX syntax validation
- HTTP API: RESTful endpoints for PDF generation and download
- Docker Support: Containerized deployment for easy setup
- MCP Integration: Compatible with MCP clients for seamless integration
Installation
Using Docker (Recommended)
Option 1: Pull from Docker Hub
docker run -p 8000:8000 pranavgnn/latex-mcp-server:latest
Option 2: Build from Source
-
Clone the repository:
git clone https://github.com/pranavgnn/latex-pdf-mcp.git cd latex-pdf-mcp -
Build the Docker image:
docker build -t latex-mcp-server . -
Run the container:
docker run -p 8000:8000 latex-mcp-server
The server will be available at http://localhost:8000.
MCP Configuration
To use this server with MCP-compatible clients (like VS Code extensions or other MCP clients), create a configuration file:
VS Code Configuration
-
Create a
.vscode/mcp.jsonfile in your workspace:{ "servers": { "latex-pdf": { "url": "http://localhost:8000/sse" } } } -
Ensure the server is running on port 8000 (as configured above)
-
The MCP client will automatically discover and connect to the LaTeX compilation tool
Configuration Options
- Server Name:
latex-pdf(can be customized) - URL:
http://localhost:8000/sse(SSE endpoint for MCP communication) - Port: Default is 8000, but can be changed in the Docker run command or app.py
Usage
Local Installation
-
Install system dependencies:
- Tectonic: Follow installation instructions at tectonic-typesetting.github.io
- ChkTeX: Install via your package manager (e.g.,
apt install chktexon Ubuntu)
-
Install Python dependencies:
pip install -r requirements.txt -
Run the server:
python app.py
Usage
MCP Tool
The server exposes a compile_latex tool that accepts:
latex(required): LaTeX source code as a stringbibliography(optional): BibTeX content for citationsfilename(optional): Custom filename for the output PDF
HTTP API
- POST
/messages: MCP protocol endpoint - GET
/download/{filename}: Download compiled PDF
Example Usage
# Example LaTeX compilation request
{
"latex": "\\documentclass{article}\n\\begin{document}\nHello, World!\n\\end{document}",
"filename": "hello.pdf"
}
For documents with citations:
{
"latex": "\\documentclass{article}\n\\addbibresource{references.bib}\n\\begin{document}\nHello \\cite{example}.\n\\printbibliography\n\\end{document}",
"bibliography": "@article{example,\n title={Example Paper},\n author={Author, A.},\n year={2023}\n}"
}
Development
Prerequisites
- Python 3.8+
- Tectonic
- ChkTeX
Running Tests
# Add test commands here when implemented
Building Docker Image
docker build -t latex-mcp-server .
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the file for details.
Acknowledgments
- Tectonic for LaTeX compilation
- ChkTeX for LaTeX validation
- Model Context Protocol for the protocol specification