From 80b83e1ed0299fb851d4b85e9ed793ef355bdd57 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 13:09:59 +0000 Subject: [PATCH 1/2] fix(hooks): treat ccd_turn as a Claude built-in and stop flagging built-ins as unknown MCP servers Claude built-ins (Claude_Browser, ccd_session_mgmt, ccd_turn) are runtime-provided and never have a config, so the PreToolUse hook reported every call to them as 'unknown mcp server with no resolvable config' (Sentry AI-GATEWAY-57Q, 37V, 19R). Skip that report for known built-ins and add ccd-turn to every hook's built-in map. --- antigravity/hooks/unbound.py | 1 + augment/hooks/unbound.py | 1 + claude-code/hooks/unbound.py | 5 +++- codex/hooks/unbound.py | 1 + copilot/hooks/unbound.py | 1 + cursor/unbound.py | 1 + tests/claude_code/hooks/test_pretool_mcp.py | 33 +++++++++++++++++++++ tests/test_mcp_fingerprint_parity.py | 9 ++++++ 8 files changed, 51 insertions(+), 1 deletion(-) diff --git a/antigravity/hooks/unbound.py b/antigravity/hooks/unbound.py index 0f9eee78c..d43720570 100644 --- a/antigravity/hooks/unbound.py +++ b/antigravity/hooks/unbound.py @@ -1184,6 +1184,7 @@ def _compute_script_hash(command: Optional[str], args: Optional[List], 'claude-design': 'claude-design', 'ccd-session': 'ccd-session', 'ccd-session-mgmt': 'ccd-session-mgmt', + 'ccd-turn': 'ccd-turn', 'ide': 'ide', } diff --git a/augment/hooks/unbound.py b/augment/hooks/unbound.py index 2928714eb..407fe1d7b 100644 --- a/augment/hooks/unbound.py +++ b/augment/hooks/unbound.py @@ -1224,6 +1224,7 @@ def _compute_script_hash(command: Optional[str], args: Optional[List], 'claude-design': 'claude-design', 'ccd-session': 'ccd-session', 'ccd-session-mgmt': 'ccd-session-mgmt', + 'ccd-turn': 'ccd-turn', 'ide': 'ide', } diff --git a/claude-code/hooks/unbound.py b/claude-code/hooks/unbound.py index 525210253..bb9ac9689 100644 --- a/claude-code/hooks/unbound.py +++ b/claude-code/hooks/unbound.py @@ -2393,6 +2393,7 @@ def _read_mcp_server_config(server_name: str, config_path: Path, cwd: Optional[s 'claude-design': 'claude-design', 'ccd-session': 'ccd-session', 'ccd-session-mgmt': 'ccd-session-mgmt', + 'ccd-turn': 'ccd-turn', 'ide': 'ide', } @@ -4368,7 +4369,9 @@ def _evaluate_pre_tool_use_policies(event: Dict, api_key: str) -> Dict: # Null fingerprint: the hook resolved no config for a real MCP server. The # gateway can't flag this — a null fingerprint yields no unknown_mcp_server # hint — so key off our own resolution result, not the gateway response. - if is_mcp and metadata.get('mcp_server') and not metadata.get('mcp_server_config'): + # Claude built-ins never have a config: the gateway names them claude-builtin:. + if (is_mcp and metadata.get('mcp_server') and not metadata.get('mcp_server_config') + and not claude_builtin_identity(metadata.get('mcp_server'))): if plugin_dirs is None: plugin_dirs, plugin_urls = _claude_plugin_launch_values() log_error( diff --git a/codex/hooks/unbound.py b/codex/hooks/unbound.py index 6dde2b591..0af4a7f4b 100644 --- a/codex/hooks/unbound.py +++ b/codex/hooks/unbound.py @@ -1541,6 +1541,7 @@ def _augment_script_hash(result, cwd): 'claude-design': 'claude-design', 'ccd-session': 'ccd-session', 'ccd-session-mgmt': 'ccd-session-mgmt', + 'ccd-turn': 'ccd-turn', 'ide': 'ide', } diff --git a/copilot/hooks/unbound.py b/copilot/hooks/unbound.py index a568722bb..25159325f 100644 --- a/copilot/hooks/unbound.py +++ b/copilot/hooks/unbound.py @@ -2954,6 +2954,7 @@ def _read_script_body_b64(command, args, cwd): 'claude-design': 'claude-design', 'ccd-session': 'ccd-session', 'ccd-session-mgmt': 'ccd-session-mgmt', + 'ccd-turn': 'ccd-turn', 'ide': 'ide', } diff --git a/cursor/unbound.py b/cursor/unbound.py index fe53b04c8..0c59b764e 100755 --- a/cursor/unbound.py +++ b/cursor/unbound.py @@ -1733,6 +1733,7 @@ def _augment_script_hash(result, cwd): 'claude-design': 'claude-design', 'ccd-session': 'ccd-session', 'ccd-session-mgmt': 'ccd-session-mgmt', + 'ccd-turn': 'ccd-turn', 'ide': 'ide', } diff --git a/tests/claude_code/hooks/test_pretool_mcp.py b/tests/claude_code/hooks/test_pretool_mcp.py index d860ca7f2..cd30e85ce 100644 --- a/tests/claude_code/hooks/test_pretool_mcp.py +++ b/tests/claude_code/hooks/test_pretool_mcp.py @@ -1490,6 +1490,39 @@ def test_resolved_unknown_server_does_not_log_the_miss(self): self.assertFalse([m for m, _ in logged if m.startswith("unknown mcp server with no resolvable config")]) + def _logged_misses(self, raw_tool): + self._patch_claude_argv(["python3"]) + logged = [] + event = { + "hook_event_name": "PreToolUse", + "tool_name": raw_tool, + "tool_input": {"q": "x"}, + "cwd": self.cwd, + "session_id": "sess", + } + with patch.object(unbound, "send_to_hook_api", lambda body, key: {"decision": "allow"}), \ + patch.object(unbound, "log_error", + lambda msg, cat='general': logged.append((msg, cat))): + unbound.process_pre_tool_use(event, "API_KEY") + return [m for m, _ in logged if m.startswith("unknown mcp server with no resolvable config")] + + def test_claude_builtin_servers_do_not_log_the_miss(self): + # Runtime-provided built-ins never have a config; the gateway names them by + # their claude-builtin: identity, so a missing config is expected, not a miss. + for raw_tool in ("mcp__ccd_turn__end_turn", + "mcp__Claude_Browser__preview_start", + "mcp__ccd_session_mgmt__list_sessions"): + with self.subTest(tool=raw_tool): + self.dispatch_diag.reset_mock() + self.assertEqual(self._logged_misses(raw_tool), []) + self.dispatch_diag.assert_not_called() + + def test_unresolved_custom_server_still_logs_the_miss(self): + misses = self._logged_misses("mcp__toolchain-agentcore__create_pr") + self.assertEqual(len(misses), 1) + self.assertIn("toolchain-agentcore", misses[0]) + self.dispatch_diag.assert_called_once() + class TestLocalScriptFingerprint(ProcessPreToolUseBase): """A stdio MCP server's script is fingerprinted for the policy call and its diff --git a/tests/test_mcp_fingerprint_parity.py b/tests/test_mcp_fingerprint_parity.py index f219b3743..a48071a13 100644 --- a/tests/test_mcp_fingerprint_parity.py +++ b/tests/test_mcp_fingerprint_parity.py @@ -60,6 +60,15 @@ def test_bare_vscode_provider_is_not_a_fingerprint(self): ) ) + def test_claude_desktop_turn_server_is_a_builtin(self): + for hook in HOOKS: + for name in ('ccd_turn', 'ccd-turn', 'CCD Turn'): + with self.subTest(hook=hook.__file__, name=name): + self.assertEqual( + hook.compute_mcp_cache_key(name, None, None, []), + 'claude-builtin:ccd-turn', + ) + def test_cached_vscode_provider_keeps_launch_identity(self): additional_data = { 'scope': 'vscode-provider-cache', From ab9702d6ddcd5c4c5544ffee4cca1243a1a2d5c1 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 30 Nov 2026 13:43:05 +0000 Subject: [PATCH 2/2] test(hooks): deny-path diagnostic test uses a custom server, not the computer-use built-in --- tests/claude_code/hooks/test_pretool_mcp.py | 23 +++++++++++---------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/claude_code/hooks/test_pretool_mcp.py b/tests/claude_code/hooks/test_pretool_mcp.py index cd30e85ce..da490e690 100644 --- a/tests/claude_code/hooks/test_pretool_mcp.py +++ b/tests/claude_code/hooks/test_pretool_mcp.py @@ -472,21 +472,22 @@ def test_resolved_config_does_not_dispatch_diagnostic(self): self.dispatch_diag.assert_not_called() def test_null_fingerprint_dispatches_diagnostic_on_deny(self): - # The real case: a null-fp MCP server the org policy DENIES (e.g. the - # blocked computer-use server, pretool_blocked=true). The deny path has no - # early return before the trigger, so the diagnostic must still dispatch. + # A null-fp custom MCP server the org policy DENIES (pretool_blocked=true). + # The deny path has no early return before the trigger, so the diagnostic + # must still dispatch. Claude built-ins are named by the gateway, so they don't. def deny_gw(request_body, api_key): return {"decision": "deny", "reason": "blocked", "pretool_blocked": True} - event = { - "hook_event_name": "PreToolUse", - "tool_name": "mcp__computer-use__request_access", - "tool_input": {}, "cwd": self.cwd, "session_id": "sess", - } - with patch.object(unbound, "send_to_hook_api", deny_gw): - unbound.process_pre_tool_use(event, "API_KEY") + for tool_name in ("mcp__computer-use__request_access", "mcp__mystery_server__do"): + event = { + "hook_event_name": "PreToolUse", + "tool_name": tool_name, + "tool_input": {}, "cwd": self.cwd, "session_id": "sess", + } + with patch.object(unbound, "send_to_hook_api", deny_gw): + unbound.process_pre_tool_use(event, "API_KEY") self.dispatch_diag.assert_called_once() - self.assertEqual(self.dispatch_diag.call_args[0][0], "computer-use") + self.assertEqual(self.dispatch_diag.call_args[0][0], "mystery_server") def test_config_file_server_takes_precedence_over_resolvers(self): # A real config-file entry must win; resolvers must not run/override it.