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

Method retryInitIfNeeded

src/mcp/session.ts:305–328  ·  view source on GitHub ↗

* Lazy default-project resolution. Three layers: * 1. await the in-flight init kicked off from `handleInitialize` (if any); * 2. if still uninitialized and we never asked the client for its roots, * do so now (one-shot); fall back to cwd if the client lacks roots; * 3. last-re

()

Source from the content-addressed store, hash-verified

303 * that were `codegraph init`'d *after* the server started.
304 */
305 private async retryInitIfNeeded(): Promise<void> {
306 if (this.resolvePromise) {
307 try { await this.resolvePromise; } catch { /* fall through to retry */ }
308 this.resolvePromise = null;
309 }
310
311 if (this.engine.hasDefaultCodeGraph()) return;
312
313 const hint = this.explicitProjectPath ?? this.engine.getProjectPath();
314 if (!hint && !this.rootsAttempted) {
315 this.rootsAttempted = true;
316 this.resolvePromise = this.clientSupportsRoots
317 ? this.initFromRoots()
318 : this.engine.ensureInitialized(process.cwd());
319 try { await this.resolvePromise; } catch { /* fall through */ }
320 this.resolvePromise = null;
321 if (this.engine.hasDefaultCodeGraph()) return;
322 }
323
324 // Last resort: walk from the best candidate (sync open). Picks up
325 // projects that appeared after the server started.
326 const candidate = hint ?? process.cwd();
327 this.engine.retryInitializeSync(candidate);
328 }
329
330 /**
331 * Ask the client for its workspace root via `roots/list` and open the

Callers 2

handleToolsListMethod · 0.95
handleToolsCallMethod · 0.95

Calls 5

initFromRootsMethod · 0.95
getProjectPathMethod · 0.80
ensureInitializedMethod · 0.80
retryInitializeSyncMethod · 0.80
hasDefaultCodeGraphMethod · 0.45

Tested by

no test coverage detected