context-mcp-server 1.0.8 → 1.1.1
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/README.md +29 -7
- package/codegraph/__pycache__/affected.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/cache.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/callflow_html.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/export.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/report.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/server.cpython-313.pyc +0 -0
- package/codegraph/__pycache__/tree_html.cpython-313.pyc +0 -0
- package/codegraph/affected.py +233 -0
- package/codegraph/cache.py +51 -2
- package/codegraph/callflow_html.py +273 -0
- package/codegraph/export.py +544 -0
- package/codegraph/extractors/__pycache__/ast_extractor.cpython-313.pyc +0 -0
- package/codegraph/extractors/ast_extractor.py +143 -16
- package/codegraph/graph/__pycache__/builder.cpython-313.pyc +0 -0
- package/codegraph/graph/__pycache__/clustering.cpython-313.pyc +0 -0
- package/codegraph/graph/__pycache__/query.cpython-313.pyc +0 -0
- package/codegraph/graph/__pycache__/symbol_resolution.cpython-313.pyc +0 -0
- package/codegraph/graph/builder.py +10 -0
- package/codegraph/graph/clustering.py +247 -10
- package/codegraph/graph/query.py +99 -0
- package/codegraph/graph/symbol_resolution.py +112 -0
- package/codegraph/report.py +53 -0
- package/codegraph/server.py +112 -20
- package/codegraph/tree_html.py +241 -0
- package/package.json +2 -2
- package/pyproject.toml +4 -1
- package/src/cli.js +329 -227
- package/src/db.js +79 -102
- package/src/search.js +73 -9
- package/src/server.js +7 -1
- package/src/templates/antigravity/GEMINI.md +96 -0
- package/src/templates/antigravity/hooks/context-mcp-post-tool-use.js +62 -0
- package/src/templates/antigravity/workflows/context-resume.md +20 -0
- package/src/templates/antigravity/workflows/graph-build.md +23 -0
- package/src/templates/antigravity/workflows/save-context.md +29 -0
- package/src/templates/claude/CLAUDE.md +140 -0
- package/src/templates/claude/commands/graph-build.md +9 -0
- package/src/templates/claude/commands/save-context.md +19 -0
- package/src/templates/claude/hooks/context-mcp-post-tool-use.js +59 -0
- package/src/templates/claude/hooks/context-mcp-pre-tool-use.js +26 -0
- package/src/templates/claude/skills/SKILL.md +144 -0
- package/src/templates/codex/AGENTS.md +107 -0
- package/src/templates/codex/hooks/context-mcp-post-tool-use.js +46 -0
- package/src/templates/codex/hooks/context-mcp-pre-tool-use.js +23 -0
- package/src/templates/codex/prompts/context-resume.md +15 -0
- package/src/templates/codex/prompts/graph-build.md +14 -0
- package/src/templates/codex/prompts/save-context.md +24 -0
- package/src/templates/cursor/commands/context-resume.md +7 -0
- package/src/templates/cursor/commands/graph-build.md +7 -0
- package/src/templates/cursor/commands/save-context.md +12 -0
- package/src/templates/{cursor-rules.mdc → cursor/cursor-rules.mdc} +13 -3
- package/src/templates/cursor/hooks/context-mcp-post-tool-use.js +55 -0
- package/src/templates/gemini/GEMINI.md +92 -0
- package/src/templates/gemini/commands/context-resume.toml +15 -0
- package/src/templates/gemini/commands/graph-build.toml +14 -0
- package/src/templates/gemini/commands/save-context.toml +24 -0
- package/src/templates/gemini/hooks/context-mcp-after-tool.js +59 -0
- package/src/templates/gemini/hooks/context-mcp-before-tool.js +26 -0
- package/src/templates/vscode/commands/context-resume.prompt.md +15 -0
- package/src/templates/vscode/commands/graph-build.prompt.md +10 -0
- package/src/templates/vscode/commands/save-context.prompt.md +16 -0
- package/src/templates/vscode/hooks/context-mcp-post-tool-use.js +58 -0
- package/src/templates/windsurf/hooks/context-mcp-post-run-command.js +57 -0
- package/src/templates/windsurf/windsurf-rules.md +86 -0
- package/src/templates/windsurf/workflows/context-resume.md +11 -0
- package/src/templates/windsurf/workflows/graph-build.md +11 -0
- package/src/templates/windsurf/workflows/save-context.md +18 -0
- package/src/tools/codegraph.js +83 -43
- package/src/tools/context.js +42 -24
- package/src/tools/plan.js +14 -11
- package/uv.lock +1101 -4
- package/src/migrator.js +0 -124
- package/src/templates/AGENTS.md +0 -80
- package/src/templates/CLAUDE.md +0 -103
- package/src/templates/GEMINI.md +0 -80
- package/src/templates/commands/graph-build.md +0 -5
- package/src/templates/commands/save-context.md +0 -9
- package/src/templates/skills/SKILL.md +0 -108
- package/src/templates/windsurf-rules.md +0 -35
- /package/src/templates/{commands → claude/commands}/context-resume.md +0 -0
package/src/migrator.js
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* migrator.js — one-time migration from flat JSON files to per-project directory structure.
|
|
3
|
-
*
|
|
4
|
-
* Old layout:
|
|
5
|
-
* ~/.context-mcp/contexts.json all entries flat
|
|
6
|
-
* ~/.context-mcp/discussions.json all discussions flat
|
|
7
|
-
* ~/.context-mcp/graphs.json all graph build records flat
|
|
8
|
-
*
|
|
9
|
-
* New layout:
|
|
10
|
-
* ~/.context-mcp/projects/<slug>/context.json
|
|
11
|
-
* ~/.context-mcp/projects/<slug>/graph.json { build, entries[] }
|
|
12
|
-
* ~/.context-mcp/projects/<slug>/summary.json
|
|
13
|
-
* ~/.context-mcp/projects/<slug>/discussions.json
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { readFileSync, existsSync, mkdirSync, unlinkSync } from 'node:fs';
|
|
17
|
-
import { join } from 'node:path';
|
|
18
|
-
|
|
19
|
-
function normPath(p) {
|
|
20
|
-
return p ? p.toLowerCase().replace(/\\/g, '/').replace(/\/$/, '') : '';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function treeFor(entry) {
|
|
24
|
-
if (entry.type === 'compaction') return 'summary';
|
|
25
|
-
return 'context';
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function readArr(filePath, key) {
|
|
29
|
-
if (!existsSync(filePath)) return [];
|
|
30
|
-
try {
|
|
31
|
-
const d = JSON.parse(readFileSync(filePath, 'utf8'));
|
|
32
|
-
return Array.isArray(d[key]) ? d[key] : (Array.isArray(d) ? d : []);
|
|
33
|
-
} catch { return []; }
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Run migration if legacy flat files are present.
|
|
38
|
-
* @param {object} opts
|
|
39
|
-
* @param {string} opts.dataDir - base data dir (~/.context-mcp)
|
|
40
|
-
* @param {string} opts.projectsDir - projects sub-dir
|
|
41
|
-
* @param {string} opts.projectsPath - path to projects.json
|
|
42
|
-
* @param {Function} opts.slugify - name → filesystem slug
|
|
43
|
-
* @param {Function} opts.flushFile - (filePath, content) atomic write
|
|
44
|
-
* @param {Array} opts.projectsIndex - current projects.json array (mutated in place)
|
|
45
|
-
*/
|
|
46
|
-
export function runMigration({ dataDir, projectsDir, projectsPath, slugify, flushFile, projectsIndex }) {
|
|
47
|
-
const legacyContexts = join(dataDir, 'contexts.json');
|
|
48
|
-
const legacyDiscussions = join(dataDir, 'discussions.json');
|
|
49
|
-
const legacyGraphs = join(dataDir, 'graphs.json');
|
|
50
|
-
|
|
51
|
-
const hasLegacy = existsSync(legacyContexts)
|
|
52
|
-
|| existsSync(legacyDiscussions)
|
|
53
|
-
|| existsSync(legacyGraphs);
|
|
54
|
-
|
|
55
|
-
if (!hasLegacy) return false;
|
|
56
|
-
|
|
57
|
-
const oldContexts = readArr(legacyContexts, 'contexts');
|
|
58
|
-
const oldDiscussions = readArr(legacyDiscussions, 'discussions');
|
|
59
|
-
const oldGraphs = readArr(legacyGraphs, 'graphs');
|
|
60
|
-
|
|
61
|
-
// Remap legacy type names to current 4-type schema
|
|
62
|
-
const TYPE_MAP = { architecture: 'note', code: 'note', error: 'bug', summary: 'compaction' };
|
|
63
|
-
const remapType = entry => {
|
|
64
|
-
if (TYPE_MAP[entry.type]) entry.type = TYPE_MAP[entry.type];
|
|
65
|
-
return entry;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
// Group everything by project name
|
|
69
|
-
const byProject = {};
|
|
70
|
-
const ensure = name => {
|
|
71
|
-
if (!byProject[name]) byProject[name] = {
|
|
72
|
-
context: [], graph: { build: null }, summary: [], discussions: [],
|
|
73
|
-
};
|
|
74
|
-
return byProject[name];
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
for (const entry of oldContexts) {
|
|
78
|
-
remapType(entry);
|
|
79
|
-
const p = entry.project || 'global';
|
|
80
|
-
const d = ensure(p);
|
|
81
|
-
if (treeFor(entry) === 'summary') d.summary.push(entry);
|
|
82
|
-
else d.context.push(entry);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
for (const disc of oldDiscussions) {
|
|
86
|
-
ensure(disc.project || 'global').discussions.push(disc);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
// Match graph build records to projects via rootPath
|
|
90
|
-
for (const graph of oldGraphs) {
|
|
91
|
-
const proj = projectsIndex.find(p => normPath(p.rootPath) === normPath(graph.path));
|
|
92
|
-
const name = proj ? proj.name : 'global';
|
|
93
|
-
const d = ensure(name);
|
|
94
|
-
d.graph.build = {
|
|
95
|
-
path: graph.path, nodes: graph.nodes, edges: graph.edges,
|
|
96
|
-
communities: graph.communities, cached: graph.cached || 0,
|
|
97
|
-
changed: graph.changed || 0, time_ms: graph.time_ms || 0,
|
|
98
|
-
summary: graph.summary || '', builtAt: graph.builtAt,
|
|
99
|
-
};
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Write per-project files
|
|
103
|
-
for (const [name, data] of Object.entries(byProject)) {
|
|
104
|
-
const dir = join(projectsDir, slugify(name));
|
|
105
|
-
mkdirSync(dir, { recursive: true });
|
|
106
|
-
flushFile(join(dir, 'context.json'), { entries: data.context });
|
|
107
|
-
flushFile(join(dir, 'graph.json'), data.graph);
|
|
108
|
-
flushFile(join(dir, 'summary.json'), { entries: data.summary });
|
|
109
|
-
flushFile(join(dir, 'discussions.json'), { discussions: data.discussions });
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Stamp dataDir onto each project record
|
|
113
|
-
for (const proj of projectsIndex) {
|
|
114
|
-
if (!proj.dataDir) proj.dataDir = `projects/${slugify(proj.name)}`;
|
|
115
|
-
}
|
|
116
|
-
flushFile(projectsPath, { projects: projectsIndex });
|
|
117
|
-
|
|
118
|
-
// Remove legacy flat files
|
|
119
|
-
try { unlinkSync(legacyContexts); } catch {}
|
|
120
|
-
try { unlinkSync(legacyDiscussions); } catch {}
|
|
121
|
-
try { unlinkSync(legacyGraphs); } catch {}
|
|
122
|
-
|
|
123
|
-
return true;
|
|
124
|
-
}
|
package/src/templates/AGENTS.md
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# Context-MCP — Codex CLI Usage Guide
|
|
2
|
-
|
|
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.
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## 1. Start of Every Conversation (MANDATORY)
|
|
9
|
-
|
|
10
|
-
Call the `context` MCP tool with `action: "resume"`, `project: "<project-name>"` **before anything else**.
|
|
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 }`
|
|
16
|
-
|
|
17
|
-
Then:
|
|
18
|
-
- `codegraph.built: true` → use `codegraph_query` before reading any files
|
|
19
|
-
- `codegraph.built: false` → call `codegraph_build(path)` first, then proceed
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## 2. When to Auto-Save Context
|
|
24
|
-
|
|
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
|
-
```
|
|
30
|
-
|
|
31
|
-
**User explicitly asks** — "save this", "remember this", "note that" → save immediately.
|
|
32
|
-
|
|
33
|
-
**During plan / implementation / discussion / research** — save only when genuinely valuable:
|
|
34
|
-
|
|
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` |
|
|
41
|
-
|
|
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`.
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
## 3. ContextGraph Pipeline
|
|
49
|
-
|
|
50
|
-
> The knowledge graph is also called **ContextGraph**. The MCP tools use the `codegraph_*` prefix — both names refer to the same thing.
|
|
51
|
-
|
|
52
|
-
### Step 1 — Build (once, fast, local)
|
|
53
|
-
```
|
|
54
|
-
codegraph_build(path) → AST graph: functions, classes, imports, edges
|
|
55
|
-
```
|
|
56
|
-
|
|
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
|
-
```
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
## 4. Graph vs File
|
|
68
|
-
|
|
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.
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
## 5. Rules
|
|
75
|
-
|
|
76
|
-
1. **`context.resume` first** — before any tool or response
|
|
77
|
-
2. **Always pass `project`**
|
|
78
|
-
3. **`search` before asking** — if user references past work
|
|
79
|
-
4. **`codegraph_query` before reading files** — graph is faster and cheaper
|
|
80
|
-
5. **Read files for bugs/logic only**
|
package/src/templates/CLAUDE.md
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: context-mcp
|
|
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".
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
# Context-MCP — Claude Usage Guide
|
|
10
|
-
|
|
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
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
## 1. Start of Every Conversation (MANDATORY)
|
|
17
|
-
|
|
18
|
-
Call `context` tool **before anything else** with:
|
|
19
|
-
- `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.
|
|
24
|
-
|
|
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 }`
|
|
29
|
-
|
|
30
|
-
Then:
|
|
31
|
-
- `codegraph.built: true` → use `codegraph_query` before reading any files
|
|
32
|
-
- `codegraph.built: false` → call `codegraph_build(path)` first, then proceed
|
|
33
|
-
|
|
34
|
-
---
|
|
35
|
-
|
|
36
|
-
## 2. When to Auto-Save Context
|
|
37
|
-
|
|
38
|
-
### Always save — no user prompt needed
|
|
39
|
-
|
|
40
|
-
**After graph build or rebuild** — every time `codegraph_build` completes:
|
|
41
|
-
```
|
|
42
|
-
context.save project: "<project>" type: "note" title: "ContextGraph built — <project>"
|
|
43
|
-
content: "nodes: X | edges: Y | communities: Z"
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
**User explicitly asks** — any phrase like "save this", "remember this", "note that" → save immediately.
|
|
47
|
-
|
|
48
|
-
**During plan / implementation / discussion / research** — save only when genuinely valuable:
|
|
49
|
-
|
|
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` |
|
|
56
|
-
|
|
57
|
-
Do NOT save: routine reads, search results, temporary debugging dead-ends.
|
|
58
|
-
|
|
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.
|
|
62
|
-
|
|
63
|
-
---
|
|
64
|
-
|
|
65
|
-
## 3. ContextGraph Pipeline
|
|
66
|
-
|
|
67
|
-
> The knowledge graph is also called **ContextGraph**. The MCP tools use the `codegraph_*` prefix — both names refer to the same thing.
|
|
68
|
-
|
|
69
|
-
### Step 1 — Build (once per project, fast, local)
|
|
70
|
-
```
|
|
71
|
-
codegraph_build(path)
|
|
72
|
-
```
|
|
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
|
-
|
|
78
|
-
### Step 2 — Query (free, instant, forever)
|
|
79
|
-
```
|
|
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
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
---
|
|
88
|
-
|
|
89
|
-
## 4. Graph vs File
|
|
90
|
-
|
|
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.
|
|
92
|
-
|
|
93
|
-
**File** — use for bugs, logic inside a specific function, tracing unexpected behavior.
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
## 5. Rules
|
|
98
|
-
|
|
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
|
package/src/templates/GEMINI.md
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# Context-MCP — Gemini CLI Usage Guide
|
|
2
|
-
|
|
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.
|
|
5
|
-
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
## 1. Start of Every Conversation (MANDATORY)
|
|
9
|
-
|
|
10
|
-
Call the `context` MCP tool with `action: "resume"`, `project: "<project-name>"` **before anything else**.
|
|
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 }`
|
|
16
|
-
|
|
17
|
-
Then:
|
|
18
|
-
- `codegraph.built: true` → use `codegraph_query` before reading any files
|
|
19
|
-
- `codegraph.built: false` → call `codegraph_build(path)` first, then proceed
|
|
20
|
-
|
|
21
|
-
---
|
|
22
|
-
|
|
23
|
-
## 2. When to Auto-Save Context
|
|
24
|
-
|
|
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
|
-
```
|
|
30
|
-
|
|
31
|
-
**User explicitly asks** — "save this", "remember this", "note that" → save immediately.
|
|
32
|
-
|
|
33
|
-
**During plan / implementation / discussion / research** — save only when genuinely valuable:
|
|
34
|
-
|
|
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` |
|
|
41
|
-
|
|
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`.
|
|
45
|
-
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
## 3. ContextGraph Pipeline
|
|
49
|
-
|
|
50
|
-
> The knowledge graph is also called **ContextGraph**. The MCP tools use the `codegraph_*` prefix — both names refer to the same thing.
|
|
51
|
-
|
|
52
|
-
### Step 1 — Build (once, fast, local)
|
|
53
|
-
```
|
|
54
|
-
codegraph_build(path) → AST graph: functions, classes, imports, edges
|
|
55
|
-
```
|
|
56
|
-
|
|
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
|
-
```
|
|
64
|
-
|
|
65
|
-
---
|
|
66
|
-
|
|
67
|
-
## 4. Graph vs File
|
|
68
|
-
|
|
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.
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
## 5. Rules
|
|
75
|
-
|
|
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
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
Call `codegraph_build` with the path `$ARGUMENTS` (if no argument given, use the current working directory).
|
|
2
|
-
|
|
3
|
-
This builds the ContextGraph for the project — parses all source files into an AST knowledge graph using tree-sitter. Takes a few seconds. Once built, use `codegraph_query` to answer any structural question about the codebase instead of reading files directly.
|
|
4
|
-
|
|
5
|
-
After build completes, report: total nodes, edges, and communities found.
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
Call the `context` MCP tool with `action: "save"` to store a note for the current project.
|
|
2
|
-
|
|
3
|
-
Parse `$ARGUMENTS` to determine:
|
|
4
|
-
- `project`: infer from current working directory name if not specified
|
|
5
|
-
- `title`: first sentence or phrase from the argument
|
|
6
|
-
- `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"`
|
|
8
|
-
|
|
9
|
-
Confirm to the user what was saved (title, type, project).
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: context-mcp
|
|
3
|
-
description: >
|
|
4
|
-
Persistent memory + ContextGraph (codebase knowledge graph) for Claude.
|
|
5
|
-
Use at the START of every conversation to resume project context. Use
|
|
6
|
-
whenever the user mentions a project, asks to remember/save something,
|
|
7
|
-
references past work, or says "pick up where we left off". Also use
|
|
8
|
-
when the user asks about code structure, dependencies, or what exists
|
|
9
|
-
in a codebase — query the ContextGraph before reading any files.
|
|
10
|
-
---
|
|
11
|
-
|
|
12
|
-
# Context-MCP
|
|
13
|
-
|
|
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.
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
## MANDATORY: Start of Every Conversation
|
|
20
|
-
|
|
21
|
-
Call `context` tool **before any tool or response** with:
|
|
22
|
-
- `action: "resume"`
|
|
23
|
-
- `project: "<basename of git repo root dir>"` — infer from `cwd` if not stated
|
|
24
|
-
- `rootPath: "<absolute path to git repo root>"` — required for sandbox + graph lookup
|
|
25
|
-
|
|
26
|
-
Both fields are required: `project` names the memory bucket, `rootPath` enables exact graph matching and file sandboxing.
|
|
27
|
-
|
|
28
|
-
Returns:
|
|
29
|
-
- `recentEntries` — decisions, bugs, notes from past sessions
|
|
30
|
-
- `activePlans` — active AI-created plans for this project
|
|
31
|
-
- `codegraph` — `{ built: true/false, nodes, edges, communities }`
|
|
32
|
-
|
|
33
|
-
Then:
|
|
34
|
-
- `codegraph.built: true` → use `codegraph_query` before reading any files
|
|
35
|
-
- `codegraph.built: false` → call `codegraph_build(path)` first, then proceed
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
|
-
## When to Auto-Save Context
|
|
40
|
-
|
|
41
|
-
### Always save — no user prompt needed
|
|
42
|
-
|
|
43
|
-
**1. After graph build or rebuild**
|
|
44
|
-
Every time `codegraph_build` completes successfully, immediately call:
|
|
45
|
-
```
|
|
46
|
-
context.save project: "<project>" type: "note" title: "ContextGraph built — <project>"
|
|
47
|
-
content: "nodes: X | edges: Y | communities: Z | built: <timestamp>"
|
|
48
|
-
```
|
|
49
|
-
|
|
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.
|
|
52
|
-
|
|
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
|
|
60
|
-
|
|
61
|
-
Do NOT save for: routine file reads, search results, explanations of existing code, temporary debugging steps that led nowhere.
|
|
62
|
-
|
|
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` |
|
|
69
|
-
|
|
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.
|
|
71
|
-
|
|
72
|
-
---
|
|
73
|
-
|
|
74
|
-
## ContextGraph Pipeline
|
|
75
|
-
|
|
76
|
-
> Also called **CodeGraph**. MCP tools use the `codegraph_*` prefix — both names mean the same thing.
|
|
77
|
-
|
|
78
|
-
### Build (once per project, ~seconds, local)
|
|
79
|
-
```
|
|
80
|
-
codegraph_build(path)
|
|
81
|
-
```
|
|
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
|
-
|
|
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
|
-
```
|
|
91
|
-
|
|
92
|
-
---
|
|
93
|
-
|
|
94
|
-
## Graph vs File
|
|
95
|
-
|
|
96
|
-
**Graph** — what exists: finding functions, classes, files, dependencies, callers, imports, paths between concepts.
|
|
97
|
-
|
|
98
|
-
**File** — bugs, logic inside a specific function, tracing unexpected behavior.
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## Rules
|
|
103
|
-
|
|
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
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
# Context-MCP — Windsurf Usage Guide
|
|
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.
|
|
5
|
-
|
|
6
|
-
## 1. Start of Every Conversation (MANDATORY)
|
|
7
|
-
|
|
8
|
-
Call `context` tool, `action: "resume"`, `project: "<project-name>"` before anything else.
|
|
9
|
-
|
|
10
|
-
Returns: `recentEntries`, `activePlans`, `codegraph { built, nodes, edges }`.
|
|
11
|
-
|
|
12
|
-
- `codegraph.built: true` → use `codegraph_query` before reading files
|
|
13
|
-
- `codegraph.built: false` → run `codegraph_build(path)` first
|
|
14
|
-
|
|
15
|
-
## 2. Save Context
|
|
16
|
-
|
|
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` |
|
|
23
|
-
|
|
24
|
-
## 3. CodeGraph
|
|
25
|
-
|
|
26
|
-
Build once: `codegraph_build(path)` — then query forever.
|
|
27
|
-
Use `codegraph_query` for structural questions. Read files for bugs/logic.
|
|
28
|
-
|
|
29
|
-
## Rules
|
|
30
|
-
|
|
31
|
-
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
|
|
File without changes
|