import os from "node:os";
import path from "node:path";
import { exec } from "node:child_process";
import { promisify } from "node:util";
const execAsync = promisify(exec);
export const sysinfoTools = [
{
name: "get_system_info",
description: "Get basic information about the host system (OS, memory, arch)",
inputSchema: {
type: "object",
properties: {},
},
},
{
name: "get_current_time",
description: "Get the current localized time on the host system",
inputSchema: {
type: "object",
properties: {},
},
},
{
name: "get_disk_usage",
description: "Get disk space information for all drives",
inputSchema: {
type: "object",
properties: {},
},
},
{
name: "get_cpu_load",
description: "Get current CPU load and average information",
inputSchema: {
type: "object",
properties: {},
},
},
{
name: "get_network_interfaces",
description: "Get details about all network interfaces",
inputSchema: {
type: "object",
properties: {},
},
},
{
name: "get_user_paths",
description: "Get absolute paths to common user folders (Home, Documents, Downloads)",
inputSchema: {
type: "object",
properties: {},
},
},
];
export async function handleSysinfoTool(name: string, args: any) {
switch (name) {
case "get_system_info": {
const info = {
platform: os.platform(),
release: os.release(),
arch: os.arch(),
totalMemory: `${Math.round(os.totalmem() / 1024 / 1024 / 1024)} GB`,
freeMemory: `${Math.round(os.freemem() / 1024 / 1024 / 1024)} GB`,
uptime: `${Math.round(os.uptime() / 3600)} hours`,
cpus: os.cpus().length,
hostname: os.hostname(),
};
return {
content: [{ type: "text", text: JSON.stringify(info, null, 2) }],
};
}
case "get_current_time": {
const now = new Date();
const timeInfo = {
iso: now.toISOString(),
local: now.toLocaleString(),
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
};
return {
content: [{ type: "text", text: JSON.stringify(timeInfo, null, 2) }],
};
}
case "get_disk_usage": {
const { stdout } = await execAsync("wmic logicaldisk get size,freespace,caption");
return {
content: [{ type: "text", text: stdout.trim() }],
};
}
case "get_cpu_load": {
const load = os.loadavg();
const cpus = os.cpus();
const info = {
loadAverage: {
"1m": load[0],
"5m": load[1],
"15m": load[2],
},
cpuModel: cpus[0].model,
cpuSpeed: cpus[0].speed,
coreCount: cpus.length,
};
return {
content: [{ type: "text", text: JSON.stringify(info, null, 2) }],
};
}
case "get_network_interfaces": {
const interfaces = os.networkInterfaces();
return {
content: [{ type: "text", text: JSON.stringify(interfaces, null, 2) }],
};
}
case "get_user_paths": {
const home = os.homedir();
const paths = {
home,
documents: path.join(home, "Documents"),
downloads: path.join(home, "Downloads"),
desktop: path.join(home, "Desktop"),
};
return {
content: [{ type: "text", text: JSON.stringify(paths, null, 2) }],
};
}
default:
return null;
}
}