Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions apps/tauri/src-tauri/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> {
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(
Expand Down
4 changes: 3 additions & 1 deletion apps/tauri/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions apps/tauri/src-tauri/src/mcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

mod endpoint;
mod host;
pub mod paths;
mod server;
pub mod shim;

Expand Down
41 changes: 41 additions & 0 deletions apps/tauri/src-tauri/src/mcp/paths.rs
Original file line number Diff line number Diff line change
@@ -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<PathBuf, String> {
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)"
))
}
17 changes: 17 additions & 0 deletions apps/tauri/src/api/mcp.test.ts
Original file line number Diff line number Diff line change
@@ -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",
});
});
});
59 changes: 59 additions & 0 deletions apps/tauri/src/api/mcp.ts
Original file line number Diff line number Diff line change
@@ -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<McpStatus> {
return invoke<McpStatus>("mcp_start");
}

export async function mcpStop(): Promise<McpStatus> {
return invoke<McpStatus>("mcp_stop");
}

export async function mcpStatus(): Promise<McpStatus> {
return invoke<McpStatus>("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<string> {
try {
return await invoke<string>("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`;
}
4 changes: 4 additions & 0 deletions apps/tauri/src/stores/preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +33,7 @@ const defaults: PrefsState = {
historyMax: 200,
maxResultRows: 5000,
mcpEnabled: false,
mcpSharedIds: [],
uiScale: 100,
animateThemeChanges: true,
};
Expand Down Expand Up @@ -58,6 +61,7 @@ function load(): PrefsState {
const parsed = JSON.parse(raw) as Partial<PrefsState>;
const merged = { ...defaults, ...parsed };
merged.uiScale = normalizeUiScale(merged.uiScale);
if (!Array.isArray(merged.mcpSharedIds)) merged.mcpSharedIds = [];
return merged;
} catch {
return { ...defaults };
Expand Down
Loading
Loading