Yes it would be feasible, depending on where you dock but would feel quite rushed. I think you might be clock watching all day. You need a couple of hours for the castle ( buy tickets beforehand to avoid the queues ) and then a hour or so to do the Royal Mile and take in the atmosphere. There is of course a lot more to Edinburgh than these two attractions. Be aware that there’s a a lot of roadworks just now in Edinburgh due to tram construction so traffic could be an issue. Also, Edinburgh has grown in popularity the last few years so please expect it to be very busy.
St Andrews is about an hour and 15 mins away but depends on the traffic on “the bridge”. Things much better now that there is the new Queensferry Crossing. The three bridges over the Firth of Forth are an added bonus if you decide to go to St Andrews. St Andrews is not big and is nice for a stroll. An afternoon would do it to look at the Old Course, University, castle , beach etc. Lots of nice coffee shops and book shops if that’s your thing. Another tip is to check for important events at the university, graduations, freshers, start of term. This can really affect your enjoyment of the town as it will be overrun by students and their families. If you do go to St Andrews, there are some very pretty fishing villages in the vicinity such as Craig, which merit a look. Sorry but I can’t help you with a tour guide. I would look at all the usual sites for listings. Enjoy your trip.