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 syntax, and monitor usage — directly from Claude, Claude Code, Cursor, VS Code, and other MCP clients.

·8 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 (claude.ai and Claude Desktop) — Anthropic's assistant, through custom connectors
  • Claude Code — Anthropic's terminal coding agent
  • Cursor and VS Code — AI-powered editors
  • Codex — OpenAI's coding agent
  • Any MCP-compatible client — the protocol is open and growing

When you connect FormaTeX as an MCP server, your AI agent can compile LaTeX, validate it, run async jobs, and monitor usage — all through natural language.

FormaTeX MCP Tools

The FormaTeX MCP server exposes tools in four groups.

Compile

compile_latex compiles LaTeX source with an engine you choose.

Parameters:

  • latex (string) — the LaTeX source code
  • engine (string) — pdflatex, xelatex, lualatex, or latexmk
  • runs (integer) — number of compilation passes
  • timeout (integer) — compile timeout in seconds

Send 0 for runs and timeout to let the API choose: automatic passes and your plan's default timeout.

Returns: text with the engine used, duration, job ID, PDF size, and a Download PDF link. The PDF itself is not inlined.

compile_smart compiles with automatic engine detection and error fixing, and retries with fallback engines. It takes latex, runs, and timeout, and picks the engine itself. This is the recommended default for most documents.

compile_async submits a job and returns a job ID immediately. It requires only latex; engine, runs, and timeout are optional. Use get_job with the jobId to poll: a completed job returns a PDF download link, a failed job returns the error log.

Validate and inspect

  • check_syntax takes latex and validates it without compiling. It does not count against your monthly compilation quota.
  • list_engines lists the LaTeX engines available on your current plan.
  • get_usage returns this month's compilation statistics and plan limits for your API key.

Fetch bytes

fetch_pdf_bytes takes a jobId and returns the compiled PDF as base64. It is the only tool that returns the file itself. Use it when the agent needs to save or inspect the PDF; for everything else the download link is enough and far cheaper in tokens.

Templates (Pro and above)

  • list_templates lists your saved templates with IDs, names, and descriptions.
  • compile_template takes a templateId and optional variables (name and value pairs), and compiles the saved template.

The server also exposes two resources, formatex://engines and formatex://usage, and a fix_latex prompt that takes your LaTeX source and error log and returns structured instructions for fixing the errors.

Connect the Hosted Server

The hosted server at https://mcp.formatex.io/mcp speaks Streamable HTTP, so there is nothing to install. You'll need an API key from your FormaTeX account. Keys start with fex_.

Claude (claude.ai and Claude Desktop)

  1. Open Customize, then Connectors, and choose Add custom connector.
  2. Enter the server URL: https://mcp.formatex.io/mcp.
  3. Sign in when prompted. The authorization page asks for your FormaTeX API key.

Add the hosted server through Connectors. The claude_desktop_config.json file is only for local servers that Claude Desktop starts itself. Once connected, ask Claude to compile directly:

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

Claude will call a compile tool and give you a link to the PDF.

Claude Code

Register the server with the CLI:

bash
claude mcp add --transport http formatex https://mcp.formatex.io/mcp \
  --header "Authorization: Bearer $FORMATEX_API_KEY"

Or commit a .mcp.json file at your project root. ${VAR} expansion works in this file, so the key stays in your environment:

json
{
  "mcpServers": {
    "formatex": {
      "type": "http",
      "url": "https://mcp.formatex.io/mcp",
      "headers": {
        "Authorization": "Bearer ${FORMATEX_API_KEY}"
      }
    }
  }
}

Cursor

Add the server to .cursor/mcp.json in your project, or to ~/.cursor/mcp.json for every project:

json
{
  "mcpServers": {
    "formatex": {
      "url": "https://mcp.formatex.io/mcp",
      "headers": {
        "Authorization": "Bearer ${env:FORMATEX_API_KEY}"
      }
    }
  }
}

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.

VS Code and Codex

VS Code reads .vscode/mcp.json; its top-level key is servers (not mcpServers), and remote entries need "type": "http". Codex reads ~/.codex/config.toml:

toml
[mcp_servers.formatex]
url = "https://mcp.formatex.io/mcp"
bearer_token_env_var = "FORMATEX_API_KEY"

Run the Local Binary Instead

If your client only supports stdio, or you prefer to run the server yourself, install the formatex-mcp binary. It needs Go 1.23 or newer:

bash
go install github.com/formatexio/mcp/cmd/formatex-mcp@latest

Prebuilt binaries are on the releases page. Point your client at the binary and pass your key in the FORMATEX_API_KEY environment variable. For Claude Desktop, edit claude_desktop_config.json:

json
{
  "mcpServers": {
    "formatex": {
      "command": "/full/path/to/formatex-mcp",
      "env": {
        "FORMATEX_API_KEY": "fex_your_api_key_here"
      }
    }
  }
}

For Claude Code the equivalent is:

bash
claude mcp add --env FORMATEX_API_KEY=fex_your_api_key_here \
  --transport stdio formatex -- /full/path/to/formatex-mcp

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_smart or compile_latex to produce the PDF
  3. Returns the download link for the compiled document

Research Assistants

AI agents can compile academic papers, check for errors, and iterate — similar to the AI-powered LaTeX error fixing pipeline:

"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. For example, generating a TypeScript function that builds a LaTeX invoice and verifying it 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 check_syntax or 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
  • Typed inputs — each tool publishes a JSON Schema for its parameters
  • Credential management — API keys are configured once in the client, 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}