Decline Elicitation Requests Asking for a Secret
MCP elicitation lets a connected server pop a form asking the human for input mid-tool-call. If that form is asking for a password, API key, or token field name, that's a server asking you to hand it a secret directly — decline it rather than let the human get social-engineered by a UI dialog.
1. Save this as the hook script
#!/usr/bin/env python3
"""Elicitation hook — declines a request if the form's field names look
like they are asking for a secret. Wire this with no matcher (all servers)
or scope to a specific server name."""
import json, re, sys
data = json.load(sys.stdin)
request = data.get("request") or {}
field_names = " ".join(str(k) for k in (request.get("fields") or request))
if re.search(r"(?i)(password|api[_-]?key|secret|token|private[_-]?key)", field_names):
print("BLOCKED: elicitation request's field names look like they are "
"asking for a secret directly. Declining.", file=sys.stderr)
sys.exit(2)
sys.exit(0)
Save to a path inside your project, e.g. .claude/hooks/decline-elicitation-for-secret-fields.sh, then chmod +x it.
2. Wire it into .claude/settings.json
{
"hooks": {
"Elicitation": [
{
"hooks": [
{"type": "command", "command": "python3 .claude/hooks/decline-elicitation-for-secret-fields.py"}
]
}
]
}
}
Before you use this
A hook runs with your local shell's permissions — review the script above before adding it, the same way you'd review any script you didn't write yourself. See our guide on hook security risks for the specific CVEs this category of feature has already produced.
Related hooks