crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[BUG] MCP HTTP client crashes with "asyncio.run() cannot be called from a running event loop" when flow uses streamable HTTP transport

Open humatic-ai opened this issue 3 months ago • 5 comments

Description

Bug Report

Summary

When a CrewAI Flow runs an agent action with an MCP server configured via streamable: true (Streamable HTTP / SSE transport), the MCP tool resolver crashes immediately with: RuntimeError: Failed to get native MCP tools: asyncio.run() cannot be called from a running event loop

The agent never receives any tools and fails before executing. ### Environment - CrewAI Studio (hosted platform) - Python 3.13.14 - crewai (latest, as installed in platform venv) - MCP server: Streamable HTTP (public HTTPS endpoint) - Flow transport: streamable: true ### Full traceback McpError: Session terminated ↓ ConnectionError: Failed to connect to MCP server: Session terminated ↓ RuntimeError: Error during setup client and list tools: Failed to connect to MCP server: Session terminated ↓ RuntimeError: asyncio.run() cannot be called from a running event loop

File "crewai/mcp/tool_resolver.py", line 368, in _resolve_native tools_list = asyncio.run(_setup_client_and_list_tools()) RuntimeError: asyncio.run() cannot be called from a running event loop

Root cause crewai/mcp/tool_resolver.py line ~368 calls asyncio.run() to fetch the MCP tool list. However, CrewAI Flows already run inside an active asyncio event loop (via asyncio.run(_run_flow()) in flow/runtime/__init__.py). Python forbids calling asyncio.run() from within a running event loop — it raises RuntimeError immediately. ### Steps to reproduce 1. Create a CrewAI Flow with a start method using call: agent 2. Configure the agent with an MCP server: ```yaml mcps: - url: https://your-mcp-server.example.com/mcp streamable: true cache_tools_list: true

Kick off the flow Observe the asyncio.run() cannot be called from a running event loop crash Expected behavior The MCP client connects to the server, discovers tools, and the agent runs normally.

Actual behavior tool_resolver.py calls asyncio.run() inside the already-running flow event loop → immediate RuntimeError → agent has zero tools → flow fails.

Proposed fix Replace the asyncio.run() call in tool_resolver.py with an async-safe alternative:

Option A — nest_asyncio (minimal change):

import nest_asyncio nest_asyncio.apply() loop = asyncio.get_event_loop() tools_list = loop.run_until_complete(_setup_client_and_list_tools()) Option B — anyio (already a CrewAI dependency):

import anyio tools_list = anyio.from_thread.run_sync( lambda: anyio.run(_setup_client_and_list_tools) ) Option C — restructure to async (cleanest long-term): Make _resolve_native an async method and await _setup_client_and_list_tools() directly, since the call site is already inside an async context.

Additional context The MCP server itself works correctly — it is confirmed reachable and functional from Claude.ai's MCP client using the same endpoint and OAuth transport The bug affects all Streamable HTTP MCP configurations in Flows (not just OAuth-protected servers) streamable: false (SSE) triggers the same crash via a slightly different code path This blocks per-user authenticated MCP use cases entirely on the CrewAI Studio platform

Steps to Reproduce

  1. Create a CrewAI Flow with a start method using call: agent 2. Configure the agent with an MCP server: mcps: - url: https://your-mcp-server.example.com/mcp streamable: true cache_tools_list: true 3. Kick off the flow 4. Observe the crash: "RuntimeError: Failed to get native MCP tools: asyncio.run() cannot be called from a running event loop" Root cause: tool_resolver.py line ~368 calls asyncio.run() inside the already-running Flow event loop (flow/runtime/init.py runs the flow via asyncio.run(_run_flow())). Python forbids nested asyncio.run() calls and raises RuntimeError immediately — the agent receives zero tools and the flow fails. The MCP server itself is confirmed working (Claude.ai connects to the same endpoint successfully). This affects all Streamable HTTP MCP configurations in Flows.

Expected behavior

The MCP client connects to the Streamable HTTP MCP server, fetches the tool list successfully, and the agent runs with all discovered tools available — calling them normally and returning results to the flow.

Screenshots/Code snippets

Subprocess execution failed: Subprocess failed with return code 1. STDERR: warning: VIRTUAL_ENV=/local/venv does not match the project environment path /tmp/crewai_qcdbrlfx_venv and will be ignored; use --active to target the active environment instead Installed 1 package in 19ms an error occurred during closing of asynchronous generator <async_generator object streamable_http_client at 0x7ff67917cf60> asyncgen: <async_generator object streamable_http_client at 0x7ff67917cf60>

  • Exception Group Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 815, in aexit | raise BaseExceptionGroup( | "unhandled errors in a TaskGroup", self._exceptions | ) from None | BaseExceptionGroup: unhandled errors in a TaskGroup (2 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_core/_tasks.py", line 275, in _run_coro | retval = await self._coro | ^^^^^^^^^^^^^^^^ | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 565, in handle_request_async | await self._handle_post_request(ctx) | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 358, in _handle_post_request | response.raise_for_status() | ~~~~~~~~~~~~~~~~~~~~~~~~~^^ | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/httpx/_models.py", line 829, in raise_for_status | raise HTTPStatusError(message, request=request, response=self) | httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://intranet.sharpsir.group/qobrix-crm/mcp' | For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 +---------------- 2 ---------------- | Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 670, in streamable_http_client | yield ( | ...<3 lines>... | ) | GeneratorExit +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 647, in streamable_http_client async with anyio.create_task_group() as tg: ~~~~~~~~~~~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 821, in aexit if self.cancel_scope.exit(type(exc), exc, exc.traceback): ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 464, in exit raise RuntimeError( ...<2 lines>... ) RuntimeError: Attempted to exit cancel scope in a different task than it was entered in an error occurred during closing of asynchronous generator <async_generator object streamablehttp_client at 0x7ff6780ec180> asyncgen: <async_generator object streamablehttp_client at 0x7ff6780ec180> Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 722, in streamablehttp_client yield streams GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 717, in streamablehttp_client async with streamable_http_client( ~~~~~~~~~~~~~~~~~~~~~~^ url, ^^^^ http_client=client, ^^^^^^^^^^^^^^^^^^^ terminate_on_close=terminate_on_close, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) as streams: ^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 235, in aexit await self.gen.athrow(value) RuntimeError: athrow(): asynchronous generator is already running Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2038, in kickoff asyncio.get_running_loop() ~~~~~~~~~~~~~~~~~~~~~~~~^^ RuntimeError: no running event loop

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 203, in _run_module_as_main File "", line 88, in _run_code File "/automation/src/crewai_studio_runner/subprocess/launcher.py", line 128, in main() ~~~~^^ File "/automation/src/crewai_studio_runner/subprocess/launcher.py", line 118, in main execute_flow(args.module_name, args.class_name, inputs, built) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/automation/src/crewai_studio_runner/subprocess/flow_launcher.py", line 148, in execute_flow return flow.kickoff(inputs=inputs, input_files=input_files) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2043, in kickoff return asyncio.run(_run_flow()) ~~~~~~~~~~~^^^^^^^^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 196, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 119, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2029, in _run_flow return await self.kickoff_async( ^^^^^^^^^^^^^^^^^^^^^^^^^ ...<3 lines>... ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2347, in kickoff_async await asyncio.gather(*tasks) File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2692, in _execute_start_method result, finished_event_id = await self._execute_method( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ start_method_name, enhanced_method ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2823, in _execute_method result = await method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2739, in enhanced_method return await original_method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/_actions.py", line 367, in run_async return await action.run(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/_actions.py", line 195, in run return await agent.kickoff_async( ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 2037, in kickoff_async executor, inputs, agent_info, parsed_tools = self._prepare_kickoff( ~~~~~~~~~~~~~~~~~~~~~^ messages, response_format, input_files ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 1484, in _prepare_kickoff mcps = self.get_mcp_tools(self.mcps) File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 1248, in get_mcp_tools return self._mcp_resolver.resolve(mcps) ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 79, in resolve tools, clients = self._resolve_native(mcp_config) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 365, in _resolve_native tools_list = future.result() File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line 460, in result return self.__get_result() ~~~~~~~~~~~~~~~~~^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line 402, in __get_result raise self._exception File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/thread.py", line 59, in run result = self.fn(*self.args, **self.kwargs) File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 196, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 119, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 336, in _setup_client_and_list_tools await discovery_client.connect() File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/client.py", line 191, in connect await self._cleanup_on_error() File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/client.py", line 350, in _cleanup_on_error await self._exit_stack.aclose() File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 705, in aclose await self.aexit(None, None, None) File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 768, in aexit raise exc File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 751, in aexit cb_suppress = await cb(*exc_details) ^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/shared/session.py", line 238, in aexit return await self._task_group.aexit(exc_type, exc_val, exc_tb) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 819, in aexit raise exc_val File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 788, in aexit await self._on_completed_fut asyncio.exceptions.CancelledError: Cancelled via cancel scope 7ff6781628f0 by <Task cancelling name='Task-5' coro=<MCPToolResolver._resolve_native.._setup_client_and_list_tools() running at /tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py:336> cb=[_run_until_complete_cb() at /var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py:181]>

Operating System

Ubuntu 20.04

Python Version

3.10

crewAI Version

Latest (as installed on CrewAI Studio hosted platform — exact version visible in pip freeze as crewai)

crewAI Tools Version

Latest (as installed on CrewAI Studio hosted platform)

Virtual Environment

Venv

Evidence

Subprocess execution failed: Subprocess failed with return code 1. STDERR: warning: VIRTUAL_ENV=/local/venv does not match the project environment path /tmp/crewai_qcdbrlfx_venv and will be ignored; use --active to target the active environment instead Installed 1 package in 19ms an error occurred during closing of asynchronous generator <async_generator object streamable_http_client at 0x7ff67917cf60> asyncgen: <async_generator object streamable_http_client at 0x7ff67917cf60>

  • Exception Group Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 815, in aexit | raise BaseExceptionGroup( | "unhandled errors in a TaskGroup", self._exceptions | ) from None | BaseExceptionGroup: unhandled errors in a TaskGroup (2 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_core/_tasks.py", line 275, in _run_coro | retval = await self._coro | ^^^^^^^^^^^^^^^^ | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 565, in handle_request_async | await self._handle_post_request(ctx) | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 358, in _handle_post_request | response.raise_for_status() | ~~~~~~~~~~~~~~~~~~~~~~~~~^^ | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/httpx/_models.py", line 829, in raise_for_status | raise HTTPStatusError(message, request=request, response=self) | httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://intranet.sharpsir.group/qobrix-crm/mcp' | For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 +---------------- 2 ---------------- | Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 670, in streamable_http_client | yield ( | ...<3 lines>... | ) | GeneratorExit +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 647, in streamable_http_client async with anyio.create_task_group() as tg: ~~~~~~~~~~~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 821, in aexit if self.cancel_scope.exit(type(exc), exc, exc.traceback): ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 464, in exit raise RuntimeError( ...<2 lines>... ) RuntimeError: Attempted to exit cancel scope in a different task than it was entered in an error occurred during closing of asynchronous generator <async_generator object streamablehttp_client at 0x7ff6780ec180> asyncgen: <async_generator object streamablehttp_client at 0x7ff6780ec180> Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 722, in streamablehttp_client yield streams GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 717, in streamablehttp_client async with streamable_http_client( ~~~~~~~~~~~~~~~~~~~~~~^ url, ^^^^ http_client=client, ^^^^^^^^^^^^^^^^^^^ terminate_on_close=terminate_on_close, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) as streams: ^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 235, in aexit await self.gen.athrow(value) RuntimeError: athrow(): asynchronous generator is already running Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2038, in kickoff asyncio.get_running_loop() ~~~~~~~~~~~~~~~~~~~~~~~~^^ RuntimeError: no running event loop

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 203, in _run_module_as_main File "", line 88, in _run_code File "/automation/src/crewai_studio_runner/subprocess/launcher.py", line 128, in main() ~~~~^^ File "/automation/src/crewai_studio_runner/subprocess/launcher.py", line 118, in main execute_flow(args.module_name, args.class_name, inputs, built) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/automation/src/crewai_studio_runner/subprocess/flow_launcher.py", line 148, in execute_flow return flow.kickoff(inputs=inputs, input_files=input_files) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2043, in kickoff return asyncio.run(_run_flow()) ~~~~~~~~~~~^^^^^^^^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 196, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 119, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2029, in _run_flow return await self.kickoff_async( ^^^^^^^^^^^^^^^^^^^^^^^^^ ...<3 lines>... ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2347, in kickoff_async await asyncio.gather(*tasks) File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2692, in _execute_start_method result, finished_event_id = await self._execute_method( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ start_method_name, enhanced_method ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2823, in _execute_method result = await method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2739, in enhanced_method return await original_method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/_actions.py", line 367, in run_async return await action.run(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/_actions.py", line 195, in run return await agent.kickoff_async( ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 2037, in kickoff_async executor, inputs, agent_info, parsed_tools = self._prepare_kickoff( ~~~~~~~~~~~~~~~~~~~~~^ messages, response_format, input_files ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 1484, in _prepare_kickoff mcps = self.get_mcp_tools(self.mcps) File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 1248, in get_mcp_tools return self._mcp_resolver.resolve(mcps) ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 79, in resolve tools, clients = self._resolve_native(mcp_config) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 365, in _resolve_native tools_list = future.result() File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line 460, in result return self.__get_result() ~~~~~~~~~~~~~~~~~^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line 402, in __get_result raise self._exception File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/thread.py", line 59, in run result = self.fn(*self.args, **self.kwargs) File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 196, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 119, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 336, in _setup_client_and_list_tools await discovery_client.connect() File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/client.py", line 191, in connect await self._cleanup_on_error() File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/client.py", line 350, in _cleanup_on_error await self._exit_stack.aclose() File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 705, in aclose await self.aexit(None, None, None) File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 768, in aexit raise exc File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 751, in aexit cb_suppress = await cb(*exc_details) ^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/shared/session.py", line 238, in aexit return await self._task_group.aexit(exc_type, exc_val, exc_tb) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 819, in aexit raise exc_val File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 788, in aexit await self._on_completed_fut asyncio.exceptions.CancelledError: Cancelled via cancel scope 7ff6781628f0 by <Task cancelling name='Task-5' coro=<MCPToolResolver._resolve_native.._setup_client_and_list_tools() running at /tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py:336> cb=[_run_until_complete_cb() at /var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py:181]> Subprocess execution failed: Subprocess failed with return code 1. STDERR: warning: VIRTUAL_ENV=/local/venv does not match the project environment path /tmp/crewai_qcdbrlfx_venv and will be ignored; use --active to target the active environment instead Installed 1 package in 19ms an error occurred during closing of asynchronous generator <async_generator object streamable_http_client at 0x7ff67917cf60> asyncgen: <async_generator object streamable_http_client at 0x7ff67917cf60>

  • Exception Group Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 815, in aexit | raise BaseExceptionGroup( | "unhandled errors in a TaskGroup", self._exceptions | ) from None | BaseExceptionGroup: unhandled errors in a TaskGroup (2 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_core/_tasks.py", line 275, in _run_coro | retval = await self._coro | ^^^^^^^^^^^^^^^^ | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 565, in handle_request_async | await self._handle_post_request(ctx) | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 358, in _handle_post_request | response.raise_for_status() | ~~~~~~~~~~~~~~~~~~~~~~~~~^^ | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/httpx/_models.py", line 829, in raise_for_status | raise HTTPStatusError(message, request=request, response=self) | httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://intranet.sharpsir.group/qobrix-crm/mcp' | For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 +---------------- 2 ---------------- | Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 670, in streamable_http_client | yield ( | ...<3 lines>... | ) | GeneratorExit +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 647, in streamable_http_client async with anyio.create_task_group() as tg: ~~~~~~~~~~~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 821, in aexit if self.cancel_scope.exit(type(exc), exc, exc.traceback): ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 464, in exit raise RuntimeError( ...<2 lines>... ) RuntimeError: Attempted to exit cancel scope in a different task than it was entered in an error occurred during closing of asynchronous generator <async_generator object streamablehttp_client at 0x7ff6780ec180> asyncgen: <async_generator object streamablehttp_client at 0x7ff6780ec180> Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 722, in streamablehttp_client yield streams GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 717, in streamablehttp_client async with streamable_http_client( ~~~~~~~~~~~~~~~~~~~~~~^ url, ^^^^ http_client=client, ^^^^^^^^^^^^^^^^^^^ terminate_on_close=terminate_on_close, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) as streams: ^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 235, in aexit await self.gen.athrow(value) RuntimeError: athrow(): asynchronous generator is already running Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2038, in kickoff asyncio.get_running_loop() ~~~~~~~~~~~~~~~~~~~~~~~~^^ RuntimeError: no running event loop

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 203, in _run_module_as_main File "", line 88, in _run_code File "/automation/src/crewai_studio_runner/subprocess/launcher.py", line 128, in main() ~~~~^^ File "/automation/src/crewai_studio_runner/subprocess/launcher.py", line 118, in main execute_flow(args.module_name, args.class_name, inputs, built) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/automation/src/crewai_studio_runner/subprocess/flow_launcher.py", line 148, in execute_flow return flow.kickoff(inputs=inputs, input_files=input_files) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2043, in kickoff return asyncio.run(_run_flow()) ~~~~~~~~~~~^^^^^^^^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 196, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 119, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2029, in _run_flow return await self.kickoff_async( ^^^^^^^^^^^^^^^^^^^^^^^^^ ...<3 lines>... ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2347, in kickoff_async await asyncio.gather(*tasks) File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2692, in _execute_start_method result, finished_event_id = await self._execute_method( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ start_method_name, enhanced_method ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2823, in _execute_method result = await method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2739, in enhanced_method return await original_method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/_actions.py", line 367, in run_async return await action.run(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/_actions.py", line 195, in run return await agent.kickoff_async( ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 2037, in kickoff_async executor, inputs, agent_info, parsed_tools = self._prepare_kickoff( ~~~~~~~~~~~~~~~~~~~~~^ messages, response_format, input_files ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 1484, in _prepare_kickoff mcps = self.get_mcp_tools(self.mcps) File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 1248, in get_mcp_tools return self._mcp_resolver.resolve(mcps) ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 79, in resolve tools, clients = self._resolve_native(mcp_config) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 365, in _resolve_native tools_list = future.result() File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line 460, in result return self.__get_result() ~~~~~~~~~~~~~~~~~^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line 402, in __get_result raise self._exception File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/thread.py", line 59, in run result = self.fn(*self.args, **self.kwargs) File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 196, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 119, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 336, in _setup_client_and_list_tools await discovery_client.connect() File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/client.py", line 191, in connect await self._cleanup_on_error() File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/client.py", line 350, in _cleanup_on_error await self._exit_stack.aclose() File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 705, in aclose await self.aexit(None, None, None) File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 768, in aexit raise exc File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 751, in aexit cb_suppress = await cb(*exc_details) ^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/shared/session.py", line 238, in aexit return await self._task_group.aexit(exc_type, exc_val, exc_tb) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 819, in aexit raise exc_val File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 788, in aexit await self._on_completed_fut asyncio.exceptions.CancelledError: Cancelled via cancel scope 7ff6781628f0 by <Task cancelling name='Task-5' coro=<MCPToolResolver._resolve_native.._setup_client_and_list_tools() running at /tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py:336> cb=[_run_until_complete_cb() at /var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py:181]>

Possible Solution

Subprocess execution failed: Subprocess failed with return code 1. STDERR: warning: VIRTUAL_ENV=/local/venv does not match the project environment path /tmp/crewai_qcdbrlfx_venv and will be ignored; use --active to target the active environment instead Installed 1 package in 19ms an error occurred during closing of asynchronous generator <async_generator object streamable_http_client at 0x7ff67917cf60> asyncgen: <async_generator object streamable_http_client at 0x7ff67917cf60>

  • Exception Group Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 815, in aexit | raise BaseExceptionGroup( | "unhandled errors in a TaskGroup", self._exceptions | ) from None | BaseExceptionGroup: unhandled errors in a TaskGroup (2 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_core/_tasks.py", line 275, in _run_coro | retval = await self._coro | ^^^^^^^^^^^^^^^^ | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 565, in handle_request_async | await self._handle_post_request(ctx) | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 358, in _handle_post_request | response.raise_for_status() | ~~~~~~~~~~~~~~~~~~~~~~~~~^^ | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/httpx/_models.py", line 829, in raise_for_status | raise HTTPStatusError(message, request=request, response=self) | httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://intranet.sharpsir.group/qobrix-crm/mcp' | For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 +---------------- 2 ---------------- | Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 670, in streamable_http_client | yield ( | ...<3 lines>... | ) | GeneratorExit +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 647, in streamable_http_client async with anyio.create_task_group() as tg: ~~~~~~~~~~~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 821, in aexit if self.cancel_scope.exit(type(exc), exc, exc.traceback): ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 464, in exit raise RuntimeError( ...<2 lines>... ) RuntimeError: Attempted to exit cancel scope in a different task than it was entered in an error occurred during closing of asynchronous generator <async_generator object streamablehttp_client at 0x7ff6780ec180> asyncgen: <async_generator object streamablehttp_client at 0x7ff6780ec180> Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 722, in streamablehttp_client yield streams GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 717, in streamablehttp_client async with streamable_http_client( ~~~~~~~~~~~~~~~~~~~~~~^ url, ^^^^ http_client=client, ^^^^^^^^^^^^^^^^^^^ terminate_on_close=terminate_on_close, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) as streams: ^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 235, in aexit await self.gen.athrow(value) RuntimeError: athrow(): asynchronous generator is already running Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2038, in kickoff asyncio.get_running_loop() ~~~~~~~~~~~~~~~~~~~~~~~~^^ RuntimeError: no running event loop

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 203, in _run_module_as_main File "", line 88, in _run_code File "/automation/src/crewai_studio_runner/subprocess/launcher.py", line 128, in main() ~~~~^^ File "/automation/src/crewai_studio_runner/subprocess/launcher.py", line 118, in main execute_flow(args.module_name, args.class_name, inputs, built) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/automation/src/crewai_studio_runner/subprocess/flow_launcher.py", line 148, in execute_flow return flow.kickoff(inputs=inputs, input_files=input_files) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2043, in kickoff return asyncio.run(_run_flow()) ~~~~~~~~~~~^^^^^^^^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 196, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 119, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2029, in _run_flow return await self.kickoff_async( ^^^^^^^^^^^^^^^^^^^^^^^^^ ...<3 lines>... ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2347, in kickoff_async await asyncio.gather(*tasks) File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2692, in _execute_start_method result, finished_event_id = await self._execute_method( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ start_method_name, enhanced_method ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2823, in _execute_method result = await method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2739, in enhanced_method return await original_method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/_actions.py", line 367, in run_async return await action.run(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/_actions.py", line 195, in run return await agent.kickoff_async( ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 2037, in kickoff_async executor, inputs, agent_info, parsed_tools = self._prepare_kickoff( ~~~~~~~~~~~~~~~~~~~~~^ messages, response_format, input_files ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 1484, in _prepare_kickoff mcps = self.get_mcp_tools(self.mcps) File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 1248, in get_mcp_tools return self._mcp_resolver.resolve(mcps) ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 79, in resolve tools, clients = self._resolve_native(mcp_config) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 365, in _resolve_native tools_list = future.result() File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line 460, in result return self.__get_result() ~~~~~~~~~~~~~~~~~^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line 402, in __get_result raise self._exception File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/thread.py", line 59, in run result = self.fn(*self.args, **self.kwargs) File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 196, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 119, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 336, in _setup_client_and_list_tools await discovery_client.connect() File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/client.py", line 191, in connect await self._cleanup_on_error() File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/client.py", line 350, in _cleanup_on_error await self._exit_stack.aclose() File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 705, in aclose await self.aexit(None, None, None) File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 768, in aexit raise exc File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 751, in aexit cb_suppress = await cb(*exc_details) ^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/shared/session.py", line 238, in aexit return await self._task_group.aexit(exc_type, exc_val, exc_tb) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 819, in aexit raise exc_val File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 788, in aexit await self._on_completed_fut asyncio.exceptions.CancelledError: Cancelled via cancel scope 7ff6781628f0 by <Task cancelling name='Task-5' coro=<MCPToolResolver._resolve_native.._setup_client_and_list_tools() running at /tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py:336> cb=[_run_until_complete_cb() at /var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py:181]>

Additional context

Subprocess execution failed: Subprocess failed with return code 1. STDERR: warning: VIRTUAL_ENV=/local/venv does not match the project environment path /tmp/crewai_qcdbrlfx_venv and will be ignored; use --active to target the active environment instead Installed 1 package in 19ms an error occurred during closing of asynchronous generator <async_generator object streamable_http_client at 0x7ff67917cf60> asyncgen: <async_generator object streamable_http_client at 0x7ff67917cf60>

  • Exception Group Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 815, in aexit | raise BaseExceptionGroup( | "unhandled errors in a TaskGroup", self._exceptions | ) from None | BaseExceptionGroup: unhandled errors in a TaskGroup (2 sub-exceptions) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_core/_tasks.py", line 275, in _run_coro | retval = await self._coro | ^^^^^^^^^^^^^^^^ | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 565, in handle_request_async | await self._handle_post_request(ctx) | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 358, in _handle_post_request | response.raise_for_status() | ~~~~~~~~~~~~~~~~~~~~~~~~~^^ | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/httpx/_models.py", line 829, in raise_for_status | raise HTTPStatusError(message, request=request, response=self) | httpx.HTTPStatusError: Client error '401 Unauthorized' for url 'https://intranet.sharpsir.group/qobrix-crm/mcp' | For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/401 +---------------- 2 ---------------- | Traceback (most recent call last): | File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 670, in streamable_http_client | yield ( | ...<3 lines>... | ) | GeneratorExit +------------------------------------

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 647, in streamable_http_client async with anyio.create_task_group() as tg: ~~~~~~~~~~~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 821, in aexit if self.cancel_scope.exit(type(exc), exc, exc.traceback): ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 464, in exit raise RuntimeError( ...<2 lines>... ) RuntimeError: Attempted to exit cancel scope in a different task than it was entered in an error occurred during closing of asynchronous generator <async_generator object streamablehttp_client at 0x7ff6780ec180> asyncgen: <async_generator object streamablehttp_client at 0x7ff6780ec180> Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 722, in streamablehttp_client yield streams GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/client/streamable_http.py", line 717, in streamablehttp_client async with streamable_http_client( ~~~~~~~~~~~~~~~~~~~~~~^ url, ^^^^ http_client=client, ^^^^^^^^^^^^^^^^^^^ terminate_on_close=terminate_on_close, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) as streams: ^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 235, in aexit await self.gen.athrow(value) RuntimeError: athrow(): asynchronous generator is already running Traceback (most recent call last): File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2038, in kickoff asyncio.get_running_loop() ~~~~~~~~~~~~~~~~~~~~~~~~^^ RuntimeError: no running event loop

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 203, in _run_module_as_main File "", line 88, in _run_code File "/automation/src/crewai_studio_runner/subprocess/launcher.py", line 128, in main() ~~~~^^ File "/automation/src/crewai_studio_runner/subprocess/launcher.py", line 118, in main execute_flow(args.module_name, args.class_name, inputs, built) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/automation/src/crewai_studio_runner/subprocess/flow_launcher.py", line 148, in execute_flow return flow.kickoff(inputs=inputs, input_files=input_files) ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2043, in kickoff return asyncio.run(_run_flow()) ~~~~~~~~~~~^^^^^^^^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 196, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 119, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2029, in _run_flow return await self.kickoff_async( ^^^^^^^^^^^^^^^^^^^^^^^^^ ...<3 lines>... ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2347, in kickoff_async await asyncio.gather(*tasks) File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2692, in _execute_start_method result, finished_event_id = await self._execute_method( ^^^^^^^^^^^^^^^^^^^^^^^^^^^ start_method_name, enhanced_method ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2823, in _execute_method result = await method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/init.py", line 2739, in enhanced_method return await original_method(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/_actions.py", line 367, in run_async return await action.run(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/flow/runtime/_actions.py", line 195, in run return await agent.kickoff_async( ^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 2037, in kickoff_async executor, inputs, agent_info, parsed_tools = self._prepare_kickoff( ~~~~~~~~~~~~~~~~~~~~~^ messages, response_format, input_files ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 1484, in _prepare_kickoff mcps = self.get_mcp_tools(self.mcps) File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/agent/core.py", line 1248, in get_mcp_tools return self._mcp_resolver.resolve(mcps) ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 79, in resolve tools, clients = self._resolve_native(mcp_config) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 365, in _resolve_native tools_list = future.result() File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line 460, in result return self.__get_result() ~~~~~~~~~~~~~~~~~^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/_base.py", line 402, in __get_result raise self._exception File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/concurrent/futures/thread.py", line 59, in run result = self.fn(*self.args, **self.kwargs) File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 196, in run return runner.run(main) ~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/runners.py", line 119, in run return self._loop.run_until_complete(task) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^ File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py", line 336, in _setup_client_and_list_tools await discovery_client.connect() File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/client.py", line 191, in connect await self._cleanup_on_error() File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/client.py", line 350, in _cleanup_on_error await self._exit_stack.aclose() File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 705, in aclose await self.aexit(None, None, None) File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 768, in aexit raise exc File "/var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/contextlib.py", line 751, in aexit cb_suppress = await cb(*exc_details) ^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/mcp/shared/session.py", line 238, in aexit return await self._task_group.aexit(exc_type, exc_val, exc_tb) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 819, in aexit raise exc_val File "/tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/anyio/_backends/_asyncio.py", line 788, in aexit await self._on_completed_fut asyncio.exceptions.CancelledError: Cancelled via cancel scope 7ff6781628f0 by <Task cancelling name='Task-5' coro=<MCPToolResolver._resolve_native.._setup_client_and_list_tools() running at /tmp/crewai_qcdbrlfx_venv/lib/python3.13/site-packages/crewai/mcp/tool_resolver.py:336> cb=[_run_until_complete_cb() at /var/cache/python/cpython-3.13.14-linux-x86_64-gnu/lib/python3.13/asyncio/base_events.py:181]>

humatic-ai avatar Aug 06 '26 14:08 humatic-ai

Hi Can i work on this issue

AlphaRex-pixel avatar Aug 06 '26 17:08 AlphaRex-pixel

Agentic systems are turning into always-on factories: one request fans out into model calls, tool calls, policy checks, and storage.

The hard part is rarely tokens/sec — it is control-plane reliability:

  1. Fan-out control — hard cap on tools/steps per request before external writes
  2. Durable id + idempotency — one write per business object (ledger / preflight)
  3. Observable long jobs — progress + cooperative cancel on multi-minute runs
  4. Expected vs actual — durable artifact id before marking success
  5. Policy before action — gate that can refuse known-bad side effects

If you share one sanitized failing run (expected vs actual + tool result), I can map which pillar is broken. Architecture only.

IgorGanapolsky avatar Aug 07 '26 17:08 IgorGanapolsky

That's the classic nested-event-loop crash - the streamable HTTP transport tries to call asyncio.run() while the Flow is already running a loop. If your MCP server supports stdio, flip streamable: false in the server config (or drop the url and use command/args), it routes around the streamable client entirely. Btw, I keep a portable Hermes OTG on a USB stick as my rescue agent for exactly these broken-pipeline moments - https://github.com/MilkyWay008/Hermes-OTG if you want to poke at it.

MilkyWay008 avatar Aug 14 '26 01:08 MilkyWay008

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Sep 13 '26 12:09 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Sep 18 '26 12:09 github-actions[bot]