The book grew out of an attempt to explain the meaning of "Faery" by means of a brief story about a cook and his cake. This would have been part of a preface to George MacDonald's famous faerie story The Golden Key. But the story grew from there and became a tale in its own right.
The most recent edition includes a previously unpublished essay by Tolkien, explaining the background and just why the elf-king spent so long in Wooton Major. It also explains how the story grew from this first idea into the published version.
The book was originally called "The Great Cake", but the title was changed to "Smith of Wootton Major" in an attempt to suggest an early work by P.G. Wodehouse.
It is not definitely connected to the Middle-earth legendarium. Both Faery and Valinor are lands outside of the normal world, but Valinor cannot normally be visited by mortals. There are lesser elven kingdoms that humans can visit and return: Faramir mentions visitors to Lorien.
The village of Wootton Major is well-known around the countryside for its annual festivals, which are particularly famous for their culinary delights. The biggest festival of them all is the Feast of Good Children. This festival is celebrated only once every twenty-four years, and the celebrations take the form of a party to which twenty-four children of the village are invited. The highpoint of the party is the Great Cake, which is remarkable for its hidden magical ingredients. Whoever swallows one of these is given the rare gift of an entry into the Land of Faery.
This year the magic star hidden inside the Great Cake was eaten by a blacksmith’s son. The boy did not feel any of its magical properties at once but on the morning of his tenth birthday the star fixed itself on his forehead and marked him as one intimate with the Faeryfolk. This boy grew up to be a blacksmith like his father, but in his free time he roamed into the Land of Faery. The star on his forehead protected him from the evils threatening mortals in that land, and the Folk called him Starbrow and told him about their land and its hidden beauties and dangers.
The years passed and it was now time for another Feast of Good Children. Smith had had his precious gift for most of his life now and the time had come for it to be passed on to some other child. So he gave up the star, and the mysterious new Master Cook baked it into the festive cake once more.