datarobot_genai.drmcp.core.server_life_cycle
server_life_cycle
BaseServerLifecycle
Base server lifecycle interface with safe default implementations.
This class provides hooks that are called at different stages of the server lifecycle. Subclasses can override any or all of these methods to add custom behavior. All methods have safe no-op defaults, so you only need to implement what you need.
Lifecycle Order
- pre_server_start() - Before server initialization
- Server starts
- post_server_start() - After server is ready
- Server runs...
- Shutdown signal received
- pre_server_shutdown() - Before server cleanup
- Server stops
Example
class MyLifecycle(BaseServerLifecycle):
async def pre_server_start(self, mcp: FastMCP) -> None:
# Initialize resources
self.db = await connect_database()
async def pre_server_shutdown(self, mcp: FastMCP) -> None:
# Clean up resources
await self.db.close()
# post_server_start not implemented - will use safe default (no-op)
Source code in datarobot_genai/drmcp/core/server_life_cycle.py
pre_server_start
async
Call before the server starts.
Use this to: - Initialize resources - Set up connections - Validate configuration - Prepare server state
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mcp
|
FastMCP
|
The FastMCP instance that will be started |
required |
Note
Override this method in your subclass to add custom initialization. The default implementation is a safe no-op.
Source code in datarobot_genai/drmcp/core/server_life_cycle.py
post_server_start
async
Call after the server has started and is ready to handle requests.
Use this to: - Register additional handlers - Start background tasks - Initialize delayed resources - Log startup completion
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mcp
|
FastMCP
|
The running FastMCP instance |
required |
Note
Override this method in your subclass to add post-startup logic. The default implementation is a safe no-op.
Source code in datarobot_genai/drmcp/core/server_life_cycle.py
pre_server_shutdown
async
Call before the server shuts down.
Use this to: - Close database connections - Save application state - Clean up temporary files - Stop background tasks - Release resources
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mcp
|
FastMCP
|
The running FastMCP instance |
required |
Note
Override this method in your subclass to add cleanup logic. The default implementation is a safe no-op. This is ALWAYS called, even on Ctrl+C or errors.