fix(mcp): use node entry for Windows configs
This commit is contained in:
1 parent
8129ecda88
commit
d88e1b1e6a
6 files changed
+132
-20
No files matched your search
@@ -67,7 +67,8 @@ import { SHORTCUT_DEFINITIONS, findShortcutConflict, normalizeShortcutSettings,
|
||||
import { normalizeSidebarHiddenTablePrefixes } from "@/lib/sidebarTableNameDisplay";
|
||||
import { normalizeSqlFormatterSettings, type SqlFormatterSettings } from "@/lib/sqlFormatterConfig";
|
||||
import { EMPTY_TABLE_COLUMN_TEMPLATE_DATA_TYPE, parseTableColumnTemplateFields, TABLE_COLUMN_TEMPLATE_DATABASE_TYPES } from "@/lib/tableColumnTemplates";
|
||||
import { buildMcpCodexConfig, buildMcpJsonConfig, buildMcpOpenCodeConfig, buildMcpVsCodeConfig, type McpEnvEntry } from "@/lib/mcpConfigTemplates";
|
||||
import { buildMcpCodexConfig, buildMcpJsonConfig, buildMcpOpenCodeConfig, buildMcpVsCodeConfig, type McpEnvEntry, type McpLaunchConfig } from "@/lib/mcpConfigTemplates";
|
||||
import { isWindows } from "@/lib/platform";
|
||||
import { combineDataTypeForDatabase, dataTypeLengthInputValue, getDataTypeOptions, getDefaultLengthForType, isDataTypeLengthDisabled, splitDataType } from "@/lib/tableStructureEditorState";
|
||||
import type { DatabaseType, SqlSnippet } from "@/types/database";
|
||||
import { uuid } from "@/lib/utils";
|
||||
@@ -1114,13 +1115,21 @@ const mcpEnvEntries = computed<McpEnvEntry[]>(() => {
|
||||
return entries;
|
||||
});
|
||||
|
||||
const mcpJsonRecommendedConfig = computed(() => buildMcpJsonConfig(mcpEnvEntries.value));
|
||||
const mcpLaunchConfig = computed<McpLaunchConfig | undefined>(() => {
|
||||
if (!isWindows() || !mcpStatus.value?.script_path) return undefined;
|
||||
return {
|
||||
command: mcpStatus.value.node_path || "node",
|
||||
args: [mcpStatus.value.script_path],
|
||||
};
|
||||
});
|
||||
|
||||
const mcpVsCodeRecommendedConfig = computed(() => buildMcpVsCodeConfig(mcpEnvEntries.value));
|
||||
const mcpJsonRecommendedConfig = computed(() => buildMcpJsonConfig(mcpEnvEntries.value, mcpLaunchConfig.value));
|
||||
|
||||
const mcpCodexRecommendedConfig = computed(() => buildMcpCodexConfig(mcpEnvEntries.value));
|
||||
const mcpVsCodeRecommendedConfig = computed(() => buildMcpVsCodeConfig(mcpEnvEntries.value, mcpLaunchConfig.value));
|
||||
|
||||
const mcpOpenCodeRecommendedConfig = computed(() => buildMcpOpenCodeConfig(mcpEnvEntries.value));
|
||||
const mcpCodexRecommendedConfig = computed(() => buildMcpCodexConfig(mcpEnvEntries.value, mcpLaunchConfig.value));
|
||||
|
||||
const mcpOpenCodeRecommendedConfig = computed(() => buildMcpOpenCodeConfig(mcpEnvEntries.value, mcpLaunchConfig.value));
|
||||
|
||||
const mcpStatusTone = computed<"ok" | "warning" | "muted">(() => {
|
||||
if (!mcpStatus.value) return "muted";
|
||||
|
||||
@@ -27,6 +27,19 @@ describe("MCP config templates", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("builds standard JSON configs with a direct node launch command", () => {
|
||||
const config = JSON.parse(buildMcpJsonConfig([], { command: "C:\\Program Files\\nodejs\\node.exe", args: ["C:\\Users\\zhiyo\\AppData\\Roaming\\npm\\node_modules\\@dbx-app\\mcp-server\\dist\\index.js"] }));
|
||||
|
||||
expect(config).toEqual({
|
||||
mcpServers: {
|
||||
dbx: {
|
||||
command: "C:\\Program Files\\nodejs\\node.exe",
|
||||
args: ["C:\\Users\\zhiyo\\AppData\\Roaming\\npm\\node_modules\\@dbx-app\\mcp-server\\dist\\index.js"],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("builds VS Code MCP config with the servers root", () => {
|
||||
const config = JSON.parse(buildMcpVsCodeConfig([["DBX_MCP_ALLOW_WRITES", "0"]]));
|
||||
|
||||
@@ -43,10 +56,31 @@ describe("MCP config templates", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("builds VS Code config with a direct node launch command", () => {
|
||||
const config = JSON.parse(buildMcpVsCodeConfig([["DBX_MCP_ALLOW_WRITES", "0"]], { command: "node", args: ["C:\\dbx\\mcp\\dist\\index.js"] }));
|
||||
|
||||
expect(config).toEqual({
|
||||
servers: {
|
||||
dbx: {
|
||||
type: "stdio",
|
||||
command: "node",
|
||||
args: ["C:\\dbx\\mcp\\dist\\index.js"],
|
||||
env: {
|
||||
DBX_MCP_ALLOW_WRITES: "0",
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("builds Codex TOML config with env entries", () => {
|
||||
expect(buildMcpCodexConfig([["DBX_MCP_ALLOW_WRITES", "0"]])).toBe(["[mcp_servers.dbx]", 'command = "dbx-mcp-server"', "", "[mcp_servers.dbx.env]", 'DBX_MCP_ALLOW_WRITES = "0"'].join("\n"));
|
||||
});
|
||||
|
||||
it("builds Codex TOML config with a direct node launch command", () => {
|
||||
expect(buildMcpCodexConfig([["DBX_MCP_ALLOW_WRITES", "0"]], { command: "node", args: ["C:\\dbx\\mcp\\dist\\index.js"] })).toBe(["[mcp_servers.dbx]", 'command = "node"', 'args = ["C:\\\\dbx\\\\mcp\\\\dist\\\\index.js"]', "", "[mcp_servers.dbx.env]", 'DBX_MCP_ALLOW_WRITES = "0"'].join("\n"));
|
||||
});
|
||||
|
||||
it("builds OpenCode config using environment entries", () => {
|
||||
const config = JSON.parse(buildMcpOpenCodeConfig([["DBX_MCP_ALLOW_DANGEROUS_SQL", "1"]]));
|
||||
|
||||
@@ -62,4 +96,17 @@ describe("MCP config templates", () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("builds OpenCode config with a direct node launch command", () => {
|
||||
const config = JSON.parse(buildMcpOpenCodeConfig([], { command: "node", args: ["C:\\dbx\\mcp\\dist\\index.js"] }));
|
||||
|
||||
expect(config).toEqual({
|
||||
mcp: {
|
||||
dbx: {
|
||||
type: "local",
|
||||
command: ["node", "C:\\dbx\\mcp\\dist\\index.js"],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1849,11 +1849,13 @@ export async function checkMcpServerStatus(): Promise<import("./tauri").McpServe
|
||||
return {
|
||||
installed: false,
|
||||
npm_available: false,
|
||||
node_path: null,
|
||||
node_version: null,
|
||||
current_version: null,
|
||||
latest_version: null,
|
||||
update_available: false,
|
||||
bin_path: null,
|
||||
script_path: null,
|
||||
install_command: "npm install -g @dbx-app/mcp-server@latest --registry=https://registry.npmjs.org",
|
||||
update_command: "npm install -g @dbx-app/mcp-server@latest --registry=https://registry.npmjs.org",
|
||||
error: "MCP Server status is only available in the desktop app.",
|
||||
|
||||
@@ -1,12 +1,38 @@
|
||||
export type McpEnvEntry = readonly [key: string, value: string];
|
||||
|
||||
export interface McpLaunchConfig {
|
||||
command: string;
|
||||
args?: readonly string[];
|
||||
}
|
||||
|
||||
const DEFAULT_MCP_LAUNCH_CONFIG: McpLaunchConfig = {
|
||||
command: "dbx-mcp-server",
|
||||
};
|
||||
|
||||
function envObject(envEntries: readonly McpEnvEntry[]): Record<string, string> {
|
||||
return Object.fromEntries(envEntries);
|
||||
}
|
||||
|
||||
export function buildMcpJsonConfig(envEntries: readonly McpEnvEntry[] = []): string {
|
||||
function launchConfig(config?: McpLaunchConfig): McpLaunchConfig {
|
||||
return config ?? DEFAULT_MCP_LAUNCH_CONFIG;
|
||||
}
|
||||
|
||||
function withLaunchConfig(dbx: Record<string, unknown>, config?: McpLaunchConfig): Record<string, unknown> {
|
||||
const launch = launchConfig(config);
|
||||
dbx.command = launch.command;
|
||||
if (launch.args && launch.args.length > 0) {
|
||||
dbx.args = [...launch.args];
|
||||
}
|
||||
return dbx;
|
||||
}
|
||||
|
||||
function tomlStringArray(values: readonly string[]): string {
|
||||
return `[${values.map((value) => JSON.stringify(value)).join(", ")}]`;
|
||||
}
|
||||
|
||||
export function buildMcpJsonConfig(envEntries: readonly McpEnvEntry[] = [], config?: McpLaunchConfig): string {
|
||||
const dbx: Record<string, unknown> = {
|
||||
command: "dbx-mcp-server",
|
||||
...withLaunchConfig({}, config),
|
||||
};
|
||||
|
||||
if (envEntries.length > 0) {
|
||||
@@ -16,10 +42,10 @@ export function buildMcpJsonConfig(envEntries: readonly McpEnvEntry[] = []): str
|
||||
return JSON.stringify({ mcpServers: { dbx } }, null, 2);
|
||||
}
|
||||
|
||||
export function buildMcpVsCodeConfig(envEntries: readonly McpEnvEntry[] = []): string {
|
||||
export function buildMcpVsCodeConfig(envEntries: readonly McpEnvEntry[] = [], config?: McpLaunchConfig): string {
|
||||
const dbx: Record<string, unknown> = {
|
||||
type: "stdio",
|
||||
command: "dbx-mcp-server",
|
||||
...withLaunchConfig({}, config),
|
||||
};
|
||||
|
||||
if (envEntries.length > 0) {
|
||||
@@ -29,8 +55,13 @@ export function buildMcpVsCodeConfig(envEntries: readonly McpEnvEntry[] = []): s
|
||||
return JSON.stringify({ servers: { dbx } }, null, 2);
|
||||
}
|
||||
|
||||
export function buildMcpCodexConfig(envEntries: readonly McpEnvEntry[] = []): string {
|
||||
const lines = ["[mcp_servers.dbx]", 'command = "dbx-mcp-server"'];
|
||||
export function buildMcpCodexConfig(envEntries: readonly McpEnvEntry[] = [], config?: McpLaunchConfig): string {
|
||||
const launch = launchConfig(config);
|
||||
const lines = ["[mcp_servers.dbx]", `command = ${JSON.stringify(launch.command)}`];
|
||||
|
||||
if (launch.args && launch.args.length > 0) {
|
||||
lines.push(`args = ${tomlStringArray(launch.args)}`);
|
||||
}
|
||||
|
||||
if (envEntries.length > 0) {
|
||||
lines.push("");
|
||||
@@ -43,10 +74,11 @@ export function buildMcpCodexConfig(envEntries: readonly McpEnvEntry[] = []): st
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
export function buildMcpOpenCodeConfig(envEntries: readonly McpEnvEntry[] = []): string {
|
||||
export function buildMcpOpenCodeConfig(envEntries: readonly McpEnvEntry[] = [], config?: McpLaunchConfig): string {
|
||||
const launch = launchConfig(config);
|
||||
const dbx: Record<string, unknown> = {
|
||||
type: "local",
|
||||
command: ["dbx-mcp-server"],
|
||||
command: [launch.command, ...(launch.args ?? [])],
|
||||
};
|
||||
|
||||
if (envEntries.length > 0) {
|
||||
|
||||
@@ -1141,11 +1141,13 @@ export interface UpdateDownloadProgress {
|
||||
export interface McpServerStatus {
|
||||
installed: boolean;
|
||||
npm_available: boolean;
|
||||
node_path: string | null;
|
||||
node_version: string | null;
|
||||
current_version: string | null;
|
||||
latest_version: string | null;
|
||||
update_available: boolean;
|
||||
bin_path: string | null;
|
||||
script_path: string | null;
|
||||
install_command: string;
|
||||
update_command: string;
|
||||
error: string | null;
|
||||
|
||||
Reference in new issue
Block a user