Preheat the oven to 175°C / 350°F.
Chop the mushrooms into thin strips. If using oyster mushrooms, remove the tough parts.
Dry-cook mushrooms in a large non-stick pan over high heat. Do not season or stir before they drain and brown at the bottom. Once browned on the bottom, stir and cook for 3 more minutes. Remove from the heat and season with salt and pepper. Transfer them to a bowl and set aside to cool.
Heat a splash of olive oil in the same pan.
Saute the onion and leeks over moderate heat.
Add the butter and, once melted, stir in the 4 tablespoons of flour. Cook the flour for a minute, stirring and scraping the bottom with a wooden spoon.
Pour in the milk and stir until thick and creamy. Remove the pan from the heat and set aside to cool for 10 minutes.
Add the egg, half the Gruyere cheese, the Kefalotyri cheese, the thyme, ground fennel, and season lightly with salt and pepper, and stir in the mushrooms.