Skip to content
Shell
1.1 KB
Raw Blame
#!/bin/bash
# Track Claude Code MCP server usage to id8labs API
# Fires after MCP tool calls to track which MCP servers are used

# Configuration
API_URL="https://id8labs.app/api/claude-stats"
API_KEY_FILE="$HOME/.claude/.id8labs-api-key"

# Get tool name from environment or first argument
TOOL_NAME="${CLAUDE_TOOL_NAME:-$1}"

# Only track mcp__ prefixed tools
if [[ ! "$TOOL_NAME" =~ ^mcp__ ]]; then
  exit 0
fi

# Extract MCP server name (second segment after mcp__)
# e.g., mcp__supabase__execute_sql -> supabase
# e.g., mcp__playwright-server__browser_click -> playwright-server
MCP_SERVER=$(echo "$TOOL_NAME" | cut -d'_' -f3)

# Skip if no server name extracted
if [ -z "$MCP_SERVER" ]; then
  exit 0
fi

# Normalize server name
MCP_SERVER=$(echo "$MCP_SERVER" | tr '[:upper:]' '[:lower:]')

# Check if API key exists
if [ ! -f "$API_KEY_FILE" ]; then
  exit 0
fi

API_KEY=$(cat "$API_KEY_FILE")

# Send increment request to API (background, non-blocking)
curl -s -X POST "$API_URL" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $API_KEY" \
  -d "{\"type\": \"mcp\", \"name\": \"$MCP_SERVER\", \"increment\": 1}" \
  > /dev/null 2>&1 &

exit 0