fix(mcp): route ssh transport layers through desktop bridge
This commit is contained in:
@@ -149,6 +149,10 @@ async function getMysqlPool(config: ConnectionConfig): Promise<import("mysql2/pr
|
||||
|
||||
type ProxyLayer = { type: "proxy" } & ProxyTunnelConfig;
|
||||
|
||||
function hasActiveSshLayer(config: ConnectionConfig): boolean {
|
||||
return config.transport_layers?.some((layer) => layer.type === "ssh" && layer.enabled !== false && !!layer.host) ?? false;
|
||||
}
|
||||
|
||||
function firstProxyLayer(config: ConnectionConfig): ProxyLayer | undefined {
|
||||
return config.transport_layers?.find((layer): layer is ProxyLayer => layer.type === "proxy" && layer.enabled !== false && !!layer.host);
|
||||
}
|
||||
@@ -502,6 +506,17 @@ async function rqliteRequest(config: ConnectionConfig, endpoint: "/db/query" | "
|
||||
}
|
||||
|
||||
export async function executeQuery(config: ConnectionConfig, sql: string, options?: QueryOptions): Promise<QueryResult> {
|
||||
if (hasActiveSshLayer(config)) {
|
||||
const result = await withTimeout(
|
||||
bridgeDataRequest<BridgeQueryResult>("/data/execute-query", {
|
||||
connection_name: config.name,
|
||||
database: config.database || "",
|
||||
sql,
|
||||
}),
|
||||
resolveTimeoutMs(options),
|
||||
);
|
||||
return convertBridgeQueryResult(result, options);
|
||||
}
|
||||
if (config.db_type === "mongodb") {
|
||||
const find = parseMongoFindCommand(sql);
|
||||
if (find) {
|
||||
@@ -561,7 +576,7 @@ export async function listTables(config: ConnectionConfig, schema?: string): Pro
|
||||
const result = await query(config, `SELECT name, type FROM sqlite_master WHERE type IN ('table', 'view') AND name NOT LIKE 'sqlite_%' ORDER BY name`);
|
||||
return result.rows.map((r) => ({ name: String(r.name || ""), type: String(r.type || "table") }));
|
||||
}
|
||||
if (!isDirectQueryType(config.db_type)) {
|
||||
if (hasActiveSshLayer(config) || !isDirectQueryType(config.db_type)) {
|
||||
const tables = await bridgeDataRequest<BridgeTableInfo[]>("/data/list-tables", {
|
||||
connection_name: config.name,
|
||||
database: config.database || "",
|
||||
@@ -594,7 +609,7 @@ export async function describeTable(config: ConnectionConfig, table: string, sch
|
||||
comment: null,
|
||||
}));
|
||||
}
|
||||
if (!isDirectQueryType(config.db_type)) {
|
||||
if (hasActiveSshLayer(config) || !isDirectQueryType(config.db_type)) {
|
||||
const columns = await bridgeDataRequest<BridgeColumnInfo[]>("/data/describe-table", {
|
||||
connection_name: config.name,
|
||||
database: config.database || "",
|
||||
|
||||
Reference in New Issue
Block a user