
kg
io.github.nnar1o由 GitHub 帳號 nnar1o 發布v0.3.0更新於 Oct 27, 2026
Local knowledge graph memory MCP server for AI assistants.
概覽
本機知識圖譜記憶伺服器,讓 AI 助理擁有持久、可編輯的專案記憶,以圖譜檔案形式保存在本機。
- 可以做什麼
- 搜尋、依 ID 取得並列出圖譜中的節點、邊、類型、關係與圖譜,以及圖譜統計
- 建立、修改和刪除帶有型別 ID 與欄位的節點
- 在節點之間建立或刪除帶型別的關係
- 切換目前圖譜,執行簡短的動詞式指令,並對搜尋結果提供回饋
- 依專案文件建立或擴充圖譜,並把目錄樹索引成獨立的產生結構,包含程式碼符號與文件章節
- 適用情境
- 適合希望助理跨工作階段保留結構化專案知識(架構、決策、事故、規則、相依性與流程),而不必每次重新閱讀文件的場景;也適合需要讓這份記憶可檢視、可比對、可納入 Git 版本管理的團隊。
- 執行需求
- 以本機 stdio MCP 伺服器形式在使用者電腦上執行;README 透過 crates.io、安裝腳本或 GitHub Releases 安裝 kg-cli 執行檔,並在用戶端設定中填入 kg-mcp 執行檔路徑。圖譜預設存放在本機目錄,可透過 .kg.toml 專案檔設定。未宣告帳號、API 金鑰或環境變數。
安裝
README
kg - local knowledge graph for your AI assistants
[image]Beta - APIs may still change and some bugs are still expected.
kg gives your AI assistant persistent, structured, editable project memory stored locally as a knowledge graph.
Instead of relying only on document chunk retrieval, you can keep architecture, decisions, incidents, rules, dependencies, and workflows in a graph that is readable, reviewable, and Git-friendly.
Use it when you want your assistant to understand an existing project across sessions — not start from zero every time.
Why use it
- Persistent memory — keep project knowledge between conversations
- Structured, not fuzzy — inspect nodes, edges, facts, and gaps directly
- Editable and reviewable — store graphs as
*.kgfiles with readable diffs - Local-first — your project memory stays on your machine in git-friendly format
- Works with MCP clients — connect it as a local stdio MCP server
Why not just RAG
Classic RAG is good for retrieving text chunks from documents.
kg-mcp is better when you want:
- stable project memory instead of repeated retrieval
- explicit facts, relations, and dependencies
- graph updates during real work with the assistant
- something you can inspect, version, diff, and improve over time
Installation
From crates.io
From script
Recommended install:
You can also download a ready binary from GitHub Releases.
Connect kg-mcp to Your AI Client
Add kg-mcp as a local stdio MCP server.
Example config:
After that:
- restart your AI client,
- confirm the
kgMCP server is available, - start using the prompts below.
Full MCP setup and reference: docs/mcp.md
SCL quickstart
kg understands short, verb-first English commands (SCL — Simple Command Language).
The active graph is resolved from your config automatically.
Core verbs
IDs
Format: <type>:snake_case — e.g. concept:fridge, bug:door_seal, process:compressor_cycle.
Relations
HAS USES STORED_IN TRIGGERS CREATED_BY AFFECTED_BY AVAILABLE_IN DOCUMENTED_IN DEPENDS_ON TRANSITIONS DECIDED_BY GOVERNED_BY READS_FROM
Tips
- Flags go after positional args. Quote multiword values.
- Separate commands with
;or newlines. Lines starting with#are comments. - Use
use <graph>to switch graphs within a script. - Canonical
kg <graph> node find ...commands still work as fallback. - Full SCL reference:
docs/scl.md
Generate a Graph
This is the first workflow for a new project: ask the assistant to create or extend a graph from your documentation.
By default, graphs are stored in ~/.kg/graphs as *.kg files.
Minimal prompt:
Example prompt with documents:
Longer prompt for this workflow: docs/ai-prompt-graph-from-docs.md
For a ready-made repository example, run cargo run --bin repo-example to generate repo-example.kg from this repo.
Automatic graph for a directory
kg can turn an existing folder into a graph automatically. It scans the directory tree, recognizes many common file types, extracts symbols for Rust, Java, JavaScript/TypeScript, Python, and C/C++, and keeps the generated structure separate from the manual graph.
For markdown-like documents, it also creates document (GDOC) and chapter (GSEC) nodes with section content.
It is a fast way to get a useful map of a codebase or workspace without modeling everything by hand. The generated index is local, refreshable, and safe to ignore in git.
Example:
This generates repo-example.kg from this repository as a local demo.
Ask the Assistant About Facts in the Graph
Once the graph exists, the normal workflow is to ask the assistant to inspect it and answer questions from it.
Example prompt:
Other useful questions:
- "What rules control retries in the
paymentsgraph?" - "Which systems write to the orders datastore?"
- "What is missing or weak in this graph?"
- "Which nodes and edges explain the authorization flow?"
Add or Update Facts Through the Assistant
You can also ask the assistant to improve the graph while you work.
Example prompt:
This works best when your main system prompt or project prompt already tells the assistant which graph belongs to the project.
Minimal project-level prompt:
Tips
Project config (.kg.toml)
kg looks for .kg.toml in the current directory and its parent directories.
Example:
Notes:
backend = "json"is the default and prefers.kgtext graphs.backend = "redb"stores graphs in.dbfiles.graph_dirsets a primary graph directory.graph_dirsadds extra directories scanned bykg listand graph resolution.
Keep Graphs in Git
The default graph directory is ~/.kg/graphs.
You can put that directory under git.
Recommended approach:
- keep the main
*.kggraph files in git, - ignore generated sidecars and local operational files,
- treat backup snapshots and event logs as local machine history unless you explicitly want to version them.
Suggested .gitignore:
In practice:
*.kgis the main graph file you usually want to review and commit,*.kglogis a local access/feedback log,*.kgindexis a generated local index,*.event.logis a local append-only change timeline,*.bakis the previous on-disk version from the last write,*.bck.*.gzare periodic compressed backup snapshots,*.migration.logis a migration report when older graphs are converted.
*.kg is git-friendly and intentionally structured to make diffs readable and merges easier when several people work on the same graph.
Export a Graph to HTML
To generate an interactive HTML view of a graph:
You can keep the generated HTML as a shareable visual snapshot of the current graph.
Documentation
docs/mcp.md- MCP setup and tool referencedocs/ai-prompt-graph-from-docs.md- longer prompt for document ingestiondocs/build-graph-from-docs.md- graph-building workflow from docsdocs/troubleshooting.md- common issues
Contact
For questions or feedback: [email protected]
來源:README.md,提交 59f2de8
工具
0版本歷史
1- v0.3.0最新Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分