code-graph-builder 0.2.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.
Files changed (2) hide show
  1. package/bin/cli.mjs +109 -0
  2. package/package.json +28 -0
package/bin/cli.mjs ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * code-graph-builder MCP server launcher
5
+ *
6
+ * Automatically detects the best way to run the Python MCP server:
7
+ * 1. uvx (fastest, auto-installs in isolated env)
8
+ * 2. pipx (similar to uvx)
9
+ * 3. Direct python3 (requires prior pip install)
10
+ *
11
+ * Usage:
12
+ * npx code-graph-builder # auto-detect
13
+ * npx code-graph-builder --pip # force pip mode
14
+ */
15
+
16
+ import { spawn, execFileSync } from "node:child_process";
17
+
18
+ const PYTHON_PACKAGE = "code-graph-builder";
19
+ const MODULE_PATH = "code_graph_builder.mcp.server";
20
+
21
+ // Pass through all env vars (CGB_WORKSPACE, API keys, etc.)
22
+ const env = { ...process.env };
23
+
24
+ /**
25
+ * Check if a command exists on PATH.
26
+ */
27
+ function commandExists(cmd) {
28
+ try {
29
+ execFileSync("which", [cmd], { stdio: "pipe" });
30
+ return true;
31
+ } catch {
32
+ return false;
33
+ }
34
+ }
35
+
36
+ /**
37
+ * Check if the Python package is importable.
38
+ */
39
+ function pythonPackageInstalled() {
40
+ try {
41
+ execFileSync("python3", ["-c", `import ${MODULE_PATH.split(".")[0]}`], {
42
+ stdio: "pipe",
43
+ });
44
+ return true;
45
+ } catch {
46
+ return false;
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Run a command as the MCP server (replaces this process's stdio).
52
+ */
53
+ function runServer(cmd, args) {
54
+ const child = spawn(cmd, args, {
55
+ stdio: "inherit",
56
+ env,
57
+ });
58
+
59
+ child.on("error", (err) => {
60
+ console.error(`Failed to start MCP server: ${err.message}`);
61
+ process.exit(1);
62
+ });
63
+
64
+ child.on("exit", (code) => {
65
+ process.exit(code ?? 0);
66
+ });
67
+ }
68
+
69
+ // ---------------------------------------------------------------------------
70
+ // Main
71
+ // ---------------------------------------------------------------------------
72
+
73
+ const forceMode = process.argv[2];
74
+
75
+ if (forceMode === "--pip" || forceMode === "--python") {
76
+ // Force direct python3 mode
77
+ if (!pythonPackageInstalled()) {
78
+ console.error(
79
+ `Error: Python package '${PYTHON_PACKAGE}' is not installed.\n` +
80
+ `Run: pip install ${PYTHON_PACKAGE}`
81
+ );
82
+ process.exit(1);
83
+ }
84
+ runServer("python3", ["-m", MODULE_PATH]);
85
+ } else if (commandExists("uvx")) {
86
+ // Preferred: uvx auto-installs in isolated env
87
+ runServer("uvx", [PYTHON_PACKAGE, ...process.argv.slice(2)]);
88
+ } else if (commandExists("uv")) {
89
+ // uv available but not uvx — use uv tool run
90
+ runServer("uv", ["tool", "run", PYTHON_PACKAGE, ...process.argv.slice(2)]);
91
+ } else if (commandExists("pipx")) {
92
+ // pipx: similar to uvx
93
+ runServer("pipx", ["run", PYTHON_PACKAGE, ...process.argv.slice(2)]);
94
+ } else if (pythonPackageInstalled()) {
95
+ // Fallback: direct python3
96
+ runServer("python3", ["-m", MODULE_PATH]);
97
+ } else {
98
+ // Nothing works — guide the user
99
+ console.error(
100
+ `code-graph-builder MCP server requires Python 3.10+.\n\n` +
101
+ `Install options (pick one):\n` +
102
+ ` 1. pip install ${PYTHON_PACKAGE} # then: npx code-graph-builder --pip\n` +
103
+ ` 2. Install uv (recommended): curl -LsSf https://astral.sh/uv/install.sh | sh\n` +
104
+ ` Then: npx code-graph-builder # auto-installs via uvx\n` +
105
+ ` 3. Install pipx: pip install pipx\n` +
106
+ ` Then: npx code-graph-builder # auto-installs via pipx\n`
107
+ );
108
+ process.exit(1);
109
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "code-graph-builder",
3
+ "version": "0.2.0",
4
+ "description": "Code knowledge graph builder with MCP server for AI-assisted code navigation",
5
+ "license": "MIT",
6
+ "bin": {
7
+ "code-graph-builder": "./bin/cli.mjs"
8
+ },
9
+ "files": [
10
+ "bin/",
11
+ "README.md"
12
+ ],
13
+ "keywords": [
14
+ "mcp",
15
+ "model-context-protocol",
16
+ "code-graph",
17
+ "knowledge-graph",
18
+ "code-navigation",
19
+ "ai-assistant"
20
+ ],
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "https://github.com/JeremyJiao01/CodeGraphWiki"
27
+ }
28
+ }