mcp_runner/server/mod.rs
1//! Server management module for MCP Runner.
2//!
3//! This module handles the lifecycle, monitoring, and process management of MCP servers.
4//! It provides functionality to start, stop, and monitor the health of MCP server processes.
5//! All public components are instrumented with `tracing` spans.
6//!
7//! # Components
8//!
9//! * `lifecycle` - Manages server lifecycle events and statuses
10//! * `monitor` - Health monitoring and automatic recovery of servers
11//! * `process` - Core process management for server instances
12//!
13//! # Examples
14//!
15//! Managing server lifecycle:
16//!
17//! ```no_run
18//! use mcp_runner::server::{ServerLifecycleManager, ServerLifecycleEvent, ServerProcess};
19//! use mcp_runner::config::ServerConfig;
20//! use std::sync::Arc;
21//! use std::collections::HashMap;
22//!
23//! // Create a server process to get a valid ServerId
24//! let config = ServerConfig {
25//! command: "sample".to_string(),
26//! args: vec![],
27//! env: HashMap::new(),
28//! };
29//! let server_process = ServerProcess::new("fetch-server".to_string(), config);
30//! let server_id = server_process.id();
31//! let server_name = "fetch-server".to_string();
32//!
33//! // Create lifecycle manager and record an event
34//! let manager = Arc::new(ServerLifecycleManager::new());
35//! manager.record_event(
36//! server_id,
37//! server_name,
38//! ServerLifecycleEvent::Started,
39//! Some("Server started successfully".to_string())
40//! ).unwrap();
41//! ```
42//!
43//! Monitoring server health:
44//!
45//! ```no_run
46//! use mcp_runner::server::{ServerMonitor, ServerMonitorConfig, ServerLifecycleManager};
47//! use std::sync::Arc;
48//! use std::time::Duration;
49//!
50//! let lifecycle_manager = Arc::new(ServerLifecycleManager::new());
51//! let config = ServerMonitorConfig {
52//! check_interval: Duration::from_secs(30),
53//! health_check_timeout: Duration::from_secs(5),
54//! auto_restart: true,
55//! max_consecutive_failures: 3,
56//! };
57//!
58//! // Create and start the monitor
59//! let mut monitor = ServerMonitor::new(lifecycle_manager, config);
60//! monitor.start().unwrap();
61//! ```
62pub mod lifecycle;
63pub mod monitor;
64mod process;
65
66pub use lifecycle::{ServerEvent, ServerLifecycleEvent, ServerLifecycleManager};
67pub use monitor::{ServerHealth, ServerMonitor, ServerMonitorConfig};
68pub use process::{ServerId, ServerProcess, ServerStatus};