icarus_core/lifecycle.rs
1//! Server lifecycle management traits
2
3use crate::error::Result;
4use async_trait::async_trait;
5
6/// Lifecycle events for MCP servers
7#[async_trait]
8pub trait IcarusServerLifecycle: Send + Sync {
9 /// Called when the server is initialized
10 async fn on_initialize(&mut self) -> Result<()> {
11 Ok(())
12 }
13
14 /// Called before the server is upgraded
15 async fn on_pre_upgrade(&self) -> Result<()> {
16 Ok(())
17 }
18
19 /// Called after the server is upgraded
20 async fn on_post_upgrade(&mut self) -> Result<()> {
21 Ok(())
22 }
23
24 /// Called when the server is about to be stopped
25 async fn on_stop(&self) -> Result<()> {
26 Ok(())
27 }
28
29 /// Called periodically for maintenance tasks
30 async fn on_heartbeat(&mut self) -> Result<()> {
31 Ok(())
32 }
33}
34
35/// Configuration for server lifecycle
36#[derive(Debug, Clone)]
37pub struct LifecycleConfig {
38 /// Heartbeat interval in seconds (0 to disable)
39 pub heartbeat_interval: u64,
40 /// Whether to enable automatic state snapshots
41 pub auto_snapshot: bool,
42 /// Maximum number of snapshots to keep
43 pub max_snapshots: u32,
44}