Skip to content

The agent that grows with you

fix(cron): a per-job MCP allowlist must not widen into every enabled server

Sahil Vishnalya11cebb30dafd
diff --git a/cron/scheduler.py b/cron/scheduler.py
index 6e711cff81c..f2acf85277d 100644
--- a/cron/scheduler.py
+++ b/cron/scheduler.py
@@ -1,4 +1,4 @@
-# health: allow FILE_LINES -- security fix for #82010: distinguish an explicitly-empty toolset allowlist (fail closed, nothing allowed) from an absent one (no restriction); the added lines are minimal fail-closed branches at this existing chokepoint
+# health: allow FILE_LINES -- security fix for #82010: distinguish an explicitly-empty toolset allowlist (fail closed, nothing allowed) from an absent one (no restriction); the added lines are minimal fail-closed branches at this existing chokepoint. Also #141468: match the `mcp-<server>` toolset spelling so a narrow job's MCP allowlist is not widened into every enabled server — a minimal branch at the same chokepoint.
"""Cron job scheduler: tick() runs due jobs (gateway calls it every 60s from a background thread).
A file lock (~/.hermes/cron/.tick.lock) keeps overlapping processes to one tick at a time.
"""
@@ -445,7 +445,10 @@ def _merge_mcp_into_per_job_toolsets(per_job: list[str], cfg: dict) -> list[str]
# lazy: avoid heavy hermes_cli import at module load; shares MCP-membership with gateway/CLI
from hermes_cli.tools_config import enabled_mcp_server_names
enabled_mcp = enabled_mcp_server_names(cfg)
- if set(result) & enabled_mcp:
+ # A job names an MCP server by its TOOLSET name (``mcp-<server>``) or by the bare alias the
+ # registry registers for it; compare against BOTH, or a job that named one server never matched
+ # and the fallback below unioned EVERY enabled server into its allowlist (#141468).
+ if set(result) & (enabled_mcp | {f"mcp-{name}" for name in enabled_mcp}):
return result
for name in sorted(enabled_mcp):
if name not in result:
diff --git a/tests/cron/test_cron_mcp_toolset_allowlist.py b/tests/cron/test_cron_mcp_toolset_allowlist.py
new file mode 100644
index 00000000000..fe25d42de86
--- /dev/null
+++ b/tests/cron/test_cron_mcp_toolset_allowlist.py
@@ -0,0 +1,57 @@
+"""A per-job MCP allowlist must stay narrow: naming one server is not naming all of them.
+
+Regression for #141468. A job names an MCP server by its TOOLSET name (``mcp-<server>``), but the
+merge helper compared the job's list against the BARE server names, so the intersection never
+matched and the fallback unioned every enabled MCP server into the job's allowlist: a job that
+asked for one server ran with all of them.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from cron.scheduler import _merge_mcp_into_per_job_toolsets
+
+
+def mcp_cfg():
+ """Three enabled MCP servers, so a widened allowlist is visible in the result."""
+ return {
+ "mcp_servers": {
+ "filesystem": {"command": "npx", "args": ["-y", "server-filesystem"]},
+ "github": {"command": "npx", "args": ["-y", "server-github"]},
+ "slack": {"command": "npx", "args": ["-y", "server-slack"]},
+ }
+ }
+
+
+def test_a_job_naming_one_mcp_server_keeps_only_that_server(mcp_cfg):
+ """The job's allowlist is an allowlist: one named server, not every enabled one."""
+ assert _merge_mcp_into_per_job_toolsets(["mcp-filesystem"], mcp_cfg) == ["mcp-filesystem"]
+
+
+def test_a_named_mcp_server_alongside_a_native_toolset_keeps_both(mcp_cfg):
+ assert _merge_mcp_into_per_job_toolsets(["mcp-filesystem", "terminal"], mcp_cfg) == [
+ "mcp-filesystem",
+ "terminal",
+ ]
+
+
+def test_the_bare_server_name_means_the_same_allowlist(mcp_cfg):
+ """The bare alias names the same server, so it also narrows the allowlist."""
+ assert _merge_mcp_into_per_job_toolsets(["filesystem"], mcp_cfg) == ["filesystem"]
+
+
+def test_a_native_toolset_allowlist_still_merges_every_enabled_server(mcp_cfg):
+ """Unchanged: a list that names no MCP server keeps every enabled one, so an
+ operator's native-toolset allowlist never silently strips MCP tools."""
+ assert _merge_mcp_into_per_job_toolsets(["terminal"], mcp_cfg) == [
+ "terminal",
+ "filesystem",
+ "github",
+ "slack",
+ ]
+
+
+def test_the_no_mcp_sentinel_still_means_no_mcp_servers(mcp_cfg):
+ assert _merge_mcp_into_per_job_toolsets(["no_mcp"], mcp_cfg) == []