feat(mcp): notify desktop UI to reload after connection add/remove
Add /reload-connections bridge route that emits mcp-reload-connections event, triggering the frontend to re-read connections from SQLite.
This commit is contained in:
parent
30b6c472ea
commit
68d8776e8f
|
|
@ -159,6 +159,7 @@ server.tool(
|
|||
name, db_type, host, port, username, password,
|
||||
database, ssl, ssh_enabled: false,
|
||||
} as Omit<ConnectionConfig, "id">);
|
||||
await notifyReload();
|
||||
return text(`Connection "${config.name}" added (id: ${config.id}).`);
|
||||
},
|
||||
);
|
||||
|
|
@ -172,6 +173,7 @@ server.tool(
|
|||
async ({ connection_name }) => {
|
||||
const removed = await backend.removeConnection(connection_name);
|
||||
if (!removed) return text(`Connection "${connection_name}" not found.`);
|
||||
await notifyReload();
|
||||
return text(`Connection "${connection_name}" removed.`);
|
||||
},
|
||||
);
|
||||
|
|
@ -200,6 +202,13 @@ async function getBridgeUrl(): Promise<string> {
|
|||
return `http://127.0.0.1:${port}`;
|
||||
}
|
||||
|
||||
async function notifyReload(): Promise<void> {
|
||||
try {
|
||||
const bridgeUrl = await getBridgeUrl();
|
||||
await fetch(`${bridgeUrl}/reload-connections`, { method: "POST" });
|
||||
} catch {}
|
||||
}
|
||||
|
||||
// Desktop-only tools: open table and execute-and-show require the Tauri bridge
|
||||
if (!isWebMode) {
|
||||
server.tool(
|
||||
|
|
|
|||
|
|
@ -74,6 +74,9 @@ pub fn start(app_handle: AppHandle, state: Arc<AppState>) {
|
|||
handle_open_table(&app, &st, body, &mut stream).await;
|
||||
} else if first_line.starts_with("POST /execute-query") {
|
||||
handle_execute_query(&app, &st, body, &mut stream).await;
|
||||
} else if first_line.starts_with("POST /reload-connections") {
|
||||
let _ = app.emit("mcp-reload-connections", ());
|
||||
respond(&mut stream, "200 OK", "ok").await;
|
||||
} else {
|
||||
let _ = stream.write_all(b"HTTP/1.1 404 Not Found\r\nContent-Length: 0\r\n\r\n").await;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,9 @@ export function useTauriEvents(deps: { openTableTarget: (target: NavigationTarge
|
|||
);
|
||||
},
|
||||
);
|
||||
listen("mcp-reload-connections", async () => {
|
||||
await connectionStore.initFromDisk();
|
||||
});
|
||||
listen<{ connection_id: string; database: string; sql: string }>("mcp-execute-query", async (event) => {
|
||||
const { connection_id, database, sql } = event.payload;
|
||||
if (!connectionStore.connections.length) await connectionStore.initFromDisk();
|
||||
|
|
|
|||
Loading…
Reference in New Issue