Repository navigation
Description
Describe the bug
For one MCP tool call, the preToolUse and permissionRequest hooks report the tool name differently:
| Event | toolName |
|---|---|
preToolUse |
github-mcp-server-get_file_contents |
permissionRequest |
github-mcp-server/get_file_contents |
preToolUse joins the server and tool with -. permissionRequest joins them with /. Built-in tools such as bash and view aren't affected, because they have no server prefix.
matcher is tested against this value and must match all of it. As a result, one MCP matcher can't target both events:
| Matcher | Fires on preToolUse |
Fires on permissionRequest |
|---|---|---|
github-mcp-server/.* |
❌ no | ✅ yes |
github-mcp-server-.* |
✅ yes | ❌ no |
Nothing warns when a matcher can never fire.
Affected version
GitHub Copilot CLI 1.0.119 (macOS arm64)
Steps to reproduce the behavior
- Create a new git repo with this file at
.github/hooks/repro.json. Replace$LOGSwith an absolute directory path.
{
"version": 1,
"hooks": {
"preToolUse": [
{ "type": "command", "bash": "cat >> $LOGS/preToolUse.jsonl" },
{ "type": "command", "matcher": "github-mcp-server/.*", "bash": "echo hit >> $LOGS/pre-slash.log" },
{ "type": "command", "matcher": "github-mcp-server-.*", "bash": "echo hit >> $LOGS/pre-hyphen.log" }
],
"permissionRequest": [
{ "type": "command", "bash": "cat >> $LOGS/permissionRequest.jsonl" },
{ "type": "command", "matcher": "github-mcp-server/.*", "bash": "echo hit >> $LOGS/perm-slash.log" },
{ "type": "command", "matcher": "github-mcp-server-.*", "bash": "echo hit >> $LOGS/perm-hyphen.log" }
]
}
}- Run:
copilot --trust-folder -p "Use the github-mcp-server get_file_contents tool to list the files at the root of the public repo octocat/Hello-World. Do not use any other tool."- Compare
toolNamein the two.jsonlfiles, and see which*.logfiles were created.
Observed payloads (session IDs, call IDs and paths redacted):
preToolUse:
{"sessionId":"<redacted>","timestamp":1796265742900,"cwd":"<redacted>","toolCallId":"<redacted>","toolName":"github-mcp-server-get_file_contents","toolArgs":{"owner":"octocat","repo":"Hello-World","path":""}}permissionRequest:
{"hookName":"permissionRequest","sessionId":"<redacted>","timestamp":1796265743002,"cwd":"<redacted>","toolName":"github-mcp-server/get_file_contents","toolInput":{"owner":"octocat","repo":"Hello-World","path":""},"permissionSuggestions":[]}The only log files created were pre-hyphen.log and perm-slash.log.
Expected behavior
All hook events should report the same toolName for the same MCP tool call. I'd suggest the server/tool form, because it matches the permission prompt and the server/tool filter syntax. With one consistent name, a single matcher such as github-mcp-server/.* would work for preToolUse, permissionRequest, and postToolUse.
Additional context
- Why this matters:
preToolUseis the hook that can deny a call. A hook author who copies theserver/toolname from the permission prompt or frompermissionRequestwrites a matcher that never fires onpreToolUse. MCP tools then run without that guard, and nothing warns about it. - Correlation: Joining a
permissionRequestto thepreToolUsecall it guarded means normalizing the separator first. - Docs: The hooks reference lists tool names for matching built-in tools only. It doesn't describe how MCP tool names are formed for each event. If the difference is intentional, please document which form each event uses.
- Related, not duplicates: Document matcher support for command hooks #3820 (matcher docs) and Documentation unclear: how to map toolName (glob/grep/view) to --allow-tool patterns #1482 (toolName → permission pattern mapping).
Activity