context-mcp-server 1.0.8 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/codegraph/__pycache__/server.cpython-313.pyc +0 -0
- package/codegraph/graph/__pycache__/query.cpython-313.pyc +0 -0
- package/codegraph/graph/query.py +43 -0
- package/codegraph/server.py +20 -17
- package/package.json +1 -1
- package/pyproject.toml +1 -1
- package/src/cli.js +94 -183
- package/src/db.js +79 -102
- package/src/search.js +73 -9
- package/src/templates/AGENTS.md +56 -46
- package/src/templates/CLAUDE.md +89 -55
- package/src/templates/GEMINI.md +56 -46
- package/src/templates/commands/save-context.md +6 -3
- package/src/templates/skills/SKILL.md +83 -50
- package/src/templates/windsurf-rules.md +69 -20
- package/src/tools/codegraph.js +46 -43
- package/src/tools/context.js +42 -24
- package/src/tools/plan.js +14 -11
- package/uv.lock +1 -1
- package/src/migrator.js +0 -124
package/src/templates/CLAUDE.md
CHANGED
|
@@ -1,103 +1,137 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: context-mcp
|
|
3
3
|
description: >
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
asks to remember/save something,
|
|
4
|
+
Persistent memory + ContextGraph for Claude.
|
|
5
|
+
Use at the START of every conversation to resume project context.
|
|
6
|
+
Use whenever the user mentions a project, asks to remember/save something,
|
|
7
|
+
references past work, or says "pick up where we left off".
|
|
8
|
+
Also use when the user asks about code structure — query ContextGraph before reading any files.
|
|
7
9
|
---
|
|
8
10
|
|
|
9
11
|
# Context-MCP — Claude Usage Guide
|
|
10
12
|
|
|
11
|
-
Persistent memory + codebase knowledge graph
|
|
12
|
-
|
|
13
|
+
Persistent memory + codebase knowledge graph across every conversation.
|
|
14
|
+
`context.resume` starts every session. `codegraph_arch` shows module structure. `codegraph_query` finds specific symbols. Files only for bugs/logic.
|
|
13
15
|
|
|
14
16
|
---
|
|
15
17
|
|
|
16
18
|
## 1. Start of Every Conversation (MANDATORY)
|
|
17
19
|
|
|
18
|
-
Call `context` tool **before
|
|
20
|
+
Call `context` tool **before any tool or response**:
|
|
19
21
|
- `action: "resume"`
|
|
20
|
-
- `project: "<basename of git repo root
|
|
21
|
-
- `rootPath: "<absolute path to git repo root>"` — required
|
|
22
|
-
|
|
23
|
-
Both fields are required: `project` names the memory bucket, `rootPath` enables exact graph matching and file sandboxing.
|
|
22
|
+
- `project: "<basename of git repo root>"` — infer from cwd
|
|
23
|
+
- `rootPath: "<absolute path to git repo root>"` — required
|
|
24
24
|
|
|
25
25
|
Returns:
|
|
26
|
-
- `recentEntries` —
|
|
27
|
-
- `activePlans` —
|
|
28
|
-
- `codegraph` — `{ built: true/false, nodes, edges
|
|
26
|
+
- `recentEntries` — last 15 entries; newest 5 have full content, rest have 200-char preview
|
|
27
|
+
- `activePlans` — in-progress plans; read them before starting any new work
|
|
28
|
+
- `codegraph` — `{ built: true/false, nodes, edges }`
|
|
29
|
+
- `stats.totalEntries` — if ≥ 20, write a compaction summary before proceeding (see Rule 4)
|
|
29
30
|
|
|
30
31
|
Then:
|
|
31
|
-
- `codegraph.built: true` → use `codegraph_query`
|
|
32
|
-
- `codegraph.built: false` → call `codegraph_build(path)` first
|
|
32
|
+
- `codegraph.built: true` → use `codegraph_arch` for structure overview, `codegraph_query` for specific lookups
|
|
33
|
+
- `codegraph.built: false` → call `codegraph_build(path)` first
|
|
33
34
|
|
|
34
35
|
---
|
|
35
36
|
|
|
36
|
-
## 2. When to
|
|
37
|
+
## 2. When to Save Context (MANDATORY TRIGGERS)
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
Call `context.save` with `type: "note"` whenever you finish something or discover something worth keeping:
|
|
39
40
|
|
|
40
|
-
**After graph build or rebuild** — every time `codegraph_build` completes:
|
|
41
41
|
```
|
|
42
|
-
context.save
|
|
43
|
-
|
|
42
|
+
context.save
|
|
43
|
+
project: "<project>"
|
|
44
|
+
title: "<what was done — up to 120 chars>"
|
|
45
|
+
why: "<why it mattered>"
|
|
46
|
+
outcome: "<what the result was>"
|
|
47
|
+
files: ["src/file.js", ...]
|
|
44
48
|
```
|
|
45
49
|
|
|
46
|
-
**
|
|
50
|
+
**Save immediately after:**
|
|
51
|
+
- Task / fix / feature complete
|
|
52
|
+
- Decision made (architecture, library, approach)
|
|
53
|
+
- Discovery — non-obvious behavior, constraint, gotcha
|
|
54
|
+
- Config / env / deploy info
|
|
55
|
+
- Graph build complete — include nodes/edges count in content
|
|
56
|
+
- User says "save this" / "remember this"
|
|
57
|
+
|
|
58
|
+
**Manual compaction** — "compact now", "compress memory", "clean up context":
|
|
59
|
+
Save a full session summary as `type: "compaction"`. Server removes old entries using it.
|
|
60
|
+
|
|
61
|
+
**Do NOT save:** routine reads, search results, explanations of existing code, dead-end debugging.
|
|
62
|
+
|
|
63
|
+
---
|
|
47
64
|
|
|
48
|
-
|
|
65
|
+
## 3. Plans (MANDATORY for multi-file work)
|
|
49
66
|
|
|
50
|
-
|
|
51
|
-
|--------------|------|
|
|
52
|
-
| Approach / library / pattern decided | `decision` |
|
|
53
|
-
| Bug found, root cause known, or fixed | `bug` |
|
|
54
|
-
| Gotcha, constraint, discovery, structure understood | `note` |
|
|
55
|
-
| Config / env var / secret / deploy step | `config` |
|
|
67
|
+
**Create a plan when:** editing 2+ files, multi-step implementation, refactor, multi-file bug fix.
|
|
56
68
|
|
|
57
|
-
|
|
69
|
+
**Skip plan for:** single-file edits, questions, simple config tweaks.
|
|
58
70
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
71
|
+
1. Call `plan.save` with `name`, `content` (full plan in markdown), `project`, `planDir` before starting
|
|
72
|
+
2. Work through the plan
|
|
73
|
+
3. Call `plan.update status:"done"` when complete — this deletes the plan
|
|
74
|
+
|
|
75
|
+
On `resume`, if `activePlans` is non-empty — read them before starting new work. Do not create a duplicate.
|
|
62
76
|
|
|
63
77
|
---
|
|
64
78
|
|
|
65
|
-
##
|
|
79
|
+
## 4. Auto-Summary Rule (MANDATORY)
|
|
66
80
|
|
|
67
|
-
|
|
81
|
+
When `resume` returns `stats.totalEntries ≥ 20`, call `context.save` **before doing anything else**:
|
|
68
82
|
|
|
69
|
-
### Step 1 — Build (once per project, fast, local)
|
|
70
83
|
```
|
|
71
|
-
|
|
84
|
+
context.save
|
|
85
|
+
type: "compaction"
|
|
86
|
+
title: "Session summary — <YYYY-MM-DD>"
|
|
87
|
+
content: "<what was built, decided, broke, current state>"
|
|
88
|
+
project: "<project>"
|
|
72
89
|
```
|
|
73
|
-
- Parses codebase into AST graph using tree-sitter (regex fallback for unsupported languages)
|
|
74
|
-
- Extracts functions, classes, imports, call edges for all code files
|
|
75
|
-
- Build files (package.json, pyproject.toml, go.mod, Dockerfile, etc.) get a single metadata node
|
|
76
|
-
- Saves graph to `~/.context-mcp/graphs.json`. Visible on `context.resume`.
|
|
77
90
|
|
|
78
|
-
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
## 5. Search Before Asking
|
|
94
|
+
|
|
95
|
+
If the user references past work → call `search` first:
|
|
79
96
|
```
|
|
80
|
-
|
|
81
|
-
codegraph_explain(path, node) → one node: type, file, depends_on, used_by
|
|
82
|
-
codegraph_path(path, from, to) → shortest path between two concepts
|
|
83
|
-
codegraph_nodes(path, type) → list all nodes of a type
|
|
84
|
-
codegraph_report(path) → god nodes, clusters, surprises
|
|
97
|
+
search query: "<what they're referencing>" project: "<project>"
|
|
85
98
|
```
|
|
86
99
|
|
|
87
100
|
---
|
|
88
101
|
|
|
89
|
-
##
|
|
102
|
+
## 6. ContextGraph Pipeline
|
|
103
|
+
|
|
104
|
+
### Build (once per project)
|
|
105
|
+
```
|
|
106
|
+
codegraph_build(path)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Query tools
|
|
110
|
+
```
|
|
111
|
+
codegraph_arch(path, limit?) → module map: every file, its exports, its imports
|
|
112
|
+
codegraph_query(path, question?, node?) → find function/class/file or answer structural question
|
|
113
|
+
codegraph_nodes(path, type) → list all nodes of a type
|
|
114
|
+
codegraph_report(path) → god nodes, clusters, structural analysis
|
|
115
|
+
```
|
|
90
116
|
|
|
91
|
-
|
|
117
|
+
| Question | Tool |
|
|
118
|
+
|---|---|
|
|
119
|
+
| What files exist and what do they export? | `codegraph_arch` |
|
|
120
|
+
| Where is function X defined? | `codegraph_query node:"X"` |
|
|
121
|
+
| What does module Y depend on? | `codegraph_query question:"what does Y import?"` |
|
|
122
|
+
| What are all the classes? | `codegraph_nodes type:"class"` |
|
|
123
|
+
| Most connected files? | `codegraph_report` |
|
|
92
124
|
|
|
93
|
-
**
|
|
125
|
+
**Never read files for structure questions — use graph tools first.**
|
|
94
126
|
|
|
95
127
|
---
|
|
96
128
|
|
|
97
|
-
##
|
|
129
|
+
## 7. Rules
|
|
98
130
|
|
|
99
|
-
1.
|
|
100
|
-
2.
|
|
101
|
-
3.
|
|
102
|
-
4.
|
|
103
|
-
5.
|
|
131
|
+
1. `context.resume` first — before any tool or response
|
|
132
|
+
2. Always pass `project`
|
|
133
|
+
3. Save on task complete — `why` + `outcome` + `files`
|
|
134
|
+
4. Compaction at ≥ 20 entries — before starting the task
|
|
135
|
+
5. Plan for multi-file work — save before starting, `status:"done"` deletes it
|
|
136
|
+
6. Search before asking about past work
|
|
137
|
+
7. Graph tools before files
|
package/src/templates/GEMINI.md
CHANGED
|
@@ -1,80 +1,90 @@
|
|
|
1
1
|
# Context-MCP — Gemini CLI Usage Guide
|
|
2
2
|
|
|
3
3
|
Persistent memory + codebase knowledge graph.
|
|
4
|
-
|
|
4
|
+
`context.resume` starts every session. `codegraph_arch` shows module structure. `codegraph_query` finds specific symbols. Files only for bugs/logic.
|
|
5
5
|
|
|
6
6
|
---
|
|
7
7
|
|
|
8
8
|
## 1. Start of Every Conversation (MANDATORY)
|
|
9
9
|
|
|
10
|
-
Call
|
|
10
|
+
Call `context` MCP tool: `action:"resume"`, `project:"<project>"` before anything else.
|
|
11
11
|
|
|
12
|
-
Returns:
|
|
13
|
-
- `recentEntries` — decisions, bugs, notes from previous conversations
|
|
14
|
-
- `activePlans` — active AI-created plans for this project
|
|
15
|
-
- `codegraph` — `{ built: true/false, nodes, edges, communities }`
|
|
12
|
+
Returns: `recentEntries`, `activePlans`, `codegraph`, `stats.totalEntries`.
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
- `codegraph.built:
|
|
19
|
-
- `
|
|
14
|
+
- `codegraph.built: true` → use graph tools before reading files
|
|
15
|
+
- `codegraph.built: false` → call `codegraph_build(path)` first
|
|
16
|
+
- `stats.totalEntries ≥ 20` → write compaction summary FIRST (see Rule 4)
|
|
17
|
+
- `activePlans` non-empty → read them before starting new work
|
|
20
18
|
|
|
21
19
|
---
|
|
22
20
|
|
|
23
|
-
## 2.
|
|
21
|
+
## 2. Save Triggers (MANDATORY)
|
|
24
22
|
|
|
25
|
-
|
|
26
|
-
```
|
|
27
|
-
context.save type: "note" title: "ContextGraph built — <project>"
|
|
28
|
-
content: "nodes: X | edges: Y | communities: Z"
|
|
29
|
-
```
|
|
23
|
+
Call `context.save` with `type: "note"` after finishing anything worth keeping:
|
|
30
24
|
|
|
31
|
-
|
|
25
|
+
| Trigger | Required fields |
|
|
26
|
+
|---|---|
|
|
27
|
+
| Task / fix / feature complete | title, why, outcome, files[] |
|
|
28
|
+
| Decision made | title, why, outcome |
|
|
29
|
+
| Discovery / constraint / gotcha | title, content |
|
|
30
|
+
| Config / env / deploy info | title, content |
|
|
31
|
+
| Graph build complete | title, content (nodes/edges count) |
|
|
32
|
+
| User says "save this" | title, content |
|
|
33
|
+
| "compact now" / "compress memory" | `type:"compaction"`, full session summary |
|
|
32
34
|
|
|
33
|
-
**
|
|
35
|
+
**Do NOT save:** routine reads, search results, explanations of existing code.
|
|
36
|
+
|
|
37
|
+
---
|
|
34
38
|
|
|
35
|
-
|
|
36
|
-
|--------------|------|
|
|
37
|
-
| Approach / library / pattern decided | `decision` |
|
|
38
|
-
| Bug found, root cause known, or fixed | `bug` |
|
|
39
|
-
| Gotcha, constraint, discovery, structure understood | `note` |
|
|
40
|
-
| Config / env var / secret / deploy step | `config` |
|
|
39
|
+
## 3. Plans (MANDATORY for multi-file work)
|
|
41
40
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
**Create a plan when:** editing 2+ files, multi-step implementation, refactor, multi-file bug fix.
|
|
42
|
+
|
|
43
|
+
1. Call `plan.save` with name, content, project before starting
|
|
44
|
+
2. Call `plan.update status:"done"` when complete — deletes the plan
|
|
45
|
+
|
|
46
|
+
Check `activePlans` on resume — don't create duplicates.
|
|
45
47
|
|
|
46
48
|
---
|
|
47
49
|
|
|
48
|
-
##
|
|
50
|
+
## 4. Auto-Summary at ≥ 20 Entries (MANDATORY)
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
When `totalEntries ≥ 20`, call `context.save` BEFORE the user's task:
|
|
51
53
|
|
|
52
|
-
### Step 1 — Build (once, fast, local)
|
|
53
54
|
```
|
|
54
|
-
|
|
55
|
+
type: "compaction" title: "Session summary — <YYYY-MM-DD>"
|
|
56
|
+
content: "<what was built, decided, broke, current state>"
|
|
57
|
+
project: "<project>"
|
|
55
58
|
```
|
|
56
59
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
codegraph_report(path) → full graph analysis
|
|
63
|
-
```
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 5. Search Before Asking
|
|
63
|
+
|
|
64
|
+
Call `search` before asking user to re-explain past work.
|
|
64
65
|
|
|
65
66
|
---
|
|
66
67
|
|
|
67
|
-
##
|
|
68
|
+
## 6. ContextGraph Tools
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
codegraph_build(path) → build AST graph (run once)
|
|
72
|
+
codegraph_arch(path, limit?) → module map: files, exports, imports
|
|
73
|
+
codegraph_query(path, question?, node?) → find symbol or answer structural question
|
|
74
|
+
codegraph_nodes(path, type) → list all nodes of a type
|
|
75
|
+
codegraph_report(path) → structural analysis
|
|
76
|
+
```
|
|
68
77
|
|
|
69
|
-
|
|
70
|
-
**File** — bugs, logic, tracing unexpected behavior.
|
|
78
|
+
Use `codegraph_arch` first. Never read files for structure questions.
|
|
71
79
|
|
|
72
80
|
---
|
|
73
81
|
|
|
74
|
-
##
|
|
82
|
+
## 7. Rules
|
|
75
83
|
|
|
76
|
-
1.
|
|
77
|
-
2.
|
|
78
|
-
3.
|
|
79
|
-
4.
|
|
80
|
-
5.
|
|
84
|
+
1. `context.resume` first — before any tool or response
|
|
85
|
+
2. Always pass `project`
|
|
86
|
+
3. Save on task complete — `why` + `outcome` + `files`
|
|
87
|
+
4. Compaction at ≥ 20 entries — before starting task
|
|
88
|
+
5. Plan before multi-file work — `status:"done"` deletes it
|
|
89
|
+
6. Search before asking about past work
|
|
90
|
+
7. Graph tools before files
|
|
@@ -2,8 +2,11 @@ Call the `context` MCP tool with `action: "save"` to store a note for the curren
|
|
|
2
2
|
|
|
3
3
|
Parse `$ARGUMENTS` to determine:
|
|
4
4
|
- `project`: infer from current working directory name if not specified
|
|
5
|
-
- `title`: first sentence or phrase
|
|
5
|
+
- `title`: first sentence or phrase (up to 120 chars — be specific)
|
|
6
|
+
- `why`: reason it mattered — what problem it solved or constraint it revealed
|
|
7
|
+
- `outcome`: result — what changed, what was verified, what shipped, which files were affected
|
|
8
|
+
- `files`: list of files changed (required for task/bug types)
|
|
6
9
|
- `content`: full argument text
|
|
7
|
-
- `type`: auto-detect —
|
|
10
|
+
- `type`: auto-detect — bug/fix/error → `"bug"`, task/done/complete/shipped/implemented → `"task"`, decision/chose/decided/approach → `"decision"`, config/env/secret/deploy → `"config"`, otherwise `"note"`
|
|
8
11
|
|
|
9
|
-
Confirm to the user
|
|
12
|
+
Confirm to the user: title, type, why, outcome, project.
|
|
@@ -12,7 +12,17 @@ description: >
|
|
|
12
12
|
# Context-MCP
|
|
13
13
|
|
|
14
14
|
Persistent memory + codebase knowledge graph across every conversation.
|
|
15
|
-
`context.resume` starts every session. `
|
|
15
|
+
`context.resume` starts every session. `codegraph_arch` shows module structure. `codegraph_query` finds specific symbols. Files only for bugs/logic.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## Subcommands
|
|
20
|
+
|
|
21
|
+
When invoked with an argument, act immediately:
|
|
22
|
+
|
|
23
|
+
**`/context-mcp resume`** — call `context` tool with `action:"resume"`, infer `project` from cwd, pass `rootPath`. Report what was returned.
|
|
24
|
+
|
|
25
|
+
**`/context-mcp save`** — call `context` tool with `action:"save"` to save the most recent thing worth keeping from this conversation. Use `type:"note"`, fill in `title`, `why`, `outcome`, `files` from context. Confirm what was saved.
|
|
16
26
|
|
|
17
27
|
---
|
|
18
28
|
|
|
@@ -23,86 +33,109 @@ Call `context` tool **before any tool or response** with:
|
|
|
23
33
|
- `project: "<basename of git repo root dir>"` — infer from `cwd` if not stated
|
|
24
34
|
- `rootPath: "<absolute path to git repo root>"` — required for sandbox + graph lookup
|
|
25
35
|
|
|
26
|
-
Both fields are required: `project` names the memory bucket, `rootPath` enables exact graph matching and file sandboxing.
|
|
27
|
-
|
|
28
36
|
Returns:
|
|
29
|
-
- `recentEntries` —
|
|
30
|
-
- `activePlans` —
|
|
37
|
+
- `recentEntries` — last 15 entries; newest 5 have full content, rest have 200-char preview
|
|
38
|
+
- `activePlans` — in-progress plans; read them before starting any new work
|
|
31
39
|
- `codegraph` — `{ built: true/false, nodes, edges, communities }`
|
|
40
|
+
- `stats.totalEntries` — if ≥ 20, write a compaction summary before proceeding (see Rule 4)
|
|
32
41
|
|
|
33
42
|
Then:
|
|
34
|
-
- `codegraph.built: true` → use `codegraph_query`
|
|
35
|
-
- `codegraph.built: false` → call `codegraph_build(path)` first
|
|
43
|
+
- `codegraph.built: true` → use `codegraph_arch` for structure overview, `codegraph_query` for specific lookups
|
|
44
|
+
- `codegraph.built: false` → call `codegraph_build(path)` first
|
|
36
45
|
|
|
37
46
|
---
|
|
38
47
|
|
|
39
|
-
## When to
|
|
48
|
+
## When to Save Context (MANDATORY TRIGGERS)
|
|
40
49
|
|
|
41
|
-
|
|
50
|
+
Call `context.save` with `type: "note"` after finishing anything worth keeping:
|
|
42
51
|
|
|
43
|
-
**1. After graph build or rebuild**
|
|
44
|
-
Every time `codegraph_build` completes successfully, immediately call:
|
|
45
52
|
```
|
|
46
|
-
context.save
|
|
47
|
-
|
|
53
|
+
context.save
|
|
54
|
+
project: "<project>"
|
|
55
|
+
title: "<what was done — up to 120 chars>"
|
|
56
|
+
why: "<why it mattered>"
|
|
57
|
+
outcome: "<what the result was>"
|
|
58
|
+
files: ["src/file.js", ...]
|
|
48
59
|
```
|
|
49
60
|
|
|
50
|
-
**
|
|
51
|
-
|
|
61
|
+
**Save immediately after:**
|
|
62
|
+
- Task / fix / feature complete
|
|
63
|
+
- Decision made (architecture, library, approach)
|
|
64
|
+
- Discovery — non-obvious behavior, constraint, gotcha
|
|
65
|
+
- Config / env / deploy info
|
|
66
|
+
- Graph build complete — include nodes/edges count in content
|
|
67
|
+
- User says "save this" / "remember this"
|
|
68
|
+
|
|
69
|
+
**Manual compaction** — "compact now", "compress memory", "clean up context":
|
|
70
|
+
Save a full session summary as `type: "compaction"`. Server removes old entries using it.
|
|
71
|
+
|
|
72
|
+
**Do NOT save:** routine reads, search results, explanations of existing code, dead-end debugging.
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Plans (MANDATORY for multi-file work)
|
|
52
77
|
|
|
53
|
-
**
|
|
54
|
-
Only save if the moment is genuinely worth keeping across sessions:
|
|
55
|
-
- A decision was made and agreed on (approach, library, pattern, architecture)
|
|
56
|
-
- A bug was found with its root cause identified, or fixed
|
|
57
|
-
- An important discovery (gotcha, constraint, non-obvious behavior, env requirement)
|
|
58
|
-
- A significant milestone reached (feature complete, refactor done, plan finalized)
|
|
59
|
-
- Something that would save future-you from re-learning it
|
|
78
|
+
**Create a plan when:** editing 2+ files, multi-step implementation, refactor, multi-file bug fix.
|
|
60
79
|
|
|
61
|
-
|
|
80
|
+
**Skip plan for:** single-file edits, questions, simple config tweaks.
|
|
62
81
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
| Bug found, root cause known, or fixed | `bug` |
|
|
67
|
-
| Gotcha, constraint, discovery, structure understood | `note` |
|
|
68
|
-
| Config / env var / secret / deploy step | `config` |
|
|
82
|
+
1. `plan.save` with name, content, project, planDir — before starting work
|
|
83
|
+
2. Work through plan
|
|
84
|
+
3. `plan.update status:"done"` when complete — deletes the plan
|
|
69
85
|
|
|
70
|
-
|
|
86
|
+
On `resume`, check `activePlans` — do not duplicate in-progress work.
|
|
71
87
|
|
|
72
88
|
---
|
|
73
89
|
|
|
74
|
-
##
|
|
90
|
+
## Auto-Summary Rule (MANDATORY)
|
|
75
91
|
|
|
76
|
-
|
|
92
|
+
When `resume` returns `stats.totalEntries ≥ 20`, call `context.save` **before the user's task**:
|
|
77
93
|
|
|
78
|
-
### Build (once per project, ~seconds, local)
|
|
79
94
|
```
|
|
80
|
-
|
|
95
|
+
type: "compaction" title: "Session summary — <date>"
|
|
96
|
+
content: "<what was built, decided, broke, current state>"
|
|
97
|
+
project: "<project>"
|
|
81
98
|
```
|
|
82
|
-
Parses codebase into AST graph via tree-sitter. Extracts functions, classes, imports, call edges for 16+ languages. Build files get a single metadata node. Saved to `~/.context-mcp/graphs.json`.
|
|
83
99
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
codegraph_report(path) → god nodes, clusters, surprises
|
|
90
|
-
```
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## Search Before Asking
|
|
103
|
+
|
|
104
|
+
If user references past work → `search` first. Never ask user to re-explain saved information.
|
|
91
105
|
|
|
92
106
|
---
|
|
93
107
|
|
|
94
|
-
##
|
|
108
|
+
## ContextGraph Pipeline
|
|
109
|
+
|
|
110
|
+
### Build (once per project)
|
|
111
|
+
```
|
|
112
|
+
codegraph_build(path) → AST graph: functions, classes, imports, edges
|
|
113
|
+
```
|
|
95
114
|
|
|
96
|
-
|
|
115
|
+
### Query tools
|
|
116
|
+
```
|
|
117
|
+
codegraph_arch(path) → module map: every file, exports, imports
|
|
118
|
+
codegraph_query(path, question?, node?) → find symbol or answer structural question
|
|
119
|
+
codegraph_nodes(path, type) → list all nodes of a type
|
|
120
|
+
codegraph_report(path) → god nodes, clusters, structural analysis
|
|
121
|
+
```
|
|
97
122
|
|
|
98
|
-
|
|
123
|
+
| Question | Tool |
|
|
124
|
+
|---|---|
|
|
125
|
+
| Architecture overview / what files exist | `codegraph_arch` |
|
|
126
|
+
| Where is function/class X defined? | `codegraph_query node:"X"` |
|
|
127
|
+
| What does module Y import? | `codegraph_query question:"..."` |
|
|
128
|
+
| List all classes/functions | `codegraph_nodes type:"class"` |
|
|
129
|
+
| Most connected / central files | `codegraph_report` |
|
|
99
130
|
|
|
100
131
|
---
|
|
101
132
|
|
|
102
133
|
## Rules
|
|
103
134
|
|
|
104
|
-
1.
|
|
105
|
-
2.
|
|
106
|
-
3.
|
|
107
|
-
4.
|
|
108
|
-
5.
|
|
135
|
+
1. `context.resume` first — before any tool or response
|
|
136
|
+
2. Always pass `project`
|
|
137
|
+
3. Save on task complete — `why` + `outcome` + `files`
|
|
138
|
+
4. Compaction at ≥ 20 entries — before starting task
|
|
139
|
+
5. Plan for multi-file work — `status:"done"` deletes it
|
|
140
|
+
6. Search before asking about past work
|
|
141
|
+
7. Graph tools before files
|
|
@@ -1,35 +1,84 @@
|
|
|
1
1
|
# Context-MCP — Windsurf Usage Guide
|
|
2
2
|
|
|
3
|
-
Persistent memory + codebase knowledge graph
|
|
4
|
-
|
|
3
|
+
Persistent memory + codebase knowledge graph.
|
|
4
|
+
`context.resume` starts every session. `codegraph_arch` shows module structure. `codegraph_query` finds specific symbols. Files only for bugs/logic.
|
|
5
|
+
|
|
6
|
+
---
|
|
5
7
|
|
|
6
8
|
## 1. Start of Every Conversation (MANDATORY)
|
|
7
9
|
|
|
8
|
-
Call `context` tool
|
|
10
|
+
Call `context` tool: `action:"resume"`, `project:"<name>"` before anything else.
|
|
9
11
|
|
|
10
|
-
Returns: `recentEntries`, `activePlans`, `codegraph
|
|
12
|
+
Returns: `recentEntries`, `activePlans`, `codegraph`, `stats.totalEntries`.
|
|
11
13
|
|
|
12
|
-
- `codegraph.built: true` → use `codegraph_query` before reading files
|
|
13
14
|
- `codegraph.built: false` → run `codegraph_build(path)` first
|
|
15
|
+
- `stats.totalEntries ≥ 20` → write compaction summary first (see Rule 4)
|
|
16
|
+
- `activePlans` non-empty → read before starting new work
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## 2. Save Triggers (MANDATORY)
|
|
21
|
+
|
|
22
|
+
Call `context.save` with `type: "note"` after finishing anything worth keeping:
|
|
23
|
+
|
|
24
|
+
| Trigger | Required fields |
|
|
25
|
+
|---|---|
|
|
26
|
+
| Task / fix / feature complete | title, why, outcome, files[] |
|
|
27
|
+
| Decision made | title, why, outcome |
|
|
28
|
+
| Discovery / constraint / gotcha | title, content |
|
|
29
|
+
| Config / env / deploy info | title, content |
|
|
30
|
+
| Graph build complete | title, content (nodes/edges count) |
|
|
31
|
+
| User says "save this" | title, content |
|
|
32
|
+
| "compact now" / "compress memory" | `type:"compaction"`, full session summary |
|
|
33
|
+
|
|
34
|
+
**Do NOT save:** routine reads, search results, explanations of existing code.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 3. Plans
|
|
39
|
+
|
|
40
|
+
Call `plan.save` before any work touching 2+ files or multiple steps.
|
|
41
|
+
Call `plan.update status:"done"` when complete — deletes the plan.
|
|
42
|
+
Check `activePlans` on resume — don't duplicate.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 4. Auto-Summary at ≥ 20 Entries (MANDATORY)
|
|
47
|
+
|
|
48
|
+
When `totalEntries ≥ 20`, call `context.save` BEFORE the user's task:
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
type: "compaction" title: "Session summary — <date>"
|
|
52
|
+
content: "<what was built, decided, broke, current state>"
|
|
53
|
+
project: "<project>"
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## 5. Search Before Asking
|
|
59
|
+
|
|
60
|
+
Call `search` before asking user to re-explain past work.
|
|
61
|
+
|
|
62
|
+
---
|
|
14
63
|
|
|
15
|
-
##
|
|
64
|
+
## 6. ContextGraph Tools
|
|
16
65
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
66
|
+
```
|
|
67
|
+
codegraph_arch(path) → module map (files, exports, imports)
|
|
68
|
+
codegraph_query(path, ...) → find specific function/class/file
|
|
69
|
+
codegraph_nodes(path, type) → list all nodes of a type
|
|
70
|
+
codegraph_report(path) → structural analysis
|
|
71
|
+
```
|
|
23
72
|
|
|
24
|
-
|
|
73
|
+
Use `codegraph_arch` first. Never read files for structure questions.
|
|
25
74
|
|
|
26
|
-
|
|
27
|
-
Use `codegraph_query` for structural questions. Read files for bugs/logic.
|
|
75
|
+
---
|
|
28
76
|
|
|
29
|
-
## Rules
|
|
77
|
+
## 7. Rules
|
|
30
78
|
|
|
31
79
|
1. `context.resume` first — every conversation
|
|
32
|
-
2.
|
|
33
|
-
3.
|
|
34
|
-
4. `
|
|
35
|
-
5.
|
|
80
|
+
2. Save on task complete — `why` + `outcome` + `files`
|
|
81
|
+
3. Compaction at ≥ 20 entries — before starting task
|
|
82
|
+
4. Plan for 2+ file changes — `status:"done"` deletes it
|
|
83
|
+
5. Search before asking about past work
|
|
84
|
+
6. Graph tools before files
|