FormaTeX

\begin{article}

FormaTeX MCP Server: LaTeX Compilation for AI Agents

FormaTeX v1.4 introduces an MCP server that lets AI agents compile LaTeX, check engine availability, and monitor usage — directly from Claude Desktop, Cursor, and other MCP clients.

·4 min read·
FormaTeX MCP Server: LaTeX Compilation for AI Agents

AI agents are increasingly capable of generating documents, writing reports, and producing structured output. But generating a PDF requires compilation infrastructure that most AI agents do not have access to. FormaTeX v1.4 introduces an MCP (Model Context Protocol) server that gives AI agents direct access to LaTeX compilation — no custom integration required.

What Is MCP?

The Model Context Protocol (MCP) is an open standard for connecting AI models to external tools and data sources. Instead of building custom API integrations for every tool, MCP provides a standardized interface that any compatible AI client can use.

MCP clients include:

  • Claude Desktop — Anthropic's desktop application for Claude
  • Cursor — AI-powered code editor
  • Any MCP-compatible client — the protocol is open and growing

When you connect FormaTeX as an MCP server, your AI agent can compile LaTeX, check available engines, and monitor usage — all through natural language.

FormaTeX MCP Tools

The FormaTeX MCP server exposes three tools:

compile_latex

Compiles LaTeX source code into a PDF.

Parameters:

  • content (string) — the LaTeX source code
  • engine (string, optional) — pdflatex, xelatex, lualatex, or latexmk

Returns: The compiled PDF binary, or an error with the TeX compilation log.

list_engines

Lists all LaTeX engines available on your current plan.

Returns: An array of engine names with their descriptions and availability status.

get_usage

Returns your current compilation usage and plan limits.

Returns: Current month's compilation count, AI request count, plan limits, and remaining quota.

Setup for Claude Desktop

Add the FormaTeX MCP server to your Claude Desktop configuration:

json
{
  "mcpServers": {
    "formatex": {
      "command": "npx",
      "args": ["-y", "@formatex/mcp-server"],
      "env": {
        "FORMATEX_API_KEY": "fxk_your_api_key_here"
      }
    }
  }
}

After restarting Claude Desktop, you can ask Claude to compile LaTeX directly:

"Compile this LaTeX document into a PDF: \documentclass{article}\begin{document}Hello from MCP!\end{document}"

Claude will use the compile_latex tool to compile the document and return the PDF.

Setup for Cursor

Add the FormaTeX MCP server to your Cursor settings:

json
{
  "mcpServers": {
    "formatex": {
      "command": "npx",
      "args": ["-y", "@formatex/mcp-server"],
      "env": {
        "FORMATEX_API_KEY": "fxk_your_api_key_here"
      }
    }
  }
}

Now Cursor can compile LaTeX as part of code generation workflows — generate a report template, compile it, and verify the output all in one conversation.

Example AI Workflows

AI-Generated Reports

Ask your AI agent to produce a complete PDF report from data:

"Here is this month's sales data: [data]. Generate a LaTeX report with a summary table and compile it to PDF."

The agent:

  1. Writes the LaTeX source with proper tables and formatting
  2. Calls compile_latex to produce the PDF
  3. Returns the compiled document

Research Assistants

AI agents can compile academic papers, check for errors, and iterate:

"Take this draft paper and compile it. If there are errors, fix them and recompile."

The agent:

  1. Calls compile_latex with the draft
  2. If compilation fails, reads the error log
  3. Fixes the LaTeX source
  4. Recompiles until successful

Developer Copilots

When generating code that includes PDF output, the AI can verify the LaTeX compiles:

"Generate a TypeScript function that builds a LaTeX invoice and compile a sample to make sure it works."

The agent:

  1. Writes the TypeScript code with a LaTeX template
  2. Extracts the LaTeX template
  3. Calls compile_latex to verify it compiles
  4. Returns verified, working code

Use Cases

ScenarioHow MCP helps
Report generationAgent writes LaTeX and compiles in one step
Document QAAgent compiles, checks output, iterates
Template developmentAgent builds and tests LaTeX templates interactively
Research automationAgent compiles papers as part of a research pipeline
EducationAgent creates worksheets, exams, handouts on demand

Why MCP Instead of Direct API Calls?

MCP provides several advantages over having the AI agent make raw HTTP calls:

  • No prompt engineering — the agent discovers tools automatically via MCP
  • Type safety — MCP schemas define parameters and return types
  • Credential management — API keys are configured once in the MCP server, not passed in prompts
  • Tool discovery — the agent can call list_engines and get_usage to understand its capabilities before compiling

The FormaTeX MCP server uses your existing API key and plan. Compilations through MCP count against the same monthly quota as direct API calls. Use get_usage to check your remaining quota before batch operations.

Get Started

\end{article}

Back to blog

\related{posts}

One quick thing

We track anonymous usage — page views, feature usage, compilation events — to understand what works and what doesn't. No ads, no personal data, no third-party sharing.

Cookie policy