add middleware for CMD wrapper