13
13
from anyio .abc import Process
14
14
from anyio .streams .file import FileReadStream , FileWriteStream
15
15
16
+
16
17
def get_windows_executable_command (command : str ) -> str :
17
18
"""
18
19
Get the correct executable command normalized for Windows.
@@ -44,15 +45,17 @@ def get_windows_executable_command(command: str) -> str:
44
45
# (permissions, broken symlinks, etc.)
45
46
return command
46
47
48
+
47
49
class DummyProcess :
48
50
"""
49
- A fallback process wrapper for Windows to handle async I/O
51
+ A fallback process wrapper for Windows to handle async I/O
50
52
when using subprocess.Popen, which provides sync-only FileIO objects.
51
-
52
- This wraps stdin and stdout into async-compatible
53
+
54
+ This wraps stdin and stdout into async-compatible
53
55
streams (FileReadStream, FileWriteStream),
54
56
so that MCP clients expecting async streams can work properly.
55
57
"""
58
+
56
59
def __init__ (self , popen_obj : subprocess .Popen [bytes ]):
57
60
self .popen : subprocess .Popen [bytes ] = popen_obj
58
61
self .stdin_raw : IO [bytes ] | None = popen_obj .stdin
@@ -79,10 +82,12 @@ def terminate(self):
79
82
"""Terminate the subprocess immediately."""
80
83
return self .popen .terminate ()
81
84
85
+
82
86
# ------------------------
83
87
# Updated function
84
88
# ------------------------
85
89
90
+
86
91
async def create_windows_process (
87
92
command : str ,
88
93
args : list [str ],
@@ -92,9 +97,9 @@ async def create_windows_process(
92
97
) -> DummyProcess :
93
98
"""
94
99
Creates a subprocess in a Windows-compatible way.
95
-
96
- On Windows, asyncio.create_subprocess_exec has incomplete support
97
- (NotImplementedError when trying to open subprocesses).
100
+
101
+ On Windows, asyncio.create_subprocess_exec has incomplete support
102
+ (NotImplementedError when trying to open subprocesses).
98
103
Therefore, we fallback to subprocess.Popen and wrap it for async usage.
99
104
100
105
Args:
@@ -118,8 +123,8 @@ async def create_windows_process(
118
123
cwd = cwd ,
119
124
bufsize = 0 , # Unbuffered output
120
125
creationflags = (
121
- subprocess .CREATE_NO_WINDOW
122
- if hasattr (subprocess , "CREATE_NO_WINDOW" )
126
+ subprocess .CREATE_NO_WINDOW
127
+ if hasattr (subprocess , "CREATE_NO_WINDOW" )
123
128
else 0
124
129
),
125
130
)
0 commit comments