project-context-map-mcp 0.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.
@@ -0,0 +1,43 @@
1
+ ---
2
+ name: project-context-map
3
+ description: Use this skill when working in a large repository and you want Claude Code to avoid reading too many files. First consult the project context map or MCP tools, identify the most relevant files for the task, and only then inspect or edit code.
4
+ ---
5
+
6
+ # Project Context Map
7
+
8
+ Use this skill when a task involves code changes, debugging, or feature work in a medium or large repository.
9
+
10
+ ## Goal
11
+
12
+ Reduce token usage and speed up edits by using the project context map before opening source files.
13
+
14
+ ## Workflow
15
+
16
+ 1. Start with the MCP if it is available.
17
+ 2. Call `get_project_summary` to understand the architecture and hotspots.
18
+ 3. Call `get_module_context` when the task already points to a feature area.
19
+ 4. Call `find_relevant_files` with the user request.
20
+ 5. Read only the top-ranked files first.
21
+ 6. Expand to neighboring files only if the first pass is insufficient.
22
+ 7. After edits, call `refresh_project_map` so `.project-map.json` and `.project-map.md` stay current.
23
+
24
+ ## Fallback
25
+
26
+ If the MCP server is not available:
27
+
28
+ 1. Look for `.project-map.json` and `.project-map.md` in the project root.
29
+ 2. Use those files to identify relevant modules and files.
30
+ 3. Only after that, inspect code files directly.
31
+
32
+ ## Rules
33
+
34
+ - Do not begin by scanning the whole repository.
35
+ - Prefer targeted reads over broad tree walks.
36
+ - Use recent git changes as a signal when ranking files.
37
+ - Treat the project map as the primary onboarding artifact for the repo.
38
+
39
+ ## Example prompts
40
+
41
+ - "Use the project context map to find the files for fixing login refresh bugs."
42
+ - "Check the project map first, then suggest where export CSV should be implemented."
43
+ - "Refresh the project map after this feature is completed."
package/README.md ADDED
@@ -0,0 +1,500 @@
1
+ # Project Context Map MCP
2
+
3
+ <div align="center">
4
+
5
+ ### Give your coding agent a map before it starts wandering
6
+
7
+ Turn a repository into structured project memory for MCP clients like Claude Code, so they can query context, inspect only relevant files, and understand topology before touching code.
8
+
9
+ [![Node 20+](https://img.shields.io/badge/node-%3E%3D20-1f6feb?style=for-the-badge)](#installation)
10
+ [![MCP Server](https://img.shields.io/badge/mcp-server-0ea5e9?style=for-the-badge)](#mcp-tools)
11
+ [![Project Memory](https://img.shields.io/badge/project-memory-16a34a?style=for-the-badge)](#what-it-generates)
12
+ [![Topology Aware](https://img.shields.io/badge/topology-imports%20%26%20usage-f59e0b?style=for-the-badge)](#topology--visual-graph)
13
+
14
+ </div>
15
+
16
+ ---
17
+
18
+ ## Why This Exists
19
+
20
+ AI coding tools often begin the same way in a medium or large repo:
21
+
22
+ - they read too many files
23
+ - they spend tokens on unrelated areas
24
+ - they rebuild context from scratch every time
25
+ - they miss the real dependency chain behind a feature or bug
26
+
27
+ `project-context-map-mcp` fixes that by generating a lightweight project memory and exposing it through MCP tools.
28
+
29
+ Instead of:
30
+
31
+ `scan everything -> guess -> open random files`
32
+
33
+ you get:
34
+
35
+ `index first -> query topology -> read sparse files -> edit with context`
36
+
37
+ ---
38
+
39
+ ## What This Project Does
40
+
41
+ This package gives you:
42
+
43
+ - an MCP server for project-aware queries
44
+ - a CLI to generate and refresh repository memory
45
+ - a readable `.project.md` with topology highlights and change log
46
+ - a machine-readable `.project-map.json`
47
+ - a human-readable `.project-map.md`
48
+ - import/dependency relationships between files
49
+ - sparse file access limited to indexed paths
50
+ - MCP-assisted writes with automatic logging
51
+ - Claude Code setup helpers and skill generation
52
+
53
+ ---
54
+
55
+ ## At A Glance
56
+
57
+ | Part | Purpose |
58
+ | --- | --- |
59
+ | `.project.md` | Main readable project memory for humans and agents |
60
+ | `.project-map.json` | Structured index used by tools |
61
+ | `.project-map.md` | Lightweight markdown summary |
62
+ | `read_project_context` | Returns `.project.md` |
63
+ | `query_topology` | Finds relevant files from natural-language queries |
64
+ | `read_files_sparse` | Reads only indexed files |
65
+ | `write_and_log` | Writes changes and appends to `.project.md` Change Log |
66
+
67
+ ---
68
+
69
+ ## Installation
70
+
71
+ ### Option 1: Global install
72
+
73
+ Best if you want to use it across many repositories.
74
+
75
+ ```bash
76
+ npm install -g project-context-map-mcp
77
+ ```
78
+
79
+ ### Option 2: Local install
80
+
81
+ Best if you want it only inside one project.
82
+
83
+ ```bash
84
+ npm install project-context-map-mcp
85
+ ```
86
+
87
+ ### Requirements
88
+
89
+ - Node.js `20` or newer
90
+ - an MCP-compatible client such as Claude Code
91
+
92
+ ---
93
+
94
+ ## Quick Start
95
+
96
+ ### 1. Generate the project memory
97
+
98
+ Run this from the root of the repo you want to index:
99
+
100
+ ```bash
101
+ project-context-map-mcp refresh --project-root .
102
+ ```
103
+
104
+ This creates:
105
+
106
+ - `.project.md`
107
+ - `.project-map.json`
108
+ - `.project-map.md`
109
+
110
+ ### 2. Configure Claude Code for that repo
111
+
112
+ ```bash
113
+ project-context-map-mcp configure-claude --project-root .
114
+ ```
115
+
116
+ This creates or updates:
117
+
118
+ - `.mcp.json`
119
+ - `.claude/skills/project-context-map/SKILL.md`
120
+
121
+ ### 3. Start the MCP server
122
+
123
+ If your client starts the server from `.mcp.json`, you usually do not need to run it manually.
124
+
125
+ If you want to run it yourself:
126
+
127
+ ```bash
128
+ project-context-map-mcp serve --project-root .
129
+ ```
130
+
131
+ ### 4. Use it from your MCP client
132
+
133
+ Typical flow:
134
+
135
+ 1. read the project context
136
+ 2. query topology with a natural-language task
137
+ 3. read only the matched files
138
+ 4. make changes
139
+ 5. refresh the map
140
+
141
+ ---
142
+
143
+ ## MCP Config
144
+
145
+ If you want to wire the server manually, add this to your MCP config:
146
+
147
+ ```json
148
+ {
149
+ "mcpServers": {
150
+ "project-context-map": {
151
+ "command": "project-context-map-mcp",
152
+ "args": ["serve", "--project-root", "."],
153
+ "env": {}
154
+ }
155
+ }
156
+ }
157
+ ```
158
+
159
+ ### Generate it automatically
160
+
161
+ ```bash
162
+ project-context-map-mcp print-mcp-config --project-root .
163
+ ```
164
+
165
+ ### Write it into the repo
166
+
167
+ ```bash
168
+ project-context-map-mcp configure-claude --project-root .
169
+ ```
170
+
171
+ ---
172
+
173
+ ## CLI Commands
174
+
175
+ ```bash
176
+ project-context-map-mcp serve --project-root .
177
+ project-context-map-mcp refresh --project-root .
178
+ project-context-map-mcp install-hooks --project-root .
179
+ project-context-map-mcp configure-claude --project-root .
180
+ project-context-map-mcp print-mcp-config --project-root .
181
+ project-context-map-mcp help
182
+ ```
183
+
184
+ <details>
185
+ <summary><strong>Command details</strong></summary>
186
+
187
+ | Command | What it does |
188
+ | --- | --- |
189
+ | `serve` | Starts the MCP server over stdio |
190
+ | `refresh` | Regenerates `.project.md`, `.project-map.json`, and `.project-map.md` |
191
+ | `install-hooks` | Installs git hooks to keep the map refreshed |
192
+ | `configure-claude` | Creates repo-local Claude Code skill and `.mcp.json` |
193
+ | `print-mcp-config` | Prints the MCP config JSON without writing files |
194
+ | `help` | Shows command help |
195
+
196
+ </details>
197
+
198
+ ---
199
+
200
+ ## MCP Tools
201
+
202
+ These are the main tools exposed by the server.
203
+
204
+ ### Core workflow tools
205
+
206
+ | Tool | Purpose |
207
+ | --- | --- |
208
+ | `read_project_context` | Returns `.project.md` content |
209
+ | `query_topology` | Takes a natural-language query and returns matched file paths from the query index |
210
+ | `read_files_sparse` | Reads file content only for indexed paths |
211
+ | `write_and_log` | Writes file changes and appends an entry to `.project.md` Change Log |
212
+
213
+ ### Additional tools
214
+
215
+ | Tool | Purpose |
216
+ | --- | --- |
217
+ | `get_project_summary` | Returns summary, stack, modules, hotspots |
218
+ | `refresh_project_map` | Regenerates the project memory artifacts |
219
+ | `get_module_context` | Returns a focused view of one module |
220
+ | `find_relevant_files` | Legacy ranking-oriented file query |
221
+ | `get_recent_git_changes` | Summarizes recent git activity |
222
+ | `explain_file_role` | Explains a file’s role and recent changes |
223
+
224
+ <details>
225
+ <summary><strong>What each core tool returns</strong></summary>
226
+
227
+ ### `read_project_context`
228
+
229
+ Returns:
230
+
231
+ - `.project.md` path
232
+ - full markdown content
233
+
234
+ ### `query_topology`
235
+
236
+ Returns:
237
+
238
+ - matched file paths
239
+ - confidence score
240
+ - match reasons
241
+ - per-file dependencies
242
+ - per-file `usedBy` relationships
243
+
244
+ ### `read_files_sparse`
245
+
246
+ Returns:
247
+
248
+ - file content for indexed files
249
+ - safe errors for files outside the repo or outside the known topology
250
+
251
+ ### `write_and_log`
252
+
253
+ Returns:
254
+
255
+ - path written
256
+ - bytes written
257
+ - appended change log entry
258
+
259
+ </details>
260
+
261
+ ---
262
+
263
+ ## Recommended Workflow
264
+
265
+ ```mermaid
266
+ flowchart LR
267
+ A[Refresh project map] --> B[Read .project.md]
268
+ B --> C[Query topology]
269
+ C --> D[Read sparse files]
270
+ D --> E[Implement change]
271
+ E --> F[Write and log]
272
+ F --> G[Refresh project map]
273
+ ```
274
+
275
+ ### Example task flow
276
+
277
+ User asks:
278
+
279
+ ```text
280
+ Fix the login bug where session expires after refresh
281
+ ```
282
+
283
+ Recommended agent behavior:
284
+
285
+ 1. call `read_project_context`
286
+ 2. call `query_topology` with the task
287
+ 3. call `read_files_sparse` with the matched file paths
288
+ 4. inspect only those files first
289
+ 5. edit code
290
+ 6. call `write_and_log` if using MCP-managed writes
291
+ 7. call `refresh_project_map`
292
+
293
+ ---
294
+
295
+ ## Topology & Visual Graph
296
+
297
+ The project map is not only a file list. It also extracts internal relationships such as:
298
+
299
+ - JavaScript and TypeScript imports
300
+ - CommonJS `require(...)` usage
301
+ - basic Python import detection
302
+ - reverse usage information with `used_by`
303
+
304
+ That data is written into:
305
+
306
+ - `.project-map.json`
307
+ - `.project.md`
308
+
309
+ `.project.md` includes a Mermaid graph so markdown viewers that support Mermaid can render a visual dependency map.
310
+
311
+ ---
312
+
313
+ ## What It Generates
314
+
315
+ ### `.project.md`
316
+
317
+ The main working document. It includes:
318
+
319
+ - project summary
320
+ - key modules
321
+ - query index preview
322
+ - topology highlights
323
+ - Mermaid dependency graph
324
+ - running change log
325
+
326
+ ### `.project-map.json`
327
+
328
+ The structured source of truth. It includes fields such as:
329
+
330
+ - `project_summary`
331
+ - `tech_stack`
332
+ - `modules`
333
+ - `files`
334
+ - `topology`
335
+ - `entrypoints`
336
+ - `dependencies`
337
+ - `recent_changes`
338
+ - `hotspots`
339
+
340
+ ### `.project-map.md`
341
+
342
+ A shorter human-readable summary.
343
+
344
+ ---
345
+
346
+ ## Claude Code Setup
347
+
348
+ After running:
349
+
350
+ ```bash
351
+ project-context-map-mcp configure-claude --project-root .
352
+ ```
353
+
354
+ your repo will contain:
355
+
356
+ ```text
357
+ .mcp.json
358
+ .claude/skills/project-context-map/SKILL.md
359
+ ```
360
+
361
+ The generated skill tells Claude Code to:
362
+
363
+ - consult project memory first
364
+ - avoid broad repo scans
365
+ - query relevant files before opening source
366
+ - refresh the project map after edits
367
+
368
+ ---
369
+
370
+ ## Git Hooks
371
+
372
+ If you want the map to stay fresh automatically:
373
+
374
+ ```bash
375
+ project-context-map-mcp install-hooks --project-root .
376
+ ```
377
+
378
+ This installs:
379
+
380
+ - `post-commit`
381
+ - `post-merge`
382
+ - `post-push`
383
+
384
+ Each hook refreshes the project memory after repository activity.
385
+
386
+ ---
387
+
388
+ ## Interactive Setup Guide
389
+
390
+ <details open>
391
+ <summary><strong>I just installed it. What should I do next?</strong></summary>
392
+
393
+ 1. Go to your repo root.
394
+ 2. Run `project-context-map-mcp refresh --project-root .`
395
+ 3. Run `project-context-map-mcp configure-claude --project-root .`
396
+ 4. Open the repo in Claude Code.
397
+ 5. Approve the MCP server from `.mcp.json`.
398
+ 6. Ask the agent to use `read_project_context` and `query_topology` first.
399
+
400
+ </details>
401
+
402
+ <details>
403
+ <summary><strong>I want to use my own MCP config instead of the generated one</strong></summary>
404
+
405
+ Use:
406
+
407
+ ```bash
408
+ project-context-map-mcp print-mcp-config --project-root .
409
+ ```
410
+
411
+ Then copy the JSON into your own MCP config file and adjust:
412
+
413
+ - server name
414
+ - command path
415
+ - working project root
416
+
417
+ </details>
418
+
419
+ <details>
420
+ <summary><strong>I only want the package inside one repo</strong></summary>
421
+
422
+ Install locally:
423
+
424
+ ```bash
425
+ npm install project-context-map-mcp
426
+ ```
427
+
428
+ Then run through `npx`:
429
+
430
+ ```bash
431
+ npx project-context-map-mcp refresh --project-root .
432
+ npx project-context-map-mcp configure-claude --project-root .
433
+ ```
434
+
435
+ </details>
436
+
437
+ <details>
438
+ <summary><strong>How do I know it is working?</strong></summary>
439
+
440
+ You should see:
441
+
442
+ - `.project.md`
443
+ - `.project-map.json`
444
+ - `.project-map.md`
445
+ - `.mcp.json` after Claude setup
446
+
447
+ You can also run:
448
+
449
+ ```bash
450
+ project-context-map-mcp help
451
+ project-context-map-mcp refresh --project-root .
452
+ ```
453
+
454
+ </details>
455
+
456
+ ---
457
+
458
+ ## Example Prompts For Your MCP Client
459
+
460
+ - `Read the project context first, then find the files involved in session refresh logic.`
461
+ - `Use query_topology to locate the API and UI files for export CSV.`
462
+ - `Check .project.md before making changes.`
463
+ - `Refresh the project map after this feature is complete.`
464
+ - `Find the files that control authentication and read only those files first.`
465
+
466
+ ---
467
+
468
+ ## Best Fit Repositories
469
+
470
+ - Node.js applications
471
+ - React apps
472
+ - Next.js projects
473
+ - mixed frontend/backend repos
474
+ - Python services
475
+ - large internal tools where AI agents are used often
476
+
477
+ ---
478
+
479
+ ## Local Development
480
+
481
+ ```bash
482
+ npm install
483
+ npm run check
484
+ node src/cli.js refresh --project-root .
485
+ node src/cli.js serve --project-root .
486
+ ```
487
+
488
+ ---
489
+
490
+ ## Current Limitations
491
+
492
+ - topology detection is strongest for JS, TS, and simple Python import patterns
493
+ - visual graph output is Mermaid markdown, not a full interactive web app
494
+ - natural-language ranking quality depends on file names, summaries, tags, and recent changes
495
+
496
+ ---
497
+
498
+ ## License
499
+
500
+ MIT
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "project-context-map-mcp",
3
+ "version": "0.1.0",
4
+ "description": "MCP server and Claude Code skill for project-aware code changes with low token usage.",
5
+ "type": "module",
6
+ "main": "src/cli.js",
7
+ "bin": {
8
+ "project-context-map-mcp": "./src/cli.js"
9
+ },
10
+ "scripts": {
11
+ "mcp": "node src/cli.js serve",
12
+ "refresh-map": "node src/cli.js refresh",
13
+ "install-hooks": "node src/cli.js install-hooks",
14
+ "configure-claude": "node src/cli.js configure-claude",
15
+ "print-mcp-config": "node src/cli.js print-mcp-config",
16
+ "check": "node --check src/cli.js && node --check src/server.js && node --check scripts/refresh-map.js && node --check scripts/install-git-hooks.js"
17
+ },
18
+ "keywords": [
19
+ "mcp",
20
+ "claude-code",
21
+ "copilot",
22
+ "context-map",
23
+ "project-memory"
24
+ ],
25
+ "author": "",
26
+ "license": "MIT",
27
+ "files": [
28
+ "src",
29
+ "scripts",
30
+ ".claude/skills/project-context-map/SKILL.md",
31
+ "README.md"
32
+ ],
33
+ "dependencies": {
34
+ "@modelcontextprotocol/sdk": "^1.12.1"
35
+ },
36
+ "engines": {
37
+ "node": ">=20"
38
+ }
39
+ }
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node scripts/refresh-map.js >/dev/null 2>&1 || true
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node scripts/refresh-map.js >/dev/null 2>&1 || true
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ node scripts/refresh-map.js >/dev/null 2>&1 || true
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { isGitRepository } from "../src/git.js";
6
+
7
+ function buildHook(name, projectRoot) {
8
+ return `#!/bin/sh
9
+ project-context-map-mcp refresh --project-root "${projectRoot}" >/dev/null 2>&1 || true
10
+ `;
11
+ }
12
+
13
+ export function installGitHooks(projectRoot = process.cwd()) {
14
+ if (!isGitRepository(projectRoot)) {
15
+ process.stderr.write("No git repository detected. Skipping hook installation.\n");
16
+ return;
17
+ }
18
+
19
+ const targetDir = path.join(projectRoot, ".git", "hooks");
20
+
21
+ for (const name of ["post-commit", "post-merge", "post-push"]) {
22
+ const target = path.join(targetDir, name);
23
+ fs.writeFileSync(target, buildHook(name, projectRoot), "utf8");
24
+ fs.chmodSync(target, 0o755);
25
+ }
26
+
27
+ process.stdout.write("Installed git hooks: post-commit, post-merge, post-push\n");
28
+ }
29
+
30
+ if (import.meta.url === `file://${process.argv[1]}`) {
31
+ installGitHooks(process.argv[2] || process.cwd());
32
+ }
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { refreshProjectMap } from "../src/indexer.js";
4
+
5
+ export function refreshMapCli(projectRoot = process.env.PROJECT_ROOT || process.cwd()) {
6
+ const result = refreshProjectMap(projectRoot);
7
+
8
+ process.stdout.write(
9
+ `${JSON.stringify(
10
+ {
11
+ message: "Project map refreshed.",
12
+ jsonPath: result.jsonPath,
13
+ markdownPath: result.markdownPath,
14
+ projectMarkdownPath: result.projectMarkdownPath,
15
+ totalFiles: result.projectMap.stats.totalFiles,
16
+ generatedAt: result.projectMap.generatedAt
17
+ },
18
+ null,
19
+ 2
20
+ )}\n`
21
+ );
22
+ }
23
+
24
+ if (import.meta.url === `file://${process.argv[1]}`) {
25
+ refreshMapCli(process.argv[2] || process.env.PROJECT_ROOT || process.cwd());
26
+ }