Block Trade/Order MCP Calls Outside a Notional Limit

A hard ceiling on the one field that actually matters for a trade-execution tool — notional size — enforced independently of whatever limit logic lives inside the MCP server itself. Defense in depth: if the server's own limit check has a bug, this is a second, completely separate gate.

Financial & Model-Risk Controls Event: PreToolUse Claude Code Open source · Free

1. Save this as the hook script

#!/usr/bin/env python3
"""PreToolUse hook — blocks an order/trade MCP tool call above a notional
ceiling. Wire to matcher "mcp__.*order.*|mcp__.*trade.*"."""
import json, sys

data = json.load(sys.stdin)
tool_input = data.get("tool_input") or {}

NOTIONAL_CEILING = 250_000

notional = tool_input.get("notional") or tool_input.get("amount") or 0
try:
    notional = float(notional)
except (TypeError, ValueError):
    notional = 0

if notional > NOTIONAL_CEILING:
    print(f"BLOCKED: order notional {notional} exceeds the {NOTIONAL_CEILING} "
          f"ceiling enforced independently of the server's own limit check.", file=sys.stderr)
    sys.exit(2)

sys.exit(0)

Save to a path inside your project, e.g. .claude/hooks/block-trade-calls-outside-notional-limit.sh, then chmod +x it.

2. Wire it into .claude/settings.json

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "mcp__.*order.*|mcp__.*trade.*",
        "hooks": [
          {"type": "command", "command": "python3 .claude/hooks/block-trade-calls-outside-notional-limit.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

← All hooks
FEEDBACK