Skip to content

The agent that grows with you

fix(mcp): preserve server deadlines through outer tool execution

Tekniumf30020ed5e1f
diff --git a/agent/tool_dispatch_helpers.py b/agent/tool_dispatch_helpers.py
index ec777417ad7..04585fdd5fb 100644
--- a/agent/tool_dispatch_helpers.py
+++ b/agent/tool_dispatch_helpers.py
@@ -104,6 +104,23 @@ def _is_destructive_command(cmd: str) -> bool:
return bool(cmd) and bool(_DESTRUCTIVE_PATTERNS.search(cmd) or _REDIRECT_OVERWRITE.search(cmd))
+def _extend_tool_timeout(tool_name: str, default: float | None) -> float | None:
+ """A registered transport budget must not be cut short by the generic executor."""
+ from tools.registry import registry
+
+ entry = registry.get_entry(tool_name)
+ if default is None or entry is None or entry.execution_timeout is None:
+ return default
+ return max(default, entry.execution_timeout)
+
+
+def _requires_extended_tool_deadline(tool_name: str) -> bool:
+ from agent.tool_executor import _resolve_concurrent_tool_timeout
+
+ default = _resolve_concurrent_tool_timeout()
+ return _extend_tool_timeout(tool_name, default) != default
+
+
def _is_mcp_tool_parallel_safe(tool_name: str) -> bool:
"""Whether an MCP tool's server opted into parallel calls; False if MCP is unavailable."""
try:
@@ -182,7 +199,7 @@ def _batch_admission(tool_call, execution_cwd: Optional[Path]) -> tuple[str, lis
return None
name, args = _peel_bridge_call(tool_name, function_args)
- if name in _NEVER_PARALLEL_TOOLS:
+ if name in _NEVER_PARALLEL_TOOLS or _requires_extended_tool_deadline(name):
return None
if name in _PATH_SCOPED_TOOLS:
scoped = _extract_parallel_scope_paths(name, args, execution_cwd=execution_cwd)
diff --git a/agent/tool_executor.py b/agent/tool_executor.py
index 79d22e2b812..4bd1bab397e 100644
--- a/agent/tool_executor.py
+++ b/agent/tool_executor.py
@@ -911,7 +911,10 @@ def _run_sequential_tool_execution_middleware(
generic deadline would report ``tool_timeout`` while the prompt is still live. They
are ``_NEVER_PARALLEL_TOOLS`` and run inline below, before any deadline is armed, so
they need no ``_SEQUENTIAL_DEADLINE_EXEMPT_TOOLS`` entry."""
+ from agent.tool_dispatch_helpers import _extend_tool_timeout
+
timeout_s = None if function_name in _SEQUENTIAL_DEADLINE_EXEMPT_TOOLS else _resolve_sequential_tool_timeout()
+ timeout_s = _extend_tool_timeout(function_name, timeout_s)
ref = _ToolCallRef(function_name, function_args, effective_task_id, tool_call_id, middleware_trace)
kwargs = dict(ref.middleware_kwargs(), execute=execute, scope_block=scope_block, display_index=display_index)
from agent.terminal_approval_batch import take_prepared_call
diff --git a/tests/agent/test_mcp_execution_deadline.py b/tests/agent/test_mcp_execution_deadline.py
new file mode 100644
index 00000000000..6f319247864
--- /dev/null
+++ b/tests/agent/test_mcp_execution_deadline.py
@@ -0,0 +1,44 @@
+"""A server-owned deadline must survive the outer executor without widening a sibling batch."""
+import json
+from types import SimpleNamespace
+
+from tools.registry import registry
+
+
+def test_registered_deadline_extends_only_its_own_call():
+ name = "mcp__deadline_probe__slow"
+ from tools.mcp_tool_registration import _register_candidates, _tool_candidates
+
+ tool = SimpleNamespace(name="slow", description="analysis", inputSchema={"type": "object"})
+ candidates = _tool_candidates("deadline_probe", [tool], lambda name: True, 1000)
+ _register_candidates("deadline_probe", candidates, check_fn=lambda: True, scope=lambda: None, lazy=True,
+ execution_timeout=1000)
+ try:
+ from agent.tool_dispatch_helpers import _extend_tool_timeout
+
+ assert _extend_tool_timeout(name, 420) == 1000
+ assert _extend_tool_timeout("read_file", 420) == 420
+ assert _extend_tool_timeout(name, 1200) == 1200
+ assert _extend_tool_timeout(name, None) is None
+ _register_candidates("deadline_probe", candidates, check_fn=lambda: True, scope=lambda: None, lazy=True)
+ assert _extend_tool_timeout(name, 100) == 100
+ finally:
+ registry.deregister(name)
+
+
+def test_extended_deadline_is_a_barrier_for_direct_and_bridged_batches():
+ # Even a normally parallel-safe tool must not extend a batch containing unrelated work.
+ name = "tool_describe"
+ old = registry.get_entry(name)
+ registry.register(name=name, toolset="deadline-probe", schema={"name": name},
+ handler=lambda args, **kw: "ok", execution_timeout=1000, override=True)
+ try:
+ from agent.tool_dispatch_helpers import _batch_admission
+
+ for exposed, args in [(name, {}), ("tool_call", {"calls": [{"name": name, "arguments": {}}]})]:
+ call = SimpleNamespace(function=SimpleNamespace(name=exposed, arguments=json.dumps(args)))
+ assert _batch_admission(call, None) is None
+ finally:
+ current = registry.get_entry(name)
+ assert current is not None
+ registry.restore_registration(name, current, old)
diff --git a/tools/mcp_tool_registration.py b/tools/mcp_tool_registration.py
index 284b25ef5cb..9591c446b8c 100644
--- a/tools/mcp_tool_registration.py
+++ b/tools/mcp_tool_registration.py
@@ -325,7 +325,7 @@ def _resolve_name_collisions(name: str, candidates: list[_Candidate]) -> list[_C
def _register_candidates(name: str, candidates: list[_Candidate], *, check_fn: Callable,
- scope: Callable[[], Optional[str]], lazy: bool, key=None) -> list[str]:
+ scope: Callable[[], Optional[str]], lazy: bool, key=None, execution_timeout=None) -> list[str]:
"""Register candidates under toolset ``mcp-{name}``; returns the names that landed. The
ownership pre-check is advisory (servers connect in parallel): ``registry.register()`` is
the atomic gate and its verdict is re-read after every call. *key* is the connection whose
@@ -352,7 +352,8 @@ def _register_candidates(name: str, candidates: list[_Candidate], *, check_fn: C
continue
registry.register(
name=c.registry_name, toolset=toolset_name, schema=c.schema, handler=c.handler, check_fn=check_fn,
- is_async=False, description=c.schema.get("description") or "", scope=scope_value)
+ is_async=False, description=c.schema.get("description") or "", scope=scope_value,
+ execution_timeout=execution_timeout)
if registry.get_toolset_for_tool(c.registry_name) == toolset_name:
_track_mcp_tool_server(c.registry_name, name)
if scope_value is not None:
@@ -418,7 +419,8 @@ def _register_server_tools(name: str, server: "MCPServerTask", config: dict) ->
server._editor_frozen_manifest = frozen
registered = _register_candidates(
name, _resolve_name_collisions(name, candidates),
- check_fn=_make_check_fn(name), scope=lambda: _core._server_registry_scope(key), lazy=False, key=key)
+ check_fn=_make_check_fn(name), scope=lambda: _core._server_registry_scope(key), lazy=False, key=key,
+ execution_timeout=config.get("timeout"))
if registered and not (_core._server_registry_scope(key) or '').startswith('editor-session:'):
_write_schema_cache(name, server, config, should_register)
return registered
@@ -583,7 +585,8 @@ def _register_connected_into_current_scope(servers: dict) -> int:
name, _select_utility_schemas(name, server, config), server.tool_timeout)
names = _register_candidates(
name, _resolve_name_collisions(name, candidates),
- check_fn=_make_check_fn(name), scope=lambda: scope, lazy=False, key=key)
+ check_fn=_make_check_fn(name), scope=lambda: scope, lazy=False, key=key,
+ execution_timeout=config.get("timeout"))
if names:
registered_servers += 1
with _core._lock:
@@ -607,7 +610,8 @@ def _register_from_cache_sync(name: str, config: dict, entry: dict) -> list[str]
candidates = _tool_candidates(name, cached_tools, _make_tool_filter(name, config), tool_timeout)
candidates += _utility_candidates(name, utility_tools_from_cache_entry(entry), tool_timeout)
registered = _register_candidates(
- name, candidates, check_fn=_make_check_fn(name), scope=_core._mcp_registry_scope, lazy=True)
+ name, candidates, check_fn=_make_check_fn(name), scope=_core._mcp_registry_scope, lazy=True,
+ execution_timeout=config.get("timeout"))
if registered:
with _core._lock:
key = _server_key(name)
diff --git a/tools/registry.py b/tools/registry.py
index 08a08631e1b..131a8c7dc63 100644
--- a/tools/registry.py
+++ b/tools/registry.py
@@ -229,6 +229,7 @@ class ToolEntry:
# Zero-arg callable whose dict is shallow-merged onto the schema at every get_definitions()
# — for fields tracking runtime config (delegate_task's description reflects limits).
dynamic_schema_overrides: Optional[Callable] = None
+ execution_timeout: float | None = None
class _PluginOverridePolicy:
@@ -710,7 +711,7 @@ class ToolRegistry:
check_fn: Callable | None = None, requires_env: list | None = None, is_async: bool = False,
description: str = "", emoji: str = "", max_result_size_chars: float | None = None,
dynamic_schema_overrides: Callable | None = None, override: bool = False,
- scope: Optional[str] = None):
+ scope: Optional[str] = None, execution_timeout: float | None = None):
"""Register a tool (called at import time by each tool file). ``override=True`` is an
explicit opt-in for plugins replacing a built-in implementation (e.g. a headed-Chrome
browser backend); without it, cross-toolset shadowing is rejected."""
@@ -774,7 +775,7 @@ class ToolRegistry:
name=name, toolset=toolset, schema=schema, handler=handler, check_fn=check_fn,
requires_env=requires_env or [], is_async=is_async,
description=description or schema.get("description", ""), emoji=emoji,
- max_result_size_chars=max_result_size_chars,
+ max_result_size_chars=max_result_size_chars, execution_timeout=execution_timeout,
dynamic_schema_overrides=dynamic_schema_overrides)
# Availability is derived per-tool (_toolset_has_exposable_tools), so this map no
# longer gates a toolset; it still feeds get_toolset_requirements ->
diff --git a/website/docs/developer-guide/plugins/index.md b/website/docs/developer-guide/plugins/index.md
index 7a77bf37c9b..5ac5838684a 100644
--- a/website/docs/developer-guide/plugins/index.md
+++ b/website/docs/developer-guide/plugins/index.md
@@ -162,6 +162,13 @@ extends the wait budget, not the cancellation or permission policy. Configure
any server-internal analysis deadline separately and leave time for its result
to reach the client. Other harnesses ignore this extension.
+An explicit per-server MCP call budget also reaches Hermes' outer tool executor. A call
+whose budget exceeds the shared concurrent-batch deadline becomes a sequential
+barrier, whether called directly or through tool search. It gets its own budget
+without extending unrelated tools in the same model response. Existing shorter
+MCP calls retain their normal parallel-admission policy; interruption and
+approval handling are unchanged.
+
The [rendered specification](https://agent-plugins.org/specification) currently
labels v1.0.0 a Working Draft, while the
[versioned specification repository](https://github.com/agentplugins/agent-plugins-spec/blob/main/spec/1.0.0.md)