
mdgraph
io.github.daoGEE/mdgraph
MDGraph 帮 AI 编程助手读项目文档。它把本地 Markdown 文档的相关章节和文档引用的代码文件连起来。查一个功能时,助手能找到当初的设计说明,再顺着说明找到对应的代码。
Documentation
MDGraph
Find the project documentation your coding agent needs.
MDGraph indexes project Markdown into a local graph and gives coding agents relevant source sections, document relationships, and reasons for each result.
A coding task may depend on an architecture decision, an API specification, and an operational note in different files. MDGraph combines keyword and entity matches with graph expansion, then packs relevant original sections within a character budget. Each result retains its document location and selection reason so the agent can cite it or continue reading.
Use it to gather documentation before a task, find documents that reference a source path, or follow relationships between decisions and designs. The core pipeline runs locally and needs no LLM or embedding service. MDGraph returns documentation evidence; your coding agent uses that evidence to reason about the task.
A Real Cross-Document Query
Suppose MCP file watching reports ENOSPC. The agent needs both the recovery rules and the server setup that uses that watcher.
flowchart LR
query["Query<br/>ENOSPC"]
operations["Operations<br/>Direct match<br/>Watch failure recovery"]
directory["Documentation index<br/>Use MDGraph"]
integration["Agent Integration<br/>Related result<br/>MCP server startup"]
query ==>|Keyword match| operations
directory -->|Markdown link| operations
directory -.->|Markdown link / graph expansion| integration
classDef neutral fill:#f8fafc,stroke:#64748b,color:#334155;
classDef direct fill:#eff6ff,stroke:#2563eb,color:#1e3a8a,stroke-width:2px;
classDef related fill:#fffbeb,stroke:#b45309,color:#78350f,stroke-width:2px;
class query,directory neutral;
class operations direct;
class integration related;
linkStyle 0 stroke:#2563eb,stroke-width:3px;
linkStyle 1 stroke:#64748b,stroke-width:1.5px;
linkStyle 2 stroke:#b45309,stroke-width:2px;
Blue marks the direct text match; orange and the dashed line mark the result found through document relationships. The document arrows preserve the actual links from the documentation index. Retrieval follows the Operations link backwards to the index, then forwards to Agent Integration.
The following excerpts come from an actual CLI run over this repository's docs/EN documents with embeddings disabled. Other results and intervening lines are omitted with [...]; paths, reasons, and source text are retained.
$ mdgraph context "ENOSPC"
## 1. docs/EN/Operations.md:32
Reason: FTS5 content match; RRF fusion (fts#1)
[...]
Startup registration errors are fatal. A later successful index can recover an indexing failure. Runtime watch errors such as `ENOSPC` or `EMFILE` set `coverageReliable: false`; a successful manual or triggered index does not prove missed native events are recovered, so health remains degraded until restart.
[...]
## 4. docs/EN/Agent_Integration.md:9
Reason: graph expansion via Operations <--LINKS_TO/markdown_link/0.9-- Use MDGraph | Use MDGraph --LINKS_TO/markdown_link/0.9--> MDGraph Agent Integration
[...]
For active documentation editing sessions, use `serve --mcp`; the same MCP process keeps the local graph fresh by default.
Operations supplies the error-handling rules. Agent Integration is reached through maintained Markdown links in the documentation index, even though that section does not mention ENOSPC. The result exposes that path, so the agent can distinguish a text match from related context. Your project's results depend on its indexed documents and relationships.
Quick Start
You need a local project with Markdown files and Node.js >=22.5.0 whose built-in node:sqlite supports FTS5. If MDGraph reports that FTS5 is unavailable, use an up-to-date Node 22 or newer build and retry. See Operations for runtime troubleshooting. A node:sqlite experimental warning is informational when the command exits successfully.
1. Install the CLI
npm install -g @daogee/mdgraph
mdgraph --version
2. Index your project
Replace /absolute/path/to/project with your project directory. Keep paths quoted if they contain spaces.
mdgraph init --path "/absolute/path/to/project"
init creates .mdgraph/config.json, adds rules to .gitignore for generated graph artifacts, and builds the first SQLite index. The configuration can be committed with your project; the graph stays in .mdgraph/graph.db locally.
The default scans project .md files, including root-level README files, while respecting .gitignore and built-in exclusions. Existing configuration is preserved. To change the scan scope, edit docs.include / docs.exclude in .mdgraph/config.json, then run mdgraph index --path "/absolute/path/to/project". See Operations for configuration and indexing details.
3. Confirm the index is ready
mdgraph status --freshness --path "/absolute/path/to/project"
Check that the document count is greater than zero and freshness is fresh. If the count is zero, check docs.include, docs.exclude, and .gitignore against the Markdown paths you intended to index, adjust those rules, and run mdgraph index again with the same --path. If the index is stale, run that indexing command before querying again.
4. Retrieve your first context
Choose a heading or entity that appears in one of your Markdown files and replace the search text below. Then replace the context question with a real task about your project.
mdgraph search --path "/absolute/path/to/project" "a heading or entity from your docs"
mdgraph context --path "/absolute/path/to/project" "your task or documentation question"
search returns ranked locations and matching reasons. context returns original sections with paths, line numbers, and selection reasons, including relationship paths when graph expansion is used. If the search finds nothing, try a distinctive term copied from an indexed document and check the scan scope from step 3.
For later Markdown edits, run mdgraph index with the same --path to refresh the graph. The MCP setup below watches for changes automatically.
Connect Your Coding Agent
1. Register the MCP server
Add a stdio server to your host's MCP settings using mdgraph as the command and serve --mcp --path /absolute/path/to/project as its arguments. Clients that use a JSON mcpServers configuration can use this template:
{
"mcpServers": {
"mdgraph": {
"type": "stdio",
"command": "mdgraph",
"args": ["serve", "--mcp", "--path", "/absolute/path/to/project"]
}
}
}
Use your host's native configuration format where it differs. Host setup notes cover Claude Code, Cursor, Copilot Chat, Codex CLI, and generic MCP clients. If the host cannot find mdgraph, replace the command with its absolute executable path from which mdgraph on macOS/Linux or where mdgraph on Windows.
2. Enable the server and check the tools
Enable or reload the server in your host. serve --mcp indexes on startup and watches Markdown changes by default. Confirm that the host lists these five tools:
| MCP tool | CLI equivalent | Use it to |
|---|---|---|
mdgraph_status | status | Check index availability, freshness, and integrated watcher health |
mdgraph_context | context | Gather relevant original sections within a character budget |
mdgraph_search | search | Find a document, heading, entity, command, or error |
mdgraph_node | node | Inspect a known document, section, entity, or source reference |
mdgraph_trace | trace | Follow graph paths with relationship kinds, provenance, and confidence |
3. Verify an agent query
Ask your agent:
Check this project's index with mdgraph_status. Then use mdgraph_context
for [describe an actual task in this project]. Cite the document paths
and sections supporting your answer.
Replace the bracketed task. Confirm that the agent makes those tool calls and receives results from your project. To keep this workflow in project instructions or rules, use the shared instruction template. If tools are missing or a call fails, follow Agent Integration for diagnosis.
Advanced Features and Documentation
The workflow above uses the default local index. Additional capabilities have separate guides:
| What you want to do | Guide |
|---|---|
| Understand retrieval, CJK matching, optional Ollama embeddings, or MMR context packing | Retrieval and Context |
| Configure indexing, inspect watcher health, enable polling, or recover from failures | Operations |
Inspect broken links, source references, and documentation health with doctor | Doctor Output |
| Run structured governance queries or derive semantic related-document edges (experimental) | Structured Query and Relationships |
| Inspect Knowledge Cards or plan and maintain a Wiki (experimental) | Knowledge Cards and Wiki Workflow |
| Integrate with CLI/MCP JSON output | Output Contracts |
| Understand the pipeline, modules, and graph records | Architecture |
Start at the documentation index for the full guide map. Use mdgraph help, mdgraph help <command>, or mdgraph usage for command and workflow guidance. Reusable MCP configuration and prompts are in agent-pack.
Verification and Compatibility
Repository fixtures cover retrieval across decisions, designs, APIs, runbooks, incidents, source references, superseded documents, and CJK text. These checks verify recorded retrieval and interface behavior; they do not establish real-agent productivity gains. See Evaluation Questions for the method and evidence limits.
Public Contracts documents stable and experimental interfaces, including the 1.0 compatibility baseline. Maintainers use the Release Checklist for release validation.
Development and Community
From a source checkout:
npm install
npm run docs:check
npm run typecheck
npm test
npm run build
Read CONTRIBUTING.md for development and smoke checks. Report bugs or focused feature requests through GitHub Issues, and follow SECURITY.md for security reports. Examples of workflows that worked in your project are welcome.
License
@daogee/mdgraphnpm install @daogee/mdgraph