Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions antigravity/hooks/unbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down
1 change: 1 addition & 0 deletions augment/hooks/unbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down
5 changes: 4 additions & 1 deletion claude-code/hooks/unbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down Expand Up @@ -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:<name>.
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(
Expand Down
1 change: 1 addition & 0 deletions codex/hooks/unbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down
1 change: 1 addition & 0 deletions copilot/hooks/unbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down
1 change: 1 addition & 0 deletions cursor/unbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}

Expand Down
56 changes: 45 additions & 11 deletions tests/claude_code/hooks/test_pretool_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1490,6 +1491,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
Expand Down
9 changes: 9 additions & 0 deletions tests/test_mcp_fingerprint_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down