Rust Minecraft Server Status Library
A high-performance, asynchronous Rust library for querying the status of both Minecraft Java Edition and Bedrock Edition servers.
Features
- Dual Protocol Support: Ping both Minecraft Java Edition (
25565) and Bedrock Edition (19132) servers - Async/Await: Built on Tokio for non-blocking operations and high concurrency
- Batch Queries: Ping multiple servers in parallel with configurable concurrency limits
- DNS Caching: Automatically caches DNS lookups and SRV records to reduce latency for repeated queries
- SRV Record Support: Automatically resolves SRV records for Java servers (mimics Minecraft client behavior)
- Structured Data: Returns richly structured, serializable data (using
serde), including version info, player counts, MOTD, map, gamemode, plugins, mods and more - Favicon Handling: Easily retrieve and save server favicons (Java Edition only)
- Robust Error Handling: Comprehensive error types using
thiserror - Extended Information: Detailed data about plugins, mods, DNS and more
- High Performance: Optimized with connection pooling, DNS caching, and efficient memory usage
Installation
Add this to your Cargo.toml:
[]
= "2.0.0"
= { = "*", = ["full"] }
Quick Start
Basic Usage
use ;
use Duration;
async
Batch Queries
use ;
async
SRV Record Lookup
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.
How It Works
-
Without explicit port (e.g.,
"mc.hypixel.net"):- Queries
_minecraft._tcp.mc.hypixel.netfor SRV records - If found, uses the target host and port from the SRV record
- If not found, uses the default port (25565)
- Results are cached for 5 minutes
- Queries
-
With explicit port (e.g.,
"mc.hypixel.net:25565"):- Skips SRV lookup entirely
- Uses the specified host and port directly
Example
use ;
async
Examples
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 statistics
Run examples with:
API Documentation
McClient
The main client for making server status queries.
let client = new
.with_timeout // Set request timeout
.with_max_parallel; // 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 thanping)
ServerStatus
The result of a successful ping.
JavaStatus
Java Edition server information.
BedrockStatus
Bedrock Edition server information.
Error Handling
The library provides comprehensive error types:
use McError;
match client.ping.await
See the documentation for a complete list of error types.
Performance
The library is optimized for performance:
- DNS Caching: DNS lookups and SRV records are cached for 5 minutes
- Connection Pooling: Efficient connection management
- Parallel Processing: Batch queries run in parallel with configurable limits
- Memory Efficient: Pre-allocated buffers and efficient data structures
- Async I/O: Non-blocking I/O operations using Tokio
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Version
Current version: 2.0.0
See CHANGELOG.md for detailed version history, new features, and migration guide.