Model Context Protocol

Connect Leafwright to your AI tools.

The Leafwright MCP server lets Claude, ChatGPT, Cursor, and Codex render PDFs, build templates, and debug failed renders from logs — no headless Chrome, no code to deploy. The agent calls a tool and gets a real signed PDF URL back.

Remote server — claude.ai and ChatGPT, no install

Leafwright runs a hosted MCP server with OAuth. In claude.ai, go to Settings → Connectors → Add custom connector, name it Leafwright, and enter the server URL:

https://leafwright.co/mcp

Leave the OAuth fields empty — the connector registers itself and opens a browser window where you sign in and pick an organization and default project. In ChatGPT, add the same URL as a connector from Settings → Connectors (developer mode). The server implements OAuth 2.1 with PKCE and Dynamic Client Registration, so any MCP client that supports remote servers can connect.

Local server — Claude Code, Cursor, and Codex

Nothing to install — the stdio server runs with npx:

npx -y @leafwright/mcp

The npm package is being published — if npx can't find it yet, the remote server above works today.

Claude Code (.mcp.json), Cursor (~/.cursor/mcp.json), and Codex all use the same configuration shape:

{
  "mcpServers": {
    "leafwright": {
      "command": "npx",
      "args": ["-y", "@leafwright/mcp"],
      "env": {}
    }
  }
}

Restart the client, then ask the agent to call leafwright_login. Open the returned verification URL, sign in, choose a project, and the full tool set appears. Project API keys are still supported for server automation via LEAFWRIGHT_API_KEY.

VariablePurpose
LEAFWRIGHT_API_KEYProject API key (lw_live_… or lw_test_…) for server automation.
LEAFWRIGHT_MCP_TOKENMCP token (mcp_…) for non-interactive setups.
LEAFWRIGHT_PROJECT_IDOverride the active default project.
LEAFWRIGHT_MCP_READ_ONLYtrue exposes only read tools — no renders, writes, or AI.

What the agent can do

Auth and context

  • leafwright_login Start browser login.
  • leafwright_auth_status Complete or check browser login.
  • leafwright_logout Revoke and clear local MCP auth.
  • leafwright_list_organizations List the token's organization.
  • leafwright_list_projects List projects in the organization.
  • leafwright_select_project Set the active project.

ReadAvailable after auth, no side effects.

  • leafwright_list_templates List the project's templates.
  • leafwright_get_template Fetch one template with drafts and versions.
  • leafwright_validate_template Validate a template before rendering.
  • leafwright_get_job Render job status and metadata.
  • leafwright_get_job_logs Render logs — failed assets, fonts, timeouts, overflow.
  • leafwright_get_usage Credits used and remaining this period.
  • leafwright_estimate_usage_cost Estimate credits and overage for a planned batch.

WriteHidden when LEAFWRIGHT_MCP_READ_ONLY=true.

  • leafwright_render_html Render raw HTML to a PDF (signed URL).
  • leafwright_render_url Render a public URL to a PDF (SSRF-protected).
  • leafwright_render_template Render a published template with JSON data.
  • leafwright_create_template Create a draft template.
  • leafwright_update_template_draft Update a draft's HTML, CSS, or sample data.
  • leafwright_ai_generate_template Generate a draft template from a prompt.
  • leafwright_ai_revise_template Revise a draft from an instruction.
  • leafwright_ai_fix_from_logs Repair a template from a failed render's logs.

The debugging loop

A code-only agent can't see its PDF. This server closes that loop:

  1. The agent renders a template — it fails or looks wrong.
  2. It calls leafwright_get_job_logs and reads the real cause: a font that 404'd, an asset that timed out, a rule that overflowed the page.
  3. It calls leafwright_ai_fix_from_logs, gets a corrected template, re-renders, and confirms it's clean.

Safe by design

The server only calls the public Leafwright API. It runs no shell commands from agent input, stores tokens in the OS keychain when possible, and supports a read-only mode. AI drafts and revises templates; publishing always requires a human in the dashboard.

Get an API key — free, 100 PDFs/monthRead the guide: give your coding agent the ability to make PDFs