Skip to content

Commit 2c513d0

Browse files
committed
fix(lib): enter runtime context before block_on in spawn_blocking for better FFI handling on Windows
1 parent a893ed6 commit 2c513d0

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,8 @@ pub extern "C" fn mcp_list_tools_init() -> usize {
792792
// Use spawn_blocking which handles FFI context better on Windows
793793
let runtime_handle_clone = runtime_handle.clone();
794794
runtime_handle.spawn_blocking(move || {
795+
// Enter runtime context BEFORE block_on to set thread-local runtime for tokio::spawn()
796+
let _guard = runtime_handle_clone.enter();
795797
runtime_handle_clone.block_on(async move {
796798
let service_guard = service_arc.lock().await;
797799
if let Some(service) = service_guard.as_ref() {
@@ -880,6 +882,8 @@ pub extern "C" fn mcp_call_tool_init(tool_name: *const c_char, arguments: *const
880882
// Use spawn_blocking which handles FFI context better on Windows
881883
let runtime_handle_clone = runtime_handle.clone();
882884
runtime_handle.spawn_blocking(move || {
885+
// Enter runtime context BEFORE block_on to set thread-local runtime for tokio::spawn()
886+
let _guard = runtime_handle_clone.enter();
883887
runtime_handle_clone.block_on(async move {
884888
let service_guard = service_arc.lock().await;
885889
if let Some(service) = service_guard.as_ref() {

0 commit comments

Comments
 (0)