Have a look at the jmx-console code. You want to get the jboss.jca and filter to get the "service=ManagedConnectionPool" and obtain the names from that.
You should be able to write the *-ds.xml file from your servlet, but you are going to have to work out how you will discover the deployment directory. I guess you could pass it as an initparam. You will need to write a temporary file first and then rename it the target *-ds.xml to avoid any troubles with early deployment before you have finished writing the configuration.