MCP LaTeX Server
Create, edit, and manage LaTeX files. Requires an external LaTeX distribution like MiKTeX, TeX Live, or MacTeX.
MCP LaTeX Server
A comprehensive Model Context Protocol (MCP) server that provides advanced LaTeX file creation, editing, and management capabilities for Large Language Models and AI assistants.
Overview
The MCP LaTeX Server enables AI assistants like Claude to seamlessly work with LaTeX documents through a standardized protocol. It provides tools for creating, editing, reading, and validating LaTeX files, making it easy to generate professional academic papers, reports, presentations, and other LaTeX documents.
Features
- 📝 Create LaTeX Documents: Generate new LaTeX files from templates or custom specifications
- ✏️ Edit Existing Files: Modify LaTeX documents with various edit operations
- 📖 Read File Contents: Access and analyze LaTeX file content
- 📁 File Management: List and organize LaTeX files in directories
- ✅ Syntax Validation: Basic LaTeX syntax checking and error detection
- 🎯 Document Types: Support for article, report, book, letter, beamer, and minimal document classes
- 📦 Package Management: Automatic handling of LaTeX packages and dependencies
- 🔧 Template System: Built-in templates for common document types
Prerequisites
Before installing the MCP LaTeX Server, ensure you have:
- Python 3.8+ installed on your system
- LaTeX Distribution (recommended for full functionality):
- Windows: MiKTeX or TeX Live
- macOS: MacTeX
- Linux: TeX Live
- VS Code (for VS Code integration)
- Claude Desktop or Claude in VS Code (for Claude integration)
Installing LaTeX Distribution
Windows (MiKTeX)
- Download MiKTeX from https://miktex.org/download
- Run the installer and follow the setup wizard
- Choose "Install packages on-the-fly" for automatic package management
Windows (TeX Live)
- Download TeX Live from https://www.tug.org/texlive/
- Run the installer (this may take some time as it's a large distribution)
macOS
# Using Homebrew
brew install --cask mactex
# Or download directly from https://www.tug.org/mactex/
Linux (Ubuntu/Debian)
sudo apt-get update
sudo apt-get install texlive-full
Linux (Fedora/RHEL)
sudo dnf install texlive-scheme-full
Installation
Method 1: Quick Setup (Recommended)
- Clone or download the repository:
git clone https://github.com/RobertoDure/mcp-latex-server
cd mcp-latex-server
- Run the setup script:
python setup.py
This will automatically install all required dependencies.
Method 2: Manual Installation
- Create a virtual environment (recommended):
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate
- Install dependencies:
pip install -r requirements.txt
- Verify installation:
python latex_server.py --help
Method 3: Using uv (Fast Python Package Manager)
- Install uv (if not already installed):
pip install uv
- Install dependencies with uv:
uv pip install -r requirements.txt
Configuration
Basic Configuration
The server can be configured to work with specific directories for LaTeX files. By default, it allows access to the current working directory and subdirectories.
Environment Variables
You can set the following environment variables:
# Set the base path for LaTeX files
export LATEX_BASE_PATH="/path/to/your/latex/files"
# Set logging level
export LATEX_LOG_LEVEL="INFO" # DEBUG, INFO, WARNING, ERROR
Configuration File
Create a config.json file in the server directory:
{
"base_path": "/path/to/your/latex/files",
"allowed_extensions": [".tex", ".sty", ".cls", ".bib"],
"max_file_size": "10MB",
"enable_validation": true,
"default_document_class": "article",
"default_packages": [
"amsmath",
"amsfonts",
"amssymb",
"graphicx",
"hyperref"
]
}
MCP Integration
Claude Desktop Integration
-
Locate Claude Desktop Configuration:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- Windows:
-
Add MCP Server Configuration:
{
"mcpServers": {
"latex-server": {
"command": "python",
"args": [
"C:\\path\\to\\mcp-latex-server\\latex_server.py"
],
"env": {
"LATEX_BASE_PATH": "C:\\path\\to\\your\\latex\\files"
},
"cwd": "C:\\path\\to\\mcp-latex-server"
}
}
}
For uv (recommended for better performance):
{
"mcpServers": {
"latex-server": {
"command": "uv",
"args": [
"--directory",
"C:\\path\\to\\mcp-latex-server",
"run",
"latex_server.py"
],
"env": {
"LATEX_BASE_PATH": "C:\\path\\to\\your\\latex\\files"
},
"cwd": "C:\\path\\to\\mcp-latex-server"
}
}
}
- Restart Claude Desktop for changes to take effect.
VS Code Integration with Claude
-
Install the Claude extension in VS Code
-
Configure MCP Server in VS Code settings:
Open VS Code settings (Ctrl+, or Cmd+,) and add:
{
"claude.mcpServers": {
"latex-server": {
"command": "python",
"args": ["C:\\path\\to\\mcp-latex-server\\latex_server.py"],
"cwd": "C:\\path\\to\\mcp-latex-server",
"env": {
"LATEX_BASE_PATH": "${workspaceFolder}"
}
}
}
}
- Alternative: Using tasks.json
Create .vscode/tasks.json in your workspace:
{
"version": "2.0.0",
"tasks": [
{
"label": "Start LaTeX MCP Server",
"type": "shell",
"command": "python",
"args": ["C:\\path\\to\\mcp-latex-server\\latex_server.py", "--base-path", "${workspaceFolder}"],
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "new"
},
"isBackground": true,
"problemMatcher": []
}
]
}
Testing the Integration
-
Start Claude Desktop or Claude in VS Code
-
Test the connection by asking Claude:
Can you list the available LaTeX tools? -
Create a test document:
Please create a simple LaTeX article with the title "Test Document" and some sample content.
Usage Examples
Basic Document Creation
# Example interaction with Claude
"Create a LaTeX article titled 'My Research Paper' with author 'John Doe' and include sections for Introduction, Methodology, Results, and Conclusion."
Advanced Document Creation
# Creating a complex document
{
"name": "create_latex_file",
"arguments": {
"file_path": "research_paper.tex",
"document_type": "article",
"title": "Advanced Machine Learning Techniques",
"author": "Jane Smith",
"date": "\\today",
"packages": ["amsmath", "amsfonts", "graphicx", "booktabs", "hyperref"],
"geometry": "margin=1in",
"content": "\\section{Introduction}\nThis paper explores...\n\n\\section{Methodology}\nWe employed..."
}
}
Editing Operations
# Replace content
{
"name": "edit_latex_file",
"arguments": {
"file_path": "document.tex",
"operation": "replace",
"search_text": "\\section{Old Section}",
"new_text": "\\section{New Section}"
}
}
# Insert content
{
"name": "edit_latex_file",
"arguments": {
"file_path": "document.tex",
"operation": "insert_after",
"search_text": "\\section{Introduction}",
"new_text": "\nThis section provides an overview of the research topic."
}
}
# Append content
{
"name": "edit_latex_file",
"arguments": {
"file_path": "document.tex",
"operation": "append",
"new_text": "\n\\section{Conclusion}\nIn conclusion, this study demonstrates..."
}
}
Available Tools
1. create_latex_file
Creates a new LaTeX document with specified parameters.
Parameters:
file_path(required): Path where the file should be createddocument_type: Document class (article, report, book, letter, beamer, minimal)title: Document titleauthor: Document authordate: Document date (default: \today)packages: List of LaTeX packages to includegeometry: Page geometry settingscontent: Main document content
2. edit_latex_file
Edits an existing LaTeX file with various operations.
Parameters:
file_path(required): Path to the file to editoperation(required): Type of edit (replace, insert_before, insert_after, append, prepend)new_text(required): New text to insert or replace withsearch_text: Text to search for (required for replace, insert_before, insert_after)line_number: Line number for insertion (alternative to search_text)
3. read_latex_file
Reads and returns the contents of a LaTeX file.
Parameters:
file_path(required): Path to the file to read
4. list_latex_files
Lists all LaTeX files in a directory.
Parameters:
directory_path: Directory to search (default: current directory)recursive: Whether to search subdirectories (default: false)
5. validate_latex
Performs basic LaTeX syntax validation.
Parameters:
file_path(required): Path to the file to validate
6. get_latex_structure
Extracts the structure of a LaTeX document (sections, subsections, etc.).
Parameters:
file_path(required): Path to the file to analyze
Troubleshooting
Common Issues
1. Server Won't Start
# Check Python version
python --version # Should be 3.8+
# Check dependencies
pip list | grep mcp
# Run with debug logging
python latex_server.py --log-level DEBUG
2. Claude Can't Connect to Server
- Verify the file paths in your configuration are correct
- Check that Python is in your system PATH
- Restart Claude Desktop after configuration changes
- Check Claude Desktop logs for error messages
3. Permission Errors
# Windows: Run as administrator if needed
# macOS/Linux: Check file permissions
chmod +x latex_server.py
4. LaTeX Compilation Issues
- Ensure LaTeX distribution is properly installed
- Check that required packages are available
- Use the validation tool to check syntax
Debug Mode
Run the server in debug mode for detailed logging:
python latex_server.py --log-level DEBUG --base-path /your/latex/path
Log Files
Check log files for troubleshooting:
- Server logs: Available in console output
- Claude Desktop logs: Check Claude's log directory
- VS Code logs: Check VS Code's output panel
Advanced Configuration
Custom Templates
Create custom templates in the templates/ directory:
% templates/custom_article.tex
\documentclass[12pt]{article}
\usepackage{your_custom_packages}
\title{{{TITLE}}}
\author{{{AUTHOR}}}
\date{{{DATE}}}
\begin{document}
\maketitle
{{{CONTENT}}}
\end{document}
Security Considerations
- The server only allows access to specified directories
- File operations are limited to LaTeX-related extensions
- Input validation prevents malicious LaTeX code execution
Performance Optimization
- Use SSD storage for LaTeX files
- Keep LaTeX distribution up to date
- Use
uvinstead ofpipfor faster dependency management
Contributing
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Update documentation
- Submit a pull request
License
This project is licensed under the MIT License. See the LICENSE file for details.
Support
For support and questions:
- Check the troubleshooting section above
- Review GitHub issues
- Create a new issue with detailed information about your problem
Changelog
Version 1.0.0
- Initial release
- Basic LaTeX file operations
- MCP integration support
- Template system
Похожие серверы
Scout Monitoring MCP
спонсорPut performance and error data directly in the hands of your AI assistant.
Alpha Vantage MCP Server
спонсорAccess financial market data: realtime & historical stock, ETF, options, forex, crypto, commodities, fundamentals, technical indicators, & more
Ollama
Integrates with Ollama to run local large language models. Requires a running Ollama instance.
Local Code Indexing for Cursor
A Python-based server that locally indexes codebases using ChromaDB to provide semantic search for tools like Cursor.
OneTool MCP
🧿 One MCP for developers - No tool tax, no context rot. 100+ tools including Brave, Gemini, Context7, Version Checker, Excel, File Ops, Database, Chrome DevTools.
Lucide Icons
Provides access to the Lucide icon library for use in LLM and agentic applications.
MemGPT MCP Server
A server that provides a memory system for LLMs, enabling persistent conversations with various providers like OpenAI, Anthropic, and OpenRouter.
Authless Remote MCP Server
A remote MCP server without authentication, designed for easy deployment on Cloudflare Workers.
Panther
Interact with the Panther security platform to write detections, query logs with natural language, and manage alerts.
Hyperlane MCP Server
Integrates with the Hyperlane protocol for cross-chain messaging and smart contract interactions.
Kubernetes Automated Installation
An agent for automatically installing Kubernetes in a Rocky Linux environment using MCP.
Remote MCP Server (Authless)
A remote MCP server deployable on Cloudflare Workers that operates without authentication.