The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cron): a configured but disabled MCP server must not widen the job either
Sahil Vishnalya7c8810dc2157
diff --git a/cron/scheduler.py b/cron/scheduler.pyindex f2acf85277d..f4fc491f773 100644--- a/cron/scheduler.py+++ b/cron/scheduler.py@@ -448,7 +448,12 @@ def _merge_mcp_into_per_job_toolsets(per_job: list[str], cfg: dict) -> list[str]# 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}):+ # A server that is CONFIGURED but disabled still counts as named: it is the user's selection, it+ # stays off, and it must not fall through to every enabled server either - the same rule the+ # interactive resolver follows (hermes_cli.tools_config._merge_mcp_servers).+ configured = cfg.get("mcp_servers") if isinstance(cfg.get("mcp_servers"), dict) else {}+ known = enabled_mcp | {str(name) for name in configured}+ if set(result) & (known | {f"mcp-{name}" for name in known}):return resultfor 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.pydeleted file mode 100644index fe25d42de86..00000000000--- a/tests/cron/test_cron_mcp_toolset_allowlist.py+++ /dev/null@@ -1,57 +0,0 @@-"""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) == []diff --git a/tests/cron/test_scheduler.py b/tests/cron/test_scheduler.pyindex d8efa2e854c..f49da6487b4 100644--- a/tests/cron/test_scheduler.py+++ b/tests/cron/test_scheduler.py@@ -157,6 +157,27 @@ class TestPerJobToolsetMcpMerge:assert result == ["web", "finnhub"]assert "playwright" not in result+ def test_the_toolset_name_spelling_is_treated_as_allowlist(self):+ # The same server named by its TOOLSET name (``mcp-<server>``) narrows just the same.+ result = _merge_mcp_into_per_job_toolsets(["web", "mcp-finnhub"], self.CFG)+ assert result == ["web", "mcp-finnhub"]+ assert "playwright" not in result++ def test_the_toolset_name_spelling_alongside_a_native_toolset_keeps_both(self):+ result = _merge_mcp_into_per_job_toolsets(["mcp-finnhub", "terminal"], self.CFG)+ assert result == ["mcp-finnhub", "terminal"]++ def test_a_configured_but_disabled_server_does_not_widen_the_allowlist(self):+ # A job pinned to a server the operator turned off must not fall through to every ENABLED+ # server: the disabled one stays off and nothing else rides in (#141468).+ result = _merge_mcp_into_per_job_toolsets(["web", "mcp-disabled_one"], self.CFG)+ assert result == ["web", "mcp-disabled_one"]+ assert not (set(result) & self._enabled_names())+ # The bare alias of the disabled server is the same selection.+ result = _merge_mcp_into_per_job_toolsets(["web", "disabled_one"], self.CFG)+ assert result == ["web", "disabled_one"]+ assert not (set(result) & self._enabled_names())+def test_no_mcp_sentinel_opts_out_and_is_stripped(self):result = _merge_mcp_into_per_job_toolsets(["web", "no_mcp"], self.CFG)assert result == ["web"]