code-graph-builder 0.9.0 → 0.11.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 +63 -36
  2. package/package.json +1 -1
package/bin/cli.mjs CHANGED
@@ -351,31 +351,32 @@ async function runSetup() {
351
351
  // Timeout after 15s
352
352
  const timer = setTimeout(() => finish(false, "Server did not respond within 15s"), 15000);
353
353
 
354
+ child.stderr.on("data", () => {}); // Suppress server logs
355
+
354
356
  child.stdout.on("data", (chunk) => {
355
357
  stdout += chunk.toString();
356
- // Look for a valid JSON-RPC response
358
+ // MCP stdio uses JSON lines (one JSON-RPC message per line)
357
359
  const lines = stdout.split("\n");
358
360
  for (const line of lines) {
359
- // MCP uses Content-Length header framing
360
- if (line.startsWith("{")) {
361
- try {
362
- const msg = JSON.parse(line);
363
- if (msg.result && msg.result.capabilities) {
364
- // Got initialize response, now request tools/list
365
- const toolsReq =
366
- `Content-Length: 80\r\n\r\n` +
367
- JSON.stringify({ jsonrpc: "2.0", id: 2, method: "tools/list", params: {} });
368
- child.stdin.write(toolsReq);
369
- stdout = "";
370
- return;
371
- }
372
- if (msg.result && msg.result.tools) {
373
- clearTimeout(timer);
374
- finish(true, `${msg.result.tools.length} tools available`);
375
- return;
376
- }
377
- } catch { /* partial JSON, wait for more */ }
378
- }
361
+ const trimmed = line.trim();
362
+ if (!trimmed || !trimmed.startsWith("{")) continue;
363
+ try {
364
+ const msg = JSON.parse(trimmed);
365
+ if (msg.result && msg.result.capabilities) {
366
+ // Got initialize response, now request tools/list
367
+ const toolsReq = JSON.stringify({
368
+ jsonrpc: "2.0", id: 2, method: "tools/list", params: {},
369
+ });
370
+ child.stdin.write(toolsReq + "\n");
371
+ stdout = "";
372
+ return;
373
+ }
374
+ if (msg.result && msg.result.tools) {
375
+ clearTimeout(timer);
376
+ finish(true, `${msg.result.tools.length} tools available`);
377
+ return;
378
+ }
379
+ } catch { /* partial JSON, wait for more */ }
379
380
  }
380
381
  });
381
382
 
@@ -389,7 +390,7 @@ async function runSetup() {
389
390
  if (!resolved) finish(false, `Server exited with code ${code}`);
390
391
  });
391
392
 
392
- // Send MCP initialize request
393
+ // Send MCP initialize request as JSON line
393
394
  const initReq = JSON.stringify({
394
395
  jsonrpc: "2.0",
395
396
  id: 1,
@@ -400,8 +401,7 @@ async function runSetup() {
400
401
  clientInfo: { name: "setup-verify", version: "1.0.0" },
401
402
  },
402
403
  });
403
- const header = `Content-Length: ${Buffer.byteLength(initReq)}\r\n\r\n`;
404
- child.stdin.write(header + initReq);
404
+ child.stdin.write(initReq + "\n");
405
405
  });
406
406
 
407
407
  if (verified.success) {
@@ -411,21 +411,48 @@ async function runSetup() {
411
411
  log(" The server may still work — try: npx code-graph-builder --server");
412
412
  }
413
413
 
414
+ // Step 4: Auto-register in Claude Code if available
414
415
  log("");
415
- log("── Setup complete ─────────────────────────────────────────");
416
- log("");
417
- log(" Add to your MCP client config:");
416
+ log("── Registering MCP server ─────────────────────────────────");
418
417
  log("");
419
- log(' {');
420
- log(' "mcpServers": {');
421
- log(' "code-graph-builder": {');
422
- log(' "command": "npx",');
423
- log(' "args": ["-y", "code-graph-builder@latest", "--server"]');
424
- log(" }");
425
- log(" }");
426
- log(" }");
418
+
419
+ if (commandExists("claude")) {
420
+ try {
421
+ // Remove existing entry first (ignore errors if not found)
422
+ try {
423
+ execSync("claude mcp remove code-graph-builder", { stdio: "pipe", shell: true });
424
+ } catch { /* not found, fine */ }
425
+
426
+ const addCmd = IS_WIN
427
+ ? 'claude mcp add --transport stdio code-graph-builder -- cmd /c npx -y code-graph-builder@latest --server'
428
+ : 'claude mcp add --transport stdio code-graph-builder -- npx -y code-graph-builder@latest --server';
429
+
430
+ execSync(addCmd, { stdio: "pipe", shell: true });
431
+ log(" ✓ Registered in Claude Code: code-graph-builder");
432
+ } catch (err) {
433
+ log(" ⚠ Failed to register in Claude Code automatically");
434
+ log(" Run manually:");
435
+ if (IS_WIN) {
436
+ log(' claude mcp add --transport stdio code-graph-builder -- cmd /c npx -y code-graph-builder@latest --server');
437
+ } else {
438
+ log(' claude mcp add --transport stdio code-graph-builder -- npx -y code-graph-builder@latest --server');
439
+ }
440
+ }
441
+ } else {
442
+ log(" Claude Code CLI not found. Add manually to your MCP client config:");
443
+ log("");
444
+ log(' {');
445
+ log(' "mcpServers": {');
446
+ log(' "code-graph-builder": {');
447
+ log(' "command": "npx",');
448
+ log(' "args": ["-y", "code-graph-builder@latest", "--server"]');
449
+ log(" }");
450
+ log(" }");
451
+ log(" }");
452
+ }
453
+
427
454
  log("");
428
- log(" Or run directly: npx code-graph-builder --server");
455
+ log("── Setup complete ─────────────────────────────────────────");
429
456
  log("");
430
457
  }
431
458
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "code-graph-builder",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "Code knowledge graph builder with MCP server for AI-assisted code navigation",
5
5
  "license": "MIT",
6
6
  "bin": {