Since the effect of running Tidy on MW Parser main pass output is poorly specified, I suggest parsing the MW Parser output using the HTML 5 algorithm and then reserializing the DOM for output.
This is what Parsoid is already doing, and Gabriel reports that the behaviour is similar to Tidy.
MWTidy::tidy() would become an abstract wrapper for the following backends:
* External tidy
* Internal tidy
* Proposed web service
* New shell wrapper (Rust or Python)
* Existing pure-PHP code in Parser.php around line 1326, labelled "bug #2702"
* Future pure-PHP code. When a compliant pure-PHP HTML 5 parser becomes available, it could be used as a low-performance backend to replace the bug 2702 code.
A new configuration variable would be introduced to control backend selection. $wgUseTidy would be retained for backwards compatibility, with compatibility code in Setup.php along the lines of
```
if ( $wgUseTidy ) {
$wgTidyConfig = array(
'cmd' => $wgTidyBin
);
}
```