mcp-pdf-tokensaver

mcp-pdf-tokensaver

A layout-aware local MCP server that analyzes PDF structures (multi-columns, tables, LaTeX equations) to save up to 90% context tokens for LLMs in Cursor and Claude Desktop. Powered by https://golocalpdf.com

Category
访问服务器

README

mcp-pdf-tokensaver

mcp-pdf-tokensaver MCP server mcp-pdf-tokensaver score

A layout-aware MCP server that analyzes PDF structures to save up to 90% context tokens for LLMs.

Stop wasting LLM tokens on PDFs. This MCP server provides layout-aware, two-pass chunking and formula protection for Cursor, Claude Desktop, and other AI editors.

License: MIT Node.js MCP npm

Why mcp-pdf-tokensaver?

Reading dense, multi-column technical papers, API documentation, or corporate PDFs inside AI editors often leads to two major frustrations:

  1. The Token Tax: Multi-column text gets scrambled, forcing you to upload full documents and waste tens of thousands of context tokens.
  2. Formula Corruption: LaTeX equations frequently get broken or mistranslated during full-text ingestion.

mcp-pdf-tokensaver provides a 100% local solution to shield your token window.

Features

  • Layout-Aware Inspection: Parse PDF structures (multi-columns, tables, headings) without uploading full text immediately.
  • Two-Pass Token Saving: LLMs first inspect the document outline via a condensed JSON schema, then selectively fetch exact text chunks based on blockId.
  • 100% Client-Side & Secure: All parsing happens locally. Your sensitive data never leaves your machine.
  • Scanned PDF Support: OCR integration for scanned documents (English).

How It Works

Instead of feeding raw PDF streams into the LLM, this server empowers your AI model with a Two-Pass Precise Retrieval Strategy:

  1. inspect_pdf_structure: The LLM scans a super-condensed layout skeleton of your PDF, mapping pages, columns, and headings in milliseconds.
  2. fetch_pdf_chunks: The LLM target-fetches only the exact text rows or equations it needs based on specific blockIds.

Token Savings Comparison

Solution Working Principle Token Impact
Traditional Full-Text Dumps entire PDF as Markdown into context 🔴 Catastrophic: 40-page doc can burn 30K+ tokens per turn
Vector RAG Local embedding search, returns top-3 chunks 🟡 Medium: No global document awareness
mcp-pdf-tokensaver Structure-aware agentic retrieval 🟢 Minimal: Saves 90%+ tokens

Installation

Option 1: Install via npm (Recommended)

npm install -g mcp-pdf-tokensaver

Option 2: Install from source

git clone https://github.com/anthropics/mcp-pdf-tokensaver.git
cd mcp-pdf-tokensaver
npm install
npm run build

Configuration

Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "pdf-tokensaver": {
      "command": "mcp-pdf-tokensaver",
      "args": []
    }
  }
}

Cursor / Windsurf

Add to your MCP settings:

{
  "mcpServers": {
    "pdf-tokensaver": {
      "command": "mcp-pdf-tokensaver",
      "args": []
    }
  }
}

Custom Configuration

You can configure limits via environment variables:

{
  "mcpServers": {
    "pdf-tokensaver": {
      "command": "mcp-pdf-tokensaver",
      "args": [],
      "env": {
        "MCP_PDF_MAX_SIZE_MB": "100",
        "MCP_PDF_MAX_PAGES": "500",
        "MCP_OCR_TIMEOUT_MS": "30000"
      }
    }
  }
}

Usage

Once configured, simply ask your AI editor to analyze a PDF:

"Help me analyze the structure of paper.pdf on my desktop. Where are the core formulas?"

The LLM will automatically call inspect_pdf_structure to get a condensed layout skeleton, then use fetch_pdf_chunks to retrieve only the relevant sections.

Tools

inspect_pdf_structure

Analyzes the layout and structural skeleton of a local PDF file.

Input:

{
  "filePath": "/path/to/your/document.pdf"
}

Output:

{
  "status": "success",
  "documentMeta": {
    "path": "/path/to/your/document.pdf",
    "totalPages": 24,
    "isEncrypted": false,
    "hasScannedPages": [],
    "estimatedFullTextTokens": 84000
  },
  "structureSkeleton": [
    {
      "blockId": "page_1_para_1",
      "type": "heading",
      "pageIndex": 0,
      "level": 1,
      "summary": "1. Introduction",
      "tokenEstimate": 8
    },
    {
      "blockId": "page_2_para_3",
      "type": "text",
      "pageIndex": 1,
      "layoutType": "double-column",
      "summary": "Discusses client-side WebAssembly...",
      "tokenEstimate": 45
    }
  ]
}

fetch_pdf_chunks

Selectively fetch specific text paragraphs or equations based on their blockId.

Input:

{
  "filePath": "/path/to/your/document.pdf",
  "blockIds": ["page_2_para_3", "page_4_para_1"]
}

Output:

{
  "status": "success",
  "fetchedChunks": {
    "page_2_para_3": {
      "type": "text",
      "content": "We implement a pure client-side PDF parsing pipeline...",
      "pageContext": "Page 2"
    },
    "page_4_para_1": {
      "type": "equation",
      "content": "$$\\Theta(N) = \\sum_{i=1}^{N} \\alpha_i$$",
      "pageContext": "Page 4"
    }
  }
}

Limitations

  • Encrypted PDFs are not supported
  • Scanned PDF OCR is limited to English
  • Maximum file size: 100MB (configurable)
  • Maximum pages: 500 (configurable)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments


Optimized by the core layout engine of GoLocalPDF — the leading privacy-first client-side PDF utility.

If you need a seamless browser-based PDF reading experience with dual-pane translation, visit golocalpdf.com.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选