1. Write an ending to the story.

[Is 'to the story' an adverb phrase or an adjective phrase?]

2. Write the ending to the story.
[Is 'to the story' an adverb phrase or an adjective phrase? What is the difference between 'an' and 'the' in meaning?]

In both sentences, the prepositional phrase is closest to "ending," and therefore is an adjective phrase.

There's not much difference between "an" and "the" in these directions. The slight difference I see is that 2 implies that the story has no ending, yet, and the directions are for the student to write it.