Heat oven to 350°F. Butter an 11x7-inch baking dish.
Melt butter in a large skillet over medium-high heat. Add shallots and garlic; sauté 2 minutes. Add mushrooms, salt and pepper; cook until mushrooms release moisture and the moisture evaporates, about 8 minutes.
Stir in Madeira; cook until liquid evaporates, about 6 minutes. Remove from heat. Place mushroom mixture in a large mixing bowl. Add bread, parsley and thyme; toss gently.
In a separate bowl, whisk together broth, cream and egg; pour over mushroom mixture and toss to coat. Transfer mixture to the prepared baking dish. Bake until golden and set, about 45 minutes.