feat(mcp): add native installs and resource discovery

This commit is contained in:
t8y2 committed 2026-09-25 12:37:26 +08:00
1 parent 3144762194
commit b8274363b8
36 files changed
+1934 -103

No files matched your search

@@ -1,7 +1,35 @@
import { describe, expect, it } from "vitest";
import { buildMcpCherryStudioConfig, buildMcpCodexConfig, buildMcpDeepSeekHarnessConfig, buildMcpJsonConfig, buildMcpOpenCodeConfig, buildMcpPiConfig, buildMcpQoderConfig, buildMcpTraeConfig, buildMcpVsCodeConfig, buildMcpWorkBuddyConfig, mcpWebBackendUrl } from "@/lib/mcp/mcpConfigTemplates";
import {
buildMcpCherryStudioConfig,
buildMcpCodexConfig,
buildMcpDeepSeekHarnessConfig,
buildMcpJsonConfig,
buildMcpOpenCodeConfig,
buildMcpPiConfig,
buildMcpQoderConfig,
buildMcpTraeConfig,
buildMcpVsCodeConfig,
buildMcpWorkBuddyConfig,
mcpWebBackendUrl,
preferMcpNativeLaunch,
} from "@/lib/mcp/mcpConfigTemplates";
describe("MCP config templates", () => {
it.each(["/Users/DBX User/.dbx/bin/dbx-mcp", "/home/dbx/.dbx/bin/dbx-mcp", "C:\\Users\\DBX User\\.dbx\\bin\\dbx-mcp.exe"])("prefers native launch for every client: %s", (binary) => {
const shim = { command: "node", args: ["/old/shim.js"], env: { DBX_DATA_DIR: "/custom/data" } };
const native = preferMcpNativeLaunch(shim, binary);
expect(native).toEqual({ command: binary, env: shim.env });
for (const builder of [buildMcpJsonConfig, buildMcpTraeConfig, buildMcpQoderConfig, buildMcpVsCodeConfig, buildMcpCherryStudioConfig, buildMcpCodexConfig, buildMcpDeepSeekHarnessConfig, buildMcpOpenCodeConfig, buildMcpPiConfig, buildMcpWorkBuddyConfig]) {
const result = builder(native);
expect(result).toContain(JSON.stringify(binary));
expect(result).toContain("DBX_DATA_DIR");
expect(result).not.toContain("shim.js");
}
expect(preferMcpNativeLaunch(shim)).toBe(shim);
expect(preferMcpNativeLaunch(shim, "")).toBe(shim);
expect(preferMcpNativeLaunch()).toBeUndefined();
});
it("builds the standard mcpServers JSON used by Claude, Cursor, TRAE, and Windsurf", () => {
const config = JSON.parse(buildMcpJsonConfig());
@@ -6,6 +6,20 @@ const tauriBackendSource = readFileSync(new URL("../../../lib/backend/tauri.ts",
const httpBackendSource = readFileSync(new URL("../../../lib/backend/http.ts", import.meta.url), "utf8");
describe("MCP server management", () => {
it("makes native installation the default while preserving npm as a migration fallback", () => {
expect(settingsDialogSource).toContain('mcpStatus.value?.installation_source === "npm"');
expect(settingsDialogSource).toContain('t("settings.mcpSwitchToNativeButton")');
expect(settingsDialogSource).toContain('t("settings.mcpNativeMigrationHint")');
expect(settingsDialogSource).toContain("await installNativeMcpServer()");
expect(settingsDialogSource).toContain("await uninstallNpmMcpServer()");
expect(settingsDialogSource).toContain("mcpStatus?.installation_source !== 'npm' && mcpStatus?.npm_installed");
expect(settingsDialogSource).toContain(':disabled="mcpInstallDisabled"');
expect(settingsDialogSource).not.toContain("!mcpStatus?.npm_available");
expect(tauriBackendSource).toContain('installation_source: "native" | "homebrew" | "npm" | null');
expect(tauriBackendSource).toContain('invoke("install_native_mcp_server")');
expect(tauriBackendSource).toContain('invoke("uninstall_npm_mcp_server")');
});
it("exposes a confirmed uninstall action only for an installed desktop server", () => {
expect(settingsDialogSource).toContain('v-if="!isWeb && mcpStatus?.installed"');
expect(settingsDialogSource).toContain('window.confirm(t("settings.mcpUninstallConfirm"))');
+2
View File
@@ -921,7 +921,9 @@ export const deleteHistoryEntry = forward("deleteHistoryEntry");
// Updates
export const checkMcpServerStatus = forward("checkMcpServerStatus");
export const installMcpServer = forward("installMcpServer");
export const installNativeMcpServer = forward("installNativeMcpServer");
export const uninstallMcpServer = forward("uninstallMcpServer");
export const uninstallNpmMcpServer = forward("uninstallNpmMcpServer");
export const loadMcpHttpServerSettings = forward("loadMcpHttpServerSettings");
export const saveMcpHttpServerSettings = forward("saveMcpHttpServerSettings");
export const mcpHttpServerStatus = forward("mcpHttpServerStatus");
+10
View File
@@ -5200,7 +5200,9 @@ export async function fetchChangelog(lang?: string): Promise<import("@/lib/app/c
export async function checkMcpServerStatus(): Promise<import("@/lib/backend/tauri").McpServerStatus> {
return {
installed: false,
installation_source: null,
npm_available: false,
npm_installed: false,
node_path: null,
node_version: null,
current_version: null,
@@ -5221,10 +5223,18 @@ export async function installMcpServer(): Promise<string> {
throw new Error("MCP Server installation is only available in the desktop app.");
}
export async function installNativeMcpServer(): Promise<string> {
throw new Error("Native MCP Server installation is only available in the desktop app.");
}
export async function uninstallMcpServer(): Promise<string> {
throw new Error("MCP Server uninstallation is only available in the desktop app.");
}
export async function uninstallNpmMcpServer(): Promise<string> {
throw new Error("MCP Server npm fallback removal is only available in the desktop app.");
}
export async function getSystemProxyUrl(): Promise<string | null> {
return null;
}
+10
View File
@@ -2968,7 +2968,9 @@ export interface UpdateDownloadProgress {
export interface McpServerStatus {
installed: boolean;
installation_source: "native" | "homebrew" | "npm" | null;
npm_available: boolean;
npm_installed: boolean;
node_path: string | null;
node_version: string | null;
current_version: string | null;
@@ -2992,10 +2994,18 @@ export async function installMcpServer(): Promise<string> {
return invoke("install_mcp_server");
}
export async function installNativeMcpServer(): Promise<string> {
return invoke("install_native_mcp_server");
}
export async function uninstallMcpServer(): Promise<string> {
return invoke("uninstall_mcp_server");
}
export async function uninstallNpmMcpServer(): Promise<string> {
return invoke("uninstall_npm_mcp_server");
}
export async function checkForUpdates(locale?: string, source?: UpdateDownloadSource): Promise<UpdateInfo> {
return invoke("check_for_updates", { locale, source });
}
@@ -8,6 +8,10 @@ const DEFAULT_MCP_LAUNCH_CONFIG: McpLaunchConfig = {
command: "dbx-mcp-server",
};
export function preferMcpNativeLaunch(config?: McpLaunchConfig, nativeBinPath?: string | null): McpLaunchConfig | undefined {
return nativeBinPath ? { command: nativeBinPath, env: config?.env } : config;
}
function launchConfig(config?: McpLaunchConfig): McpLaunchConfig {
return config ?? DEFAULT_MCP_LAUNCH_CONFIG;
}
@@ -41,7 +45,7 @@ export function buildMcpJsonConfig(config?: McpLaunchConfig): string {
}
export function buildMcpTraeConfig(config?: McpLaunchConfig, nativeBinPath?: string): string {
return buildMcpJsonConfig(nativeBinPath ? { command: nativeBinPath, env: config?.env } : config);
return buildMcpJsonConfig(preferMcpNativeLaunch(config, nativeBinPath));
}
export function buildMcpQoderConfig(config?: McpLaunchConfig, nativeBinPath?: string): string {
@@ -81,7 +81,9 @@ export function previewJdbcUpdate(): JdbcPluginStatus {
export function previewMcpUpdate(): McpServerStatus {
return {
installed: true,
installation_source: "npm",
npm_available: true,
npm_installed: true,
node_path: "/preview/bin/node",
node_version: "v22.18.0",
current_version: "0.4.88",