feat(mcp): trace relevance + closure-collection + god-file rendering + cold-start handshake (#580)

Trace endpoint relevance (overloaded names resolve to the real implementation instead of an empty protocol/delegate stub), Swift closure-collection synthesizer, multi-phase god-file explore rendering, and serve --mcp cold-start handshake sped ~811ms→~90ms (proxy answers initialize/tools-list locally). Full suite green (1090 pass).
This commit is contained in:
Colby Mchenry
2026-05-31 18:41:41 -05:00
committed by GitHub
parent b026e64b41
commit 3a1ddf41cd
12 changed files with 756 additions and 92 deletions
+13 -3
View File
@@ -10,10 +10,20 @@
* inotify watch set — that's the entire point of issue #411.
*/
import CodeGraph, { findNearestCodeGraphRoot } from '../index';
import type CodeGraph from '../index';
import { findNearestCodeGraphRoot } from '../directory';
import { watchDisabledReason } from '../sync';
import { ToolHandler } from './tools';
// Lazy-load the heavy CodeGraph chain (sqlite + query/graph/context layers) OFF
// the MCP startup path. It's only needed once a tool actually opens a project —
// not to answer initialize/tools-list — so deferring it lets `serve --mcp` (and
// the daemon it spawns) bind + register tools in ~Node-startup time instead of
// ~800ms, closing the "No such tool available" cold-start race that made headless
// agents flounder. require() is sync + cached on the CommonJS build.
const loadCodeGraph = (): typeof import('../index').default =>
(require('../index') as typeof import('../index')).default;
export interface MCPEngineOptions {
/**
* Whether to start the file watcher when initializing. Daemon and direct
@@ -118,7 +128,7 @@ export class MCPEngine {
try { this.cg.close(); } catch { /* ignore */ }
this.cg = null;
}
this.cg = CodeGraph.openSync(resolvedRoot);
this.cg = loadCodeGraph().openSync(resolvedRoot);
this.projectPath = resolvedRoot;
this.toolHandler.setDefaultCodeGraph(this.cg);
this.startWatching();
@@ -154,7 +164,7 @@ export class MCPEngine {
this.projectPath = resolvedRoot;
try {
this.cg = await CodeGraph.open(resolvedRoot);
this.cg = await loadCodeGraph().open(resolvedRoot);
this.toolHandler.setDefaultCodeGraph(this.cg);
this.startWatching();
this.catchUpSync();