🚀 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 許可證。