From 70c6c7abf2557dd2c2b01000ea8aa36abcc07193 Mon Sep 17 00:00:00 2001 From: Anandesh Sharma Date: Fri, 27 Feb 2026 04:00:32 +0530 Subject: [PATCH] fix: prepare MCP tools in execute_task for delegated agents MCP tools are only resolved during the kickoff preparation path, but when an agent receives a delegated task via execute_task(), MCP tools are never prepared. This means sub-agents with MCP servers configured cannot use their MCP tools when receiving delegated work. Check if the MCP resolver hasn't been initialized yet and resolve MCP tools at the start of execute_task() to ensure they're available for delegated agents. Fixes #4571 Co-Authored-By: Claude Opus 4.6 --- lib/crewai/src/crewai/agent/core.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/crewai/src/crewai/agent/core.py b/lib/crewai/src/crewai/agent/core.py index 21edbd1601..226868ff6a 100644 --- a/lib/crewai/src/crewai/agent/core.py +++ b/lib/crewai/src/crewai/agent/core.py @@ -334,6 +334,15 @@ def execute_task( ValueError: If the max execution time is not a positive integer. RuntimeError: If the agent execution fails for other reasons. """ + # Ensure MCP tools are resolved for delegated agents that haven't + # gone through the full kickoff preparation path. + if self.mcps and self._mcp_resolver is None: + mcp_tools = self.get_mcp_tools(self.mcps) + if mcp_tools: + if self.tools is None: + self.tools = [] + self.tools.extend(mcp_tools) + handle_reasoning(self, task) self._inject_date_to_task(task)