project-context-map-mcp 0.1.2 → 0.1.6

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/PROMPTS.md ADDED
@@ -0,0 +1,98 @@
1
+ # Prompt Pack
2
+
3
+ This file contains tested starter prompts for `project-context-map-mcp`.
4
+
5
+ These prompts are written for MCP clients such as Claude Code, Cursor, and VS Code Copilot Chat after the server is already connected.
6
+
7
+ ## Best General Starter
8
+
9
+ ```text
10
+ Use the `project-context-map` MCP server first. Get the project summary, find the files most relevant to this task: [task], and read only those files before proposing or making changes.
11
+ ```
12
+
13
+ ## Repo Understanding
14
+
15
+ ```text
16
+ Use the project context map to summarize this repository: main purpose, entrypoints, top modules, hotspots, and how the CLI, server, and indexer fit together.
17
+ ```
18
+
19
+ ```text
20
+ Use the `project-context-map` MCP server first. Get the project summary, then inspect `src/cli.js`, `src/server.js`, and the project map generation code to explain how startup and indexing work.
21
+ ```
22
+
23
+ ## Bug Investigation
24
+
25
+ ```text
26
+ Use the MCP tools to investigate this bug: [bug description]. Start with the project summary, find the relevant files, read only those files, explain the likely root cause, and then propose or apply a fix.
27
+ ```
28
+
29
+ ```text
30
+ Use the project topology first for this issue: [bug description]. Prefer source files over docs, then inspect only the matched files.
31
+ ```
32
+
33
+ ## Feature Work
34
+
35
+ ```text
36
+ I want to add [feature]. Use the project map to identify the impacted modules, relevant files, and likely downstream effects before editing anything.
37
+ ```
38
+
39
+ ```text
40
+ Use the `project-context-map` MCP server to find the code paths involved in [feature]. Read only the matched files and make the smallest safe change.
41
+ ```
42
+
43
+ ## Targeted Code Search
44
+
45
+ ```text
46
+ Use `query_topology` to find all files related to npm publishing, package configuration, and release safety checks. Then read only the matched source and config files.
47
+ ```
48
+
49
+ ```text
50
+ Use the MCP tools to find where [system or feature area] is implemented. Show the matched files and why they matter before editing code.
51
+ ```
52
+
53
+ ## Module Understanding
54
+
55
+ ```text
56
+ Use `get_module_context` for `src` and explain how the CLI, MCP server, ranking, and project map generation fit together.
57
+ ```
58
+
59
+ ```text
60
+ Explain the role of `src/cli.js` and how it interacts with `src/server.js`, using the project map and recent changes.
61
+ ```
62
+
63
+ ## Change Risk
64
+
65
+ ```text
66
+ Use the project map and recent git changes to tell me which files are riskiest to modify for [task].
67
+ ```
68
+
69
+ ```text
70
+ Check recent git changes and project hotspots, then identify the safest place to implement [task].
71
+ ```
72
+
73
+ ## Prompt Writing Tips
74
+
75
+ - Broad prompts often rank docs first, especially for words like `project`, `map`, or `MCP`.
76
+ - More precise prompts work better when they mention specific files, modules, or feature areas.
77
+ - A strong workflow is: `get_project_summary` -> `find_relevant_files` or `query_topology` -> `read_files_sparse`.
78
+ - For debugging and implementation, prefer prompts that say `prefer source files over docs`.
79
+
80
+ ## Client-Specific Versions
81
+
82
+ ### Claude Code
83
+
84
+ ```text
85
+ Use the `project-context-map` MCP server first. Start with `get_project_summary`, then find the files most relevant to [task], and read only the necessary files before making changes.
86
+ ```
87
+
88
+ ### Cursor
89
+
90
+ ```text
91
+ Use the connected MCP server `project-context-map` for repo understanding. First get a project summary, then query the most relevant files for: [task]. Read only those files, explain your plan briefly, and then implement the change.
92
+ ```
93
+
94
+ ### VS Code Copilot Chat
95
+
96
+ ```text
97
+ Use the `project-context-map` MCP server to summarize this repo and identify the files relevant to [task].
98
+ ```
package/README.md CHANGED
@@ -11,6 +11,8 @@ Turn a repository into structured project memory for MCP clients like Claude Cod
11
11
  [![Project Memory](https://img.shields.io/badge/project-memory-16a34a?style=for-the-badge)](#what-it-generates)
12
12
  [![Topology Aware](https://img.shields.io/badge/topology-imports%20%26%20usage-f59e0b?style=for-the-badge)](#topology--visual-graph)
13
13
 
14
+ [![Project Context Map MCP server](https://mcprush.com/badge/project-context-map-mcp/card.svg)](https://mcprush.com/to/project-context-map-mcp?ref=badge)
15
+
14
16
  </div>
15
17
 
16
18
  ---
@@ -138,6 +140,11 @@ Typical flow:
138
140
  4. make changes
139
141
  5. refresh the map
140
142
 
143
+ Prompt examples:
144
+
145
+ - See [PROMPTS.md](./PROMPTS.md) for tested starter prompts for Claude Code, Cursor, and VS Code Copilot Chat.
146
+ - For best results, use prompts that name the feature area, module, or source files you want the agent to inspect.
147
+
141
148
  ---
142
149
 
143
150
  ## MCP Config
@@ -457,11 +464,14 @@ project-context-map-mcp refresh --project-root .
457
464
 
458
465
  ## Example Prompts For Your MCP Client
459
466
 
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.`
467
+ Tested prompt templates now live in [PROMPTS.md](./PROMPTS.md).
468
+
469
+ Quick examples:
470
+
471
+ - `Use the project context map first, then find the files involved in session refresh logic.`
472
+ - `Use query_topology to locate the files related to npm publishing, package configuration, and release safety checks.`
473
+ - `Use get_module_context for src and explain how the CLI and MCP server fit together.`
474
+ - `Find the files that control authentication and prefer source files over docs.`
465
475
 
466
476
  ---
467
477
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "project-context-map-mcp",
3
- "version": "0.1.2",
4
- "description": "MCP server and Claude Code skill for project-aware code changes with low token usage.",
3
+ "version": "0.1.6",
4
+ "description": "MCP server and Claude Code skill for project-aware code changes with low token usage.\nmcprush.com-2ae221dd5221ac77c562f870",
5
5
  "type": "module",
6
6
  "main": "src/cli.js",
7
7
  "bin": {
@@ -13,7 +13,7 @@
13
13
  "install-hooks": "node src/cli.js install-hooks",
14
14
  "configure-claude": "node src/cli.js configure-claude",
15
15
  "print-mcp-config": "node src/cli.js print-mcp-config",
16
- "lint": "node --check src/cli.js && node --check src/claude.js && node --check src/git.js && node --check src/indexer.js && node --check src/ranker.js && node --check src/server.js && node --check src/utils.js && node --check scripts/install-git-hooks.js && node --check scripts/refresh-map.js && node --check test/claude.test.js && node --check test/helpers.js && node --check test/indexer.test.js && node --check test/ranker.test.js && node --check test/utils.test.js",
16
+ "lint": "node --check src/cli.js && node --check src/claude.js && node --check src/git.js && node --check src/indexer.js && node --check src/ranker.js && node --check src/server.js && node --check src/utils.js && node --check scripts/install-git-hooks.js && node --check scripts/refresh-map.js && node --check test/claude.test.js && node --check test/helpers.js && node --check test/hooks.test.js && node --check test/indexer.test.js && node --check test/ranker.test.js && node --check test/server.test.js && node --check test/utils.test.js",
17
17
  "check": "npm run lint && npm test",
18
18
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --runInBand",
19
19
  "prepublishOnly": "npm run check"
@@ -31,6 +31,7 @@
31
31
  "src",
32
32
  "scripts",
33
33
  ".claude/skills/project-context-map/SKILL.md",
34
+ "PROMPTS.md",
34
35
  "README.md"
35
36
  ],
36
37
  "dependencies": {
@@ -1,26 +1,45 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { execFileSync } from "node:child_process";
3
4
  import fs from "node:fs";
4
5
  import path from "node:path";
5
6
  import { isGitRepository } from "../src/git.js";
6
7
 
7
- function buildHook(name, projectRoot) {
8
+ function shellQuote(value) {
9
+ return `'${String(value).replace(/'/g, "'\\''")}'`;
10
+ }
11
+
12
+ export function buildHook(name, projectRoot) {
13
+ const resolvedRoot = path.resolve(projectRoot);
8
14
  return `#!/bin/sh
9
- project-context-map-mcp refresh --project-root "${projectRoot}" >/dev/null 2>&1 || true
15
+ project-context-map-mcp refresh --project-root ${shellQuote(resolvedRoot)} >/dev/null 2>&1 || true
10
16
  `;
11
17
  }
12
18
 
19
+ function resolveHooksDir(projectRoot) {
20
+ const resolvedRoot = path.resolve(projectRoot);
21
+ const gitHooksPath = execFileSync("git", ["-C", resolvedRoot, "rev-parse", "--git-path", "hooks"], {
22
+ encoding: "utf8",
23
+ stdio: ["ignore", "pipe", "ignore"]
24
+ }).trim();
25
+
26
+ return path.resolve(resolvedRoot, gitHooksPath);
27
+ }
28
+
13
29
  export function installGitHooks(projectRoot = process.cwd()) {
14
- if (!isGitRepository(projectRoot)) {
30
+ const resolvedRoot = path.resolve(projectRoot);
31
+
32
+ if (!isGitRepository(resolvedRoot)) {
15
33
  process.stderr.write("No git repository detected. Skipping hook installation.\n");
16
34
  return;
17
35
  }
18
36
 
19
- const targetDir = path.join(projectRoot, ".git", "hooks");
37
+ const targetDir = resolveHooksDir(resolvedRoot);
38
+ fs.mkdirSync(targetDir, { recursive: true });
20
39
 
21
40
  for (const name of ["post-commit", "post-merge", "post-push"]) {
22
41
  const target = path.join(targetDir, name);
23
- fs.writeFileSync(target, buildHook(name, projectRoot), "utf8");
42
+ fs.writeFileSync(target, buildHook(name, resolvedRoot), "utf8");
24
43
  fs.chmodSync(target, 0o755);
25
44
  }
26
45
 
package/src/server.js CHANGED
@@ -30,12 +30,59 @@ function asTextResult(payload) {
30
30
  };
31
31
  }
32
32
 
33
+ function asErrorResult(message) {
34
+ return {
35
+ isError: true,
36
+ content: [
37
+ {
38
+ type: "text",
39
+ text: JSON.stringify({ error: message }, null, 2)
40
+ }
41
+ ]
42
+ };
43
+ }
44
+
45
+ function requireNonEmptyString(value, fieldName) {
46
+ if (typeof value !== "string" || value.trim().length === 0) {
47
+ throw new Error(`Invalid "${fieldName}": expected a non-empty string.`);
48
+ }
49
+ return value;
50
+ }
51
+
52
+ function requireString(value, fieldName) {
53
+ if (typeof value !== "string") {
54
+ throw new Error(`Invalid "${fieldName}": expected a string.`);
55
+ }
56
+ return value;
57
+ }
58
+
59
+ function requireStringArray(value, fieldName) {
60
+ if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
61
+ throw new Error(`Invalid "${fieldName}": expected an array of strings.`);
62
+ }
63
+ return value;
64
+ }
65
+
66
+ function parsePositiveInt(value, fallback, fieldName, max = 1000) {
67
+ if (value === undefined || value === null) {
68
+ return fallback;
69
+ }
70
+ const parsed = typeof value === "number" ? value : Number(value);
71
+ if (!Number.isInteger(parsed) || parsed < 1) {
72
+ throw new Error(`Invalid "${fieldName}": expected a positive integer.`);
73
+ }
74
+ return Math.min(parsed, max);
75
+ }
76
+
33
77
  function getRoot(args) {
78
+ if (args?.projectRoot !== undefined && typeof args.projectRoot !== "string") {
79
+ throw new Error('Invalid "projectRoot": expected a string.');
80
+ }
34
81
  return resolveProjectRoot(args?.projectRoot);
35
82
  }
36
83
 
37
84
  export function createServer() {
38
- return new Server(
85
+ const instance = new Server(
39
86
  {
40
87
  name: "project-context-map",
41
88
  version: "0.1.0"
@@ -48,11 +95,13 @@ export function createServer() {
48
95
  "Use project map tools before reading many files. Prefer get_project_summary and find_relevant_files first, then inspect only the returned files."
49
96
  }
50
97
  );
51
- }
52
98
 
53
- const server = createServer();
99
+ registerHandlers(instance);
100
+ return instance;
101
+ }
54
102
 
55
- server.setRequestHandler(ListToolsRequestSchema, async () => {
103
+ function registerHandlers(targetServer) {
104
+ targetServer.setRequestHandler(ListToolsRequestSchema, async () => {
56
105
  return {
57
106
  tools: [
58
107
  {
@@ -251,107 +300,125 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
251
300
  };
252
301
  });
253
302
 
254
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
255
- const { name, arguments: args = {} } = request.params;
303
+ targetServer.setRequestHandler(CallToolRequestSchema, async (request) => {
304
+ const { name, arguments: args = {} } = request.params;
256
305
 
257
- if (name === "read_project_context") {
258
- return asTextResult(readProjectContext(getRoot(args)));
259
- }
306
+ try {
307
+ if (name === "read_project_context") {
308
+ return asTextResult(readProjectContext(getRoot(args)));
309
+ }
260
310
 
261
- if (name === "query_topology") {
262
- const projectMap = loadProjectMap(getRoot(args));
263
- const result = findRelevantFiles(args.query, projectMap, Number(args.limit || 8));
264
- const matchedPaths = result.matches.map((item) => item.path);
265
- const topology = matchedPaths.map((filePath) => {
266
- const file = projectMap.files.find((item) => item.path === filePath);
267
- return {
268
- path: filePath,
269
- module: file?.module || "",
270
- dependencies: file?.dependencies || [],
271
- usedBy: file?.used_by || []
272
- };
273
- });
311
+ if (name === "query_topology") {
312
+ const query = requireNonEmptyString(args.query, "query");
313
+ const limit = parsePositiveInt(args.limit, 8, "limit", 100);
314
+ const projectMap = loadProjectMap(getRoot(args));
315
+ const result = findRelevantFiles(query, projectMap, limit);
316
+ const matchedPaths = result.matches.map((item) => item.path);
317
+ const topology = matchedPaths.map((filePath) => {
318
+ const file = projectMap.files.find((item) => item.path === filePath);
319
+ return {
320
+ path: filePath,
321
+ module: file?.module || "",
322
+ dependencies: file?.dependencies || [],
323
+ usedBy: file?.used_by || []
324
+ };
325
+ });
274
326
 
275
- return asTextResult({
276
- query: args.query,
277
- matchedPaths,
278
- confidence: result.confidence,
279
- matches: result.matches,
280
- topology
281
- });
282
- }
327
+ return asTextResult({
328
+ query,
329
+ matchedPaths,
330
+ confidence: result.confidence,
331
+ matches: result.matches,
332
+ topology
333
+ });
334
+ }
283
335
 
284
- if (name === "read_files_sparse") {
285
- return asTextResult(readFilesSparse(getRoot(args), args.paths || []));
286
- }
336
+ if (name === "read_files_sparse") {
337
+ const paths = requireStringArray(args.paths ?? [], "paths");
338
+ return asTextResult(readFilesSparse(getRoot(args), paths));
339
+ }
287
340
 
288
- if (name === "write_and_log") {
289
- return asTextResult(writeAndLog(getRoot(args), args.path, args.content, args.summary || ""));
290
- }
341
+ if (name === "write_and_log") {
342
+ const targetPath = requireNonEmptyString(args.path, "path");
343
+ const content = requireString(args.content, "content");
344
+ const summary = args.summary === undefined ? "" : requireString(args.summary, "summary");
345
+ return asTextResult(writeAndLog(getRoot(args), targetPath, content, summary));
346
+ }
291
347
 
292
- if (name === "get_project_summary") {
293
- const projectMap = loadProjectMap(getRoot(args));
294
- return asTextResult({
295
- projectRoot: projectMap.projectRoot,
296
- generatedAt: projectMap.generatedAt,
297
- projectSummary: projectMap.project_summary,
298
- techStack: projectMap.tech_stack,
299
- stats: projectMap.stats,
300
- entrypoints: projectMap.entrypoints,
301
- topModules: projectMap.modules.slice(0, 12),
302
- hotspots: (projectMap.hotspots || []).slice(0, 10)
303
- });
304
- }
348
+ if (name === "get_project_summary") {
349
+ const projectMap = loadProjectMap(getRoot(args));
350
+ return asTextResult({
351
+ projectRoot: projectMap.projectRoot,
352
+ generatedAt: projectMap.generatedAt,
353
+ projectSummary: projectMap.project_summary,
354
+ techStack: projectMap.tech_stack,
355
+ stats: projectMap.stats,
356
+ entrypoints: projectMap.entrypoints,
357
+ topModules: projectMap.modules.slice(0, 12),
358
+ hotspots: (projectMap.hotspots || []).slice(0, 10)
359
+ });
360
+ }
305
361
 
306
- if (name === "refresh_project_map") {
307
- const result = refreshProjectMap(getRoot(args));
308
- return asTextResult({
309
- message: "Project map refreshed.",
310
- jsonPath: result.jsonPath,
311
- markdownPath: result.markdownPath,
312
- projectMarkdownPath: result.projectMarkdownPath,
313
- generatedAt: result.projectMap.generatedAt,
314
- totalFiles: result.projectMap.stats.totalFiles
315
- });
316
- }
362
+ if (name === "refresh_project_map") {
363
+ const result = refreshProjectMap(getRoot(args));
364
+ return asTextResult({
365
+ message: "Project map refreshed.",
366
+ jsonPath: result.jsonPath,
367
+ markdownPath: result.markdownPath,
368
+ projectMarkdownPath: result.projectMarkdownPath,
369
+ generatedAt: result.projectMap.generatedAt,
370
+ totalFiles: result.projectMap.stats.totalFiles
371
+ });
372
+ }
317
373
 
318
- if (name === "get_module_context") {
319
- const result = getModuleContext(getRoot(args), args.module);
374
+ if (name === "get_module_context") {
375
+ const moduleName = requireNonEmptyString(args.module, "module");
376
+ const result = getModuleContext(getRoot(args), moduleName);
320
377
 
321
- if (!result) {
322
- return asTextResult({
323
- error: `Module not found in project map: ${args.module}`
324
- });
325
- }
378
+ if (!result) {
379
+ return asTextResult({
380
+ error: `Module not found in project map: ${moduleName}`
381
+ });
382
+ }
326
383
 
327
- return asTextResult(result);
328
- }
384
+ return asTextResult(result);
385
+ }
329
386
 
330
- if (name === "find_relevant_files") {
331
- const projectMap = loadProjectMap(getRoot(args));
332
- const result = findRelevantFiles(args.task, projectMap, Number(args.limit || 8));
333
- return asTextResult(result);
334
- }
387
+ if (name === "find_relevant_files") {
388
+ const task = requireNonEmptyString(args.task, "task");
389
+ const limit = parsePositiveInt(args.limit, 8, "limit", 100);
390
+ const projectMap = loadProjectMap(getRoot(args));
391
+ const result = findRelevantFiles(task, projectMap, limit);
392
+ return asTextResult(result);
393
+ }
335
394
 
336
- if (name === "get_recent_git_changes") {
337
- const result = getRecentGitChanges(getRoot(args), Number(args.days || 5));
338
- return asTextResult(result);
339
- }
395
+ if (name === "get_recent_git_changes") {
396
+ const days = parsePositiveInt(args.days, 5, "days", 3650);
397
+ const result = getRecentGitChanges(getRoot(args), days);
398
+ return asTextResult(result);
399
+ }
340
400
 
341
- if (name === "explain_file_role") {
342
- const result = explainFile(getRoot(args), args.path);
401
+ if (name === "explain_file_role") {
402
+ const targetPath = requireNonEmptyString(args.path, "path");
403
+ const result = explainFile(getRoot(args), targetPath);
343
404
 
344
- if (!result) {
345
- return asTextResult({
346
- error: `File not found in project map: ${args.path}`
347
- });
348
- }
405
+ if (!result) {
406
+ return asTextResult({
407
+ error: `File not found in project map: ${targetPath}`
408
+ });
409
+ }
349
410
 
350
- return asTextResult(result);
351
- }
411
+ return asTextResult(result);
412
+ }
352
413
 
353
- throw new Error(`Unknown tool: ${name}`);
354
- });
414
+ return asErrorResult(`Unknown tool: ${name}`);
415
+ } catch (error) {
416
+ return asErrorResult(error?.message || String(error));
417
+ }
418
+ });
419
+ }
420
+
421
+ const server = createServer();
355
422
 
356
423
  export async function startServer() {
357
424
  const transport = new StdioServerTransport();
package/src/utils.js CHANGED
@@ -87,9 +87,60 @@ export function relativeProjectPath(projectRoot, targetPath) {
87
87
  return toPosixPath(path.relative(projectRoot, targetPath));
88
88
  }
89
89
 
90
+ function resolveNearestRealPath(targetPath) {
91
+ let current = path.resolve(targetPath);
92
+ const missing = [];
93
+
94
+ while (true) {
95
+ try {
96
+ const stat = fs.lstatSync(current);
97
+ if (stat.isSymbolicLink()) {
98
+ try {
99
+ const real = fs.realpathSync(current);
100
+ return path.join(real, ...missing.reverse());
101
+ } catch {
102
+ const linkTarget = fs.readlinkSync(current);
103
+ const resolvedTarget = path.resolve(path.dirname(current), linkTarget);
104
+ return resolveNearestRealPath(path.join(resolvedTarget, ...missing.reverse()));
105
+ }
106
+ }
107
+
108
+ const real = fs.realpathSync(current);
109
+ return path.join(real, ...missing.reverse());
110
+ } catch (error) {
111
+ if (error?.code !== "ENOENT") {
112
+ throw error;
113
+ }
114
+
115
+ const parent = path.dirname(current);
116
+ if (parent === current) {
117
+ return path.resolve(targetPath);
118
+ }
119
+
120
+ missing.push(path.basename(current));
121
+ current = parent;
122
+ }
123
+ }
124
+ }
125
+
90
126
  export function isPathInsideProject(projectRoot, targetPath) {
91
- const relativePath = path.relative(projectRoot, targetPath);
92
- return relativePath === "" || (!relativePath.startsWith("..") && !path.isAbsolute(relativePath));
127
+ const resolvedRoot = path.resolve(projectRoot);
128
+ const resolvedTarget = path.resolve(targetPath);
129
+ const relativePath = path.relative(resolvedRoot, resolvedTarget);
130
+
131
+ if (relativePath !== "" && (relativePath.startsWith("..") || path.isAbsolute(relativePath))) {
132
+ return false;
133
+ }
134
+
135
+ if (!fs.existsSync(resolvedRoot)) {
136
+ return true;
137
+ }
138
+
139
+ const realRoot = fs.realpathSync(resolvedRoot);
140
+ const realTarget = resolveNearestRealPath(resolvedTarget);
141
+ const realRelative = path.relative(realRoot, realTarget);
142
+
143
+ return realRelative === "" || (!realRelative.startsWith("..") && !path.isAbsolute(realRelative));
93
144
  }
94
145
 
95
146
  export function shouldIgnoreDirectory(dirname) {