# Clone repository and run install script
git clone https://github.com/DarkPhilosophy/mcp-system-monitor.git
cd mcp-system-monitor
chmod +x install.sh
sudo ./install.sh # Linux
{
"mcp": {
"mcp-system-monitor": {
"type": "remote",
"url": "http://localhost:57996/",
"enabled": true
}
}
}
A Model Context Protocol (MCP) server implementation designed for AI agents to monitor and interact with Linux servers (Ubuntu, CentOS, RedHat, etc.). This server provides comprehensive system information including CPU, memory, disk, network, and process data through both MCP protocol and HTTP REST API, enabling AI agents to perform remote system monitoring and management tasks.
This project was developed and integrated using Claude Code Max, an advanced AI-powered development platform. The entire codebase, architecture design, testing, and documentation were created with Claude Code Max's assistance, making it a comprehensive AI-assisted development project.
Maintainer: DarkPhilosophy @DarkPhilosophy
Repository: https://github.com/DarkPhilosophy/mcp-system-monitor
Original Project by: Thinh Nguyen
Original Repository: https://github.com/hungtrungthinh/mcp-system-monitor
id field)tools/call responses to wrap results in proper MCP content format { content: [{ type: "text", text: "..." }] }┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ HTTP Client │ │ MCP Client │ │ Other Tools │
└─────────┬───────┘ └─────────┬───────┘ └─────────┬───────┘
│ │ │
└──────────────────────┼──────────────────────┘
│
┌─────────────▼─────────────┐
│ HTTP Server │
│ (Port 57996) │
│ (Axum Framework) │
└─────────────┬─────────────┘
│
┌─────────────▼─────────────┐
│ MCP Server │
│ (JSON-RPC Handler) │
│ (Protocol Implementation)│
└─────────────┬─────────────┘
│
┌─────────────▼─────────────┐
│ System Monitor │
│ (Core Monitoring Logic) │
│ (sysinfo integration) │
└─────────────┬─────────────┘
│
┌─────────────▼─────────────┐
│ Linux System Layer │
│ (procfs, sysfs, commands)│
│ (CPU, Memory, Disk, etc.)│
└───────────────────────────┘
git clone https://github.com/hungtrungthinh/mcp-system-monitor.git
cd mcp-system-monitor
# Development build
cargo build
# Production build
cargo build --release
# Development mode
cargo run
# Production mode
cargo run --release
The server will start on port 8080 by default.
# Clone repository and run install script
git clone https://github.com/DarkPhilosophy/mcp-system-monitor.git
cd mcp-system-monitor
chmod +x install.sh
sudo ./install.sh # Linux
# or
./install.sh # macOS
The script will:
# Clone and build
git clone https://github.com/DarkPhilosophy/mcp-system-monitor.git
cd mcp-system-monitor
cargo build --release
# Run the server
cargo run --release
# Health check
curl http://localhost:57996/health
# Get system information
curl http://localhost:57996/api/system/info
# Get CPU information
curl http://localhost:57996/api/system/cpu
# In another terminal
cargo run --example client
sudo ./install.sh # Automated installation
Edit ~/.config/opencode/opencode.json and add to the mcp section:
{
"mcp": {
"mcp-system-monitor": {
"type": "remote",
"url": "http://localhost:57996/",
"enabled": true
}
}
}
Full example ~/.config/opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"model": "mistral/devstral-medium-latest",
"mcp": {
"mcp-system-monitor": {
"type": "remote",
"url": "http://localhost:57996/",
"enabled": true
}
}
}
If you prefer stdio transport instead of HTTP:
{
"mcp": {
"mcp-system-monitor": {
"type": "local",
"command": [
"/opt/mcp-system-monitor/target/release/mcp-system-monitor",
"--stdio"
],
"enabled": true
}
}
}
Once configured, you can query system information directly from OpenCode:
User: What's my current CPU usage?
OpenCode will call: tools/call with method "get_cpu_info"
Response: CPU usage percentage and details
All MCP methods are available as tools:
initialize - Initialize MCP sessiontools/list - List available monitoring toolstools/call - Call specific monitoring tool with parameters:get_system_info - Get system informationget_cpu_info - Get CPU informationget_memory_info - Get memory informationget_disk_info - Get disk informationget_network_info - Get network informationget_processes - Get all processesget_process_by_pid - Get specific processget_system_metrics - Get complete system metricsOpenCode: "Show me the top CPU consuming processes"
→ Calls: tools/call with "get_processes"
→ Returns: Process list sorted by CPU usage
→ OpenCode analyzes and presents results
Connection refused error:
# Ensure service is running
sudo systemctl status mcp-system-monitor # Linux
# or
launchctl list | grep mcp-system-monitor # macOS
# Check if service is listening on port 57996
curl http://localhost:57996/health
Permission denied for --stdio mode:
# Ensure binary has correct permissions
chmod +x /opt/mcp-system-monitor/target/release/mcp-system-monitor
OpenCode can't find the MCP server:
# Verify opencode.json syntax
cat ~/.config/opencode/opencode.json | python3 -m json.tool
# Test MCP connection manually
curl -X POST http://localhost:57996 \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":"1","method":"tools/list","params":{}}'
http://localhost:8080
Currently, no authentication is required. For production use, implement appropriate authentication mechanisms.
All API responses are in JSON format with the following structure:
{
"jsonrpc": "2.0",
"id": "request-id",
"result": { ... },
"error": null
}
GET /healthHealth check endpoint.
Response:
{
"status": "healthy",
"service": "MCP System Monitor",
"timestamp": "2024-01-01T00:00:00Z"
}
GET /api/system/infoGet comprehensive system information.
Response:
{
"hostname": "server.example.com",
"os_name": "Ubuntu",
"os_version": "20.04.3 LTS",
"kernel_version": "5.4.0-74-generic",
"uptime": 86400,
"boot_time": "2024-01-01T00:00:00Z"
}
GET /api/system/cpuGet CPU information and usage statistics.
Response:
{
"name": "Intel(R) Core(TM) i7-8700K",
"brand": "GenuineIntel",
"frequency": 3600,
"cores": 6,
"usage_percent": 45.2,
"temperature": 65.5
}
GET /api/system/memoryGet memory information including RAM and swap usage.
Response:
{
"total": 16777216000,
"used": 8388608000,
"free": 8388608000,
"available": 12582912000,
"swap_total": 2147483648,
"swap_used": 0,
"swap_free": 2147483648,
"usage_percent": 50.0,
"swap_usage_percent": 0.0
}
GET /api/system/disksGet disk information for all mounted filesystems.
Response:
[
{
"name": "/dev/sda1",
"mount_point": "/",
"file_system": "ext4",
"total_space": 107374182400,
"used_space": 53687091200,
"free_space": 53687091200,
"usage_percent": 50.0
}
]
GET /api/system/networksGet network interface information and statistics.
Response:
[
{
"interface": "eth0",
"ip_address": "192.168.1.100",
"mac_address": "00:11:22:33:44:55",
"bytes_received": 1073741824,
"bytes_transmitted": 536870912,
"packets_received": 1000000,
"packets_transmitted": 500000,
"errors_received": 0,
"errors_transmitted": 0
}
]
GET /api/system/processesGet information about all running processes.
Response:
[
{
"pid": 1,
"name": "systemd",
"command": "/sbin/init",
"cpu_usage": 0.1,
"memory_usage": 1048576,
"memory_usage_percent": 0.01,
"status": "S",
"start_time": "2024-01-01T00:00:00Z",
"user": "root",
"priority": 0
}
]
GET /api/system/processes/{pid}Get information about a specific process by PID.
Parameters:
pid (path): Process IDResponse:
{
"pid": 1234,
"name": "nginx",
"command": "nginx: master process",
"cpu_usage": 0.5,
"memory_usage": 2097152,
"memory_usage_percent": 0.02,
"status": "S",
"start_time": "2024-01-01T00:00:00Z",
"user": "www-data",
"priority": 0
}
GET /api/system/metricsGet complete system metrics snapshot.
Response:
{
"timestamp": "2024-01-01T00:00:00Z",
"system_info": { ... },
"cpu_info": { ... },
"memory_info": { ... },
"disks": [ ... ],
"networks": [ ... ],
"processes": [ ... ]
}
POST /api/monitoring/startStart continuous monitoring.
Response:
{
"started": true,
"message": "Monitoring started successfully"
}
POST /api/monitoring/stopStop continuous monitoring.
Response:
{
"stopped": true,
"message": "Monitoring stopped successfully"
}
GET /api/monitoring/statusGet monitoring status.
Response:
{
"monitoring_active": true,
"last_update": "2024-01-01T00:00:00Z",
"service_status": "running"
}
# Get system information
curl http://localhost:8080/api/system/info
# Get CPU usage and temperature
curl http://localhost:8080/api/system/cpu
# Get memory information
curl http://localhost:8080/api/system/memory
# Get disk usage
curl http://localhost:8080/api/system/disks
# Get network interfaces
curl http://localhost:8080/api/system/networks
# Get top processes by CPU usage
curl http://localhost:8080/api/system/processes
# Get specific process details
curl http://localhost:8080/api/system/processes/1234
# Get complete system metrics
curl http://localhost:8080/api/system/metrics
# Start continuous monitoring
curl -X POST http://localhost:8080/api/monitoring/start
# Stop monitoring
curl -X POST http://localhost:8080/api/monitoring/stop
import requests
base_url = "http://localhost:8080"
# Get system info
response = requests.get(f"{base_url}/api/system/info")
system_info = response.json()
# Get CPU info
response = requests.get(f"{base_url}/api/system/cpu")
cpu_info = response.json()
# Get processes
response = requests.get(f"{base_url}/api/system/processes")
processes = response.json()
const axios = require('axios');
const baseUrl = 'http://localhost:8080';
// Get system info
const systemInfo = await axios.get(`${baseUrl}/api/system/info`);
// Get CPU info
const cpuInfo = await axios.get(`${baseUrl}/api/system/cpu`);
// Get processes
const processes = await axios.get(`${baseUrl}/api/system/processes`);
The server implements the Model Context Protocol for system monitoring using JSON-RPC 2.0 with Streamable HTTP transport.
initialize - Initialize MCP session with protocol version negotiationtools/list - List all available monitoring toolstools/call - Call a specific monitoring toolinitialized - Signal initialization completeWhen calling tools/call, use these tool names:
get_system_info - Get system informationget_cpu_info - Get CPU informationget_memory_info - Get memory informationget_disk_info - Get disk informationget_network_info - Get network informationget_processes - Get all processesget_system_metrics - Get complete system metrics{
"jsonrpc": "2.0",
"id": 0,
"method": "initialize",
"params": {
"protocolVersion": "2025-06-18",
"clientInfo": {
"name": "opencode",
"version": "1.0"
},
"capabilities": {}
}
}
{
"jsonrpc": "2.0",
"id": 0,
"result": {
"protocolVersion": "2025-06-18",
"capabilities": {
"tools": {}
},
"serverInfo": {
"name": "mcp-system-monitor",
"version": "0.1.0"
}
}
}
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": null
}
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "get_system_info",
"arguments": {}
}
}
{
"jsonrpc": "2.0",
"id": 2,
"result": {
"content": [
{
"type": "text",
"text": "{\n \"hostname\": \"hp\",\n \"os_name\": \"Bazzite\",\n \"os_version\": \"43.20251222.0 (Silverblue)\",\n \"kernel_version\": \"6.17.7-ba22.fc43.x86_64\",\n \"uptime\": 172051,\n \"boot_time\": \"2025-12-23T11:29:47Z\"\n}"
}
]
}
}
{
"jsonrpc": "2.0",
"method": "initialized",
"params": {}
}
{
"jsonrpc": "2.0",
"id": "123",
"result": null,
"error": {
"code": -32601,
"message": "Method not found",
"data": null
}
}
{
"hostname": "string", // System hostname
"os_name": "string", // Operating system name
"os_version": "string", // Operating system version
"kernel_version": "string", // Kernel version
"uptime": "number", // System uptime in seconds
"boot_time": "datetime" // System boot time (ISO 8601)
}
{
"name": "string", // CPU model name
"brand": "string", // CPU brand information
"frequency": "number", // CPU frequency in MHz
"cores": "number", // Number of CPU cores
"usage_percent": "number", // CPU usage percentage (0.0-100.0)
"temperature": "number|null" // CPU temperature in Celsius
}
{
"total": "number", // Total physical memory in bytes
"used": "number", // Used physical memory in bytes
"free": "number", // Free physical memory in bytes
"available": "number", // Available physical memory in bytes
"swap_total": "number", // Total swap space in bytes
"swap_used": "number", // Used swap space in bytes
"swap_free": "number", // Free swap space in bytes
"usage_percent": "number", // Memory usage percentage (0.0-100.0)
"swap_usage_percent": "number" // Swap usage percentage (0.0-100.0)
}
{
"name": "string", // Device name
"mount_point": "string", // Mount point
"file_system": "string", // File system type
"total_space": "number", // Total disk space in bytes
"used_space": "number", // Used disk space in bytes
"free_space": "number", // Free disk space in bytes
"usage_percent": "number" // Disk usage percentage (0.0-100.0)
}
{
"interface": "string", // Network interface name
"ip_address": "string", // IP address
"mac_address": "string", // MAC address
"bytes_received": "number", // Total bytes received
"bytes_transmitted": "number", // Total bytes transmitted
"packets_received": "number", // Total packets received
"packets_transmitted": "number", // Total packets transmitted
"errors_received": "number", // Total receive errors
"errors_transmitted": "number" // Total transmit errors
}
{
"pid": "number", // Process ID
"name": "string", // Process name
"command": "string", // Full command line
"cpu_usage": "number", // CPU usage percentage
"memory_usage": "number", // Memory usage in bytes
"memory_usage_percent": "number", // Memory usage percentage
"status": "string", // Process status
"start_time": "datetime", // Process start time (ISO 8601)
"user": "string", // Process owner
"priority": "number" // Process priority
}
This project was entirely developed using Claude Code Max, an advanced AI-powered development platform. The development process included:
The integration with Claude Code Max demonstrates the capabilities of AI-assisted development in creating production-ready, enterprise-grade software solutions.
mcp-system-monitor/
├── src/
│ ├── main.rs # Application entry point
│ ├── lib.rs # Library exports and documentation
│ ├── server.rs # MCP protocol handler
│ ├── http_server.rs # HTTP REST API server
│ ├── types/ # Data structures and constants
│ │ ├── mod.rs # Module exports
│ │ ├── protocol.rs # MCP protocol types
│ │ ├── system.rs # System data structures
│ │ └── constants.rs # Protocol constants
│ └── system_monitor/ # System monitoring logic
│ ├── mod.rs # Module exports
│ ├── core.rs # Core monitoring functionality
│ ├── helpers.rs # Utility functions
│ └── linux.rs # Linux-specific implementations
├── examples/
│ └── client.rs # Example HTTP client
├── tests/
│ └── integration_test.rs # Integration tests
├── .vscode/ # VS Code configuration
├── Cargo.toml # Dependencies and build configuration
├── Cargo.lock # Dependency lock file
├── README.md # This file
├── LICENSE # MIT License
├── Dockerfile # Docker containerization
├── docker-compose.yml # Docker Compose configuration
├── deploy.sh # Deployment script
└── test_server.sh # Server testing script
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
git clone https://github.com/hungtrungthinh/mcp-system-monitor.git
cd mcp-system-monitor
# Install cargo-watch for development
cargo install cargo-watch
# Install cargo-audit for security
cargo install cargo-audit
# Run in development mode with auto-reload
cargo watch -x run
# Run tests
cargo test
# Run tests with output
cargo test -- --nocapture
# Check code quality
cargo clippy
# Check for security vulnerabilities
cargo audit
Add methods to src/system_monitor/core.rs:
impl SystemMonitor {
pub fn get_new_metric(&mut self) -> Result<NewMetricInfo> {
self.refresh();
self.linux_info.get_new_metric()
}
}
Add routes to src/http_server.rs:
.route("/api/system/new-metric", get(Self::get_new_metric))
Add handlers to src/server.rs:
METHOD_GET_NEW_METRIC => self.handle_get_new_metric(id).await,
Add method constants to src/types/constants.rs:
pub const METHOD_GET_NEW_METRIC: &str = "getNewMetric";
# Run all tests
cargo test
# Run specific test
cargo test test_name
# Run tests with output
cargo test -- --nocapture
# Run integration tests
cargo test --test integration_test
# Run with verbose output
cargo test --test integration_test -- --nocapture
# Run the example client
cargo run --example client
# Run clippy for code quality
cargo clippy
# Run clippy with all warnings
cargo clippy -- -W clippy::all
# Format code
cargo fmt
# Check formatting
cargo fmt -- --check
# Check for security vulnerabilities
cargo audit
# Update dependencies
cargo update
# Build for production
cargo build --release
# The binary will be in target/release/mcp-system-monitor
Create /etc/systemd/system/mcp-system-monitor.service:
[Unit]
Description=MCP System Monitor Server
After=network.target
[Service]
Type=simple
User=mcp-monitor
Group=mcp-monitor
WorkingDirectory=/opt/mcp-system-monitor
ExecStart=/opt/mcp-system-monitor/mcp-system-monitor
Restart=always
RestartSec=5
Environment=RUST_LOG=info
[Install]
WantedBy=multi-user.target
Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable mcp-system-monitor
sudo systemctl start mcp-system-monitor
sudo systemctl status mcp-system-monitor
# Build the image
docker build -t mcp-system-monitor .
# Run the container
docker run -d -p 8080:8080 --name mcp-monitor mcp-system-monitor
# Start with docker-compose
docker-compose up -d
# View logs
docker-compose logs -f
# Stop services
docker-compose down
Create /etc/nginx/sites-available/mcp-system-monitor:
server {
listen 80;
server_name your-domain.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Enable the site:
sudo ln -s /etc/nginx/sites-available/mcp-system-monitor /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
# Install certbot
sudo apt install certbot python3-certbot-nginx
# Get SSL certificate
sudo certbot --nginx -d your-domain.com
# Auto-renewal
sudo crontab -e
# Add: 0 12 * * * /usr/bin/certbot renew --quiet
Set environment variables:
export RUST_LOG=info
export RUST_BACKTRACE=1
Create /etc/logrotate.d/mcp-system-monitor:
/var/log/mcp-system-monitor.log {
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 644 mcp-monitor mcp-monitor
postrotate
systemctl reload mcp-system-monitor
endscript
}
# Allow only specific IPs
sudo ufw allow from 192.168.1.0/24 to any port 8080
# Or use specific IPs
sudo ufw allow from 10.0.0.5 to any port 8080
For production use, implement authentication:
// Add to http_server.rs
use tower_http::auth::RequireAuthorizationLayer;
let auth_layer = RequireAuthorizationLayer::bearer("your-secret-token");
The server uses standard JSON-RPC error codes:
-32600: Invalid Request - The JSON sent is not a valid Request object-32601: Method not found - The method does not exist / is not available-32602: Invalid params - Invalid method parameter(s)-32603: Internal error - Internal JSON-RPC error-32700: Parse error - Invalid JSON was received by the server-32001: Process not found - The specified process PID does not exist-32002: Monitoring already started - Continuous monitoring is already active-32003: Monitoring not started - Continuous monitoring is not active-32004: System command failed - A required system command failed to execute-32005: Permission denied - Insufficient permissions to access system information{
"jsonrpc": "2.0",
"id": "request-id",
"result": null,
"error": {
"code": -32001,
"message": "Process with PID 9999 not found",
"data": null
}
}
git clone https://github.com/your-username/mcp-system-monitor.git
cd mcp-system-monitor
git checkout -b feature/your-feature-name
# Make code changes
# Add tests
# Update documentation
cargo test
cargo clippy
cargo fmt -- --check
git add .
git commit -m "feat: add new feature description"
git push origin feature/your-feature-name
# Create PR on GitHub
Use conventional commit format:
type(scope): description
[optional body]
[optional footer]
Types:
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changesrefactor: Code refactoringtest: Test changeschore: Maintenance tasksThis project is licensed under the MIT License - see the LICENSE file for details.
This software is intended for legitimate system monitoring and management purposes only. Any unauthorized use, modification, or exploitation of this software for malicious purposes, including but not limited to unauthorized system access, data theft, or system disruption, is strictly prohibited and may violate applicable laws and regulations. Users are responsible for ensuring compliance with all applicable laws and regulations in their jurisdiction. The authors disclaim any liability for misuse of this software.
When reporting issues, please include:
import requests
import json
class SystemMonitorAgent:
def __init__(self, server_url):
self.server_url = server_url
def get_system_health(self):
response = requests.get(f"{self.server_url}/api/system/metrics")
metrics = response.json()
# AI analysis of system health
cpu_usage = metrics['cpu_info']['usage_percent']
memory_usage = metrics['memory_info']['usage_percent']
if cpu_usage > 80 or memory_usage > 90:
return "CRITICAL"
elif cpu_usage > 60 or memory_usage > 70:
return "WARNING"
else:
return "HEALTHY"
def recommend_actions(self, health_status):
if health_status == "CRITICAL":
return ["Restart high-CPU processes", "Increase memory", "Scale horizontally"]
elif health_status == "WARNING":
return ["Monitor closely", "Optimize resource usage"]
else:
return ["Continue monitoring"]
class SystemMonitorAgent {
constructor(serverUrl) {
this.serverUrl = serverUrl;
}
async analyzeSystemHealth() {
const response = await fetch(`${this.serverUrl}/api/system/metrics`);
const metrics = await response.json();
const analysis = {
cpuHealth: this.analyzeCPU(metrics.cpu_info),
memoryHealth: this.analyzeMemory(metrics.memory_info),
diskHealth: this.analyzeDisks(metrics.disks),
recommendations: []
};
return analysis;
}
analyzeCPU(cpuInfo) {
if (cpuInfo.usage_percent > 80) {
return { status: 'CRITICAL', message: 'High CPU usage detected' };
}
return { status: 'HEALTHY', message: 'CPU usage normal' };
}
}
Note: The project roadmap is not public at this time. Please contact the author for more information if needed.
Sign in to leave a comment.