Skip to main content
Glama

kb — the fetch-once knowledge base for AI agents

Tests License: MIT 中文文档

Check before fetching. Save after fetching. Never re-fetch. Never fabricate.

AI agents repeatedly download the same documents, forget what they learned, and invent dates or authors when asked to save notes. kb adds a local discipline layer that makes the desired loop explicit:

question → search the library → hit: read and answer
                         └── miss: fetch externally → save → answer

kb fetch-once loop

Why kb?

Problem

Typical knowledge base

kb

Check before an external fetch

Prompt convention

kb_search / kb_exists make it explicit

Duplicate documents

Often stored twice

Three-layer dedup with merge-on-conflict

Missing source metadata

Agent may guess

Blank stays blank; metadata is verbatim

Scanned PDFs

Easy to treat as readable

Marked ocr_required, never silently faked

Chinese search

Often needs embeddings

SQLite FTS5 trigram + short-query fallback

Infrastructure

API keys and vector DBs

One local SQLite file

No embeddings. No API keys. No vector database. Just Python, SQLite, six MCP tools, a CLI, and a localhost web console.

Related MCP server: Open Brain Knowledge MCP Server

30-second quick start

git clone https://github.com/zonion088-design/kb.git
cd kb
python -m venv .venv
# macOS/Linux: source .venv/bin/activate
# Windows:    .venv\\Scripts\\Activate.ps1
pip install -r requirements.txt

python kb.py init
python examples/seed_demo.py
python kb.py search "储能系统"

The demo data is clearly fictional and safe to delete. Re-running the seed script demonstrates duplicate detection instead of creating second copies.

Connect it to an agent

Claude Code:

claude mcp add kb -- python /absolute/path/to/kb/mcp_kb_server.py

Claude Desktop (claude_desktop_config.json):

{
  "mcpServers": {
    "kb": {
      "command": "python",
      "args": ["/absolute/path/to/kb/mcp_kb_server.py"]
    }
  }
}

Then load the operating rules into your agent instructions:

@/absolute/path/to/kb/KB_RULES.md

The six MCP tools

Tool

Result

kb_search

Search documents with compact snippets and metadata filters

kb_exists

Check whether a source document is already present

kb_get_doc

Read the full document with truncation and OCR warnings

kb_save_report

Save fetched research text and source metadata

kb_save_file

Archive a local file and extract supported PDFs

kb_stats

Inspect totals, document types, and OCR backlog

The write path deduplicates by source external_id, file SHA-256, and a title/date suspected-duplicate check. Existing records are merged by filling empty fields; existing values are not overwritten.

Try the web console and CLI

python server.py          # http://127.0.0.1:8643
python kb.py --help       # init / add-text / add-file / search / get / stats / ...

The localhost console gives humans editing and deletion controls while the MCP tools keep agents on the append-and-search path.

Honest limitations

  • Keyword search, not semantic search: this is intentional and keeps the default local and dependency-light.

  • OCR is detected and flagged; OCR processing is not included.

  • Single user, one machine; no auth, sync, or multi-tenant server.

  • PDF extraction quality depends on pypdf and the source file.

Development

python -m unittest discover -s tests -v

See CONTRIBUTING.md for focused contributions and KB_RULES.md for the design contract. The roadmap lives in docs/ROADMAP.md.

License

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables LLMs to manage file-based knowledge bases with dual storage (Markdown + SQLite). Supports creating, searching, and organizing articles across multiple knowledge bases with full-text search capabilities.
    4 npm
    3
    MIT
  • F
    license
    A
    quality
    D
    maintenance
    A persistent, cross-session knowledge base for AI agents that indexes session history into a searchable SQLite database with full-text search, enabling recall of past sessions, stored knowledge, and summaries.
    10
    -
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables AI agents to search, read, and traverse a local knowledge base of Markdown files using full-text search and relationship graph, reducing token usage.
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables AI agents to store, search, and manage persistent memories, todos, kanban boards, reminders, and progress trackers in a local SQLite database.
    Apache 2.0