Skip to main content
hooksSource-backed

MCP Config Privacy Scanner - Claude Code Hook

PreToolUse hook that reviews proposed writes to MCP configuration files and blocks inline credential values, credential-bearing URLs, and broad filesystem roots before they are saved.

by MkDev11·added 2026-06-05·
Trigger:PreToolUse
Review first review before installing

Open the source and read safety notes before installing.

Citation facts

Source-backed facts for citing this resource, derived directly from the registry — also available as plain text for AI assistants.

Source URLs
https://code.claude.com/docs/en/mcp, https://github.com/modelcontextprotocol/modelcontextprotocol
Safety notes
Runs before Write, Edit, and MultiEdit tool calls and reads only the pending file path plus proposed new text, including replacement fragments for partial edits., Blocks matching MCP configuration edits with exit code 2 when it finds inline credential values, credential-bearing URLs, or broad filesystem roots for filesystem MCP servers., Does not start MCP servers, contact remote MCP endpoints, edit files, delete files, or inspect existing config beyond the proposed tool input., Text and JSON heuristics can miss unusual config shapes or flag reviewed local setups; use `MCP_CONFIG_PRIVACY_ALLOWLIST` only for documented exceptions., Set `MCP_CONFIG_PRIVACY_MODE=advisory` to warn without blocking while a team tunes its MCP policy.
Privacy notes
Runs locally and makes no network calls., Does not print credential values, URLs, or full config content; it reports only finding categories., The target file path, finding category, allowlist pattern, and mode variable can still appear in terminal output, Claude Code transcripts, CI logs, or screenshots., Use environment-variable expansion or a secret manager for MCP credentials so private tokens are not committed to project-scoped config files.
Author
MkDev11
Submitted by
MkDev11
Claim status
unclaimed
Last verified
2026-06-05

Decision playbook

Review trust signals before you adopt

Signals are present but mixed. Use the checklist below to confirm the source and operational safety for your environment.

Compare context
Selected

0

Current score

63

Baseline

Delta

No baseline selected

No major trust-signal divergence detected in the current selection.

Source and provenance checks

Needs review

Confirm ownership and provenance before trusting install instructions.

  • Source link availableRequired

    Open the canonical repository and verify ownership.

    Done
  • Source provenance statusRequired

    Marked as source-backed.

    Done
  • Metadata reviewed

    No reviewed flag detected in metadata.

    Pending

Safety and privacy checks

Complete

Validate risk disclosures before installation or API wiring.

  • Safety notes presentRequired

    Review the listed safety guidance before running commands.

    Done
  • Privacy notes presentRequired

    Review data handling notes before connecting accounts or secrets.

    Done
  • Trust level risk gateRequired

    Trust level does not block evaluation.

    Done

Package and install checks

Needs review

Check package metadata and artifact integrity signals.

  • Install payload available

    Install or copy payload is available for review.

    Done
  • Package verification flag

    No package verification flag provided.

    Pending
  • Checksum metadata

    No checksum provided for downloaded artifact.

    Pending

Compare-driven decision checks

Needs review

Use compare context to validate trade-offs before adoption.

  • Compare tray has multiple entries

    Add at least one more entry to compare trust differences.

    Pending
  • Baseline comparison available

    No baseline peer selected yet.

    Pending
  • Diverging trust signals identified

    No major trust-signal divergence found.

    Pending

Setup at a glance

CLI install

Copy-ready — paste the snippet to get started.

5 minutes

Adoption plan

Balanced adoption plan

Current risk score 24/100. Use staged verification before broader rollout.

Risk 24

Pre-adoption checks

Validate source and review signals before any execution.

  • Confirm source provenanceRequired

    Source URL/provenance metadata is present.

    Done
  • Confirm metadata review state

    No review metadata found; increase manual validation.

    Pending
  • Verify install payload

    Install/config payload exists and can be inspected.

    Done

Security checks

Confirm safety, privacy, and package integrity signals.

  • Review safety notesRequired

    Safety notes are present.

    Done
  • Review privacy notesRequired

    Privacy notes are present.

    Done
  • Verify package integrity metadata

    No package verification/checksum metadata.

    Pending

Rollout

Adopt in controlled steps based on the selected plan.

  • Run in isolated sandbox firstRequired

    Use a constrained sandbox and observe behavior across multiple tasks.

    Pending
  • Roll out graduallyRequired

    Roll out to a small cohort before wider usage.

    Pending
  • Set monitoring and fallback

    Define rollback path and monitor errors after adoption.

    Pending

Evidence readiness

Evidence readiness matrix · balanced

Missing required evidence: Metadata review. Risk score 31.

Risk 31

Source provenance

Present

Source repository/provenance is listed.

Required in this preset

Metadata review

Missing

Review metadata is missing.

Required in this preset

Safety notes

Present

Safety notes are present.

Required in this preset

Privacy notes

Present

Privacy notes are present.

Optional in this preset

Package integrity

Missing

Package integrity metadata is missing.

Optional in this preset

Install payload

Present

Install payload is available.

Required in this preset

Required gaps: Metadata review

Decision timeline

Decision timeline · balanced

Blocking gaps: Check metadata review status. Risk 28.

Risk 28

triage

Confirm source provenanceRequired

Source/provenance metadata is available.

Done

triage

Check metadata review statusRequired

Review metadata is missing.

Pending

verify

Review safety notesRequired

Safety notes are available.

Done

verify

Review privacy notes

Privacy notes are available.

Done

verify

Validate package integrity metadata

Package integrity metadata is missing.

Pending

rollout

Verify install payload and commandsRequired

Install payload is available.

Done

Blockers: Check metadata review status

Prerequisite readiness

Prerequisite readiness

3 prerequisites to line up before setup. Have accounts and credentials ready first. Includes a review or approval gate.

0/3 ready
Account & credentials1Install & runtime1Review & approval15 minutes

Safety & privacy surface

Safety & privacy surface

5 safety and 4 privacy notes across 4 risk areas. Review closely: credentials & tokens, network access.

4 areas
  • SafetyLocal filesRuns before Write, Edit, and MultiEdit tool calls and reads only the pending file path plus proposed new text, including replacement fragments for partial edits.
  • SafetyCredentials & tokensBlocks matching MCP configuration edits with exit code 2 when it finds inline credential values, credential-bearing URLs, or broad filesystem roots for filesystem MCP servers.
  • SafetyNetwork accessDoes not start MCP servers, contact remote MCP endpoints, edit files, delete files, or inspect existing config beyond the proposed tool input.
  • SafetyGeneralText and JSON heuristics can miss unusual config shapes or flag reviewed local setups; use `MCP_CONFIG_PRIVACY_ALLOWLIST` only for documented exceptions.
  • SafetyGeneralSet `MCP_CONFIG_PRIVACY_MODE=advisory` to warn without blocking while a team tunes its MCP policy.
  • PrivacyNetwork accessRuns locally and makes no network calls.
  • PrivacyCredentials & tokensDoes not print credential values, URLs, or full config content; it reports only finding categories.
  • PrivacyLocal filesThe target file path, finding category, allowlist pattern, and mode variable can still appear in terminal output, Claude Code transcripts, CI logs, or screenshots.
  • PrivacyCredentials & tokensUse environment-variable expansion or a secret manager for MCP credentials so private tokens are not committed to project-scoped config files.

Safety notes

  • Runs before Write, Edit, and MultiEdit tool calls and reads only the pending file path plus proposed new text, including replacement fragments for partial edits.
  • Blocks matching MCP configuration edits with exit code 2 when it finds inline credential values, credential-bearing URLs, or broad filesystem roots for filesystem MCP servers.
  • Does not start MCP servers, contact remote MCP endpoints, edit files, delete files, or inspect existing config beyond the proposed tool input.
  • Text and JSON heuristics can miss unusual config shapes or flag reviewed local setups; use `MCP_CONFIG_PRIVACY_ALLOWLIST` only for documented exceptions.
  • Set `MCP_CONFIG_PRIVACY_MODE=advisory` to warn without blocking while a team tunes its MCP policy.

Privacy notes

  • Runs locally and makes no network calls.
  • Does not print credential values, URLs, or full config content; it reports only finding categories.
  • The target file path, finding category, allowlist pattern, and mode variable can still appear in terminal output, Claude Code transcripts, CI logs, or screenshots.
  • Use environment-variable expansion or a secret manager for MCP credentials so private tokens are not committed to project-scoped config files.

Prerequisites

  • Claude Code CLI with hooks enabled.
  • bash, jq, grep, sort, and a reviewed `.claude/settings.json` or user-level hook configuration.
  • A team MCP policy for approved servers, credential storage, filesystem scopes, and remote transports.

Schema details

Install type
cli
Reading time
6 min
Difficulty score
39
Troubleshooting
Yes
Breaking changes
No
Source repository stats
Scope
Source repo
Runtime and command metadata
Trigger
PreToolUse
Script language
bash
Script body
#!/usr/bin/env bash
set -u

# Claude Code PreToolUse hook for Write/Edit/MultiEdit. It scans proposed
# changes to MCP configuration files before they reach disk. It reads only the
# pending tool input and never contacts an MCP server.

if ! command -v jq >/dev/null 2>&1; then
  exit 0
fi

input=$(cat)
tool_name=$(printf '%s' "$input" | jq -r '.tool_name // .toolName // empty')

case "$tool_name" in
  Write|Edit|MultiEdit|write|edit|multiedit) ;;
  *) exit 0 ;;
esac

file_path=$(printf '%s' "$input" | jq -r '.tool_input.file_path // .toolInput.file_path // .tool_input.path // .toolInput.path // empty')
content=$(printf '%s' "$input" | jq -r '
  [ .tool_input.content,
    .toolInput.content,
    .tool_input.new_string,
    .toolInput.new_string,
    (.tool_input.edits[]?.new_string),
    (.toolInput.edits[]?.new_string) ]
  | map(select(. != null)) | join("\n")
')
edit_new_content=$(printf '%s' "$input" | jq -r '
  [ .tool_input.new_string,
    .toolInput.new_string,
    (.tool_input.edits[]?.new_string),
    (.toolInput.edits[]?.new_string) ]
  | map(select(. != null)) | join("\n")
')

if [ -z "$content" ]; then
  exit 0
fi

is_mcp_target=0
case "$file_path" in
  .mcp.json|*/.mcp.json|mcp.json|*/mcp.json|*/managed-mcp.json|*claude_desktop_config.json|*/.vscode/mcp.json|*/.cursor/mcp.json|*/.windsurf/mcp_config.json)
    is_mcp_target=1
    ;;
esac

if printf '%s\n' "$content" | grep -Eq '"mcpServers"[[:space:]]*:'; then
  is_mcp_target=1
fi

if [ "$is_mcp_target" -ne 1 ]; then
  exit 0
fi

if [ -n "${MCP_CONFIG_PRIVACY_ALLOWLIST:-}" ]; then
  if printf '%s\n%s\n' "$file_path" "$content" | grep -Eq -- "$MCP_CONFIG_PRIVACY_ALLOWLIST"; then
    exit 0
  fi
fi

findings=""
add_finding() {
  findings="${findings}${1}"$'\n'
}

if printf '%s' "$content" | jq -e . >/dev/null 2>&1; then
  inline_keys=$(printf '%s' "$content" | jq -r '
    .. | objects
    | [(.env? // {}), (.headers? // {})]
    | .[]
    | objects
    | to_entries[]?
    | select(
        (.key | test("(TOKEN|KEY|SECRET|PASSWORD|PAT|COOKIE|SESSION|PRIVATE|CREDENTIAL|AUTHORIZATION)"; "i"))
        and (.value | type == "string")
        and ((.value | test("^(Bearer\\s+)?(\\$[A-Za-z_][A-Za-z0-9_]*|\\$\\{[A-Za-z_][A-Za-z0-9_]*\\})$|^<[^>]+>$|^$|^REPLACE_|^your-|^example"; "i")) | not)
      )
    | .key
  ' 2>/dev/null | sort -u)

  if [ -n "$inline_keys" ]; then
    add_finding "inline credential value in env or headers"
  fi

  credential_urls=$(printf '%s' "$content" | jq -r '
    .. | strings
    | select(test("https?://[^[:space:]\"<>]+[?&](access_token|api_key|token|password|client_secret)="; "i"))
  ' 2>/dev/null | head -n 1)

  if [ -n "$credential_urls" ]; then
    add_finding "credential-bearing URL in MCP config"
  fi

  broad_roots=$(printf '%s' "$content" | jq -r '
    .. | objects
    | select((.command? // "" | tostring | test("filesystem|server-filesystem|@modelcontextprotocol/server-filesystem"; "i")))
    | [.args[]?]
    | map(tostring)[]
    | select(test("^(~|/|/Users|/home|/root|[A-Za-z]:\\\\Users)(/)?$"))
  ' 2>/dev/null | head -n 1)

  if [ -n "$broad_roots" ]; then
    add_finding "broad filesystem root exposed to filesystem MCP server"
  fi
fi

secret_name_re='(TOKEN|KEY|SECRET|PASSWORD|PAT|COOKIE|SESSION|PRIVATE|CREDENTIAL|AUTHORIZATION)'
literal_secret_re="\"[A-Za-z0-9_ -]*${secret_name_re}[A-Za-z0-9_ -]*\"[[:space:]]*:[[:space:]]*\"(Bearer[[:space:]]+)?[^\"\\$<{][^\"]{8,}\""
default_expansion_secret_re="\"[A-Za-z0-9_ -]*${secret_name_re}[A-Za-z0-9_ -]*\"[[:space:]]*:[[:space:]]*\"(Bearer[[:space:]]+)?\\$\{[A-Za-z_][A-Za-z0-9_]*:-[^}\"]{8,}\}\""
credential_url_re='https?://[^[:space:]"<>]+[?&](access_token|api_key|token|password|client_secret)='
bare_secret_value_re='^"?(Bearer[[:space:]]+)?(sk-[A-Za-z0-9_-]{12,}|[A-Za-z0-9_./+=-]{24,})"?$'
broad_root_value_re='^"?(~|/|/Users|/home|/root|[A-Za-z]:\\Users)/?"?$'

if [ -n "$edit_new_content" ]; then
  if printf '%s\n' "$edit_new_content" | grep -Eq -- "$bare_secret_value_re"; then
    add_finding "inline credential value in env or headers"
  fi

  if printf '%s\n' "$edit_new_content" | grep -Eq -- "$broad_root_value_re"; then
    add_finding "broad filesystem root exposed to filesystem MCP server"
  fi
fi

if printf '%s\n' "$content" | grep -Eiq -- "$literal_secret_re"; then
  add_finding "inline credential value in env or headers"
fi

if printf '%s\n' "$content" | grep -Eiq -- "$default_expansion_secret_re"; then
  add_finding "inline credential value in env or headers"
fi

if printf '%s\n' "$content" | grep -Eiq -- "$credential_url_re"; then
  add_finding "credential-bearing URL in MCP config"
fi

if printf '%s\n' "$content" | grep -Eiq 'server-filesystem|@modelcontextprotocol/server-filesystem|filesystem'; then
  if printf '%s\n' "$content" | grep -Eq '"(~|/|/Users|/home|/root|[A-Za-z]:\\Users)"'; then
    add_finding "broad filesystem root exposed to filesystem MCP server"
  fi
fi

if [ -z "$findings" ]; then
  exit 0
fi

echo "MCP config privacy scanner: risky MCP configuration edit detected." >&2
printf '%s' "$findings" | sort -u | while IFS= read -r finding; do
  [ -n "$finding" ] || continue
  echo "  - $finding" >&2
done
echo "Use environment-variable expansion, remove credential query strings, or narrow filesystem roots before writing the config." >&2
echo "Set MCP_CONFIG_PRIVACY_MODE=advisory to warn without blocking, or MCP_CONFIG_PRIVACY_ALLOWLIST for a reviewed local exception." >&2

if [ "${MCP_CONFIG_PRIVACY_MODE:-block}" = "advisory" ]; then
  exit 0
fi

exit 2
Collection metadata
Estimated setup
5 minutes
Difficulty
intermediate
Full copyable content
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "$HOME/.claude/hooks/mcp-config-privacy-scanner.sh"
          }
        ]
      }
    ]
  }
}

About this resource

Overview

MCP configuration can quietly expand what a Claude session can see. A project .mcp.json, desktop config, or managed MCP policy can add servers with credentials, remote endpoints, and filesystem paths. That is useful when intentional, but risky when a generated edit saves literal tokens or hands a filesystem server a broad root.

This PreToolUse hook runs before Claude Code writes MCP-related configuration. It scans the proposed content locally and blocks three concrete privacy risks: inline credential values in env or headers, URLs that carry credential query parameters, and broad filesystem roots for filesystem MCP servers.

Features

  • Watches Write, Edit, and MultiEdit calls for .mcp.json, managed-mcp.json, mcp.json, claude_desktop_config.json, and content that contains an mcpServers object.
  • Parses complete JSON when available, then falls back to text heuristics for partial edits.
  • Flags literal credential-like values in MCP env or headers objects while allowing environment-variable references such as ${MCP_TOKEN}.
  • Flags credential-bearing remote URLs that include token-like query parameters.
  • Flags filesystem MCP server configs that expose broad roots such as /, ~, /home, /Users, /root, or a Windows user root.
  • Reports finding categories only, without echoing the secret value, URL, or full config.

How It Works

Claude Code sends the pending tool call to the hook on stdin. The script extracts the tool name, target path, and new text from the Write/Edit/MultiEdit payload. It scans only MCP-looking targets: known MCP config filenames or content containing an mcpServers key.

When the proposed text is valid JSON, the hook uses jq to inspect env, headers, string URLs, and filesystem server arguments. For partial edits, it uses conservative grep patterns so a changed line can still be caught before it is saved. If any risky pattern is found, the hook exits 2, which blocks the write and returns the reason to Claude Code.

Use Cases

  • Stop project-scoped .mcp.json changes from committing literal service tokens.
  • Review remote MCP server URLs before a bearer token, API key, or password is embedded in a query string.
  • Keep generated filesystem server configs from exposing an entire home directory or root filesystem.
  • Run the guard in advisory mode while a team inventories approved MCP servers and credential handling.

Installation

  1. Create a user-owned hooks directory: mkdir -p "$HOME/.claude/hooks"
  2. Create the hook file: touch "$HOME/.claude/hooks/mcp-config-privacy-scanner.sh"
  3. Paste the script body into that file and make it executable: chmod +x "$HOME/.claude/hooks/mcp-config-privacy-scanner.sh"
  4. Add the configuration below to ~/.claude/settings.json for a user hook. If you instead store this hook inside a project's .claude/hooks directory, keep the matching $CLAUDE_PROJECT_DIR/.claude/hooks/... command only in that reviewed project's .claude/settings.json; do not copy a project-relative command into user-level settings.

Hook Configuration

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "$HOME/.claude/hooks/mcp-config-privacy-scanner.sh"
          }
        ]
      }
    ]
  }
}

Script

#!/usr/bin/env bash
# Paste the scriptBody from this entry into:
# ~/.claude/hooks/mcp-config-privacy-scanner.sh

Configuration Options

  • MCP_CONFIG_PRIVACY_MODE=advisory prints warnings but exits 0.
  • MCP_CONFIG_PRIVACY_ALLOWLIST is an extended grep pattern checked against the target path and proposed content. Use it only for reviewed local exceptions.

Expected Behavior

  • Allowed: MCP config that references credentials with environment-variable expansion.
  • Blocked: MCP config that places a literal credential-like value in an env or headers object.
  • Blocked: Remote MCP URL strings that include credential-style query parameters.
  • Blocked: Filesystem MCP server arguments that expose an entire home or root directory.

Limitations

  • The hook is a local pre-write scanner. It does not prove an MCP server is safe, authenticated correctly, or least-privilege at runtime.
  • Regex and JSON heuristics can miss obfuscated secrets or unusual config layouts.
  • Partial edits may not contain enough JSON context to identify every server type.
  • A project can still add risky MCP config through another editor unless the same policy is enforced in review or CI.

Troubleshooting

The hook does not run

Confirm the file is executable and that the hook config is in the active Claude Code settings file. Then run /hooks or the relevant Claude Code config diagnostic command to confirm the PreToolUse hook is loaded.

A placeholder was blocked

Use environment-variable expansion for credential values or set advisory mode while tuning the policy. Avoid realistic-looking token placeholders in shared MCP config.

A reviewed filesystem server was blocked

Narrow the path to the minimum directory the MCP server needs. If a broad path is truly required, document the reason and add a local allowlist pattern.

Duplicate Check

Checked content/hooks/ for MCP config, mcpServers, privacy scanner, environment variable leak, secret scanner, and prompt injection. Existing hook content includes a pre-write secret scanner and package/download guards, but no existing hook focuses on MCP configuration privacy, credential-bearing MCP URLs, and filesystem MCP root exposure before config writes.

Sources

Source citations

Add this badge to your README

Show that MCP Config Privacy Scanner - Claude Code Hook is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.

Listed on HeyClaude
[![Listed on HeyClaude](https://heyclau.de/badge/hooks/mcp-config-privacy-scanner-hook.svg)](https://heyclau.de/entry/hooks/mcp-config-privacy-scanner-hook)

How it compares

MCP Config Privacy Scanner - Claude Code Hook side by side with its closest alternative on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.

1 trust signal differ across this comparison (Submitter).

Field

PreToolUse hook that reviews proposed writes to MCP configuration files and blocks inline credential values, credential-bearing URLs, and broad filesystem roots before they are saved.

Open dossier

PreToolUse hook that blocks edits adding remote MCP server URLs unless their host appears in an explicit allowlist, reducing accidental connection to unreviewed OAuth, SSE, or Streamable HTTP MCP endpoints.

Open dossier
Next steps
Trust
Review statusNot reviewedNot reviewed
Package trustPackage not verifiedPackage not verified
Source provenanceSource-backedSource-backed
SubmitterDiffersMkDev11JSONbored
Install riskReview firstReview first
Notes Safety ✓ Privacy ✓ Safety ✓ Privacy ✓
Brand
Categoryhookshooks
SourceSource-backedSource-backed
AuthorMkDev11JSONbored
Added2026-06-052026-06-05
Platforms
Harness
Source repo
Safety notesRuns before Write, Edit, and MultiEdit tool calls and reads only the pending file path plus proposed new text, including replacement fragments for partial edits. Blocks matching MCP configuration edits with exit code 2 when it finds inline credential values, credential-bearing URLs, or broad filesystem roots for filesystem MCP servers. Does not start MCP servers, contact remote MCP endpoints, edit files, delete files, or inspect existing config beyond the proposed tool input. Text and JSON heuristics can miss unusual config shapes or flag reviewed local setups; use `MCP_CONFIG_PRIVACY_ALLOWLIST` only for documented exceptions. Set `MCP_CONFIG_PRIVACY_MODE=advisory` to warn without blocking while a team tunes its MCP policy.This hook blocks unreviewed remote hosts in MCP-related config edits; it does not prove an allowed host is safe. Run a separate authorization and source review before adding a new host to the allowlist. The hook fails open when jq is unavailable, so CI or pre-commit checks should cover high-assurance environments.
Privacy notesRuns locally and makes no network calls. Does not print credential values, URLs, or full config content; it reports only finding categories. The target file path, finding category, allowlist pattern, and mode variable can still appear in terminal output, Claude Code transcripts, CI logs, or screenshots. Use environment-variable expansion or a secret manager for MCP credentials so private tokens are not committed to project-scoped config files.The hook reads pending config text from Claude Code tool input but does not write files or call the network. Blocked hostnames are printed to stderr and may reveal internal MCP endpoints in the local terminal.
Prerequisites
  • Claude Code CLI with hooks enabled.
  • bash, jq, grep, sort, and a reviewed `.claude/settings.json` or user-level hook configuration.
  • A team MCP policy for approved servers, credential storage, filesystem scopes, and remote transports.
  • Claude Code CLI with hooks enabled.
  • bash, jq, grep, and awk available locally.
  • ALLOWED_MCP_HOSTS set to a comma-separated list of reviewed remote MCP hosts.
Install
mkdir -p "$HOME/.claude/hooks" && touch "$HOME/.claude/hooks/mcp-config-privacy-scanner.sh" && chmod +x "$HOME/.claude/hooks/mcp-config-privacy-scanner.sh"
mkdir -p .claude/hooks
cat > .claude/hooks/mcp-server-url-allowlist.sh <<'MCP_SERVER_URL_ALLOWLIST_HOOK'
#!/usr/bin/env bash
set -u

if ! command -v jq >/dev/null 2>&1; then
  exit 0
fi

input=$(cat)
file=$(printf '%s' "$input" | jq -r '.tool_input.file_path // .tool_input.path // ""')
text=$(printf '%s' "$input" | jq -r '
  def scalar_strings:
    if type == "string" then .
    elif type == "array" then .[] | scalar_strings
    elif type == "object" then .[] | scalar_strings
    else empty end;

  def decoded_config_strings:
    try (fromjson | scalar_strings) catch empty;

  [.tool_input.content, .tool_input.new_string, (.tool_input.edits[]?.new_string)]
  | map(select(type == "string"))
  | .[]
  | ., decoded_config_strings
' 2>/dev/null)
normalized_text=$(printf '%s' "$text" | sed 's#\\/#/#g')

case "$file" in
  *mcp*.json|*.mcp.json|*.claude/settings.json|*/settings.json) ;;
  *) exit 0 ;;
esac

hosts=$(printf '%s' "$normalized_text" | grep -Eo 'https?://[^"[:space:]]+' | awk -F/ '{print $3}' | sort -u)
[ -z "$hosts" ] && exit 0

allowlist=$(printf '%s' "${ALLOWED_MCP_HOSTS:-}" | tr ',' ' ')
for host in $hosts; do
  case " $allowlist " in
    *" $host "*) ;;
    *)
      echo "Blocked remote MCP URL: $host is not in ALLOWED_MCP_HOSTS." >&2
      exit 2
      ;;
  esac
done

exit 0
MCP_SERVER_URL_ALLOWLIST_HOOK
chmod +x .claude/hooks/mcp-server-url-allowlist.sh
Config
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "$HOME/.claude/hooks/mcp-config-privacy-scanner.sh"
          }
        ]
      }
    ]
  }
}
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write|Edit|MultiEdit",
        "hooks": [
          {
            "type": "command",
            "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/mcp-server-url-allowlist.sh"
          }
        ]
      }
    ]
  }
}
Citations
ClaimUnclaimedUnclaimed
Open in the interactive comparison tool

Related guides

Signals

Loading live community signals…

More like this, weekly

A short, calm digest of reviewed Claude resources. Unsubscribe any time.