Microgrid is a typical low-inertia system with uncertainty due to the high penetration of power electronics and renewable energy. Therefore, it is necessary to consider the issue of frequency security when planning microgrids. In this paper, we propose a frequency-constrained optimal planning approach involving both long- and short-term uncertainties to optimally design the critical equipment size for a microgrid while ensuring frequency security in case of a power disturbance. This approach explicitly considers the distinct characteristics of primary frequency responses (e.g., different delivery times) and formulates the frequency constraints as second-order cone constraints. The long-term uncertainties about load demand and unit investment cost of developing technology are addressed by a set of credible scenarios. In each long-term scenario, the short-term uncertainty in the operational stage associated with wind power is described by the Wasserstein-metric ambiguity set. To efficiently solve the proposed model, we first reformulate the distributionally robust joint chance constraint and bilinear terms to enable the proposed model as a mixed-integer second-order cone programming (MISCOP) and then a logic-based Benders decomposition is introduced to solve the MISOCP. Case studies demonstrate the effectiveness and scalability of the proposed method.