Module server

Source
Expand description

Server management module for MCP Runner.

This module handles the lifecycle, monitoring, and process management of MCP servers. It provides functionality to start, stop, and monitor the health of MCP server processes. All public components are instrumented with tracing spans.

§Components

  • lifecycle - Manages server lifecycle events and statuses
  • monitor - Health monitoring and automatic recovery of servers
  • process - Core process management for server instances

§Examples

Managing server lifecycle:

use mcp_runner::server::{ServerLifecycleManager, ServerLifecycleEvent, ServerProcess};
use mcp_runner::config::ServerConfig;
use std::sync::Arc;
use std::collections::HashMap;

// Create a server process to get a valid ServerId
let config = ServerConfig {
    command: "sample".to_string(),
    args: vec![],
    env: HashMap::new(),
};
let server_process = ServerProcess::new("fetch-server".to_string(), config);
let server_id = server_process.id();
let server_name = "fetch-server".to_string();

// Create lifecycle manager and record an event
let manager = Arc::new(ServerLifecycleManager::new());
manager.record_event(
    server_id,
    server_name,
    ServerLifecycleEvent::Started,
    Some("Server started successfully".to_string())
).unwrap();

Monitoring server health:

use mcp_runner::server::{ServerMonitor, ServerMonitorConfig, ServerLifecycleManager};
use std::sync::Arc;
use std::time::Duration;

let lifecycle_manager = Arc::new(ServerLifecycleManager::new());
let config = ServerMonitorConfig {
    check_interval: Duration::from_secs(30),
    health_check_timeout: Duration::from_secs(5),
    auto_restart: true,
    max_consecutive_failures: 3,
};

// Create and start the monitor
let mut monitor = ServerMonitor::new(lifecycle_manager, config);
monitor.start().unwrap();

Re-exports§

pub use lifecycle::ServerEvent;
pub use lifecycle::ServerLifecycleEvent;
pub use lifecycle::ServerLifecycleManager;
pub use monitor::ServerHealth;
pub use monitor::ServerMonitor;
pub use monitor::ServerMonitorConfig;

Modules§

lifecycle
Server lifecycle management for MCP servers.
monitor

Structs§

ServerId
Unique identifier for a server process
ServerProcess
Represents a running MCP server process.

Enums§

ServerStatus
Status of a server process