summaryrefslogtreecommitdiff
path: root/mcp-servers/token-gated-mcp-server/.claude/hooks/log-mcp-commands.sh
blob: 9b3d09e1c90180416edabd2aff99e0aa6a873ea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash

# Hook script to log MCP-related commands for debugging
# Used in PreToolUse hooks for Bash tool

# Parse the command from input
command=$(echo "$CLAUDE_HOOK_DATA" | jq -r '.tool_input.command // empty')
description=$(echo "$CLAUDE_HOOK_DATA" | jq -r '.tool_input.description // "No description"')

# Exit if no command
if [ -z "$command" ]; then
  exit 0
fi

# Create log directory if it doesn't exist
LOG_DIR="$HOME/.claude/logs"
mkdir -p "$LOG_DIR"

# Log file with date
LOG_FILE="$LOG_DIR/token-gate-$(date +%Y%m%d).log"

# Timestamp for log entry
timestamp=$(date '+%Y-%m-%d %H:%M:%S')

# Log FastMCP commands
if [[ "$command" == *"fastmcp"* ]]; then
  echo "[$timestamp] FastMCP: $command - $description" >> "$LOG_FILE"
  echo "🚀 Running FastMCP command..."
  
  # Provide helpful hints
  if [[ "$command" == *"dev"* ]]; then
    echo "💡 Tip: Use 'npx fastmcp inspect' for visual debugging"
  fi
fi

# Log ngrok commands
if [[ "$command" == *"ngrok"* ]]; then
  echo "[$timestamp] ngrok: $command" >> "$LOG_FILE"
  echo "🌐 Setting up ngrok tunnel..."
  echo "💡 Remember to use the HTTPS URL with /mcp endpoint in claude.ai"
fi

# Log npm/node commands related to MCP
if [[ "$command" == *"npm"* ]] || [[ "$command" == *"node"* ]] || [[ "$command" == *"tsx"* ]]; then
  if [[ "$command" == *"radius"* ]] || [[ "$command" == *"mcp"* ]] || [[ "$command" == *"server"* ]]; then
    echo "[$timestamp] MCP Server: $command" >> "$LOG_FILE"
  fi
fi

# Log token configuration checks
if [[ "$command" == *"EVMAUTH"* ]] || [[ "$command" == *"echo"* ]]; then
  if [[ "$command" == *"CONTRACT"* ]] || [[ "$command" == *"CHAIN"* ]] || [[ "$command" == *"TOKEN"* ]]; then
    echo "[$timestamp] Config Check: $command" >> "$LOG_FILE"
    echo "🔍 Checking token configuration..."
  fi
fi

# Log RPC tests
if [[ "$command" == *"curl"* ]] && [[ "$command" == *"rpc"* ]]; then
  echo "[$timestamp] RPC Test: $command" >> "$LOG_FILE"
  echo "🔗 Testing RPC connection..."
fi

# Security check - warn about potentially dangerous commands
if [[ "$command" == *"rm -rf"* ]] || [[ "$command" == *"sudo rm"* ]]; then
  echo "⚠️  DANGER: Destructive command detected!"
  echo "[$timestamp] BLOCKED: $command" >> "$LOG_FILE"
  exit 2  # Block the command
fi

# Warn about npm publish in development
if [[ "$command" == *"npm publish"* ]]; then
  echo "⚠️  WARNING: About to publish to npm registry!"
  echo "   Ensure version is updated and changes are committed"
  echo "[$timestamp] NPM Publish: $command" >> "$LOG_FILE"
  
  if [ "$NODE_ENV" != "production" ]; then
    echo "❌ Blocking npm publish in non-production environment"
    exit 2
  fi
fi

exit 0