MCP LaTeX Server
Enables AI assistants to create, edit, and validate LaTeX documents through a standardized protocol with support for multiple document classes and package management. It provides tools for document structure analysis and file organization to streamline the generation of professional academic papers.
README
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
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。