diff --git a/apps/cli/src/mcp.ts b/apps/cli/src/mcp.ts index 932c9385..9515b9e8 100644 --- a/apps/cli/src/mcp.ts +++ b/apps/cli/src/mcp.ts @@ -4,6 +4,8 @@ * Thin wrapper: initializes Node.js runtime, then delegates to chatlab-mcp. */ +import fs from 'fs' +import path from 'path' import { loadConfig } from '@openchatlab/config' import { NodePathProvider, @@ -14,6 +16,13 @@ import { import { startMcpServer } from 'chatlab-mcp' import { getVersion } from './version' +function resolveNativeBinding(): string | undefined { + if (process.versions.electron) return undefined + const nativePath = path.resolve(__dirname, '../native/better_sqlite3.node') + if (fs.existsSync(nativePath)) return nativePath + return undefined +} + function initMcpRuntime(): DatabaseManager { const config = loadConfig() const userDataDir = config.data.user_data_dir || undefined @@ -26,7 +35,8 @@ function initMcpRuntime(): DatabaseManager { process.exit(1) } - return new DatabaseManager(pathProvider) + const nativeBinding = resolveNativeBinding() + return new DatabaseManager(pathProvider, { nativeBinding }) } export async function startCliMcpServer(): Promise {