diff --git a/plugins/plugin_utils/transport.py b/plugins/plugin_utils/transport.py index 38f5921..3141885 100644 --- a/plugins/plugin_utils/transport.py +++ b/plugins/plugin_utils/transport.py @@ -123,18 +123,21 @@ def _stdout_read(self, wait_timeout: int = 5) -> dict: """ response = {} + buffer = b"" if self._process: - rfd, wfd, efd = select.select([self._process.stdout], [], [], wait_timeout) - if not (rfd or wfd or efd): - # Process has timeout - raise AnsibleConnectionFailure( - f"MCP server response timeout after {wait_timeout} seconds." - ) - - if self._process.stdout in rfd: - response = json.loads( - os.read(self._process.stdout.fileno(), 4096).decode("utf-8").strip() - ) + while True: + rfd, wfd, efd = select.select([self._process.stdout], [], [], wait_timeout) + if self._process.stdout in rfd: + buffer += os.read(self._process.stdout.fileno(), 4096) + if b"\n" in buffer: + line, buffer = buffer.split(b"\n", 1) + response = json.loads(line.decode("utf-8")) + break + else: + # Process has timeout + raise AnsibleConnectionFailure( + f"MCP server response timeout after {wait_timeout} seconds." + ) return response def _stdin_write(self, data: dict) -> None: diff --git a/tox.ini b/tox.ini index 8568e96..a8054d5 100644 --- a/tox.ini +++ b/tox.ini @@ -7,7 +7,7 @@ deps = black flake8 isort - mypy + {[testenv:mypy]deps} skip_install = true allowlist_externals = {[testenv:mypy]allowlist_externals} @@ -22,13 +22,14 @@ setenv = {[testenv:mypy]setenv} [testenv:mypy] -deps = mypy +deps = + mypy + ansible-core skip_install = true allowlist_externals = mkdir ln rm - ansible-galaxy commands = rm -rf {toxinidir}/.collection_root ansible-galaxy collection install git+https://github.com/ansible-collections/ansible.utils.git --collections-path {toxinidir}/.collection_root