pdfsearch-mcp

pdfsearch-mcp

Enables local indexing and semantic search of PDF documents (like AGLC4 style guide) with OCR support, allowing LLM tools to query PDF content and retrieve relevant text snippets with context.

Category
访问服务器

README

pdfsearch-mcp

Minimal MCP server that indexes and searches PDFs (AGLC4 by default) for use by LLM tools (Claude Desktop, Claude Code, Codex, etc.). Search runs locally with no external APIs.

Quickstart (Node)

  • Place the PDF at data/AGLC4.pdf.
  • Install: npm install
  • Build index: npm run index
  • Run server (stdio): npm run dev (TS) or npm start (compiled)

Quickstart (Docker)

  • Build: docker build -t pdfsearch-mcp .
  • Run (mount data):
    • mkdir -p data && cp path/to/AGLC4.pdf data/AGLC4.pdf
    • docker run -i --rm -v "$PWD/data:/app/data" pdfsearch-mcp

The server communicates over stdio per MCP; configure your client/tool to launch the command and speak MCP.

Making the PDF Machine-Readable (OCR)

  • The indexer auto-detects image-only PDFs. If minimal text is found, it runs OCR via ocrmypdf and writes data/AGLC4.ocr.pdf, then indexes that.
  • Local install:
    • macOS: brew install ocrmypdf tesseract
    • Debian/Ubuntu: sudo apt-get install -y ocrmypdf tesseract-ocr
  • Environment:
    • OCR_LANG (default eng) — tesseract language(s), e.g. eng+fra.
    • OCR_FORCE=1 — force OCR even if a text layer exists.
  • Docker image already includes OCR tools.

Commands

  • npm run index — Extracts text from the PDF and creates a local search index under data/index/.
  • npm run dev — Runs the MCP server in TypeScript via tsx.
  • npm run build — Compiles TypeScript to dist/.
  • npm start — Runs the compiled server.
  • npm run search -- "query" — Quick local search without MCP.
  • npm run health — Prints whether the PDF and index are present.
  • npm run setup — Install deps, index the default PDF, and start the server.
  • npm run list-tools — Minimal MCP client printing the server tool list.
  • npm run call-tool -- '{"name":"searchpdf-mcp","arguments":{"query":"..."}}' — Call a tool via MCP stdio and print JSON.

MCP Integration

  • Transport: stdio
  • Command (compiled): node dist/src/server.js
  • Command (dev): npm run dev
  • Tools:
    • searchpdf-mcp — input { query: string, limit?: number, source?: string, before?: number, after?: number, budget?: number, phraseBoost?: number, phraseOnly?: boolean }; returns text snippets with scores and added context from neighboring sections.

Config

  • PDF_PATH — Path to the PDF to index; defaults to data/AGLC4.pdf.
  • OCR_LANG — OCR language(s) for ocrmypdf (default eng), e.g. eng+fra.
  • OCR_FORCE=1 — Force OCR even if a text layer exists.
  • MCP_CMD — Override the server command used by list-tools/call-tool (e.g. "node dist/src/server.js").
  • before/after/budget — Optional context tuning parameters for previews.

config.json

You can configure source and index directories and auto-index behavior via a config.json at the repo root:

{
  "pdfDir": "data",          // directory containing source PDFs
  "indexDir": "data/index",  // directory to store built indexes
  "autoIndex": true,          // scan + build missing/stale indexes on startup
  "watch": true               // watch pdfDir for changes and auto-index
}

Environment variables override these values: PDF_DIR, INDEX_DIR, AUTO_INDEX, WATCH_INDEX.

Multiple PDFs

  • Index per PDF: npm run index -- --pdf path/to/SomeDoc.pdf writes to <indexDir>/SomeDoc/index.json (and updates the legacy <indexDir>/index.json).
  • Tool selection: pass source in searchpdf-mcp args (name, basename, or path). Examples:
    • { "source": "data/AGLC4.pdf", "query": "neutral citation" }
    • { "source": "AGLC4", "query": "ibid" }

Auto-indexing

  • On startup, the server scans pdfDir for *.pdf and builds indexes for any new or changed files (via content hash).
  • If watch is true, the server watches pdfDir and automatically reindexes PDFs when they are added or updated.

Claude Desktop Example

Add to your Claude Desktop config (merge keys accordingly):

{
  "mcpServers": {
    "aglc4": {
      "command": "node",
  "args": ["dist/src/server.js"],
      "env": {}
    }
  }
}

For Docker:

{
  "mcpServers": {
    "aglc4": {
      "command": "docker",
      "args": [
        "run", "-i", "--rm",
        "-v", "${HOME}/aglc4-data:/app/data",
        "pdfsearch-mcp"
      ]
    }
  }
}

Ensure ${HOME}/aglc4-data/AGLC4.pdf exists and that you’ve run indexing (or let the server/client invoke indexing step before use).

Notes

  • Indexing happens locally; only the canonical PDF is stored in data/.
  • If you update the PDF, re-run npm run index.
  • For client configuration, point tools to execute npm start (or the Docker image) as an MCP server.
  • On startup, the server logs an index summary and warns if the index appears stale (PDF changed). Re-run indexing if prompted.

Agent Usage

  • See docs/agent-usage.md for comprehensive MCP integration details, example requests, and tuning options.

Changelog

  • 0.2.0
    • Rename project to pdfsearch-mcp and tool to searchpdf-mcp.
    • Richer search previews with surrounding context and page numbers.
    • Extract shared logic to src/lib/pdf.ts; add Vitest tests.
    • Reindexing flow now tags pages using pdf-parse pagerender.
  • 0.1.0
    • Initial release.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选