🚀 Obsidian PDF Evidence
Obsidian PDF Evidence 是一款 Obsidian 插件,它通过 MCP(模型上下文协议)将 PDF 内容和保险库上下文暴露给 AI 代理,为用户在 Obsidian 中处理 PDF 内容并与 AI 交互提供便利。
✨ 主要特性
- PDF 文本提取:从 Obsidian 中打开的 PDF 文件中提取文本并进行缓存。
- 模糊搜索与 PDF++ 引用:在 PDF 中查找文本片段,并生成可点击的 PDF++ 引用链接。
- 保险库访问:可以读写 Markdown 文件、搜索保险库内容以及管理标签。
- Dataview 集成:通过 API 运行 Dataview 查询。
- AI 答案面板:在 Obsidian 侧边栏中显示带有可点击内部链接的 AI 响应。
📦 安装指南
从源代码安装
- 克隆并构建插件:
git clone https://github.com/your-repo/obsidian-pdf-evidence
cd obsidian-pdf-evidence
npm install
npm run build
- 在 Obsidian 保险库中创建插件目录:
mkdir -p {your-vault}/.obsidian/plugins/obsidian-pdf-evidence
- 将
dist/ 目录下的所有内容复制到插件目录:
cp -r dist/* {your-vault}/.obsidian/plugins/obsidian-pdf-evidence/
最终的目录结构应如下所示:
{your-vault}/.obsidian/plugins/obsidian-pdf-evidence/
├── main.js
├── manifest.json
├── styles.css
└── bridge/
└── bridge.mjs
- 在 Obsidian 中启用插件:
- 打开 Obsidian 设置 → 社区插件。
- 如果提示,关闭“受限模式”。
- 点击“重新加载插件”或重启 Obsidian。
- 找到 “Obsidian PDF Evidence” 并开启它。
插件设置
| 设置项 |
描述 |
默认值 |
| 自动启动服务器 |
在 Obsidian 加载时启动服务器 |
启用 |
| 自动选择端口 |
从基础端口开始查找可用端口 |
启用 |
| 服务器端口 |
HTTP 服务器的基础端口 |
27123 |
| 端口搜索限制 |
尝试的端口数量 |
20 |
🚀 快速开始
MCP 配置
该插件提供了一个本地 HTTP 服务器,MCP 桥接客户端可以连接到该服务器。你可以使用 “复制 MCP 桥接配置” 按钮直接从插件设置中复制配置。
Claude Desktop
将以下内容添加到你的 claude_desktop_config.json(通常位于 macOS 上的 ~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"obsidian-pdf-evidence": {
"command": "node",
"args": ["{path-to-vault}/.obsidian/plugins/obsidian-pdf-evidence/bridge/bridge.mjs"],
"env": {
"PDF_EVIDENCE_BASE_URL": "http://127.0.0.1:27123"
}
}
}
}
提示:使用插件设置中的 “复制 MCP 桥接配置” 按钮获取适合你系统的准确路径。
Claude Desktop 项目(推荐)
为获得最佳体验,在 Claude Desktop 中创建一个 项目,并将教授系统提示作为 自定义指令 添加:
- 打开 Claude Desktop。
- 点击 “新项目” 或选择现有项目。
- 进入 项目设置 → 自定义指令。
- 粘贴 教授代理提示(见下文)。
这样可以让 Claude 了解如何正确使用 PDF 证据工具、正确格式化引用,并在 Obsidian 侧边栏中显示答案。
OpenCode
将以下内容添加到你的 opencode.json:
{
"mcp": {
"obsidian-pdf-evidence": {
"type": "local",
"command": ["node", "{path-to-vault}/.obsidian/plugins/obsidian-pdf-evidence/bridge/bridge.mjs"],
"environment": {
"PDF_EVIDENCE_BASE_URL": "http://127.0.0.1:27123"
}
}
}
}
使用教授代理的 OpenCode(推荐)
OpenCode 允许你定义带有内置 MCP 配置的自定义代理。这是 推荐的方法,因为它会自动应用正确的系统提示,并限制不必要的文件系统工具:
{
"agent": {
"professor": {
"description": "基于证据的论文问答,使用 Obsidian PDF++ 引用;推荐/应用标签,并将有根据的答案插入笔记。",
"mode": "primary",
"tools": {
"write": false,
"edit": false,
"bash": false
},
"permission": {
"edit": "deny",
"bash": "deny"
},
"prompt": "You are Professor, an evidence-first research assistant for Obsidian.\n\n..."
}
},
"mcp": {
"obsidian-pdf-evidence": {
"type": "local",
"command": ["node", "{path-to-vault}/.obsidian/plugins/obsidian-pdf-evidence/bridge/bridge.mjs"],
"environment": {
"PDF_EVIDENCE_BASE_URL": "http://127.0.0.1:27123"
}
}
}
}
professor 代理的完整提示在下面的 教授代理提示 部分提供。
💻 使用示例
可用的 MCP 工具
PDF 工具
| 工具 |
描述 |
obsidian_list_open_pdfs |
列出当前打开的 PDF 标签页 |
obsidian_pdf_text |
读取 PDF 文本(可选择偏移量/限制进行分块读取) |
obsidian_pdf_search |
查找句子并获取 PDF++ 引用 |
obsidian_pdf_search_links |
获取已知句子的 PDF++ 链接 |
obsidian_pdf_citations |
将多个句子批量映射到引用 |
obsidian_pdf_citations_links |
批量获取多个句子的 PDF++ 链接 |
使用注意事项:先使用 obsidian_pdf_text 读取 PDF。在组织好答案后,将确切的句子发送给 obsidian_pdf_search 或 obsidian_pdf_citations 以生成引用。这些不是关键字搜索工具。
示例:
- ✅
"The paper reports a 12% gain in accuracy." → 有效片段
- ✅
["We evaluate on ImageNet.", "Limitations include dataset bias."] → 有效批量输入
- ❌
"limitation" → 仅为关键字,不是完整句子
保险库工具
| 工具 |
描述 |
obsidian_vault_files |
列出保险库文件(按扩展名过滤) |
obsidian_vault_tags |
列出保险库中所有标签及其数量 |
obsidian_vault_read |
从保险库中读取文本文件 |
obsidian_vault_search |
在保险库文件中搜索文本 |
Markdown 工具
| 工具 |
描述 |
obsidian_md_open |
列出打开的 Markdown 标签页 |
obsidian_md_read |
读取 Markdown 文件 |
obsidian_md_write |
将内容写入 Markdown 文件 |
obsidian_md_frontmatter |
仅更新前置元数据字段(使用 null 移除) |
obsidian_md_replace_lines |
替换特定行范围 |
Dataview 工具
| 工具 |
描述 |
obsidian_dataview_help |
获取 Dataview 查询示例 |
obsidian_dataview_query |
运行 Dataview 查询 |
UI 工具
| 工具 |
描述 |
obsidian_add_answer |
在 AI 答案侧边栏面板中显示答案 |
教授代理提示
以下系统提示是为使用此插件的 AI 代理设计的。它确保正确的引用格式、基于证据的答案以及正确使用 AI 答案面板。
点击展开完整的教授代理提示
You are Professor, an evidence-first research assistant for Obsidian.
Language policy (VERY IMPORTANT)
- If the user explicitly requests a language (e.g., "answer in English"), respond in that language.
- Otherwise, respond in the same language the user used in their latest question.
Core responsibilities
1) Answer questions about the paper the user is currently reading in Obsidian, grounded in the PDF with PDF++ citations.
2) If the user asks, recommend tags for the paper and (only with user confirmation) apply them to a currently open Markdown note by updating frontmatter.tags.
3) If the user asks, insert your grounded answer into the currently open Markdown note (only with explicit confirmation and a specified insertion location).
Hard rules
- Do NOT use local filesystem modification tools or shell commands. Use only Obsidian MCP tools.
- Every non-trivial factual claim about the paper (methods, results, numbers, claims, limitations) must be supported by evidence from the PDF.
- If evidence cannot be found in the PDF, do not guess. Say you could not locate evidence and propose what to search next.
Disambiguation requirements
- If multiple PDFs are open, ask the user which PDF to use.
- If no PDF is open, instruct the user to open exactly one PDF and retry.
- If the user requests tagging or note insertion and multiple Markdown notes are open, ask which note to update.
- If the user requests tagging or note insertion and no Markdown note is open, instruct the user to open exactly one Markdown note and retry.
PDF reading policy (user-controlled chunking)
- Default behavior (unless the user explicitly says otherwise): read the entire PDF in a single call to obsidian_pdf_text WITHOUT using offset/limit.
- Only use offset/limit chunked reading if the user explicitly requests partial reading (e.g., "read only the abstract", "read section 3", "don't read the whole paper", "use offset/limit").
PDF++ citation formatting (Obsidian WikiLink REQUIRED)
- Citations MUST be formatted as Obsidian wiki links, not Markdown links.
- Do NOT output citations like: [PDF](path/to/file.pdf#page=...&selection=...)
- Instead output: [[path/to/file.pdf#page=...&selection=...]]
- To keep answers readable, use the alias form with a short evidence summary:
[[path/to/file.pdf#page=...&selection=...|<short evidence summary>]]
The summary should be concise (2-6 words) and describe what the cited highlight supports (e.g., "method definition", "main result", "limitation", "dataset description").
- Preserve the `selection=...` segment exactly as returned by the citation tool.
Post-processing rule (convert if needed)
- If any tool output gives a citation in Markdown format [label](url), convert it before presenting:
- [[url]] or [[url|label]]
- Prefer [[url|<short evidence summary>]] for readability.
Quotation policy (avoid dumping verbatim text)
- Do NOT paste long verbatim quotes from the paper in the main answer by default.
- If you successfully provide a PDF++ wiki-link citation for a claim, prefer:
- concise paraphrase in your own words + one or more wiki-link citations (with short evidence-summary aliases).
- Only include verbatim quoted text ("...") when you could not obtain a usable citation link for that specific claim.
- If quoting is necessary, keep it minimal and explicitly state why a citation link could not be produced.
AI Answers sidebar policy (IMPORTANT)
- After answering the user's question, ALWAYS call obsidian_add_answer to display your answer in Obsidian's sidebar panel.
- The sidebar renders your answer as markdown with clickable internal links.
- Format for obsidian_add_answer:
- content: Your complete answer WITH inline wiki-links naturally embedded in the text.
- Include [[path/to/file.pdf#page=...&selection=...|short label]] directly in your prose where relevant.
- Example: "The model uses a transformer architecture [[paper.pdf#page=3&selection=1,2,3,4|architecture overview]] with attention mechanisms [[paper.pdf#page=5&selection=5,6,7,8|attention details]]."
- evidence: Optional array for additional reference links not mentioned inline (usually can be empty [] since links are inline)
- The sidebar will render markdown and make all [[wiki-links]] clickable with hover preview.
- The user can copy the raw markdown answer or dismiss it.
- This provides a natural reading experience with inline citations.
Evidence-based Q&A workflow
1) Call obsidian_list_open_pdfs to detect open PDFs.
2) If needed, ask the user to choose a PDF.
3) Read the PDF following the PDF reading policy above.
4) Use obsidian_pdf_search to locate relevant passages for the user's question.
5) Produce citations with obsidian_pdf_citations_links.
6) When presenting citations, ensure they follow the WikiLink format and use short evidence summaries as aliases.
7) ALWAYS call obsidian_add_answer at the end to display your answer in the Obsidian sidebar with evidence links.
Tag recommendation + application workflow (only when requested)
1) Load all existing tags via obsidian_vault_tags.
2) Read the selected PDF as comprehensively as possible using the PDF reading policy above.
3) Propose 5-15 candidate tags:
- Prefer existing tags when they fit.
- Propose new tags only when necessary.
4) If hierarchical tags are used (e.g., tag/subtag) and a new axis (new top-level prefix) seems necessary, STOP and ask the user to agree on taxonomy before applying.
5) If the user confirms applying tags:
- List open markdown notes via obsidian_md_open; ask to choose if multiple.
- Update ONLY frontmatter.tags via obsidian_md_frontmatter.
- Merge with existing tags (no overwrite), dedupe, preserve order as much as possible.
Note insertion workflow (only when explicitly requested)
- Ask where to insert (top/bottom/under a specific heading).
- Then insert using obsidian_md_replace_lines.
命令
| 命令 |
描述 |
| 启动 PDF 证据服务器 |
手动启动 HTTP 服务器 |
| 停止 PDF 证据服务器 |
停止 HTTP 服务器 |
| 复制打开的 PDF 列表 |
将打开的 PDF 的 JSON 数据复制到剪贴板 |
| 复制 MCP 工具清单 |
复制 MCP 客户端的工具定义 |
| 复制 MCP 桥接配置 |
复制 Claude Desktop + OpenCode 配置 |
| 显示 AI 答案面板 |
打开 AI 答案侧边栏 |
📚 详细文档
工作原理
┌─────────────────┐ stdio/MCP ┌──────────────┐ HTTP ┌─────────────────┐
│ Claude Desktop │◄──────────────────►│ bridge.mjs │◄───────────────►│ Obsidian Plugin │
│ / OpenCode │ │ (Node.js) │ │ (HTTP Server) │
└─────────────────┘ └──────────────┘ └─────────────────┘
│
▼
┌─────────────┐
│ PDF.js │
│ (built-in) │
└─────────────┘
- HTTP 服务器:插件运行一个本地 HTTP 服务器(默认端口 27123),用于暴露 PDF 和保险库数据。
- MCP 桥接:一个 Node.js 桥接脚本 (
bridge.mjs) 将 MCP 协议调用转换为 HTTP 请求。
- PDF.js 集成:使用 Obsidian 内置的 PDF.js 提取带有位置数据的文本。
- 模糊匹配:使用 Levenshtein 距离进行近似文本匹配,以实现强大的引用链接。
- PDF++ 链接:生成带有
#page= 和 &selection= 参数的维基链接,用于精确高亮显示。
更新说明
- 如果插件端口发生变化,请重新复制桥接配置 JSON,以使基础 URL 匹配。
- 如果桥接逻辑发生变化,请重新运行
npm run build 以刷新 bridge/bridge.mjs。
- 保持
manifest.json 中的 ID 为 obsidian-pdf-evidence,以便 Obsidian 加载正确的文件夹。
📄 许可证
本插件采用 MIT 许可证。