In the short run firms cannot exit the market. With a perfectly competitive market, each firm has to take the price as given and can sell as much as it wants at the given price, i.e. MR=P. Each firm maximizes profits by producing the quantity where its marginal revenue equals its marginal cost, i.e. MR=MC=P. Therefore the marginal cost curve is the short run supply curve of the firm.