second-brain-mcp
<!-- mcp-name: io.github.ddmanyes/mcp-second-brain -->
# second-brain MCP Server
**A self-maintaining personal knowledge base for AI agents β a plain-Markdown vault, powered by MCP.**
[](https://github.com/ddmanyes/second-brain-mcp/actions/workflows/ci.yml)
[](https://www.python.org/)
[](LICENSE)
π English Β· [ηΉι«δΈζ](README.zh.md)
---
A local knowledge base your AI agent can read, write, and **maintain on its own**. Save a paper or note with one command β second-brain converts it to Markdown, OCRs every figure, embeds it for semantic search, and auto-links it to related notes. Notes you stop reading compress themselves over time, so recall stays cheap as the vault grows.
Everything is plain Markdown β sync via Google Drive / iCloud / git, switch agents anytime, **zero lock-in**.
## Highlights
- **One command saves anything** β `save_article(url_or_pdf)` fetches, converts to Markdown, OCRs figures (Claude Vision), embeds, and auto-links.
- **Figure-level search** β `search_figures("UMAP melanocyte")` returns the exact panel across your whole library.
- **Self-organizing** β new notes auto-link to related ones; frequently-read notes extract reusable rules.
- **Memory that forgets like a brain** β Ebbinghaus ranking; stale notes auto-compress (60β90% fewer tokens).
- **Read-only housekeeping audit** β inspect article metadata, links, exact duplicate candidates, inbox age, and source freshness without changing the vault.
- **Session continuity** β `get_context()` reloads goals + top notes + rules at the start of every session.
- **Pluggable backend** β DuckDB (default, offline) or Postgres + pgvector (central, multi-machine). Self-hosted embeddings optional; BM25 fallback when offline.
## Quick Start (Claude Code)
```bash
pip install mcp-second-brain
playwright install chromium
claude mcp add --scope user second-brain \
--env SECOND_BRAIN_PATH=~/second-brain \
-- python -m mcp_second_brain
```
The vault directory and templates are created on first run. Then tell your agent `init_vault` to verify.
> β οΈ PyPI currently lags the source tree. For the newest build β plus Claude Desktop, Windows, and multi-machine / central-server setups β see **[NEW_MACHINE_SETUP.md](NEW_MACHINE_SETUP.md)**.
## Core Tools
| Tool | What it does |
| :--- | :--- |
| `auth_context` | Read the authenticated caller's canonical UUID, role, and RBAC state |
| `get_context` | Session start β goals + top-ranked notes + auto-rules |
| `save_article` | URL / PDF β Markdown + figures + embeddings |
| `search_notes` / `search_figures` | Hybrid BM25 + semantic search (note text / figure content) |
| `search_articles` | Structured author, ORCID, DOI/PMID/PMCID and year search for papers |
| `audit_article_records` | Bounded, read-only article housekeeping and social-source freshness report |
| `new_note` / `update_note` / `append_to_note` | Create & edit notes (auto-filed, auto-indexed, auto-linked) |
| `vault_sleep` | Compress old, low-activity notes |
| `get_agent_instructions` | Serve the full filing SOP (AGENTS.md) to remote agents |
Full tool reference (46 tools) lives in **[AGENTS.md](AGENTS.md)**.
Use `search_notes` when you need content, `health_check` when the server or index may be
unhealthy, and `audit_article_records` when you need a housekeeping report. Audit results
never merge, archive, or delete notes automatically.
## How It Works
```text
Any source (paper Β· PDF Β· web Β· note)
β save_article Β· new_note
βΌ
Markdown vault βββΊ index (DuckDB, or Postgres + pgvector)
00-inbox/ β’ BM25 + semantic search
10-projects/ β’ figure OCR + vision descriptions
20-areas/ β’ auto-wikilinks between related notes
30-resources/ β’ Ebbinghaus ranking β weekly auto-compression
decisions/ memory/
β
βΌ
Your AI agent queries it β search_notes Β· search_figures Β· get_context
```
The **vault is the source of truth**; the index is rebuildable anytime (`sync_index`). Filing conventions live in one operating manual β [AGENTS.md](AGENTS.md) β served to any agent via `get_agent_instructions()`, so every agent files things the same way without being re-taught.
## Vault Structure
```text
vault/
βββ 00-inbox/ Unprocessed captures
βββ 10-projects/ Active projects
βββ 20-areas/ Ongoing research / coding domains
βββ 30-resources/ Papers & articles (save_article writes here)
βββ 40-archive/ Auto-compressed originals
βββ decisions/ Architecture Decision Records
βββ memory/ goals.md Β· rules.md (injected every session)
βββ templates/ Note templates
```
### Legacy author metadata
`search_articles` reads structured frontmatter, so older article notes without
`authors` are not guessed from body text or references. A bounded two-phase CLI can
prepare those notes safely: first create and review a manifest, then apply it separately.
```bash
python -m mcp_second_brain.author_backfill \
--vault "<vault>" --limit 20 --out /tmp/author-backfill.json
python -m mcp_second_brain.author_backfill \
--vault "<vault>" --apply --manifest /tmp/author-backfill.json
```
Apply on the central writer host only. Each entry requires an exact DOI/PMID/PMCID or
title match and unchanged content/body hashes; successful writes are reindexed.
## Documentation
- **[AGENTS.md](AGENTS.md)** β filing SOP, naming conventions, full tool reference (single source of truth)
- **[NEW_MACHINE_SETUP.md](NEW_MACHINE_SETUP.md)** β source install, self-hosting, multi-machine central server, API keys
- **[CONTEXT.md](CONTEXT.md)** β domain model / ubiquitous language
## Design Notes
Inspired by biological memory: the Ebbinghaus forgetting curve (`access_count / ln(age_days)`) for ranking, and sleep-dependent consolidation (weekly LLM compression of low-access notes). Built with [MarkItDown](https://github.com/microsoft/markitdown) Β· [DuckDB](https://duckdb.org) Β· [pgvector](https://github.com/pgvector/pgvector) Β· [FastMCP](https://github.com/jlowin/fastmcp) Β· [Playwright](https://playwright.dev) Β· [Claude API](https://docs.anthropic.com).
## License
MIT Β© 2026 Chan Chi Ru. See [LICENSE](LICENSE).
TDQS
Scored across 46 tools
Several search/retrieval tools overlap in purpose (search_notes, search_articles, search_snippets, search_news_tool, search_grouped, query_graph), and sync tools (sync_index, sync_notes, sync_chunks_tool) or write tools (update_note, append_to_note, new_note) can be confused without careful reading. The descriptions do clarify target and method, so boundaries exist but require effort.
Mostly snake_case, but patterns vary: verb_noun (search_notes), noun-first (auth_context, index_stats, vault_sleep, sleep_status, health_check), and an inconsistent _tool suffix on about nine tools. The naming is readable but not uniform.
46 tools is well above the typical 3β15 range and feels heavy even for a broad vault-management domain. Many tools could be consolidated or grouped without losing capability.
The surface covers note CRUD, search, indexing, article ingestion, figure management, graph queries, synthesis, admin, and health checks. Minor gaps exist (e.g., no explicit delete/rename/move note tool), but archival/pruning tools mitigate some of that.