* Start the worker-thread query pool after resolving the default project * (which may be absent). Honors `CODEGRAPH_QUERY_POOL_SIZE`; best-effort: * if workers can't spawn on this platform the ToolHandler keeps serving reads * in-process, so the pool can only help, never break, tool calls.
(root: string | null)
| 150 | * in-process, so the pool can only help, never break, tool calls. |
| 151 | */ |
| 152 | private maybeStartPool(root: string | null): void { |
| 153 | if (this.opts.readOnly || !this.opts.queryPool || this.queryPool || this.closed) return; |
| 154 | const envSize = process.env.CODEGRAPH_QUERY_POOL_SIZE; |
| 155 | let size = resolvePoolSize(envSize, os.cpus().length); |
| 156 | if ((envSize === undefined || envSize === '') && this.opts.queryPoolDefaultMax !== undefined) { |
| 157 | size = Math.min(size, this.opts.queryPoolDefaultMax); |
| 158 | } |
| 159 | if (size <= 0) { |
| 160 | process.stderr.write('[CodeGraph MCP] Query pool disabled (CODEGRAPH_QUERY_POOL_SIZE=0); serving reads in-process.\n'); |
| 161 | return; |
| 162 | } |
| 163 | try { |
| 164 | this.queryPool = new QueryPool({ root, size }); |
| 165 | this.toolHandler.setQueryPool(this.queryPool); |
| 166 | process.stderr.write(`[CodeGraph MCP] Query pool: up to ${size} worker thread(s) for concurrent reads.\n`); |
| 167 | } catch (err) { |
| 168 | const msg = err instanceof Error ? err.message : String(err); |
| 169 | process.stderr.write(`[CodeGraph MCP] Query pool unavailable (${msg}); serving reads in-process.\n`); |
| 170 | this.queryPool = null; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Convenience for {@link MCPServer} compatibility: pre-seed an explicit |
no test coverage detected