File tree Expand file tree Collapse file tree
apps/desktop/src-tauri/src/mcp Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments