project-context-map-mcp 0.1.3 → 0.1.7

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tamojit
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -8,8 +8,10 @@ Turn a repository into structured project memory for MCP clients like Claude Cod
8
8
 
9
9
  [![Node 20+](https://img.shields.io/badge/node-%3E%3D20-1f6feb?style=for-the-badge)](#installation)
10
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)
11
+ [![CI Checks](https://img.shields.io/github/actions/workflow/status/tamojit-123/project-context-map-mcp/ci.yml?branch=main&style=for-the-badge&label=CI)](https://github.com/tamojit-123/project-context-map-mcp/actions/workflows/ci.yml)
12
+ [![License: MIT](https://img.shields.io/badge/license-MIT-16a34a?style=for-the-badge)](./LICENSE)
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)
13
15
 
14
16
  </div>
15
17
 
@@ -34,6 +36,13 @@ you get:
34
36
 
35
37
  `index first -> query topology -> read sparse files -> edit with context`
36
38
 
39
+ | Without Project Context Map | With Project Context Map |
40
+ | --- | --- |
41
+ | Agent scans directories & opens 15–30 unrelated files | Calls `get_project_summary` + `query_topology` first |
42
+ | Re-discovers architecture every new session | Reads `.project.md` & `.project-map.json` immediately |
43
+ | Misses downstream callers / import edges | Sees `dependencies` and `usedBy` before editing |
44
+ | High prompt token usage on medium/large repos | Calls `read_files_sparse` on only 2–5 matched files |
45
+
37
46
  ---
38
47
 
39
48
  ## What This Project Does
@@ -68,6 +77,21 @@ This package gives you:
68
77
 
69
78
  ## Installation
70
79
 
80
+ ### Option 0: Zero-install with `npx` (Fastest)
81
+
82
+ Add this directly to your MCP client config (Claude Code `.mcp.json`, Cursor, Claude Desktop, or VS Code) without installing anything globally:
83
+
84
+ ```json
85
+ {
86
+ "mcpServers": {
87
+ "project-context-map": {
88
+ "command": "npx",
89
+ "args": ["-y", "project-context-map-mcp", "serve", "--project-root", "."]
90
+ }
91
+ }
92
+ }
93
+ ```
94
+
71
95
  ### Option 1: Global install
72
96
 
73
97
  Best if you want to use it across many repositories.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-context-map-mcp",
3
- "version": "0.1.3",
3
+ "version": "0.1.7",
4
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",
@@ -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"
@@ -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) {