File tree 1 file changed +20
-5
lines changed 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -176,11 +176,26 @@ async def stdin_writer():
176
176
try :
177
177
yield read_stream , write_stream
178
178
finally :
179
- # Clean up process to prevent any dangling orphaned processes
180
- if sys .platform == "win32" :
181
- await terminate_windows_process (process )
182
- else :
183
- process .terminate ()
179
+ # MCP spec: stdio shutdown sequence
180
+ # 1. Close input stream to server
181
+ # 2. Wait for server to exit, or send SIGTERM if it doesn't exit in time
182
+ # 3. Send SIGKILL if still not exited
183
+ if process .stdin :
184
+ await process .stdin .aclose ()
185
+ try :
186
+ with anyio .fail_after (2.0 ):
187
+ await process .wait ()
188
+ except TimeoutError :
189
+ if sys .platform == "win32" :
190
+ await terminate_windows_process (process )
191
+ else :
192
+ process .terminate ()
193
+ try :
194
+ with anyio .fail_after (2.0 ):
195
+ await process .wait ()
196
+ except TimeoutError :
197
+ process .kill ()
198
+ await process .wait ()
184
199
await read_stream .aclose ()
185
200
await write_stream .aclose ()
186
201
You can’t perform that action at this time.
0 commit comments