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

Method constructor

src/mcp/engine.ts:110–144  ·  view source on GitHub ↗
(opts: MCPEngineOptions = {})

Source from the content-addressed store, hash-verified

108 private queryPool: QueryPool | null = null;
109
110 constructor(opts: MCPEngineOptions = {}) {
111 this.opts = { readOnly: opts.readOnly ?? false, watch: opts.watch ?? true, queryPool: opts.queryPool ?? false, queryPoolDefaultMax: opts.queryPoolDefaultMax };
112 this.toolHandler = new ToolHandler(null);
113 this.toolHandler.setProjectLifecycle({
114 open: (root, open) => {
115 // Explicit projects and read-only fallbacks also hold SQLite handles.
116 // Fence them before opening, just like the default daemon project.
117 assertNoRebuild(root);
118 if (this.opts.readOnly) return loadCodeGraph().openSync(root, { readOnly: true });
119 if (!this.opts.watch) return open();
120 const lease = acquireProject(root, open, this.watchOptions());
121 this.explicitProjects.set(lease.cg, lease);
122 return lease.cg;
123 },
124 activate: (cg) => this.explicitProjects.get(cg)?.ready() ?? Promise.resolve(),
125 release: (cg) => this.releaseExplicitProject(cg),
126 });
127 // A tool call found the default project's database replaced on disk (a
128 // `codegraph index` rebuild) and reopened it (#1902). Reconcile the new
129 // file with the usual catch-up — `sync()` serializes on the index mutex,
130 // so it never overlaps an in-flight watcher sync. Only when this engine is
131 // watching, i.e. it is the project's writer: a read-only engine (writer
132 // lock held elsewhere, watching disabled) must not start writing.
133 this.toolHandler.setOnDatabaseReopened((cg) => {
134 if (cg === this.cg && cg.isWatching()) this.catchUpSync(true);
135 });
136 if (opts.writerLockRoot && !this.opts.readOnly) {
137 assertNoRebuild(opts.writerLockRoot);
138 const writer = tryAcquireWriterLock(opts.writerLockRoot, 'fallback');
139 if (writer.kind === 'taken') {
140 throw new Error(writerLockHeldMessage(writer.existing, writer.pidPath));
141 }
142 this.writerLockRoot = opts.writerLockRoot;
143 }
144 }
145
146 /**
147 * Start the worker-thread query pool after resolving the default project

Callers

nothing calls this directly

Calls 15

watchOptionsMethod · 0.95
catchUpSyncMethod · 0.95
assertNoRebuildFunction · 0.90
acquireProjectFunction · 0.90
tryAcquireWriterLockFunction · 0.90
writerLockHeldMessageFunction · 0.90
setProjectLifecycleMethod · 0.80
setOnDatabaseReopenedMethod · 0.80
isWatchingMethod · 0.80
loadCodeGraphFunction · 0.70
readyMethod · 0.65

Tested by

no test coverage detected