terminal_kb

terminal_kb

Enables local agents to search and retrieve cited evidence from PDFs and Markdown notes, including page-specific passages and rendered page images.

Category
Visit Server

README

Terminal Knowledge Base

一个只面向终端的本地知识库,用于管理 PDF、Markdown 笔记和论文写作证据。它不依赖 Obsidian 或 Zotero,可以直接通过 CLI、脚本和 MCP agent 使用。

特性

  • SQLite FTS5 全文检索,支持中文和英文
  • PDF 按页解析,返回 citekey、页码和原文片段
  • Markdown 笔记递归导入,保留稳定 citekey
  • BibTeX 书目文件和研究草稿目录
  • JSON-RPC over stdio MCP server,可接入 Codex 等终端 agent
  • 可选 LanceDB + Sentence Transformers 向量索引
  • 所有索引和解析结果均为本地可重建文件

环境要求

  • Linux/macOS
  • Python 3.11+
  • pdftotextpdfinfopdftoppm(推荐安装 poppler

基础全文检索不需要额外 Python 依赖。推荐使用 Python 3.12 虚拟环境和 uv

uv python install 3.12
uv venv --python 3.12 .venv
uv pip install --python .venv/bin/python -e .

可选依赖:

# 向量检索(CPU 环境)
uv pip install --python .venv/bin/python lancedb sentence-transformers

# 更复杂的 PDF 版面、表格和公式解析
uv pip install --python .venv/bin/python docling

非N卡:

uv pip install --python .venv/bin/python \
  torch==2.6.0+cpu \
  --index-url https://download.pytorch.org/whl/cpu

快速开始

./kb init
./kb add ~/Books/paper.pdf --title "Paper title" --author "Doe, Jane" --year 2024
./kb add ~/notes/method.md --title "Method notes"
./kb index --all
./kb search "retrieval augmented generation" --limit 5

常用命令:

./kb status
./kb doctor
./kb show <citekey> --page 2
./kb passage --citekey <citekey> --page 2
./kb cite <citekey> --page 2
./kb page-image <citekey> 2 --dpi 150

论文引用格式为:[@citekey, p. 2]

导入现有目录

kb add 可以逐个添加文件。批量导入时可使用 shell:

find ~/Books/final -type f \( -iname '*.pdf' -o -iname '*.md' \) -print0 |
  while IFS= read -r -d '' file; do
    ./kb add "$file"
  done
./kb index --all --force

MCP agent 接入

serve-mcp 使用 stdin/stdout 传输 JSON-RPC,不需要额外 MCP SDK:

[mcp_servers.terminal_kb]
command = "/absolute/path/to/knowledge-base/kb"
args = ["--root", "/absolute/path/to/knowledge-base", "serve-mcp"]

提供的工具包括:

  • search_library:搜索 PDF 和 Markdown 证据
  • get_passage:取得带页码的精确片段
  • get_document:查看文档元数据和状态
  • get_page_image:渲染 PDF 页面核对公式、表格和图形
  • find_evidence:按论断寻找证据
  • index_status:查看索引状态

向量检索

向量索引是可选功能,在 .kb/config.toml 中启用:

enable_vectors = true
embedding_model = "BAAI/bge-small-zh-v1.5"

然后重建:

./kb index --all --force

首次运行会从 Hugging Face 下载模型。

验证

./kb doctor
.venv/bin/python -m unittest discover -s tests -v

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured