diff --git a/apps/tauri/src-tauri/src/commands.rs b/apps/tauri/src-tauri/src/commands.rs index b6a7ff2b..5072063a 100644 --- a/apps/tauri/src-tauri/src/commands.rs +++ b/apps/tauri/src-tauri/src/commands.rs @@ -962,6 +962,12 @@ pub fn mcp_status( mcp.status() } +/// Resolve the bundled/session `querya-mcp` shim path (#2011). +#[tauri::command] +pub fn mcp_shim_executable() -> Result { + crate::mcp::paths::mcp_shim_executable().map(|p| p.display().to_string()) +} + /// Spawn an extension process and run `system.handshake` (#1903). #[tauri::command] pub async fn ext_host_start( diff --git a/apps/tauri/src-tauri/src/lib.rs b/apps/tauri/src-tauri/src/lib.rs index c7d0ef87..7d9bffef 100644 --- a/apps/tauri/src-tauri/src/lib.rs +++ b/apps/tauri/src-tauri/src/lib.rs @@ -35,7 +35,8 @@ use commands::{ mongo_list_databases, mongo_ping, profiles_connect_mongo, profiles_connect_mysql, profiles_connect_postgres, profiles_connect_redis, profiles_connect_sqlite, profiles_delete, profiles_list, profiles_upsert, redis_get, redis_key_metas, redis_ping, redis_read_key, - redis_scan, redis_set, mcp_start, mcp_status, mcp_stop, ssh_tunnel_close, ssh_tunnel_list, + redis_scan, redis_set, mcp_start, mcp_status, mcp_stop, mcp_shim_executable, ssh_tunnel_close, + ssh_tunnel_list, ssh_tunnel_open, ext_host_start, ext_host_call, ext_host_ping, ext_host_stop, ext_host_list, ext_hello_panel_executable, }; @@ -150,6 +151,7 @@ pub fn run() { mcp_start, mcp_stop, mcp_status, + mcp_shim_executable, ext_host_start, ext_host_call, ext_host_ping, diff --git a/apps/tauri/src-tauri/src/mcp/mod.rs b/apps/tauri/src-tauri/src/mcp/mod.rs index 46c59b74..89472ea5 100644 --- a/apps/tauri/src-tauri/src/mcp/mod.rs +++ b/apps/tauri/src-tauri/src/mcp/mod.rs @@ -2,6 +2,7 @@ mod endpoint; mod host; +pub mod paths; mod server; pub mod shim; diff --git a/apps/tauri/src-tauri/src/mcp/paths.rs b/apps/tauri/src-tauri/src/mcp/paths.rs new file mode 100644 index 00000000..24976ba4 --- /dev/null +++ b/apps/tauri/src-tauri/src/mcp/paths.rs @@ -0,0 +1,41 @@ +//! Resolve the `querya-mcp` stdio shim next to the desktop binary. + +use std::env; +use std::path::PathBuf; + +const NAME: &str = if cfg!(windows) { + "querya-mcp.exe" +} else { + "querya-mcp" +}; + +/// Absolute path when the shim sits beside the running executable. +pub fn mcp_shim_executable() -> Result { + if let Ok(raw) = env::var("QUERYA_MCP_SHIM") { + let path = PathBuf::from(raw.trim()); + if path.is_file() { + return Ok(path); + } + return Err(format!( + "QUERYA_MCP_SHIM is set but not a file: {}", + path.display() + )); + } + + let mut exe = env::current_exe().map_err(|e| format!("current_exe: {e}"))?; + exe.pop(); + let sibling = exe.join(NAME); + if sibling.is_file() { + return Ok(sibling); + } + if exe.ends_with("deps") { + exe.pop(); + let candidate = exe.join(NAME); + if candidate.is_file() { + return Ok(candidate); + } + } + Err(format!( + "{NAME} not found next to the app (build --bin querya-mcp or set QUERYA_MCP_SHIM)" + )) +} diff --git a/apps/tauri/src/api/mcp.test.ts b/apps/tauri/src/api/mcp.test.ts new file mode 100644 index 00000000..8cebae96 --- /dev/null +++ b/apps/tauri/src/api/mcp.test.ts @@ -0,0 +1,17 @@ +import { describe, expect, it } from "vitest"; +import { mcpClientSnippet } from "./mcp"; + +describe("mcpClientSnippet", () => { + it("builds Claude / Cursor mcpServers shape", () => { + const json = JSON.parse(mcpClientSnippet("cursor", "/opt/querya-mcp")); + expect(json.mcpServers.querya.command).toBe("/opt/querya-mcp"); + }); + + it("builds VS Code servers shape", () => { + const json = JSON.parse(mcpClientSnippet("vscode", "/opt/querya-mcp")); + expect(json.servers.querya).toEqual({ + type: "stdio", + command: "/opt/querya-mcp", + }); + }); +}); diff --git a/apps/tauri/src/api/mcp.ts b/apps/tauri/src/api/mcp.ts new file mode 100644 index 00000000..8d71afb5 --- /dev/null +++ b/apps/tauri/src/api/mcp.ts @@ -0,0 +1,59 @@ +import { invoke } from "@tauri-apps/api/core"; + +export type McpStatus = { + running: boolean; + port: number | null; + sessionCount: number; + endpointPath: string; +}; + +export type McpClientKind = "claude" | "cursor" | "vscode" | "generic"; + +export async function mcpStart(): Promise { + return invoke("mcp_start"); +} + +export async function mcpStop(): Promise { + return invoke("mcp_stop"); +} + +export async function mcpStatus(): Promise { + return invoke("mcp_status"); +} + +/** Best-effort path to the stdio shim next to the desktop binary. */ +export function defaultMcpShimPath(): string { + const name = + typeof navigator !== "undefined" && /Win/i.test(navigator.userAgent) + ? "querya-mcp.exe" + : "querya-mcp"; + return name; +} + +export async function mcpShimExecutable(): Promise { + try { + return await invoke("mcp_shim_executable"); + } catch { + return defaultMcpShimPath(); + } +} + +export function mcpClientSnippet( + kind: McpClientKind, + shimPath: string, +): string { + const path = shimPath.trim() || defaultMcpShimPath(); + const body = + kind === "vscode" + ? { + servers: { + querya: { type: "stdio", command: path }, + }, + } + : { + mcpServers: { + querya: { command: path }, + }, + }; + return `${JSON.stringify(body, null, 2)}\n`; +} diff --git a/apps/tauri/src/stores/preferences.ts b/apps/tauri/src/stores/preferences.ts index 99e27f5c..fa374814 100644 --- a/apps/tauri/src/stores/preferences.ts +++ b/apps/tauri/src/stores/preferences.ts @@ -15,6 +15,8 @@ export type PrefsState = { historyMax: number; maxResultRows: number; mcpEnabled: boolean; + /** Connection ids exposed to MCP clients (session filter). */ + mcpSharedIds: string[]; /** Percent — default 100. Presets or 1% fine values (75–200). */ uiScale: number; animateThemeChanges: boolean; @@ -31,6 +33,7 @@ const defaults: PrefsState = { historyMax: 200, maxResultRows: 5000, mcpEnabled: false, + mcpSharedIds: [], uiScale: 100, animateThemeChanges: true, }; @@ -58,6 +61,7 @@ function load(): PrefsState { const parsed = JSON.parse(raw) as Partial; const merged = { ...defaults, ...parsed }; merged.uiScale = normalizeUiScale(merged.uiScale); + if (!Array.isArray(merged.mcpSharedIds)) merged.mcpSharedIds = []; return merged; } catch { return { ...defaults }; diff --git a/apps/tauri/src/ui/PreferencesDialog.vue b/apps/tauri/src/ui/PreferencesDialog.vue index d1a6a620..dbe56ce6 100644 --- a/apps/tauri/src/ui/PreferencesDialog.vue +++ b/apps/tauri/src/ui/PreferencesDialog.vue @@ -7,6 +7,16 @@ import { } from "../theme/queryaTheme"; import { useQueryaMotion } from "../motion"; import type { QueryaMotionLevel } from "../motion/types"; +import { + mcpClientSnippet, + mcpShimExecutable, + mcpStart, + mcpStatus, + mcpStop, + type McpClientKind, + type McpStatus, +} from "../api/mcp"; +import { useConnectionsStore } from "../stores/connections"; import { usePreferencesStore } from "../stores/preferences"; import { allShortcuts, @@ -120,8 +130,83 @@ const searchEl = ref(null); const shortcutChip = ref<(typeof shortcutCategories)[number]>("All"); const themeMode = ref(readStoredTheme()); const prefs = usePreferencesStore(); +const connections = useConnectionsStore(); const motion = useQueryaMotion(); const extMsg = ref(null); +const mcpLive = ref(null); +const mcpBusy = ref(false); +const mcpMsg = ref(null); +const mcpShimPath = ref("querya-mcp"); +const syncingMcpToggle = ref(false); + +const mcpShareable = computed(() => + connections.items.filter((c) => !c.mock), +); + +function mcpShared(id: string): boolean { + return prefs.state.mcpSharedIds.includes(id); +} + +function setMcpShared(id: string, on: boolean) { + const set = new Set(prefs.state.mcpSharedIds); + if (on) set.add(id); + else set.delete(id); + prefs.state.mcpSharedIds = [...set]; +} + +async function refreshMcp() { + try { + mcpLive.value = await mcpStatus(); + mcpShimPath.value = await mcpShimExecutable(); + } catch (err) { + mcpMsg.value = String(err); + } +} + +async function applyMcpEnabled(want: boolean) { + if (syncingMcpToggle.value || mcpBusy.value) return; + mcpBusy.value = true; + mcpMsg.value = null; + try { + mcpLive.value = want ? await mcpStart() : await mcpStop(); + syncingMcpToggle.value = true; + prefs.state.mcpEnabled = mcpLive.value.running; + } catch (err) { + mcpMsg.value = String(err); + syncingMcpToggle.value = true; + prefs.state.mcpEnabled = false; + await refreshMcp(); + } finally { + syncingMcpToggle.value = false; + mcpBusy.value = false; + } +} + +async function onMcpToggle(ev: Event) { + const checked = (ev.target as HTMLInputElement).checked; + await applyMcpEnabled(checked); +} + +async function copyMcpConfig(kind: McpClientKind) { + const text = mcpClientSnippet(kind, mcpShimPath.value); + try { + await navigator.clipboard.writeText(text); + mcpMsg.value = `Copied ${kind} MCP config`; + } catch (err) { + mcpMsg.value = String(err); + } +} + +watch( + () => [props.open, category.value] as const, + async ([open, cat]) => { + if (!open || cat !== "mcp") return; + await refreshMcp(); + if (prefs.state.mcpEnabled && !mcpLive.value?.running) { + await applyMcpEnabled(true); + } + }, +); const searchQuery = computed(() => search.value.trim().toLowerCase()); const hasSearch = computed(() => searchQuery.value.length > 0); @@ -578,7 +663,7 @@ onUnmounted(() => window.removeEventListener("keydown", onKey, true)); -
+

MCP Server

Let AI clients (Claude, Cursor, VS Code, Gemini…) read shared @@ -588,42 +673,78 @@ onUnmounted(() => window.removeEventListener("keydown", onKey, true));

Enable MCP server {{ - prefs.state.mcpEnabled - ? "Running · stub host (Rust MCP epic next)" + mcpLive?.running + ? `Running · port ${mcpLive.port ?? "—"} · ${mcpLive.sessionCount} session${mcpLive.sessionCount === 1 ? "" : "s"}` : "Stopped — enable to expose Querya tools to MCP clients" }}
+

+ Endpoint: {{ mcpLive.endpointPath }} +

Shared connections

-

- No live connections yet. Open Demo or a database, then choose which - sessions MCP clients may read. +

+ No connections yet. Connect a database, then choose which sessions + MCP clients may read.

+

Connect a client

- Copy client configs and manage the access token when the in-process - MCP host lands. + Copy a stdio config that starts + {{ mcpShimPath }}, which talks to this running app.

- + Copy Claude Desktop config - + Copy Cursor config - + Copy VS Code config
+

{{ mcpMsg }}

@@ -1163,6 +1284,40 @@ kbd { font-weight: 650; } +.hint.mono { + font-family: var(--q-font-mono); + font-size: 11px; + word-break: break-all; +} + +.share-list { + list-style: none; + margin: 0; + padding: 0; + display: flex; + flex-direction: column; + gap: 6px; +} + +.share-row { + display: flex; + align-items: center; + gap: 8px; + font-size: 12px; + cursor: pointer; +} + +.share-name { + flex: 1; + min-width: 0; + color: var(--q-foreground); +} + +.share-meta { + color: var(--q-muted-foreground); + font-size: 11px; +} + .footer { flex: 0 0 auto; display: flex;