| 350 | |
| 351 | class McpClient: |
| 352 | def __init__(self, binary, env, stderr_path): |
| 353 | self.stderr_path = stderr_path |
| 354 | self.stderr_stream = stderr_path.open("w", encoding="utf-8") |
| 355 | self.process = subprocess.Popen( |
| 356 | [str(binary)], |
| 357 | stdin=subprocess.PIPE, |
| 358 | stdout=subprocess.PIPE, |
| 359 | stderr=self.stderr_stream, |
| 360 | text=True, |
| 361 | bufsize=1, |
| 362 | env=env, |
| 363 | ) |
| 364 | self.condition = threading.Condition() |
| 365 | self.responses = {} |
| 366 | self.other_output = [] |
| 367 | self.stdout_closed = False |
| 368 | self.reader = threading.Thread(target=self._read_stdout, daemon=True) |
| 369 | self.reader.start() |
| 370 | |
| 371 | def _read_stdout(self): |
| 372 | assert self.process.stdout is not None |