Skip to content

Commit ede6463

Browse files
committed
MCP server can now be auto-reconnected by agents
The issue was that when the app hot-reloaded during development, the newly started version of the app didn't accept the old session ID.
1 parent 2f9160a commit ede6463

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

apps/desktop/src-tauri/src/mcp/server.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -308,23 +308,23 @@ async fn handle_mcp_post<R: Runtime>(
308308
.and_then(|v| v.to_str().ok())
309309
.map(|s| s.to_string());
310310

311-
// Only validate if client sends a session ID (stateless clients may not)
311+
// On session mismatch, auto-adopt the client's session ID instead of rejecting.
312+
// This is a single-user localhost server, so strict session validation adds no
313+
// security benefit and breaks the workflow when the app restarts during dev.
312314
if let Some(ref client_session) = provided_session
313315
&& let Ok(session_guard) = state.session_id.read()
314316
&& let Some(ref expected_session) = *session_guard
315317
&& client_session != expected_session
316318
{
317-
log::warn!(
318-
"MCP: Session ID mismatch (got: {}, expected: {})",
319+
log::info!(
320+
"MCP: Session ID mismatch (got: {}, expected: {}), auto-adopting client session",
319321
client_session,
320322
expected_session
321323
);
322-
let error = McpResponse::error(request.id.clone(), INVALID_REQUEST, "Invalid session ID");
323-
return if use_sse {
324-
build_sse_response(error, None)
325-
} else {
326-
(StatusCode::BAD_REQUEST, Json(error)).into_response()
327-
};
324+
drop(session_guard);
325+
if let Ok(mut session_guard) = state.session_id.write() {
326+
*session_guard = Some(client_session.clone());
327+
}
328328
}
329329

330330
// Validate protocol version matches negotiated version

0 commit comments

Comments
 (0)