(self, timeout=60)
| 64 | self.proc.stdin.flush() |
| 65 | |
| 66 | def _read_message(self, timeout=60): |
| 67 | result = {} |
| 68 | |
| 69 | def reader(): |
| 70 | try: |
| 71 | result["line"] = self.proc.stdout.readline() |
| 72 | except Exception as ex: |
| 73 | result["exc"] = ex |
| 74 | |
| 75 | th = threading.Thread(target=reader, daemon=True) |
| 76 | th.start() |
| 77 | th.join(timeout) |
| 78 | if th.is_alive(): |
| 79 | raise McpError("timeout after %ss (hang)" % timeout) |
| 80 | if "exc" in result: |
| 81 | raise McpError("read error: %r" % result["exc"]) |
| 82 | line = result.get("line", b"") |
| 83 | if not line: |
| 84 | self._stderr_thread.join(timeout=1) |
| 85 | stderr = self.stderr_text().strip() |
| 86 | detail = ": %s" % stderr[-1200:] if stderr else "" |
| 87 | raise McpError("EOF / server closed stdout%s" % detail) |
| 88 | # strict: an invalid-UTF-8 JSON-RPC response is itself a failure. |
| 89 | return json.loads(line.decode("utf-8", "strict")) |
| 90 | |
| 91 | def request(self, method, params=None, timeout=60): |
| 92 | self._id += 1 |
no test coverage detected