From 3fbedd732e5179759d797927fd0f2cf4324682b2 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sat, 16 May 2026 23:36:37 -0700 Subject: [PATCH] =?UTF-8?q?feat:=20add=20supports=5Fparallel=5Ftool=5Fcall?= =?UTF-8?q?s=20for=20MCP=20servers=20(#26825)=20=E2=80=94=20port=20to=20to?= =?UTF-8?q?ol=5Fdispatch=5Fhelpers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit 395e9dd9e by Teknium targeted module-level _is_mcp_tool_parallel_safe and _should_parallelize_tool_batch helpers in pre-refactor run_agent.py. Both helpers now live in agent/tool_dispatch_helpers.py — re-applied to that module. The tools/mcp_tool.py portion (the public is_mcp_tool_parallel_safe API + _parallel_safe_servers tracking) merged cleanly from main via the prior merge commit. Co-authored-by: Teknium <127238744+teknium1@users.noreply.github.com> --- agent/tool_dispatch_helpers.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/agent/tool_dispatch_helpers.py b/agent/tool_dispatch_helpers.py index 289e10fb027..30aa8869db9 100644 --- a/agent/tool_dispatch_helpers.py +++ b/agent/tool_dispatch_helpers.py @@ -87,6 +87,19 @@ def _is_destructive_command(cmd: str) -> bool: return False +def _is_mcp_tool_parallel_safe(tool_name: str) -> bool: + """Check if an MCP tool comes from a server with parallel tool calls enabled. + + Lazy-imports from ``tools.mcp_tool`` to avoid circular dependencies. + Returns False if the MCP module is not available. + """ + try: + from tools.mcp_tool import is_mcp_tool_parallel_safe + return is_mcp_tool_parallel_safe(tool_name) + except Exception: + return False + + def _should_parallelize_tool_batch(tool_calls) -> bool: """Return True when a tool-call batch is safe to run concurrently.""" if len(tool_calls) <= 1: @@ -126,7 +139,9 @@ def _should_parallelize_tool_batch(tool_calls) -> bool: continue if tool_name not in _PARALLEL_SAFE_TOOLS: - return False + # Check if it's an MCP tool from a server that opted into parallel calls. + if not _is_mcp_tool_parallel_safe(tool_name): + return False return True