# What Happens During Server Startup and Shutdown in the Lifespan Handler

> Understand the server startup and shutdown process within the lifespan handler. Learn how FastAPI initialization, telemetry startup, and resource cleanup are orchestrated during the server's lifecycle.

- Repository: [ahujasid/blender-mcp](https://github.com/ahujasid/blender-mcp)
- Tags: internals
- Published: 2026-04-13

---

**The lifespan handler in [`src/blender_mcp/server.py`](https://github.com/ahujasid/blender-mcp/blob/main/src/blender_mcp/server.py) uses an asynchronous generator to orchestrate FastAPI initialization, telemetry startup, and graceful resource cleanup during the server's lifecycle.**

The `blender-mcp` repository implements a Model Context Protocol (MCP) server using FastAPI, where the `server_lifespan` generator manages critical setup and teardown phases. This handler ensures that background services start before requests are accepted and that all resources are properly released when the process terminates.

## How the Lifespan Handler Works in blender-mcp

The `server_lifespan