get_server_status
Retrieve CPU, memory, and uptime status of local or remote servers via SSH for real-time server monitoring and performance analysis.
Instructions
获取服务器的CPU、内存和运行状态
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | No | 远程服务器地址或SSH配置中的主机名 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"host": {
"description": "远程服务器地址或SSH配置中的主机名",
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- index.ts:109-130 (registration)Registers the get_server_status tool with MCP server, including description, input schema (optional host), and inline handler for local server status.server.tool( "get_server_status", "获取服务器的CPU、内存和运行状态", { host: z.string().optional().describe("远程服务器地址或SSH配置中的主机名") }, async () => { return { content: [{ type: 'text', text: JSON.stringify({ cpuCount: os.cpus().length, cpuRel: getLocalCpuUsage(), memory: os.freemem(), memoryUsage: ((1 - os.freemem() / os.totalmem()) * 100).toFixed(2) + '', uptime: os.uptime(), type: 'local' }, null, 2) }] }; } );
- index.ts:115-129 (handler)Handler function that computes local server status: CPU count and relative usage (using getLocalCpuUsage helper), free memory, memory usage percentage, uptime, and type 'local', formatted as JSON in text content.async () => { return { content: [{ type: 'text', text: JSON.stringify({ cpuCount: os.cpus().length, cpuRel: getLocalCpuUsage(), memory: os.freemem(), memoryUsage: ((1 - os.freemem() / os.totalmem()) * 100).toFixed(2) + '', uptime: os.uptime(), type: 'local' }, null, 2) }] }; }
- index.ts:112-114 (schema)Input schema for the tool: optional 'host' string parameter described as remote server address or SSH config hostname.{ host: z.string().optional().describe("远程服务器地址或SSH配置中的主机名") },
- index.ts:86-98 (helper)Helper function to calculate local CPU usage percentage (idle time averaged across all CPUs). Called by the handler.export function getLocalCpuUsage() { const cpus = os.cpus(); let totalIdle = 0, totalTick = 0; cpus.forEach((cpu) => { for (let type in cpu.times) { totalTick += cpu.times[type as keyof typeof cpu.times]; } totalIdle += cpu.times.idle; }); const idle = totalIdle / cpus.length; const total = totalTick / cpus.length; return 1 - idle / total; }