Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(mcp): use linux local data dir

t8y2d91f1fbb385e
diff --git a/docs/content/docs/mcp.cn.mdx b/docs/content/docs/mcp.cn.mdx
index ce655b1d2e..3af5b42565 100644
--- a/docs/content/docs/mcp.cn.mdx
+++ b/docs/content/docs/mcp.cn.mdx
@@ -202,7 +202,7 @@ MCP Server 从 DBX 的 SQLite 数据库读取连接信息:
| 平台 | 路径 |
| ------- | -------------------------------------------------- |
| macOS | `~/Library/Application Support/com.dbx.app/dbx.db` |
-| Linux | `~/.config/com.dbx.app/dbx.db` |
+| Linux | `~/.local/share/com.dbx.app/dbx.db` |
| Windows | `%APPDATA%\com.dbx.app\dbx.db` |
### UI 联动
diff --git a/docs/content/docs/mcp.mdx b/docs/content/docs/mcp.mdx
index 73238258dc..048d1dee1c 100644
--- a/docs/content/docs/mcp.mdx
+++ b/docs/content/docs/mcp.mdx
@@ -202,7 +202,7 @@ The MCP Server reads DBX's SQLite database:
| Platform | Path |
| -------- | -------------------------------------------------- |
| macOS | `~/Library/Application Support/com.dbx.app/dbx.db` |
-| Linux | `~/.config/com.dbx.app/dbx.db` |
+| Linux | `~/.local/share/com.dbx.app/dbx.db` |
| Windows | `%APPDATA%\com.dbx.app\dbx.db` |
### UI Integration
diff --git a/packages/mcp-server/README.md b/packages/mcp-server/README.md
index dc83bfe776..7dbeec00fd 100644
--- a/packages/mcp-server/README.md
+++ b/packages/mcp-server/README.md
@@ -117,7 +117,7 @@ AI Agent → MCP Server → Database
The MCP server reads your database connections from DBX's SQLite database:
- **macOS**: `~/Library/Application Support/com.dbx.app/dbx.db`
-- **Linux**: `~/.config/com.dbx.app/dbx.db`
+- **Linux**: `~/.local/share/com.dbx.app/dbx.db`
- **Windows**: `%APPDATA%\com.dbx.app\dbx.db`
## DBX UI Integration
@@ -234,7 +234,7 @@ DBX_MCP_ALLOW_DANGEROUS_SQL=1
MCP Server 从 DBX 的 SQLite 数据库读取连接信息:
- **macOS**: `~/Library/Application Support/com.dbx.app/dbx.db`
-- **Linux**: `~/.config/com.dbx.app/dbx.db`
+- **Linux**: `~/.local/share/com.dbx.app/dbx.db`
- **Windows**: `%APPDATA%\com.dbx.app\dbx.db`
### DBX UI 联动
diff --git a/packages/node-core/src/database.ts b/packages/node-core/src/database.ts
index 85ccacb933..a23ff09465 100644
--- a/packages/node-core/src/database.ts
+++ b/packages/node-core/src/database.ts
@@ -1,11 +1,12 @@
import type { ConnectionConfig, ProxyTunnelConfig } from "./connections.js";
import { createServer, connect as netConnect, type Server, type Socket } from "node:net";
import { readFile } from "node:fs/promises";
+import { homedir } from "node:os";
import { join } from "node:path";
-import { homedir, platform } from "node:os";
import Database from "better-sqlite3";
import { sqlSafetyFromEnv } from "./sql-safety.js";
import { isDirectQueryType } from "./diagnostics.js";
+import { bridgePortFilePath } from "./paths.js";
export interface TableInfo {
name: string;
@@ -325,23 +326,10 @@ interface MongoDocumentResult {
total: number;
}
-function bridgeAppDataDir(): string {
- const home = homedir();
- switch (platform()) {
- case "darwin":
- return join(home, "Library", "Application Support", "com.dbx.app");
- case "win32":
- return join(process.env.APPDATA || join(home, "AppData", "Roaming"), "com.dbx.app");
- default:
- return join(home, ".config", "com.dbx.app");
- }
-}
-
async function bridgeDataRequest<T>(path: string, body: Record<string, unknown>): Promise<T> {
let bridgeUrl: string;
try {
- const portFile = join(bridgeAppDataDir(), "mcp-bridge-port");
- const port = (await readFile(portFile, "utf-8")).trim();
+ const port = (await readFile(bridgePortFilePath(), "utf-8")).trim();
bridgeUrl = `http://127.0.0.1:${port}`;
} catch {
throw new Error("DBX desktop app is not running. This database type requires DBX to be running for query execution.");
diff --git a/packages/node-core/src/paths.ts b/packages/node-core/src/paths.ts
index ec1cdfe934..959ef60fd5 100644
--- a/packages/node-core/src/paths.ts
+++ b/packages/node-core/src/paths.ts
@@ -3,19 +3,26 @@ import { join } from "node:path";
export function appDataDir(): string {
// 支持 DBX_DATA_DIR 环境变量(与 Rust 侧 data_dir.rs 保持一致)
- const envDir = process.env.DBX_DATA_DIR;
- if (envDir && envDir.trim() !== "") {
- return envDir;
+ return appDataDirFromInputs({
+ platform: platform(),
+ home: homedir(),
+ appData: process.env.APPDATA,
+ envDataDir: process.env.DBX_DATA_DIR,
+ });
+}
+
+export function appDataDirFromInputs(options: { platform: NodeJS.Platform; home: string; appData?: string; envDataDir?: string }): string {
+ if (options.envDataDir && options.envDataDir.trim() !== "") {
+ return options.envDataDir;
}
- const home = homedir();
- switch (platform()) {
+ switch (options.platform) {
case "darwin":
- return join(home, "Library", "Application Support", "com.dbx.app");
+ return join(options.home, "Library", "Application Support", "com.dbx.app");
case "win32":
- return join(process.env.APPDATA || join(home, "AppData", "Roaming"), "com.dbx.app");
+ return join(options.appData || join(options.home, "AppData", "Roaming"), "com.dbx.app");
default:
- return join(home, ".config", "com.dbx.app");
+ return join(options.home, ".local", "share", "com.dbx.app");
}
}
diff --git a/packages/node-core/tests/paths.test.ts b/packages/node-core/tests/paths.test.ts
new file mode 100644
index 0000000000..248059152c
--- /dev/null
+++ b/packages/node-core/tests/paths.test.ts
@@ -0,0 +1,11 @@
+import assert from "node:assert/strict";
+import { test } from "vitest";
+import { appDataDirFromInputs } from "../src/paths.js";
+
+test("default app data dir matches Tauri local data dir on Linux", () => {
+ assert.equal(appDataDirFromInputs({ platform: "linux", home: "/home/dbx" }), "/home/dbx/.local/share/com.dbx.app");
+});
+
+test("DBX_DATA_DIR overrides the default app data dir", () => {
+ assert.equal(appDataDirFromInputs({ platform: "linux", home: "/home/dbx", envDataDir: "/tmp/dbx-data" }), "/tmp/dbx-data");
+});