Your Pentax MX is an analog camera. It was designed and built in a time when all photography was analog. The only analog electronics in your Pentax MX is the light meter and associated battery. Everything else is purely mechanical.
To release the mechanical shutter of your Pentax camera requires mechanical movement of the shutter button. This can be accomplished without touching the shutter button yourself only with a mechanical cable release. The size of the threads for mechanical shutter cables is near universal. The tapered threads such as are found on the example linked above will fit the vast majority of film cameras with threads in the shutter button produced in the last 60-80 years. The design and use of such a cable release was so universal back in the time your Pentax MX was made that it isn't even mentioned in the fairly detailed Owner's Manual.
I suppose it would be theoretically possible to design and built an external digital intervalometer that uses some sort of servo motor to actuate a mechanical cable release. But to the best of my knowledge (which may well be too limited at this point as I have never previously looked for such a device) no such product has ever been commercially offered. This DIY project made something similar but only needed to actuate the shutter with a camera set shutter time. It could probably have been modified to enable bulb mode. Battery capacity on both ends might need to be increased to allow holding the shutter open against the spring loaded shutter button.
Keep in mind that long exposure times don't have to be minutely precise at all. The difference between two batches of the same film might be greater than a 1/2 second inaccuracy for a 20 second shot. Also keep in mind that the development of film relies on timed processes that are also subject to the same types of inaccuracies: the technician normally uses a freestanding timer to tell them when to stop the development of the film and it takes a time interval for all of the developer to be rinsed from the film's emulsion. Even when film is developed in an automatic developing machine all of the developer doesn't instantly dry from the film when it is removed from the developer bath before entering the rinse bath.
If you're not familiar with the Schwarzschild effect you need to consider the necessary adjustment of exposure times over one second when using analog film. This will have a far greater effect on setting proper exposure with film than the imprecision of using analog mechanical shutter control with an unconnected timer.