project-context-map-mcp 0.1.11 → 0.1.13

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "project-context-map-mcp",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "mcpName": "io.github.tamojit-123/project-context-map-mcp",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,8 +18,11 @@
18
18
  "install-hooks": "node src/cli.js install-hooks",
19
19
  "configure-claude": "node src/cli.js configure-claude",
20
20
  "print-mcp-config": "node src/cli.js print-mcp-config",
21
+ "sync-server-json": "node scripts/sync-server-json.js",
22
+ "mcp:validate": "mcp-publisher validate",
23
+ "mcp:publish": "mcp-publisher publish",
21
24
  "build": "npm run lint",
22
- "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",
25
+ "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 scripts/sync-server-json.js && node --check test/claude.test.js && node --check test/git.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",
23
26
  "check": "npm run lint && npm test",
24
27
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --runInBand",
25
28
  "prepublishOnly": "npm run check"
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+
6
+ const rootDir = process.cwd();
7
+ const packageJsonPath = path.join(rootDir, "package.json");
8
+ const serverJsonPath = path.join(rootDir, "server.json");
9
+
10
+ const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
11
+ const serverJson = JSON.parse(fs.readFileSync(serverJsonPath, "utf8"));
12
+
13
+ serverJson.version = packageJson.version;
14
+
15
+ if (Array.isArray(serverJson.packages)) {
16
+ for (const pkg of serverJson.packages) {
17
+ if (pkg && typeof pkg === "object") {
18
+ pkg.version = packageJson.version;
19
+ }
20
+ }
21
+ }
22
+
23
+ fs.writeFileSync(serverJsonPath, `${JSON.stringify(serverJson, null, 2)}\n`, "utf8");
24
+ process.stdout.write(`Synced server.json to version ${packageJson.version}\n`);
package/src/claude.js CHANGED
@@ -70,7 +70,11 @@ export function writeMcpConfig(projectRoot, options = {}) {
70
70
  let current = {};
71
71
 
72
72
  if (fs.existsSync(targetPath)) {
73
- current = JSON.parse(fs.readFileSync(targetPath, "utf8"));
73
+ try {
74
+ current = JSON.parse(fs.readFileSync(targetPath, "utf8"));
75
+ } catch (error) {
76
+ throw new Error(`Invalid JSON in ${targetPath}: ${error.message}`);
77
+ }
74
78
  }
75
79
 
76
80
  const config = {
package/src/git.js CHANGED
@@ -1,8 +1,11 @@
1
1
  import { execFileSync } from "node:child_process";
2
2
 
3
+ const GIT_MAX_BUFFER = 10 * 1024 * 1024;
4
+
3
5
  function runGit(projectRoot, args) {
4
6
  return execFileSync("git", ["-C", projectRoot, ...args], {
5
7
  encoding: "utf8",
8
+ maxBuffer: GIT_MAX_BUFFER,
6
9
  stdio: ["ignore", "pipe", "ignore"]
7
10
  }).trim();
8
11
  }
@@ -29,7 +32,7 @@ export function getRecentGitChanges(projectRoot, days = 5) {
29
32
  "log",
30
33
  `--since=${days} days ago`,
31
34
  "--date=short",
32
- "--pretty=format:__COMMIT__%n%H%n%ad%n%s",
35
+ "--pretty=format:%x1e%H%x1f%ad%x1f%s%x1f",
33
36
  "--name-only"
34
37
  ]);
35
38
 
@@ -43,19 +46,18 @@ export function getRecentGitChanges(projectRoot, days = 5) {
43
46
  }
44
47
 
45
48
  const blocks = output
46
- .split("__COMMIT__")
49
+ .split("\x1e")
47
50
  .map((block) => block.trim())
48
51
  .filter(Boolean);
49
52
 
50
53
  const hotspotCounter = new Map();
51
54
  const commits = blocks.map((block) => {
52
- const lines = block
55
+ const [hash = "", date = "", summary = "", filesPart = ""] = block.split("\x1f");
56
+ const files = filesPart
53
57
  .split(/\r?\n/u)
54
58
  .map((line) => line.trim())
55
59
  .filter(Boolean);
56
60
 
57
- const [hash, date, summary, ...files] = lines;
58
-
59
61
  for (const filePath of files) {
60
62
  hotspotCounter.set(filePath, (hotspotCounter.get(filePath) || 0) + 1);
61
63
  }
package/src/indexer.js CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  MAP_JSON_FILE,
6
6
  MAP_MD_FILE,
7
7
  PROJECT_MD_FILE,
8
+ atomicWriteFileSync,
8
9
  firstNonEmptyLine,
9
10
  isPathInsideProject,
10
11
  isTextLikeFile,
@@ -373,18 +374,26 @@ function buildDependencies(projectRoot, techStack) {
373
374
  const packageJsonPath = path.join(projectRoot, "package.json");
374
375
 
375
376
  if (pathExists(packageJsonPath)) {
376
- const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
377
- const names = dedupe([
378
- ...Object.keys(packageJson.dependencies || {}),
379
- ...Object.keys(packageJson.devDependencies || {})
380
- ]).slice(0, 50);
381
-
382
- dependencies.push(
383
- ...names.map((name) => ({
384
- ecosystem: "npm",
385
- name
386
- }))
387
- );
377
+ let packageJson = null;
378
+ try {
379
+ packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf8"));
380
+ } catch {
381
+ packageJson = null;
382
+ }
383
+
384
+ if (packageJson && typeof packageJson === "object") {
385
+ const names = dedupe([
386
+ ...Object.keys(packageJson.dependencies || {}),
387
+ ...Object.keys(packageJson.devDependencies || {})
388
+ ]).slice(0, 50);
389
+
390
+ dependencies.push(
391
+ ...names.map((name) => ({
392
+ ecosystem: "npm",
393
+ name
394
+ }))
395
+ );
396
+ }
388
397
  }
389
398
 
390
399
  if (techStack.includes("springboot")) {
@@ -766,15 +775,16 @@ export function writeAndLog(projectRootInput, targetPath, content, changeSummary
766
775
  throw new Error("Refusing to write outside the project root.");
767
776
  }
768
777
 
778
+ const exactContent = String(content ?? "");
769
779
  fs.mkdirSync(path.dirname(absolutePath), { recursive: true });
770
- writeText(absolutePath, String(content || "").replace(/\n$/u, ""));
780
+ atomicWriteFileSync(absolutePath, exactContent);
771
781
 
772
782
  const normalizedPath = relativeProjectPath(projectRoot, absolutePath);
773
783
  const logResult = appendChangeLog(projectRoot, `${normalizedPath}${changeSummary ? ` - ${changeSummary}` : ""}`);
774
784
 
775
785
  return {
776
786
  path: normalizedPath,
777
- bytesWritten: Buffer.byteLength(String(content || ""), "utf8"),
787
+ bytesWritten: Buffer.byteLength(exactContent, "utf8"),
778
788
  log: logResult
779
789
  };
780
790
  }
package/src/utils.js CHANGED
@@ -60,15 +60,39 @@ export function readJsonIfExists(filePath) {
60
60
  return null;
61
61
  }
62
62
 
63
- return JSON.parse(fs.readFileSync(filePath, "utf8"));
63
+ try {
64
+ return JSON.parse(fs.readFileSync(filePath, "utf8"));
65
+ } catch {
66
+ return null;
67
+ }
68
+ }
69
+
70
+ export function atomicWriteFileSync(filePath, content) {
71
+ const dir = path.dirname(filePath);
72
+ const base = path.basename(filePath);
73
+ const tempPath = path.join(dir, `.${base}.${process.pid}.${Date.now()}.tmp`);
74
+
75
+ try {
76
+ fs.writeFileSync(tempPath, content, "utf8");
77
+ fs.renameSync(tempPath, filePath);
78
+ } catch (error) {
79
+ try {
80
+ if (fs.existsSync(tempPath)) {
81
+ fs.unlinkSync(tempPath);
82
+ }
83
+ } catch {
84
+ // Ignore temp cleanup failure
85
+ }
86
+ throw error;
87
+ }
64
88
  }
65
89
 
66
90
  export function writeJson(filePath, value) {
67
- fs.writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`, "utf8");
91
+ atomicWriteFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
68
92
  }
69
93
 
70
94
  export function writeText(filePath, value) {
71
- fs.writeFileSync(filePath, `${value}\n`, "utf8");
95
+ atomicWriteFileSync(filePath, `${value}\n`);
72
96
  }
73
97
 
74
98
  export function readTextIfExists(filePath) {