The Markdown All in One VSCode extension includes a Table of Contents (ToC) feature to create and keep a ToC up-to-date.
In a markdown file, run Markdown All in One: Create Table of Contents
to
create one. The contents will be kept up-to-date automatically on save.
Configure the levels included in the ToC with the setting
markdown.extension.toc.levels
e.g:
"markdown.extension.toc.levels": "3..6"