Skip to content

Commit 234562e

Browse files
author
Zehee
committed
docs: make Chinese README the default; English moved to README.en.md
1 parent 79004db commit 234562e

4 files changed

Lines changed: 497 additions & 497 deletions

File tree

‎README.en.md‎

Lines changed: 336 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,336 @@
1+
# Kimi Code Memory MCP Server
2+
3+
[中文](./README.md)
4+
5+
[![CI](https://github.com/Zehee/kimi-code-memory-mcp-server/actions/workflows/ci.yml/badge.svg)](https://github.com/Zehee/kimi-code-memory-mcp-server/actions/workflows/ci.yml)
6+
[![npm version](https://img.shields.io/npm/v/kimi-code-memory-mcp-server.svg)](https://www.npmjs.com/package/kimi-code-memory-mcp-server)
7+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](./LICENSE)
8+
9+
A local stdio MCP server that gives [Kimi Code CLI](https://github.com/MoonshotAI/kimi-code) cross-session memory.
10+
11+
> **Note:** This package is published to npm as `kimi-code-memory-mcp-server`. You can install it directly or run it from source.
12+
13+
User-facing memories are stored as plain Markdown files on disk. Refined turn summaries use a local SQLite cache, but no vector database, graph database, or external cloud service is required.
14+
15+
## Features
16+
17+
- **Markdown-first memories** — human-readable, git-friendly, LLM-compatible.
18+
- **Structured long-term memory** — `memory/decisions/`, `memory/knowledge/`, `memory/rules/`, `memory/reference/`.
19+
- **Workspace essence** — condensed digest (≤15 KB) generated from `memory/`.
20+
- **Cross-session context recovery** — parses Kimi Code CLI's `wire.jsonl` directly.
21+
- **Theme tracing** — associate conversation turns and memories with themes, then trace their evolution.
22+
- **Refined turn summaries** — reusable turn-level atomic summaries shared across themes.
23+
- **Rebuilding index** — `index.json` is a cache; `.md` files are the source of truth.
24+
25+
## Theme Tracing
26+
27+
Most context windows only look **vertically** through time. Theme tracing also looks **horizontally**: it finds turns across multiple sessions that belong to the same topic and surfaces their evolution.
28+
29+
Each conversation turn is treated as a column. Turns that share a theme are linked together so you can ask questions like "How did the login module evolve?" instead of only "What did we just say?"
30+
31+
```mermaid
32+
%%{init: {'theme': 'base'}}%%
33+
flowchart LR
34+
subgraph SessionA["Session A"]
35+
A1["🟦 Turn 1<br/>Login form"]
36+
A2["🟥 Turn 5<br/>DB schema draft"]
37+
end
38+
39+
subgraph SessionB["Session B"]
40+
B1["🟦 Turn 2<br/>JWT strategy"]
41+
B2["🟥 Turn 4<br/>Migration plan"]
42+
end
43+
44+
subgraph SessionC["Session C"]
45+
C1["🟦 Turn 3<br/>OAuth flow"]
46+
C2["🟥 Turn 6<br/>Index tuning"]
47+
end
48+
49+
A1 -. "login-module theme" .-> B1
50+
B1 -. "login-module theme" .-> C1
51+
A2 -. "database-design theme" .-> B2
52+
B2 -. "database-design theme" .-> C2
53+
```
54+
55+
Tools: `tag_theme`, `trace_theme`, `list_themes`, `search_context`, `refine_session_turns`, `load_turn_context`.
56+
57+
## Why Markdown?
58+
59+
Most agent memory systems default to vector databases. That works for fuzzy retrieval, but it also makes memories opaque, hard to audit, and hard to version-control.
60+
61+
This project starts from the opposite assumption:
62+
63+
> Memories should be **judged, structured, and owned by the user** before they are stored.
64+
65+
Markdown + YAML frontmatter gives you:
66+
67+
- Full readability and editability
68+
- Native git diff support
69+
- No required external database or cloud service
70+
- Compatibility with any LLM that can read text
71+
72+
See [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md) for the design rationale.
73+
74+
## Install
75+
76+
Node.js ≥ 18 is required.
77+
78+
### From npm (recommended)
79+
80+
```bash
81+
npm install -g kimi-code-memory-mcp-server
82+
```
83+
84+
### From source
85+
86+
```bash
87+
git clone https://github.com/Zehee/kimi-code-memory-mcp-server.git
88+
cd kimi-code-memory-mcp-server
89+
npm install
90+
npm run build
91+
```
92+
93+
## Quick Setup (recommended)
94+
95+
After installing from npm, run the setup command to configure Kimi Code CLI automatically:
96+
97+
```bash
98+
npx kimi-memory-setup
99+
```
100+
101+
This will:
102+
103+
1. Detect your `~/.kimi-code` directory.
104+
2. Inject memory protocol rules at the top of `~/.kimi-code/AGENTS.md`.
105+
3. Install the `memory-manage` skill to `~/.kimi-code/skills/memory-manage`.
106+
4. Add the `kimi-memory` MCP server entry to `~/.kimi-code/mcp.json`.
107+
108+
Preview changes without writing anything:
109+
110+
```bash
111+
npx kimi-memory-setup --dry-run
112+
```
113+
114+
Remove the injected configuration later:
115+
116+
```bash
117+
npx kimi-memory-setup --undo
118+
```
119+
120+
## Configure Kimi Code CLI (manual)
121+
122+
If you prefer to configure manually, edit `~/.kimi-code/mcp.json` and add the server.
123+
124+
If you installed from npm with `-g`, use the absolute path to `dist/server.js` inside your global `node_modules`:
125+
126+
```json
127+
{
128+
"mcpServers": {
129+
"kimi-memory": {
130+
"command": "node",
131+
"args": ["/absolute/path/to/global/node_modules/kimi-code-memory-mcp-server/dist/server.js"],
132+
"enabled": true
133+
}
134+
}
135+
}
136+
```
137+
138+
Or run it directly via `npx` (no install required):
139+
140+
```json
141+
{
142+
"mcpServers": {
143+
"kimi-memory": {
144+
"command": "npx",
145+
"args": ["-y", "kimi-code-memory-mcp-server"],
146+
"enabled": true
147+
}
148+
}
149+
}
150+
```
151+
152+
If you built from source, point to your local `dist/server.js`:
153+
154+
```json
155+
{
156+
"mcpServers": {
157+
"kimi-memory": {
158+
"command": "node",
159+
"args": ["/absolute/path/to/kimi-code-memory-mcp-server/dist/server.js"],
160+
"enabled": true
161+
}
162+
}
163+
}
164+
```
165+
166+
The server name **`kimi-memory`** is important because the bundled `AGENTS.md` rules call tools as `mcp__kimi-memory__*` (for example `mcp__kimi-memory__bootstrap_workspace`).
167+
168+
Restart Kimi Code CLI to load the server.
169+
170+
## Optional: Install User-Level AGENTS.md Startup Hook
171+
172+
For automatic memory recovery and behavioral rules on every session start, copy the bundled `AGENTS.md` to your Kimi Code user directory:
173+
174+
```bash
175+
cp AGENTS.md ~/.kimi-code/AGENTS.md
176+
```
177+
178+
This installs a startup hook that tells Kimi Code CLI to call `bootstrap_workspace` at the beginning of every session, and to follow the memory classification and decision-guard rules. Because `AGENTS.md` is injected into **every** session, it is the right place for memory-related behavior protocols.
179+
180+
> **Note:** Keep `AGENTS.md` focused on memory-related conventions only. Do not include tool preferences that belong to other MCP servers.
181+
>
182+
> **Prerequisite:** The MCP server must be registered under the name `kimi-memory` in `~/.kimi-code/mcp.json`, otherwise the `mcp__kimi-memory__*` calls in `AGENTS.md` will fail.
183+
184+
## Optional: Install the Memory Skill
185+
186+
This repository also includes a lightweight Skill (`skills/memory-manage/SKILL.md`) that reminds Kimi Code CLI to call the memory tools when the user expresses a memory-related intent.
187+
188+
```bash
189+
cp -r skills/memory-manage ~/.kimi-code/skills/memory-manage
190+
```
191+
192+
The Skill does **not** enforce behavior on its own; it is a dispatcher. The actual protocols (when to remember, decision guard, etc.) live in `AGENTS.md`.
193+
194+
## Quick Start
195+
196+
After the server is loaded, the agent can call memory tools naturally (tool names are prefixed with the MCP server name you configured, e.g. `mcp__kimi-memory__*`):
197+
198+
```text
199+
User: Let's use SQLite for the cache layer.
200+
Agent: [calls mcp__kimi-memory__remember] key=use-sqlite-cache, folder=memory/decisions
201+
202+
User: Why did we choose SQLite?
203+
Agent: [calls mcp__kimi-memory__search] query=SQLite cache decision
204+
[calls mcp__kimi-memory__recall] key=use-sqlite-cache, folder=memory/decisions
205+
→ "We chose SQLite over Redis because..."
206+
207+
User: How has the cache design evolved?
208+
Agent: [calls mcp__kimi-memory__tag_theme] theme=cache-design
209+
[calls mcp__kimi-memory__trace_theme] theme=cache-design
210+
→ shows related turns and decisions across sessions
211+
```
212+
213+
## See It in Action
214+
215+
The diagram below shows how `kimi-memory` sees conversation history: turns are vertical bars on a timeline, clusters group related turns, sessions are horizontal containers, and themes connect relevant turns across sessions.
216+
217+
![Turns, clusters, sessions, and theme tracing over time](./assets/contextFlow.svg)
218+
219+
The animated clip below is a real Kimi Code CLI session using `kimi-memory`. The user asks for two cross-session summaries — first the evolution history of the MCP memory server itself, then the evolution history of the E2E testing tools. The agent retrieves related memories and conversation turns, then synthesizes structured answers.
220+
221+
![Kimi Memory MCP Server demo](https://github.com/user-attachments/assets/a8947676-1487-47ed-8e0c-8d15f8662618)
222+
223+
## Storage Layout
224+
225+
The server stores data under `~/.kimi-code-memory/<workspace-id>/`:
226+
227+
```text
228+
~/.kimi-code-memory/workspace-a1b2c3d4/
229+
├── index.json # v3-kv metadata cache (rebuildable)
230+
├── memory/
231+
│ ├── decisions/ # architecture and product decisions
232+
│ ├── knowledge/ # project-specific knowledge
233+
│ ├── rules/ # conventions and guardrails
234+
│ └── reference/ # external references
235+
├── essence/
236+
│ └── essence.md # workspace digest (≤15 KB)
237+
├── notes/ # scratch notes
238+
├── themes/
239+
│ └── my-theme.json # theme -> turn/memory refs
240+
└── refined/
241+
└── refined.sqlite # turn-level summaries
242+
```
243+
244+
You can override the storage root with the `MEMORY_STORE_ROOT` environment variable.
245+
246+
### Environment Variables
247+
248+
| Variable | Purpose |
249+
|----------|---------|
250+
| `MEMORY_STORE_ROOT` | Override the default `~/.kimi-code-memory` storage root. |
251+
| `MEMORY_SESSIONS_ROOT` | Override the default `~/.kimi-code/sessions` path used to discover `wire.jsonl` files. |
252+
| `KIMI_CODE_HOME` | Alternative to `MEMORY_SESSIONS_ROOT`; sessions are read from `<KIMI_CODE_HOME>/sessions`. |
253+
254+
## Tools
255+
256+
| Tool | Purpose |
257+
|------|---------|
258+
| `remember` | Write a Markdown memory |
259+
| `recall` | Read a memory by key |
260+
| `recall_recent` | List recently updated memories |
261+
| `search` | Keyword search across memories |
262+
| `list` | List memories |
263+
| `list_tags` | List all tags |
264+
| `delete` | Delete a memory |
265+
| `move` | Move or rename a memory |
266+
| `organize_memories` | Distill `memory/` into `essence/essence.md` |
267+
| `sync_workspace_index` | Rebuild `index.json` from disk |
268+
| `bootstrap_workspace` | Load context, essence, and memory tree |
269+
| `load_workspace_context` | Load recent conversation context |
270+
| `load_more_context` | Load older conversation rounds |
271+
| `search_context` | Search across all session wires |
272+
| `load_turn_context` | Load specific turn details |
273+
| `tag_theme` | Associate a turn or memory with a theme |
274+
| `trace_theme` | Trace a theme's evolution |
275+
| `list_themes` | List themes |
276+
| `refine_session_turns` | Generate refined turn summaries |
277+
278+
## Development
279+
280+
```bash
281+
git clone https://github.com/Zehee/kimi-code-memory-mcp-server.git
282+
cd kimi-code-memory-mcp-server
283+
npm install
284+
npm run build
285+
npm test
286+
npm run lint
287+
```
288+
289+
See [`docs/CONTRIBUTING.md`](./docs/CONTRIBUTING.md) for contribution guidelines.
290+
291+
## Project Structure
292+
293+
```text
294+
src/
295+
├── server.ts # MCP server entry
296+
├── config.ts # defaults and paths
297+
├── theme-manager.ts # theme storage
298+
├── refined-manager.ts # refined turn storage
299+
├── dao/
300+
│ ├── index.ts # index.json DAO (v3-kv)
301+
│ └── memory-store.ts # Markdown file operations
302+
├── context/
303+
│ └── wire-context.ts # wire.jsonl parsing
304+
├── tools/
305+
│ ├── index.ts # tool schemas & dispatch
306+
│ ├── memory-tools.ts # memory CRUD
307+
│ ├── context-tools.ts # context recovery
308+
│ ├── theme-tools.ts # theme tracing
309+
│ └── system-tools.ts # organize/sync/bootstrap
310+
└── utils/
311+
├── frontmatter.ts
312+
├── paths.ts
313+
└── validation.ts
314+
```
315+
316+
## Roadmap
317+
318+
- [x] Modular source structure
319+
- [x] ESLint + Prettier
320+
- [x] Basic integration tests
321+
- [x] Core test coverage for context/theme tools
322+
- [ ] Optional local embedding search
323+
- [ ] Optional LLM-based turn refinement
324+
- [ ] Pluggable wire format adapters
325+
- [ ] Memory usage benchmarks
326+
327+
## Related Documents
328+
329+
- [`docs/ARCHITECTURE.md`](./docs/ARCHITECTURE.md) — system design and data flow
330+
- [`docs/three-layer-memory-model.md`](./docs/three-layer-memory-model.md) — the theoretical memory model behind this server
331+
- [`docs/search-logic.md`](./docs/search-logic.md) — how `search` and `search_context` work
332+
- [`docs/CONTRIBUTING.md`](./docs/CONTRIBUTING.md) — how to contribute
333+
334+
## License
335+
336+
MIT

0 commit comments

Comments
 (0)