Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions plugins/plugin_utils/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 4 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ deps =
black
flake8
isort
mypy
{[testenv:mypy]deps}
skip_install = true
allowlist_externals =
{[testenv:mypy]allowlist_externals}
Expand All @@ -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
Expand Down
Loading