A modern Node.js library for interacting with Minecraft Java Edition servers. Query server status and execute RCON commands with ease.
- ✅ Server status checking (MOTD, players, version)
- 🔑 Secure RCON command execution
- 📢 Built-in
saycommand helper - ⏱️ Configurable timeouts (10s default)
- 🔍 Debug logging capabilities
- 🛡️ Comprehensive error handling
npm install mc-server-utilimport { getMinecraftServerStatus } from 'mc-server-util';
try {
const status = await getMinecraftServerStatus('mc.example.com');
console.log(`Server version: ${status.version.name}`);
console.log(`Players online: ${status.players.online}`);
} catch (error) {
console.error('Server offline:', error.message);
}import { sendRconCommand } from 'mc-server-util';
const response = await sendRconCommand(
'mc.example.com',
25575,
'secure-password',
'whitelist add PlayerName'
);
console.log('Command response:', response);import { sendRconSayCommand } from 'mc-server-util';
await sendRconSayCommand(
'mc.example.com',
'secure-password',
'Server maintenance in 5 minutes!'
);Returns: Promise<ServerStatus>
ServerStatus Object:
{
online: boolean,
version: {
name: string,
protocol: number
},
players: {
max: number,
online: number,
sample?: Player[],
nicknames?: string
},
description: string,
favicon?: string
}Returns: Promise<string>
Returns: Promise<string>
// Enable debug logging
await getMinecraftServerStatus('mc.example.com', 25565, true);
// Example debug output:
// Connected to server, sending handshake
// Handshake packet: 0f0000...
// Received data chunk: 0f0000...// Create custom timeout (in milliseconds)
const status = await getMinecraftServerStatus('mc.example.com', 25565, {
debug: false,
timeout: 15000
});Common error scenarios:
Connection timeout- Server not respondingRCON authentication failed- Incorrect passwordInvalid RCON packet- Protocol mismatch
Example error handling:
try {
await sendRconCommand('mc.example.com', 25575, 'wrong-password', 'help');
} catch (error) {
if (error.message.includes('authentication failed')) {
console.error('Invalid RCON credentials');
} else {
console.error('Connection error:', error.message);
}
}-
Never hardcode credentials
Use environment variables:import dotenv from 'dotenv'; dotenv.config(); sendRconCommand( process.env.MC_HOST, process.env.MC_RCON_PORT, process.env.MC_RCON_PASSWORD, 'save-all' );
-
Validate user input
Sanitize command inputs:const sanitizeInput = (input) => input.replace(/[^\w\s-]/g, ''); const safeCommand = sanitizeInput(userInput);
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/your-feature) - Commit changes with descriptive messages
- Push to your branch (
git push origin feature/your-feature) - Open a Pull Request
MIT © Alex Mashkovtsev
Protocol Reference
For low-level protocol details, see the Minecraft Protocol Specification.