One of the biggest pain points with MCP servers is that Claude defaults to built-in Read/Grep/Glob even when you have better tools available. CLAUDE.md instructions work for a few turns then drift. Allowlisting helps with permissions but not priority. The fix that actually works: a PreToolUse hook that checks if your MCP server is running, and if so, denies Grep/Glob with a redirect message. Here’s the pattern: bash #!/bin/bash # Block Grep/Glob when your MCP server is available # Fast path: no socket = allow (MCP not running, don’t break anything) # Socket exists: verify it’s actually listening (handles stale sockets after kill -9) SOCK="$CLAUDE_PROJECT_DIR:-.}/.vexp/daemon.sock" if [ -S “$SOCK” ] && python3 -c " import socket,sys s=socket.socket(socket.AF_UNIX,socket.SOCK_STREAM) s.settimeout(0.5) s.connect(sys.argv[1]) s.close() " “$SOCK” 2 >/dev/null; then printf ‘{“hookSpecificOutput”:{“hookEventName”:“PreToolUse”,“permissionDecision”:“deny”,“permissionDecisionReason”:“Use run_pipeline instead of Grep/Glob.”}}’ else printf ‘{“hookSpecificOutput”:{“hookEventName”:“PreToolUse”,“permissionDecision”:“allow”,“permissionDecisionReason”:“MCP unavailable, falling back to Grep/Glob.”}}’ fi exit 0 Hook config in settings.json : json { “hooks”: { “PreToolUse”: [ { “matcher”: "Grep ] } ] } } Key details: It’s conditional — only blocks when the MCP server is actually running. If the daemon is down, Grep/Glob work normally. No broken workflows. Stale socket detection — the Python connectivity check handles the case where the daemon was killed with kill -9 and left a dead socket file behind. Without this you’d get false denials. The deny reason tells Claude what to use instead. Claude reads the reason and switches to the MCP tool on the next turn. Timeout at 3000ms so it doesn’t hang if something goes wrong. This pattern works for any MCP server, not just mine — just swap the socket path and the tool name in the deny reason. The general idea is: hook intercepts the built-in tool, checks if a better alternative is available, redirects if yes, falls through if no. For context, this is part of vexp (context engine I’m building — previous posts here and here ). The hook gets installed automatically during setup. But the pattern is generic enough that anyone building MCP tooling can adapt it. Curious if anyone has found other approaches to the tool priority problem. submitted by /u/Objective_Law2034
Originally posted by u/Objective_Law2034 on r/ClaudeCode
