Skip to content
Shell
873 B
Raw Blame
#!/bin/bash
# Kill all MCP server processes and free memory

echo "πŸ” Finding MCP processes..."
MCP_BEFORE=$(ps aux | grep -E "mcp-server|npm exec.*mcp" | grep -v grep | wc -l | tr -d ' ')
MEM_BEFORE=$(ps aux | grep -E "mcp-server|npm exec.*mcp" | grep -v grep | awk '{sum+=$6} END {print int(sum/1024)}')

if [ "$MCP_BEFORE" -eq 0 ]; then
    echo "βœ… No MCP servers running"
    exit 0
fi

echo "   Found $MCP_BEFORE processes using ${MEM_BEFORE}MB"
echo ""
echo "πŸ—‘οΈ  Killing MCP servers..."

pkill -f "mcp-server" 2>/dev/null
pkill -f "npm exec.*mcp" 2>/dev/null
sleep 1

MCP_AFTER=$(ps aux | grep -E "mcp-server|npm exec.*mcp" | grep -v grep | wc -l | tr -d ' ')

if [ "$MCP_AFTER" -eq 0 ]; then
    echo "βœ… All MCP servers killed"
    echo "πŸ’Ύ Freed ~${MEM_BEFORE}MB of memory"
else
    echo "⚠️  $MCP_AFTER processes still running (may need sudo)"
fi