Overleaf MCP Server

repository·master·Indexed 41 days ago

https://github.com/mjyoo2/overleafmcp

An MCP (Model Context Protocol) server that enables AI assistants to read Overleaf projects, parse LaTeX document structure, and push section-level edits via Git. Version 1.0.0 provides tools for listing files, reading content, and performing targeted LaTeX edits using a brace-balanced parser for sections like \part, \chapter, and \section.

Tokens
2.4K
Snippets
4
Records
11
Agent score
6%

What's inside Overleaf MCP

  1. Configure Multi-Project Support via projects.json

    master

    If you need to manage multiple Overleaf projects, use a projects.json file instead of environment variables. When using this method, omit the env block from your Claude Desktop configuration.

    1. Create the projects.json file: Place this file in the following location:

    • Windows: %APPDATA%\overleaf-mcp\projects.json
    • macOS / Linux: ~/.config/overleaf-mcp/projects.json (or $XDG_CONFIG_HOME/overleaf-mcp/projects.json)

    File Content Format:

    {
      "projects": {
        "default": {
          "name": "Main Paper",
          "projectId": "...",
          "gitToken": "olp_..."
        },
        "thesis": {
          "name": "PhD Thesis",
          "projectId": "...",
          "gitToken": "olp_..."
        }
      }
    }

    2. Update Claude Desktop Config:

    {
      "mcpServers": {
        "overleaf": {
          "command": "cmd",
          "args": ["/c", "npx", "-y", "@mjyoo2/overleaf-mcp"]
        }
      }
    }

    (Note: Remove cmd /c on macOS/Linux)

    3. Usage: Reference a specific project in tool calls using the projectName parameter (e.g., projectName: "thesis"). If omitted, the default entry is used. To use a custom path for the config file, set the OVERLEAF_PROJECTS_CONFIG environment variable.

    {
      "projects": {
        "default": {
          "name": "Main Paper",
          "projectId": "...",
          "gitToken": "olp_..."
        },
        "thesis": {
          "name": "PhD Thesis",
          "projectId": "...",
          "gitToken": "olp_..."
        }
      }
    }
  2. Local Development: Running the Server Manually

    master

    To test the server locally without using the npm package or Claude Desktop, you can run the script directly via Node.js.

    1. Clone and Install:

    git clone https://github.com/mjyoo2/OverleafMCP.git
    cd OverleafMCP
    npm install

    2. Smoke-test via Shell: Run the server and provide credentials via environment variables. You should see Overleaf MCP server running on stdio on stderr.

    OVERLEAF_PROJECT_ID=... OVERLEAF_GIT_TOKEN=... node overleaf-mcp-server.js

    3. Use in Claude Desktop (Local Script): Point the command to node and the args to the absolute path of the script.

    {
      "mcpServers": {
        "overleaf": {
          "command": "node",
          "args": ["/absolute/path/to/OverleafMCP/overleaf-mcp-server.js"],
          "env": {
            "OVERLEAF_PROJECT_ID": "...",
            "OVERLEAF_GIT_TOKEN": "olp_..."
          }
        }
      }
    }

    (On Windows, use double backslashes in the path: "C:\\Users\\you\\...")

    OVERLEAF_PROJECT_ID=... OVERLEAF_GIT_TOKEN=... node overleaf-mcp-server.js
  3. Get Overleaf Project ID and Git Token

    master

    To authenticate the MCP server, you need two pieces of information from Overleaf:

    1. Project ID: Open your Overleaf project in a browser. The ID is the string in the URL: https://www.overleaf.com/project/[PROJECT_ID].
    2. Git Token: In Overleaf, navigate to Account Settings $\rightarrow$ Git Integration $\rightarrow$ Create Token.
  4. Quick Start: Install Overleaf MCP for Claude Desktop

    master

    To use the Overleaf MCP server with Claude Desktop, add the server configuration to your claude_desktop_config.json file. This method uses npx to run the package without manual cloning or installation.

    Config file locations:

    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Linux: ~/.config/claude/claude_desktop_config.json

    macOS / Linux Configuration:

    {
      "mcpServers": {
        "overleaf": {
          "command": "npx",
          "args": ["-y", "@mjyoo2/overleaf-mcp"],
          "env": {
            "OVERLEAF_PROJECT_ID": "YOUR_OVERLEAF_PROJECT_ID",
            "OVERLEAF_GIT_TOKEN": "YOUR_OVERLEAF_GIT_TOKEN"
          }
        }
      }
    }

    Windows Configuration: (Note: Windows requires cmd /c to locate npx)

    {
      "mcpServers": {
        "overleaf": {
          "command": "cmd",
          "args": ["/c", "npx", "-y", "@mjyoo2/overleaf-mcp"],
          "env": {
            "OVERLEAF_PROJECT_ID": "YOUR_OVERLEAF_PROJECT_ID",
            "OVERLEAF_GIT_TOKEN": "YOUR_OVERLEAF_GIT_TOKEN"
          }
        }
      }
    }

    After updating the config, restart Claude Desktop. The overleaf tools should appear in the 🔧 menu.

  5. How LaTeX section parsing works

    master

    The server uses a brace-balanced parser to identify LaTeX sectioning commands. This allows it to correctly handle nested macros within titles (e.g., \section{Use of \emph{X}}).

    Supported section types include:

    • \part
    • \chapter
    • \section
    • \subsection
    • \subsubsection

    It also handles starred variants (e.g., \section*) and the optional short-title form [short]{long}.

  6. Configure Overleaf MCP Server via Environment Variables

    master

    For a single-project setup, you can configure the server using environment variables. This is the recommended method for simple integrations.

    Required variables:

    • OVERLEAF_PROJECT_ID: The unique ID of your Overleaf project.
    • OVERLEAF_GIT_TOKEN or OVERLEAF_GIT_TOKEN_FILE: Your Overleaf Git token. If using the file option, provide the path to a file containing only the token.

    Optional variables:

    • OVERLEAF_PROJECT_NAME: A custom display name for the project.

    When these are set, the server synthesizes a configuration under the key default.

    # Example using direct token
    export OVERLEAF_PROJECT_ID="your_project_id"
    export OVERLEAF_GIT_TOKEN="your_git_token"
    
    # Example using token file
    export OVERLEAF_PROJECT_ID="your_project_id"
    export OVERLEAF_GIT_TOKEN_FILE="/path/to/token.txt"
  7. Reference: Available Overleaf MCP Tools

    master

    The following tools are exposed by the Overleaf MCP server:

    • list_projects: List all configured projects.
    • list_files: List files in a project.
      • extension (optional): Filter by extension.
      • projectName (optional): Defaults to "default".
    • read_file: Read a specific file.
      • filePath (required)
      • projectName (optional)
    • get_sections: Get all sections from a LaTeX file.
      • filePath (required)
      • projectName (optional)
    • get_section_content: Get content of a specific section.
      • filePath (required)
      • sectionTitle (required)
      • projectName (optional)
    • status_summary: Get a comprehensive project status summary.
      • projectName (optional)
    • write_file: Write full content of a file.
      • filePath (required)
      • content (required)
      • commitMessage (required)
      • projectName (optional)
    • write_section: Write content of a specific section.
      • filePath (required)
      • sectionTitle (required)
      • newContent (required): Must include the section heading.
      • commitMessage (required)
      • projectName (optional)
  8. Configure Multi-Project Setup with projects.json

    master

    To manage multiple Overleaf projects, use a projects.json configuration file. The server searches for this file in the following order of priority:

    1. Path specified by OVERLEAF_PROJECTS_CONFIG environment variable.
    2. User config directory:
      • Windows: %APPDATA%/overleaf-mcp/projects.json
      • Others: $XDG_CONFIG_HOME/overleaf-mcp/projects.json (falls back to ~/.config/overleaf-mcp/projects.json)
    3. Current Working Directory: ./projects.json
    4. Package directory: <package_dir>/projects.json (legacy)

    The file must follow a specific schema where projects are keyed by an identifier.

  9. Reference: Configuration Precedence and Environment Variables

    master

    The server resolves configuration using the following priority (first match wins):

    1. Env vars (single project): OVERLEAF_PROJECT_ID + OVERLEAF_GIT_TOKEN. (Optional: OVERLEAF_PROJECT_NAME for display name).
    2. Token from a file: Set OVERLEAF_PROJECT_ID and OVERLEAF_GIT_TOKEN_FILE=/path/to/token.txt. The file is read once and whitespace/newlines are trimmed.
    3. Multi-project file: OVERLEAF_PROJECTS_CONFIG=/absolute/path/projects.json.
    4. User config dir: projects.json in %APPDATA%\overleaf-mcp\ (Windows) or ~/.config/overleaf-mcp/ (macOS/Linux).
    5. Working directory: ./projects.json.
    6. Package directory: projects.json next to the server script.

    Note: If environment variables are set, they shadow file-based configurations, and a notice is logged to stderr.

  10. Use write_section for targeted LaTeX edits

    master

    The write_section tool is safer than write_file for editing LaTeX documents because it only replaces the content within a specific section (e.g., \section{Title}). This prevents accidental deletion of the rest of the document.

    Requirements:

    • filePath: Path to the .tex file.
    • sectionTitle: The exact title of the section to replace.
    • newContent: The replacement content, including the section heading.
    • commitMessage: A Git commit message for the change.
  11. Reference: Overleaf MCP Tool Definitions

    master

    The Overleaf MCP server provides the following tools for interacting with Overleaf projects via Git:

    ToolDescription
    list_projectsList all configured Overleaf projects
    list_filesList files in a project (supports extension filter)
    read_fileRead the content of a specific file
    get_sectionsRetrieve all LaTeX sectioning commands (part, chapter, section, etc.) from a file
    get_section_contentGet the content of a specific LaTeX section by its title
    status_summaryGet a summary of the project (total files, main file, total sections)
    write_fileOverwrite a file and push changes to Overleaf
    write_sectionReplace a specific LaTeX section by title, leaving the rest of the file intact

    All tools accept an optional projectName argument to specify which project to operate on (defaults to default).