Skip to content

Commit 005e411

Browse files
feat: wire MCP bridge into sqlkit Tauri setup and commands
Integrates the MCP bridge into sqlkit's app lifecycle: - Initialize McpServerHandle as managed Tauri state - Read mcp-config.json and auto-start bridge in setup hook - Register get_mcp_status and save_mcp_config Tauri commands Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
1 parent fcc1d80 commit 005e411

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

‎src-tauri/src/lib.rs‎

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub mod agent_adapters;
2222
pub mod capabilities;
2323
pub mod common;
2424
pub mod db;
25+
pub mod mcp_bridge;
2526

2627
use std::sync::Arc;
2728
use std::sync::OnceLock;
@@ -140,6 +141,37 @@ pub fn run() {
140141
app.manage(cancel_map);
141142
let executor: Arc<dyn lib::ToolExecutor> = Arc::new(SqlKitToolExecutor);
142143
app.manage(executor);
144+
app.manage(crate::mcp_bridge::McpServerHandle::new());
145+
146+
{
147+
let app_data_dir = app.path().app_data_dir().map_err(|e| format!("{}", e))?
148+
.to_path_buf();
149+
let config = crate::mcp_bridge::McpConfig::load(&app_data_dir);
150+
if config.auto_start {
151+
let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel();
152+
let server_handle: tauri::State<'_, crate::mcp_bridge::McpServerHandle> =
153+
app.state();
154+
{
155+
let mut tx = server_handle.shutdown_tx.lock().unwrap();
156+
*tx = Some(shutdown_tx);
157+
}
158+
let bridge_handle = app.handle().clone();
159+
let data_dir = app_data_dir.clone();
160+
let preferred = config.port.unwrap_or(9121);
161+
tauri::async_runtime::spawn(async move {
162+
if let Err(e) = crate::mcp_bridge::start(
163+
bridge_handle,
164+
data_dir,
165+
preferred,
166+
shutdown_rx,
167+
)
168+
.await
169+
{
170+
log::error!("MCP bridge failed to start: {}", e);
171+
}
172+
});
173+
}
174+
}
143175

144176
use tauri::{Emitter, Listener};
145177

@@ -292,6 +324,8 @@ pub fn run() {
292324
commands::generate_ddl_for_objects,
293325
commands::execute_sql_content,
294326
commands::get_app_version,
327+
crate::mcp_bridge::get_mcp_status,
328+
crate::mcp_bridge::save_mcp_config,
295329
])
296330
.run(tauri::generate_context!())
297331
.expect("error while running tauri application");

0 commit comments

Comments
 (0)