| Crates.io | rust-mc-status |
| lib.rs | rust-mc-status |
| version | 2.0.0 |
| created_at | 2025-08-20 21:49:48.129799+00 |
| updated_at | 2025-11-09 13:02:27.102572+00 |
| description | High-performance asynchronous Rust library for querying Minecraft server status (Java & Bedrock) |
| homepage | |
| repository | https://github.com/NameOfShadow/rust-mc-status |
| max_upload_size | |
| id | 1803991 |
| size | 177,668 |
A high-performance, asynchronous Rust library for querying the status of both Minecraft Java Edition and Bedrock Edition servers.
25565) and Bedrock Edition (19132) serversserde), including version info, player counts, MOTD, map, gamemode, plugins, mods and morethiserrorAdd this to your Cargo.toml:
[dependencies]
rust-mc-status = "2.0.0"
tokio = { version = "*", features = ["full"] }
use rust_mc_status::{McClient, ServerEdition};
use std::time::Duration;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = McClient::new()
.with_timeout(Duration::from_secs(5))
.with_max_parallel(10);
// Ping a Java server (automatically uses SRV lookup if port not specified)
let status = client.ping("mc.hypixel.net", ServerEdition::Java).await?;
println!("Server is online: {}", status.online);
println!("Latency: {:.2} ms", status.latency);
if let Some((online, max)) = status.players() {
println!("Players: {}/{}", online, max);
}
Ok(())
}
use rust_mc_status::{McClient, ServerEdition, ServerInfo};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = McClient::new();
let servers = vec![
ServerInfo {
address: "mc.hypixel.net".to_string(),
edition: ServerEdition::Java,
},
ServerInfo {
address: "geo.hivebedrock.network:19132".to_string(),
edition: ServerEdition::Bedrock,
},
];
let results = client.ping_many(&servers).await;
for (server, result) in results {
match result {
Ok(status) => println!("{}: Online ({}ms)", server.address, status.latency),
Err(e) => println!("{}: Error - {}", server.address, e),
}
}
Ok(())
}
When pinging Java servers without an explicit port, the library automatically performs an SRV DNS lookup for _minecraft._tcp.{hostname}. This mimics the behavior of the official Minecraft client.
Without explicit port (e.g., "mc.hypixel.net"):
_minecraft._tcp.mc.hypixel.net for SRV recordsWith explicit port (e.g., "mc.hypixel.net:25565"):
use rust_mc_status::{McClient, ServerEdition};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = McClient::new();
// This will perform SRV lookup for _minecraft._tcp.example.com
let status = client.ping("example.com", ServerEdition::Java).await?;
// This will skip SRV lookup and use port 25565 directly
let status = client.ping("example.com:25565", ServerEdition::Java).await?;
Ok(())
}
The library includes several example programs:
basic_usage.rs - Basic server status queries and error handlingadvanced_usage.rs - Advanced features including batch queries, plugins, mods, and faviconssrv_lookup_example.rs - Detailed demonstration of SRV record lookupperformance_test.rs - Performance benchmarking and speed testscache_management.rs - Cache management and statisticsRun examples with:
cargo run --example basic_usage
cargo run --example advanced_usage
cargo run --example srv_lookup_example
cargo run --example performance_test --release # Use --release for accurate performance measurements
cargo run --example cache_management
The main client for making server status queries.
let client = McClient::new()
.with_timeout(Duration::from_secs(5)) // Set request timeout
.with_max_parallel(10); // Set max concurrent queries
Methods:
new() - Create a new client with default settingswith_timeout(timeout) - Set the request timeoutwith_max_parallel(max) - Set the maximum number of parallel queriestimeout() - Get the current request timeoutmax_parallel() - Get the maximum number of parallel queriesping(address, edition) - Ping a single serverping_java(address) - Ping a Java Edition serverping_bedrock(address) - Ping a Bedrock Edition serverping_many(servers) - Ping multiple servers in parallelclear_dns_cache() - Clear DNS cacheclear_srv_cache() - Clear SRV record cacheclear_all_caches() - Clear all cachescache_stats() - Get cache statisticsresolve_dns_timed(host, port) - Resolve DNS and measure resolution time (useful for cache benchmarking)is_online(address, edition) - Quick check if server is online (faster than ping)The result of a successful ping.
pub struct ServerStatus {
pub online: bool, // Whether the server is online
pub ip: String, // Resolved IP address
pub port: u16, // Server port
pub hostname: String, // Original hostname
pub latency: f64, // Latency in milliseconds
pub dns: Option<DnsInfo>, // DNS information
pub data: ServerData, // Server-specific data
}
impl ServerStatus {
pub fn players(&self) -> Option<(i64, i64)>; // Get (online, max) players
}
Java Edition server information.
pub struct JavaStatus {
pub version: JavaVersion, // Version information
pub players: JavaPlayers, // Player information
pub description: String, // Server description (MOTD)
pub favicon: Option<String>, // Base64-encoded favicon
pub map: Option<String>, // Current map name
pub gamemode: Option<String>, // Game mode
pub software: Option<String>, // Server software
pub plugins: Option<Vec<JavaPlugin>>, // List of plugins
pub mods: Option<Vec<JavaMod>>, // List of mods
}
impl JavaStatus {
pub fn save_favicon(&self, filename: &str) -> Result<(), McError>;
}
Bedrock Edition server information.
pub struct BedrockStatus {
pub edition: String, // Minecraft edition
pub motd: String, // Message of the day
pub version: String, // Server version
pub online_players: String, // Online players count
pub max_players: String, // Maximum players
pub map: Option<String>, // Current map name
pub software: Option<String>, // Server software
pub game_mode: String, // Game mode
// ... and more
}
The library provides comprehensive error types:
use rust_mc_status::McError;
match client.ping("server.com", ServerEdition::Java).await {
Ok(status) => println!("Server is online!"),
Err(McError::Timeout) => println!("Request timed out"),
Err(McError::DnsError(msg)) => println!("DNS error: {}", msg),
Err(McError::ConnectionError(msg)) => println!("Connection error: {}", msg),
Err(e) => println!("Other error: {}", e),
}
See the documentation for a complete list of error types.
The library is optimized for performance:
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
Current version: 2.0.0
See CHANGELOG.md for detailed version history, new features, and migration guide.