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.
@@ -1,103 +1,137 @@
1
1
  ---
2
2
  name: context-mcp
3
3
  description: >
4
- Guides Claude on using the context-mcp memory + knowledge graph system.
5
- Trigger at the start of every conversation, when the user mentions a project,
6
- asks to remember/save something, or says "pick up where we left off".
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 for Claude.
12
- Every conversation starts with `context.resume`. Every codebase question uses `codegraph_query`. Files only read for bugs/logic.
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 anything else** with:
20
+ Call `context` tool **before any tool or response**:
19
21
  - `action: "resume"`
20
- - `project: "<basename of git repo root dir>"` — infer from cwd if not stated
21
- - `rootPath: "<absolute path to git repo root>"` — required for sandbox + graph lookup
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` — decisions, bugs, notes from previous conversations
27
- - `activePlans` — active AI-created plans for this project
28
- - `codegraph` — `{ built: true/false, nodes, edges, communities }`
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` before reading any files
32
- - `codegraph.built: false` → call `codegraph_build(path)` first, then proceed
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 Auto-Save Context
37
+ ## 2. When to Save Context (MANDATORY TRIGGERS)
37
38
 
38
- ### Always save no user prompt needed
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 project: "<project>" type: "note" title: "ContextGraph built — <project>"
43
- content: "nodes: X | edges: Y | communities: Z"
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
- **User explicitly asks** — any phrase like "save this", "remember this", "note that" → save immediately.
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
- **During plan / implementation / discussion / research** — save only when genuinely valuable:
65
+ ## 3. Plans (MANDATORY for multi-file work)
49
66
 
50
- | What happened | Type |
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
- Do NOT save: routine reads, search results, temporary debugging dead-ends.
69
+ **Skip plan for:** single-file edits, questions, simple config tweaks.
58
70
 
59
- **Making any kind of plan** → call `plan.save` immediately with the plan summary and `planDir` pointing to your platform's plans folder.
60
- Need past info `search` before asking user.
61
- Always pass `project`. Auto-compact fires at >20 entries.
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
- ## 3. ContextGraph Pipeline
79
+ ## 4. Auto-Summary Rule (MANDATORY)
66
80
 
67
- > The knowledge graph is also called **ContextGraph**. The MCP tools use the `codegraph_*` prefix both names refer to the same thing.
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
- codegraph_build(path)
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
- ### Step 2 — Query (free, instant, forever)
91
+ ---
92
+
93
+ ## 5. Search Before Asking
94
+
95
+ If the user references past work → call `search` first:
79
96
  ```
80
- codegraph_query(path, question) → fetch any details about the codebase
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
- ## 4. Graph vs File
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
- **Graph** use for any question about what exists in the codebase: finding functions, classes, files, understanding what a module contains, dependencies, callers, imports, paths between concepts.
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
- **File** use for bugs, logic inside a specific function, tracing unexpected behavior.
125
+ **Never read files for structure questions use graph tools first.**
94
126
 
95
127
  ---
96
128
 
97
- ## 5. Rules
129
+ ## 7. Rules
98
130
 
99
- 1. **`context.resume` first** — before any tool or response
100
- 2. **Always pass `project`** — never save to global unless truly cross-project
101
- 3. **`search` before asking**if user references past work, find it first
102
- 4. **`codegraph_query` before reading files**graph is faster and cheaper
103
- 5. **Read files for bugs/logic**graph is structure only, not behavior
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
@@ -1,80 +1,90 @@
1
1
  # Context-MCP — Gemini CLI Usage Guide
2
2
 
3
3
  Persistent memory + codebase knowledge graph.
4
- Every conversation starts with `context.resume`. Every codebase question uses `codegraph_query`. Files only read for bugs/logic.
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 the `context` MCP tool with `action: "resume"`, `project: "<project-name>"` **before anything else**.
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
- Then:
18
- - `codegraph.built: true` → use `codegraph_query` before reading any files
19
- - `codegraph.built: false` → call `codegraph_build(path)` first, then proceed
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. When to Auto-Save Context
21
+ ## 2. Save Triggers (MANDATORY)
24
22
 
25
- **After graph build or rebuild** every time `codegraph_build` completes:
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
- **User explicitly asks** "save this", "remember this", "note that" → save immediately.
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
- **During plan / implementation / discussion / research** save only when genuinely valuable:
35
+ **Do NOT save:** routine reads, search results, explanations of existing code.
36
+
37
+ ---
34
38
 
35
- | What happened | Type |
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
- Do NOT save: routine reads, search results, temporary debugging dead-ends.
43
- **Making any kind of plan** → call `plan.save` immediately with the plan summary and `planDir` pointing to your platform's plans folder.
44
- Need past info → `search` before asking. Always pass `project`.
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
- ## 3. ContextGraph Pipeline
50
+ ## 4. Auto-Summary at ≥ 20 Entries (MANDATORY)
49
51
 
50
- > The knowledge graph is also called **ContextGraph**. The MCP tools use the `codegraph_*` prefix — both names refer to the same thing.
52
+ When `totalEntries 20`, call `context.save` BEFORE the user's task:
51
53
 
52
- ### Step 1 — Build (once, fast, local)
53
54
  ```
54
- codegraph_build(path) → AST graph: functions, classes, imports, edges
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
- ### Step 2 — Query (free, instant)
58
- ```
59
- codegraph_query(path, question) → fetch any details about the codebase
60
- codegraph_path(path, from, to) → shortest path
61
- codegraph_nodes(path, type) → list nodes by type
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
- ## 4. Graph vs File
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
- **Graph** use for any question about what exists: finding functions, classes, files, dependencies, callers, imports, paths between concepts.
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
- ## 5. Rules
82
+ ## 7. Rules
75
83
 
76
- 1. **`context.resume` first** — before any tool or response
77
- 2. **Always pass `project`** — never save to global unless truly cross-project
78
- 3. **`search` before asking**if user references past work, find it first
79
- 4. **`codegraph_query` before reading files**graph is faster and cheaper
80
- 5. **Read files for bugs/logic**graph is structure only, not behavior
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 from the argument
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 — if mentions a bug/fix → `"bug"`, decision/chose/decided → `"decision"`, config/env/secret/deploy → `"config"`, otherwise `"note"`
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 what was saved (title, type, project).
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. `codegraph_query` answers every structure question. Files only for bugs/logic.
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` — decisions, bugs, notes from past sessions
30
- - `activePlans` — active AI-created plans for this project
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` before reading any files
35
- - `codegraph.built: false` → call `codegraph_build(path)` first, then proceed
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 Auto-Save Context
48
+ ## When to Save Context (MANDATORY TRIGGERS)
40
49
 
41
- ### Always save no user prompt needed
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 project: "<project>" type: "note" title: "ContextGraph built — <project>"
47
- content: "nodes: X | edges: Y | communities: Z | built: <timestamp>"
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
- **2. When user explicitly asks**
51
- Any phrase like "save this", "remember this", "note that", "log this" → `context.save` immediately with whatever was just discussed.
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
- **3. During plan / implementation / discussion / research save when something valuable happens**
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
- Do NOT save for: routine file reads, search results, explanations of existing code, temporary debugging steps that led nowhere.
80
+ **Skip plan for:** single-file edits, questions, simple config tweaks.
62
81
 
63
- | What happened | Type |
64
- |--------------|------|
65
- | Approach / library / pattern decided | `decision` |
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
- Always pass `project`. **Making any plan** → `plan.save` immediately (planDir = your platform's plans folder). Need past info → `search` before asking user. Auto-compact fires at >20 entries.
86
+ On `resume`, check `activePlans` do not duplicate in-progress work.
71
87
 
72
88
  ---
73
89
 
74
- ## ContextGraph Pipeline
90
+ ## Auto-Summary Rule (MANDATORY)
75
91
 
76
- > Also called **CodeGraph**. MCP tools use the `codegraph_*` prefix — both names mean the same thing.
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
- codegraph_build(path)
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
- ### Query (free, instant, forever)
85
- ```
86
- codegraph_query(path, question?, node?) → structural question OR single-node lookup (or both in one call)
87
- codegraph_path(path, from, to) → shortest path between two concepts
88
- codegraph_nodes(path, type) list all nodes of a type
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
- ## Graph vs File
108
+ ## ContextGraph Pipeline
109
+
110
+ ### Build (once per project)
111
+ ```
112
+ codegraph_build(path) → AST graph: functions, classes, imports, edges
113
+ ```
95
114
 
96
- **Graph** what exists: finding functions, classes, files, dependencies, callers, imports, paths between concepts.
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
- **File** bugs, logic inside a specific function, tracing unexpected behavior.
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. **`context.resume` first** — before any tool or response
105
- 2. **Always pass `project`** — never save to global unless truly cross-project
106
- 3. **`search` before asking**if user references past work, find it first
107
- 4. **`codegraph_query` before reading files**graph is faster and cheaper
108
- 5. **Read files for bugs/logic only**graph is structure, not behavior
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 for Windsurf.
4
- Every conversation starts with `context.resume`. Every structural question uses `codegraph_query`. Files only read for bugs/logic.
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, `action: "resume"`, `project: "<project-name>"` before anything else.
10
+ Call `context` tool: `action:"resume"`, `project:"<name>"` before anything else.
9
11
 
10
- Returns: `recentEntries`, `activePlans`, `codegraph { built, nodes, edges }`.
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
- ## 2. Save Context
64
+ ## 6. ContextGraph Tools
16
65
 
17
- | Situation | Action |
18
- |-----------|--------|
19
- | Decision made | `context.save` type: `"decision"` |
20
- | Bug found/fixed | `context.save` type: `"bug"` |
21
- | Discovery / structure understood | `context.save` type: `"note"` |
22
- | Making any plan | `plan.save` + `planDir` |
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
- ## 3. CodeGraph
73
+ Use `codegraph_arch` first. Never read files for structure questions.
25
74
 
26
- Build once: `codegraph_build(path)` — then query forever.
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. Always pass `project`
33
- 3. `search` before asking the user about past work
34
- 4. `codegraph_query` before reading files
35
- 5. Files only for bugs and logic
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