fix(mcp): use linux local data dir

This commit is contained in:
t8y2
2026-06-24 15:51:10 +08:00
parent 829f6dc7eb
commit d91f1fbb38
6 changed files with 33 additions and 27 deletions
+1 -1
View File
@@ -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 联动
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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 联动
+3 -15
View File
@@ -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.");
+15 -8
View File
@@ -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");
}
}
+11
View File
@@ -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");
});