Skip to content

Commit 58cec7d

Browse files
committed
fix(lib): switch to single-threaded Tokio runtime to resolve TLS issues on Windows
1 parent fe8ee1e commit 58cec7d

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/lib.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ pub struct McpClient {
247247
/// Get or create the global Tokio runtime
248248
fn get_runtime() -> &'static tokio::runtime::Runtime {
249249
GLOBAL_RUNTIME.get_or_init(|| {
250-
tokio::runtime::Builder::new_multi_thread()
250+
// Use single-threaded runtime to avoid TLS issues with nested spawns on Windows
251+
tokio::runtime::Builder::new_current_thread()
251252
.enable_all()
252253
.build()
253254
.expect("Failed to create Tokio runtime")
@@ -802,11 +803,8 @@ pub extern "C" fn mcp_list_tools_init() -> usize {
802803
if let Some(client) = client_opt.as_ref() {
803804
// Clone the Arc to share the service across async boundaries
804805
let service_arc = client.service.clone();
805-
// Enter runtime context before spawning (Windows fix)
806-
let runtime = get_runtime();
807-
let _enter = runtime.enter();
808-
// Spawn async task directly on the global runtime (like the official rmcp examples)
809-
runtime.spawn(async move {
806+
// Spawn async task on the runtime
807+
get_runtime().spawn(async move {
810808
let service_guard = service_arc.lock().await;
811809
if let Some(service) = service_guard.as_ref() {
812810
match service.list_tools(None).await {
@@ -888,11 +886,8 @@ pub extern "C" fn mcp_call_tool_init(tool_name: *const c_char, arguments: *const
888886
let client_opt = client_mutex.lock().unwrap();
889887
if let Some(client) = client_opt.as_ref() {
890888
let service_arc = client.service.clone();
891-
// Enter runtime context before spawning (Windows fix)
892-
let runtime = get_runtime();
893-
let _enter = runtime.enter();
894-
// Spawn async task directly on the global runtime (like the official rmcp examples)
895-
runtime.spawn(async move {
889+
// Spawn async task on the runtime
890+
get_runtime().spawn(async move {
896891
let service_guard = service_arc.lock().await;
897892
if let Some(service) = service_guard.as_ref() {
898893
// Parse arguments

0 commit comments

Comments
 (0)