Skip to content

Commit b5659ed

Browse files
committed
fix(lib): use current-thread runtime for McpClient on Windows for better compatibility
1 parent b03a54f commit b5659ed

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/lib.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,16 @@ pub struct McpClient {
246246
/// Returns NULL on error
247247
#[no_mangle]
248248
pub extern "C" fn mcp_client_new() -> *mut McpClient {
249-
match tokio::runtime::Runtime::new() {
249+
// On Windows, use current-thread runtime for better compatibility
250+
let runtime_result = if cfg!(windows) {
251+
tokio::runtime::Builder::new_current_thread()
252+
.enable_all()
253+
.build()
254+
} else {
255+
tokio::runtime::Runtime::new()
256+
};
257+
258+
match runtime_result {
250259
Ok(runtime) => {
251260
let client = Box::new(McpClient {
252261
runtime,
@@ -324,8 +333,15 @@ pub extern "C" fn mcp_connect(
324333
};
325334

326335
// Create a new McpClient with runtime
336+
// On Windows, use current-thread runtime for better compatibility
327337
let new_client = McpClient {
328-
runtime: match tokio::runtime::Runtime::new() {
338+
runtime: match if cfg!(windows) {
339+
tokio::runtime::Builder::new_current_thread()
340+
.enable_all()
341+
.build()
342+
} else {
343+
tokio::runtime::Runtime::new()
344+
} {
329345
Ok(r) => r,
330346
Err(e) => {
331347
let error = format!(r#"{{"error": "Failed to create runtime: {}"}}"#, e);

0 commit comments

Comments
 (0)