A firm will always wish to produce at the quantity where marginal costs equal marginal revenues. Therefore, the supply curve must slope upwards.
Economists have determined that the quantity where MR equals MC is the optimal quantity at which to produce. At this quantity, a firm maximizes its profits or minimizes its losses.
So, if the price of selling a good or service goes up, firms will be willing to produce more of those goods. As the price goes up, marginal revenue goes up. As marginal revenue goes up, firms should produce more so that MC will equal MR.
The other way of looking at this is that marginal costs tend to go up as the quantity produced goes up. When this happens, firms must raise their prices so that MR will equal MC.
When we consider the supply curve of a commodity for the whole market, it is definitely a definitely a upward sloping curve. This shape of the supply curve reflects the reality that the number of firms willing to supply that commodity increases as the market price increases. Thus it is not quite correct to say that upward sloping demand curve is because of marginal cost.
Marginal cost is a concept applicable only to a firm. Also the Marginal cost curve for the firm is not always upward sloping. As a matter of fact, the marginal cost curves for a firm operating in a competitive market is more likely to be U-shaped, while that for a monopoly is more likely to be downward sloping curve.
In a perfectly competitive market, the the upward sloping part of the U-shaped marginal cost also represents the supply curve of the firm. In this case the actual quantity supplied by the firm is determined by the point where the marginal cost equals the market price. In long term this point tends to become the lowest point on the U-shaped marginal cost curve.
In case of a monopoly market marginal cost curve does not represent the supply curve. As mentioned earlier, the marginal cost curve for a monopoly is likely to be a downward sloping curve, while the supply curve is always an upward sloping curve.