MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / doInitialize

Method doInitialize

src/mcp/engine.ts:220–261  ·  view source on GitHub ↗
(searchFrom: string)

Source from the content-addressed store, hash-verified

218 }
219
220 private async doInitialize(searchFrom: string): Promise<void> {
221 this.toolHandler.setDefaultProjectHint(searchFrom);
222
223 // Up-walk first; when nothing is indexed at or above searchFrom, a bounded
224 // down-scan may adopt a SINGLE indexed sub-project as the default (#1606 —
225 // the workspace-container shape where only children are indexed). Zero or
226 // several candidates → no default project, but SAY so (#1607): the silent
227 // variant of this state read as "CodeGraph is broken" and was diagnosable
228 // only by knowing to look for a missing ~/.codegraph/daemons/ entry.
229 const res = resolveServerRoot(searchFrom);
230 const resolvedRoot = res.root;
231 if (!resolvedRoot) {
232 // Sessions may still discover a project later via roots/list, and the
233 // per-call retry re-resolves — this state is recoverable, hence stderr
234 // (not a failure) + candidates surfaced through the tool-call error.
235 this.projectPath = searchFrom;
236 this.toolHandler.setKnownSubprojects(res.candidates, searchFrom);
237 process.stderr.write(
238 `[CodeGraph MCP] No .codegraph/ at or above ${searchFrom}: no default project, live sync disabled.\n`
239 );
240 if (res.candidates.length > 0) {
241 const rels = res.candidates.map((c) => path.relative(searchFrom, c) || '.');
242 process.stderr.write(
243 `[CodeGraph MCP] Indexed sub-projects found: ${rels.join(', ')}. Pass \`projectPath\` per call, or launch with --path.\n`
244 );
245 }
246 return;
247 }
248 if (res.viaSubScan) this.logSubprojectAdoption(searchFrom, resolvedRoot);
249
250 this.projectPath = resolvedRoot;
251 try {
252 this.cg = await loadCodeGraph().open(resolvedRoot);
253 this.toolHandler.setDefaultCodeGraph(this.cg);
254 this.startWatching();
255 this.catchUpSync();
256 this.maybeStartPool(resolvedRoot);
257 } catch (err) {
258 const msg = err instanceof Error ? err.message : String(err);
259 process.stderr.write(`[CodeGraph MCP] Failed to open project at ${resolvedRoot}: ${msg}\n`);
260 }
261 }
262
263 /** One stderr line when the default project came from the down-scan (#1606). */
264 private logSubprojectAdoption(searchFrom: string, root: string): void {

Callers 1

ensureInitializedMethod · 0.95

Calls 12

logSubprojectAdoptionMethod · 0.95
startWatchingMethod · 0.95
catchUpSyncMethod · 0.95
maybeStartPoolMethod · 0.95
resolveServerRootFunction · 0.90
setDefaultProjectHintMethod · 0.80
setKnownSubprojectsMethod · 0.80
setDefaultCodeGraphMethod · 0.80
loadCodeGraphFunction · 0.70
writeMethod · 0.65
joinMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected