Looking for a Table of Contents sample for the ArcGIS Server JavaScript API
Is this what you are looking for? I found it by searching the Code Gallery page on the ArcGIS API for Javascript Resource Center.
There's a new TOC sample called Table of Content/Legend Widget for JavaScript API by Nianwei Liu, which fits the bill almost perfectly. It doesn't (seem to) allow feature layers but this is a compromise I can live with since it answers the other requirements very well.
Here is a link to another example. This TOC/Legend is automatically generated by the layers in the MXD.
http://stlouis.esri.com/apps/exportmap/
It is part of one of the printing with ArcPy samples located below.
http://blogs.esri.com/Dev/blogs/arcgisserver/archive/2011/04/12/An-introduction-to-arcpy.mapping-for-ArcGIS-Server-developers.aspx
-Mike