Skip to content

preToolUse and permissionRequest report different toolName for the same MCP tool call (server-tool vs server/tool), so one matcher can't cover both #5655

Backlog

Description

@k4otix

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

  1. Create a new git repo with this file at .github/hooks/repro.json. Replace $LOGS with 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" }
    ]
  }
}
  1. 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."
  1. Compare toolName in the two .jsonl files, and see which *.log files 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: preToolUse is the hook that can deny a call. A hook author who copies the server/tool name from the permission prompt or from permissionRequest writes a matcher that never fires on preToolUse. MCP tools then run without that guard, and nothing warns about it.
  • Correlation: Joining a permissionRequest to the preToolUse call 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

  1. added
    area:mcp
    area:plugins
    and removed on Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:mcparea:plugins

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions