We develop a semi-analytical formalism for the determination of the evolution of the stellar mass accretion rate for specified density and velocity profiles that emerge from the runaway collapse of a prestellar cloud core. In the early phase, when the infall of matter from the surrounding envelope is substantial, the star accumulates mass primarily because of envelope-induced gravitational instability in a protostellar disk. In this phase, we model the envelope mass accretion rate from the isothermal free-fall collapse of a molecular cloud core. The disk gains mass from the envelope, and transports matter to the star via a disk accretion mechanism that includes episodic gravitational instability and mass accretion bursts according to the Toomre $Q$-criterion. In a later phase, mass is accreted on to the star due to gravitational torques within the spiral structures in the disc, in a manner that analytical theory suggests has a mass accretion rate $\propto t^{-6/5}$. Our model provides a self-consistent evolution of the mass accretion rate by joining the spherical envelope accretion (dominant at the earlier stage) with the disk accretion (important at the later stage), and accounts for the presence of episodic accretion bursts at appropriate times.