io.github.joesaby/doctree-mcp

编码与调试

by joesaby

BM25 search + tree navigation over markdown docs for AI agents. No embeddings, no LLM calls.

什么是 io.github.joesaby/doctree-mcp

BM25 search + tree navigation over markdown docs for AI agents. No embeddings, no LLM calls.

README

doctree-mcp

Agentic document retrieval over markdown, CSV, and JSONL. BM25 + tree navigation via MCP — no vector DB, no embeddings, no LLM calls at index time.

The pitch: MCP provides the structural primitives (a navigable tree, BM25, glossary, row lookup). The bundled skills provide the procedural knowledge (how to walk that tree). Together the agent behaves like a trained research librarian — not a one-shot searcher. See The Skill + MCP Pattern.


Quick Start

Have docs already? Point a client at them:

bash
# In your AI tool's MCP config — see docs/CLIENTS.md for per-tool snippets
{ "mcpServers": { "doctree": {
    "command": "bunx", "args": ["doctree-mcp"],
    "env": { "DOCS_ROOT": "./docs", "WIKI_WRITE": "1" }
} } }

Restart the tool → ask "search the docs for X" or invoke the doc-read prompt.

Starting fresh? Scaffold a Karpathy-style LLM wiki:

bash
bunx doctree-mcp init          # configure current tool
bunx doctree-mcp init --all    # configure every supported client
bunx doctree-mcp init --dry-run

Creates docs/wiki/ (LLM-maintained) + docs/raw-sources/ (your inputs), writes the MCP config, installs a post-write lint hook, appends wiki conventions to CLAUDE.md / AGENTS.md / .cursor/rules/.


Operation Modes

ModeUse whenGuide
stdio (default)Local dev, agent on your machineClient setup
HTTP (Streamable HTTP)Teams, CI, hosted agentsDeployment — Railway · Fly · Render · Cloudflare Containers · Docker
CLIinit, lint, debug-indexOperation modes

Full decision tree: Operation Modes.


How It Works — Retrieve · Curate · Add

code
Agent: "How does token refresh work?"

→ search_documents("token refresh")
  #1  auth/middleware.md § Token Refresh Flow       score: 12.4
  #2  auth/oauth.md       § Refresh Token Lifecycle  score: 8.7

→ get_tree("docs:auth:middleware")
  [n1] # Auth Middleware
    [n4] ## Token Refresh Flow
      [n5] ### Automatic Refresh

→ navigate_tree("docs:auth:middleware", "n4")   ← n4 + descendants

Core read tools (always on):

ToolPurpose
search_documentsBM25 keyword search + facet filters + glossary expansion (markdown · CSV · JSONL)
get_treeTable of contents — headings, word counts, summaries
get_node_contentFull text of a specific section by node ID
navigate_treeA section plus all descendants in one call
lookup_rowO(1) exact-key lookup for structured data rows (e.g. PROJ-44)

Wiki write tools (opt-in with WIKI_WRITE=1):

ToolPurpose
find_similarDuplicate detection with overlap ratios
draft_wiki_entryScaffold: suggested path, inferred frontmatter, glossary hits
write_wiki_entryValidated write: path containment, schema, duplicate guards, dry-run

Safety: path containment · frontmatter validation · duplicate detection · dry-run · overwrite protection.

Deprecated aliases (list_documents, find_files, find_symbol) are superseded by search_documents — still functional, no longer recommended.


The Skill + MCP Pattern

Most retrieval tools hand the agent a search box and hope for the best. doctree-mcp hands it a tree, and the bundled skills teach it how to walk one.

  • MCP = structural primitives. search_documents, get_tree, navigate_tree, get_node_content, lookup_row return tree positions the agent reasons over — not finished answers.
  • Skills = procedural knowledge. /doc-read, /doc-write, /doc-lint encode breadcrumb drill-down: search → outline → navigate → retrieve. The agent learns the policy, not just the API.

That pairing doesn't exist cleanly elsewhere:

ApproachPrimitiveSkill teachesGap
Managed hybrid RAG (Cloudflare AI Search, Nia)Flat chunks + similarityBlack-box score, no audit trail
Tool-returns-answer (Context7)2 tools returning answersQuery shapeAgent can't reason about skipped content
Skill-over-CLI (QMD)CLI over flat searchQuery expansionNo tree to navigate
doctree-mcp + /doc-readNavigable treeBreadcrumbs, multi-instance routing, wiki compilation

Why iterative retrieval wins:

  • Context rot. Stuffing a 1M-token window with chunks degrades output. Breadcrumb navigation keeps working memory small.
  • Auditability. search_documents → get_tree → navigate_tree → get_node_content is a replayable trail. A cosine score is not. Regulated domains can ship the former.
  • Progressive disclosure. Fewer navigable primitives beat tool sprawl (cf. Cloudflare Code Mode).

Multi-instance = client-side federation. Register several doctree servers under different names; the /doc-read skill encodes the routing policy. Add or remove instances without touching the skill. See Client setup → Multi-instance routing.


The LLM Wiki Pattern

code
┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│  Raw Sources    │     │  The Wiki        │     │  The Schema     │
│  (immutable)    │ ──→ │  (LLM-maintained)│ ←── │  (you define)   │
│  notes · logs   │     │  runbooks · refs │     │  CLAUDE.md rules │
└─────────────────┘     └─────────────────┘     └─────────────────┘

Inspired by Karpathy's LLM Wiki. Full walkthrough: docs/LLM-WIKI-GUIDE.md.


Configuration (summary)

yaml
---
title: "Descriptive Title"
description: "One-line summary — boosts ranking"
tags: [relevant, terms]
type: runbook          # runbook | guide | reference | tutorial | architecture | adr
category: auth
---

All non-reserved frontmatter fields become filter facets:

code
search_documents("auth", filters: { type: "runbook", tags: ["production"] })

Common env vars:

VariableDefaultDescription
DOCS_ROOT./docsDocs folder
DOCS_GLOB**/*.mdComma-separated globs (**/*.md,**/*.csv,**/*.jsonl)
DOCS_ROOTSWeighted multi-collection (./wiki:1.0,./rfcs:0.5)
PORT3100HTTP mode port
WIKI_WRITE(unset)1 enables write tools
GLOSSARY_PATH$DOCS_ROOT/glossary.jsonQuery-expansion glossary

Full reference: docs/CONFIGURATION.md.

Glossary — place glossary.json in docs root for bidirectional query expansion:

json
{ "CLI": ["command line interface"], "K8s": ["kubernetes"] }

Acronym definitions like "TLS (Transport Layer Security)" are also auto-extracted.

Structured data — CSV/JSONL files become documents where each row is a tree node. Column roles (id, title, description, facets, URL) are auto-detected from headers. See docs/STRUCTURED-DATA.md.


Running from Source

bash
git clone https://github.com/joesaby/doctree-mcp.git
cd doctree-mcp && bun install

DOCS_ROOT=./docs bun run serve          # stdio
DOCS_ROOT=./docs bun run serve:http     # HTTP (port 3100)
DOCS_ROOT=./docs bun run index          # CLI: inspect indexed output
bun test

Performance

OperationTimeToken cost
Full index (900 docs)2–5s0
Incremental re-index~50ms0
Search5–30ms~300–1K tokens
Tree outline<1ms~200–800 tokens

Docs

Setup & operation

  • Operation Modes — stdio · HTTP · CLI
  • Client Setup — Claude Code · Cursor · Windsurf · Codex · OpenCode · Claude Desktop
  • Deployment — Railway · Fly.io · Render · Cloudflare Containers · Docker
  • Configuration — env vars, frontmatter, ranking tuning

Patterns & concepts

Source


Standing on Shoulders

License

MIT

常见问题

io.github.joesaby/doctree-mcp 是什么?

BM25 search + tree navigation over markdown docs for AI agents. No embeddings, no LLM calls.

相关 Skills

前端设计

by anthropics

Universal
热门

面向组件、页面、海报和 Web 应用开发,按鲜明视觉方向生成可直接落地的前端代码与高质感 UI,适合做 landing page、Dashboard 或美化现有界面,避开千篇一律的 AI 审美。

想把页面做得既能上线又有设计感,就用前端设计:组件到整站都能产出,难得的是能避开千篇一律的 AI 味。

编码与调试
未扫描165.3k

网页应用测试

by anthropics

Universal
热门

用 Playwright 为本地 Web 应用编写自动化测试,支持启动开发服务器、校验前端交互、排查 UI 异常、抓取截图与浏览器日志,适合调试动态页面和回归验证。

借助 Playwright 一站式验证本地 Web 应用前端功能,调 UI 时还能同步查看日志和截图,定位问题更快。

编码与调试
未扫描165.3k

网页构建器

by anthropics

Universal
热门

面向复杂 claude.ai HTML artifact 开发,快速初始化 React + Tailwind CSS + shadcn/ui 项目并打包为单文件 HTML,适合需要状态管理、路由或多组件交互的页面。

在 claude.ai 里做复杂网页 Artifact 很省心,多组件、状态和路由都能顺手搭起来,React、Tailwind 与 shadcn/ui 组合效率高、成品也更精致。

编码与调试
未扫描165.3k

相关 MCP Server

GitHub

编辑精选

by GitHub

热门

GitHub 是 MCP 官方参考服务器,让 Claude 直接读写你的代码仓库和 Issues。

这个参考服务器解决了开发者想让 AI 安全访问 GitHub 数据的问题,适合需要自动化代码审查或 Issue 管理的团队。但注意它只是参考实现,生产环境得自己加固安全。

编码与调试
89.1k

by Context7

热门

Context7 是实时拉取最新文档和代码示例的智能助手,让你告别过时资料。

它能解决开发者查找文档时信息滞后的问题,特别适合快速上手新库或跟进更新。不过,依赖外部源可能导致偶尔的数据延迟,建议结合官方文档使用。

编码与调试
60.0k

by tldraw

热门

tldraw 是让 AI 助手直接在无限画布上绘图和协作的 MCP 服务器。

这解决了 AI 只能输出文本、无法视觉化协作的痛点——想象让 Claude 帮你画流程图或白板讨论。最适合需要快速原型设计或头脑风暴的开发者。不过,目前它只是个基础连接器,你得自己搭建画布应用才能发挥全部潜力。

编码与调试
49.5k

评论