How to close mocp server on exiting terminal

MOC version: 
moc 5.15.2

Although I think I know what you're asking, you might want to provide a little more context.

If my understanding is correct, then the answer currently is "not within MOC itself". However, I do see it as a worthwhile addition to have a server configuration parameter which specifies what the server should do once all clients have disconnected: continue, stop or quit.

Would that resolve your use case?