Skip to content

Commit 18fc14c

Browse files
Fix anyio.to_thread.run_sync usage for Windows subprocess calls
The run_sync method doesn't accept keyword arguments directly. Wrap subprocess.run calls in lambda functions to fix the TypeError.
1 parent 4e8e4e8 commit 18fc14c

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/mcp/client/stdio/__init__.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,22 +259,24 @@ async def _kill_process_tree_windows(pid: int) -> None:
259259
# Use taskkill with /T flag to kill the process tree
260260
# Note: shell=True is needed on Windows for taskkill to work properly
261261
result = await anyio.to_thread.run_sync(
262-
subprocess.run,
263-
["taskkill", "/F", "/T", "/PID", str(pid)],
264-
capture_output=True,
265-
shell=True,
266-
check=False,
262+
lambda: subprocess.run(
263+
["taskkill", "/F", "/T", "/PID", str(pid)],
264+
capture_output=True,
265+
shell=True,
266+
check=False,
267+
)
267268
)
268269

269270
# If taskkill failed, try without /T flag as a fallback
270271
# This handles the case where the process might have already exited
271272
if result.returncode != 0:
272273
await anyio.to_thread.run_sync(
273-
subprocess.run,
274-
["taskkill", "/F", "/PID", str(pid)],
275-
capture_output=True,
276-
shell=True,
277-
check=False,
274+
lambda: subprocess.run(
275+
["taskkill", "/F", "/PID", str(pid)],
276+
capture_output=True,
277+
shell=True,
278+
check=False,
279+
)
278280
)
279281

280282

0 commit comments

Comments
 (0)