MCP Academy · Lesson

The Lifespan Startup Hook

Open connections once when the server boots.

Boot Once, Use Many Times

Some setup should happen once when your server boots, like opening a database connection, not on every single tool call. 🚀

Meet the Lifespan

The lifespan is a hook that runs startup code before requests arrive, then runs teardown code after the server stops.

All lessons in this course

  1. The Lifespan Startup Hook
  2. Share State via App Context
  3. Access the Context Object
  4. Clean Shutdown & Resource Release
← Back to MCP Academy