Skip to content

Commit a4eb8da

Browse files
committed
perf(mcp): move table creation to background task
Moving create_tables to the background task prevents blocking the main thread during startup, allowing the MCP server to respond to the initial handshake immediately. This significantly improves perceived performance and connectivity with clients that have short timeouts. Signed-off-by: Roman Gushchin <[email protected]>
1 parent 59694ed commit a4eb8da

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/bin/semcode-mcp.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5178,16 +5178,18 @@ async fn main() -> Result<()> {
51785178
// Create MCP server
51795179
let server = Arc::new(McpServer::new(&database_path, &args.git_repo, args.model_path).await?);
51805180

5181-
// Ensure tables exist
5182-
server.db.create_tables().await?;
5183-
51845181
// Spawn background task to index current commit if needed
51855182
eprintln!("[Background] Spawning background indexing task");
51865183
let db_for_indexing = server.db.clone();
51875184
let git_repo_for_indexing = args.git_repo.clone();
51885185
let indexing_state_for_bg = server.indexing_state.clone();
51895186
let notification_tx_for_bg = server.notification_tx.clone();
51905187
let _indexing_handle = tokio::spawn(async move {
5188+
// Ensure tables exist before indexing
5189+
if let Err(e) = db_for_indexing.create_tables().await {
5190+
eprintln!("[Background] Error creating/verifying tables: {}", e);
5191+
}
5192+
51915193
index_current_commit_background(
51925194
db_for_indexing,
51935195
git_repo_for_indexing,

0 commit comments

Comments
 (0)