Mcp Pdf Reader — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited Mcp Pdf Reader (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
<div align="center">
🚀 基于 Model Context Protocol 的智能 PDF 处理服务器
功能强大 · 易于使用 · 智能识别
</div>
MCP PDF Reader 是一个专业的 PDF 文档处理工具,通过 Model Context Protocol (MCP) 为 AI 应用提供强大的 PDF 文本提取、搜索、OCR 识别等功能。它能够智能识别 PDF 类型,自动选择最佳处理策略,为用户提供高效便捷的文档处理体验。
npm install在你的 AI 客户端(如 Cursor)配置文件中添加:
{
"mcpServers": {
"pdf-reader": {
"command": "node",
"args": ["你的项目路径/mcp_pdf_reader/index.js"]
}
}
}如果需要使用 OCR 功能,有两种配置方式:
#### 方式一:环境变量配置(推荐)
设置环境变量:
# Windows
set BAIDU_OCR_API_KEY=你的API密钥
set BAIDU_OCR_SECRET_KEY=你的Secret密钥
# Linux/Mac
export BAIDU_OCR_API_KEY=你的API密钥
export BAIDU_OCR_SECRET_KEY=你的Secret密钥#### 方式二:配置文件配置
也可以直接在 Cursor 配置文件中配置:
{
"mcpServers": {
"pdf-reader": {
"command": "node",
"args": ["你的项目路径/mcp_pdf_reader/index.js"],
"env": {
"BAIDU_OCR_API_KEY": "你的API密钥",
"BAIDU_OCR_SECRET_KEY": "你的Secret密钥"
}
}
}
}重启 Cursor 或你的 MCP 客户端,即可开始使用!
| 功能 | 工具名称 | 说明 | 推荐指数 |
|---|---|---|---|
| 智能阅读 | read-pdf-smart | 自动识别文本/扫描型 PDF,选择最佳策略 | ⭐⭐⭐⭐⭐ |
| 文本提取 | read-pdf | 从文本型 PDF 提取内容,支持页码范围 | ⭐⭐⭐⭐ |
| 内容搜索 | search-pdf | 全文搜索,支持正则、大小写、全字匹配 | ⭐⭐⭐⭐ |
| 元数据提取 | pdf-metadata | 获取 PDF 文件的完整元数据信息 | ⭐⭐⭐ |
| OCR 识别 | ocr-pdf-legacy | 百度 OCR 识别(手动传递密钥) | ⭐⭐⭐ |
| 自动 OCR | ocr-pdf-auto-legacy | 百度 OCR 识别(自动读取环境变量) | ⭐⭐⭐⭐ |
{
"@modelcontextprotocol/sdk": "^1.12.1", // MCP 协议框架
"axios": "^1.12.2", // HTTP 请求库
"pdf-parse": "^1.1.1", // PDF 文本解析
"pdf-to-png-converter": "^3.10.0", // PDF 转图片工具
"pdf-lib": "^1.17.1", // PDF 文档操作库
"zod": "^3.25.61" // 参数验证库
}最智能的 PDF 阅读工具,适合 99% 的使用场景。
#### 参数说明
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
file | string | 必填 | PDF 文件的完整路径 |
pages | string | 'all' | 页码范围(支持 'first', 'last', 'all', '1-5', '1,3,5') |
language_type | enum | 'CHN_ENG' | OCR 语言类型(需要时使用) |
#### 使用示例
// 示例 1: 读取整个 PDF(自动选择最佳方式)
{
"file": "D:\\Documents\\report.pdf"
}
// 示例 2: 只读取前 3 页
{
"file": "D:\\Documents\\report.pdf",
"pages": "1-3"
}
// 示例 3: 只读取第一页和最后一页
{
"file": "D:\\Documents\\book.pdf",
"pages": "first"
}基础文本提取工具,适用于文本型 PDF。
#### 参数说明
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
file | string | 必填 | PDF 文件路径 |
pages | string | 'all' | 页码范围(如 '1-5', '1,3,5', 'all') |
include_metadata | boolean | true | 是否包含 PDF 元数据 |
clean_text | boolean | false | 是否清理和规范化文本 |
#### 使用示例
// 基本提取
{
"file": "D:\\Documents\\report.pdf"
}
// 仅提取第 5-10 页,清理文本,不包含元数据
{
"file": "D:\\Documents\\report.pdf",
"pages": "5-10",
"clean_text": true,
"include_metadata": false
}PDF 全文搜索工具,支持高级搜索选项。
#### 参数说明
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
file | string | 必填 | PDF 文件路径 |
query | string | 必填 | 要搜索的文本 |
case_sensitive | boolean | false | 是否区分大小写 |
whole_word | boolean | false | 是否全字匹配 |
#### 使用示例
// 不区分大小写的搜索
{
"file": "D:\\Documents\\manual.pdf",
"query": "API"
}
// 全字匹配 + 区分大小写
{
"file": "D:\\Documents\\code.pdf",
"query": "const",
"case_sensitive": true,
"whole_word": true
}元数据提取工具,获取 PDF 文件信息(不读取文本内容)。
#### 提取的元数据
#### 使用示例
{
"file": "D:\\Documents\\thesis.pdf"
}#### ocr-pdf-auto-legacy(推荐)
自动 OCR 识别工具(从环境变量读取密钥,更方便)。
##### 参数说明
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
file | string | 必填 | PDF 文件路径 |
pages | string | 'first' | 页码范围(支持 'first', 'last', 'all', '1-5', '1,3,5') |
language_type | enum | 'CHN_ENG' | 语言类型 |
detect_direction | boolean | false | 是否检测方向 |
detect_language | boolean | false | 是否检测语言 |
##### 支持的语言类型
CHN_ENG - 中英文混合(默认)ENG - 英文JAP - 日文KOR - 韩文FRE - 法文SPA - 西班牙文POR - 葡萄牙文GER - 德文ITA - 意大利文RUS - 俄文##### 使用示例
// 识别第一页(默认)
{
"file": "D:\\Documents\\invoice.pdf"
}
// 识别所有页面(最多 10 页)
{
"file": "D:\\Documents\\contract.pdf",
"pages": "all",
"detect_direction": true,
"detect_language": true
}
// 只识别最后一页
{
"file": "D:\\Documents\\report.pdf",
"pages": "last"
}#### 1. 克隆或下载项目
git clone https://github.com/your-repo/mcp-pdf-reader.git
cd mcp-pdf-reader#### 2. 安装依赖
npm install#### 3. 配置 Cursor(或其他 MCP 客户端)
编辑 Cursor 配置文件,添加 MCP 服务器配置:
{
"mcpServers": {
"pdf-reader": {
"command": "node",
"args": ["你的完整项目路径/mcp_pdf_reader/index.js"]
}
}
}#### 4. (可选)配置百度 OCR
获取百度 OCR API 密钥:
API Key 和 Secret Key配置环境变量:
方式 1:永久配置(推荐)
Windows 系统设置:
BAIDU_OCR_API_KEY = 你的 API KeyBAIDU_OCR_SECRET_KEY = 你的 Secret Key方式 2:临时配置
# Windows CMD
set BAIDU_OCR_API_KEY=your_api_key
set BAIDU_OCR_SECRET_KEY=your_secret_key
# Windows PowerShell
$env:BAIDU_OCR_API_KEY="your_api_key"
$env:BAIDU_OCR_SECRET_KEY="your_secret_key"
# Linux/Mac
export BAIDU_OCR_API_KEY=your_api_key
export BAIDU_OCR_SECRET_KEY=your_secret_key#### 5. 重启客户端
重启 Cursor 或你的 MCP 客户端以加载配置。
@modelcontextprotocol/sdk 实现pdf-parse 和 pdf-lib 进行文本提取默认最大文件大小:50MB
修改限制(在 index.js 中):
if (stats.size > 50 * 1024 * 1024) { // 修改这里的数值
throw new Error(`文件过大: ${(stats.size / 1024 / 1024).toFixed(2)}MB。最大支持 50MB。`);
}默认最多处理:10 页
修改限制(在 index.js 中):
if (pageNumbers.length > 10) { // 修改这里的数值
pageNumbers = pageNumbers.slice(0, 10);
}可以调整质量判断规则(在 index.js 中):
// 每页最少字符数
if (text.length < 50 * pageCount) return 'poor';
// 字母数字占比最低要求
if (ratio < 0.3) return 'poor';┌─────────────────────────────────────────────────────────────┐
│ 你的需求是什么? │
└─────────────────┬───────────────────────────────────────────┘
│
┌─────────────┼─────────────┐
│ │ │
读取 PDF 搜索内容 查看信息
│ │ │
▼ ▼ ▼
┌─────────┐ ┌─────────┐ ┌──────────┐
│不确定类型│ │ 文本搜索 │ │ 元数据 │
│ │ └─────────┘ └──────────┘
│ │ │ │
│ │ ▼ ▼
│ │ search-pdf pdf-metadata
│ │
│ ┌────┴────┐
│ │ │
│ 文本型 扫描型
│ │ │
│ ▼ ▼
│ read-pdf ocr-pdf-auto
│
└────▼────────────────┐
read-pdf-smart │ ⭐ 推荐!自动识别
(智能选择) │
────────────────────────┘#### 1. 优先使用 read-pdf-smart
// ✅ 推荐:让工具自动判断
{
"file": "unknown-document.pdf"
}#### 2. 处理大文件时指定页码范围
// ✅ 推荐:只处理需要的页面
{
"file": "large-book.pdf",
"pages": "1-10" // 只读前 10 页
}#### 3. OCR 识别时使用正确的语言类型
// ✅ 推荐:指定正确的语言
{
"file": "japanese-doc.pdf",
"language_type": "JAP" // 日文文档
}#### 4. 搜索时使用合适的选项
// ✅ 推荐:搜索代码关键字时使用全字匹配
{
"file": "code-documentation.pdf",
"query": "const",
"whole_word": true // 避免匹配到 "constant"
}// 在 index.js 中添加
server.tool(
"your-new-tool",
{
param1: z.string().describe("参数说明"),
param2: z.number().optional()
},
async ({ param1, param2 }) => {
try {
// 你的处理逻辑
return {
content: [{
type: "text",
text: "处理结果"
}]
};
} catch (error) {
return {
content: [{
type: "text",
text: `错误: ${error.message}`
}]
};
}
}
);由于 MCP 协议的限制,不能直接使用 console.log。建议:
// 写入日志文件
import fs from 'fs';
fs.appendFileSync('debug.log', `[${new Date().toISOString()}] ${message}\n`);我们欢迎所有形式的贡献!
本项目采用 MIT 许可证。详见 LICENSE 文件。
<div align="center">
如果这个项目对你有帮助,请给个 ⭐ Star 支持一下!
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.