Add missing refresh-stats tool to system-monitor-server

The `mcp-app.ts` UI was calling a `refresh-stats` tool that didn't exist
on the server, causing the example to fail. This was introduced in
PR #131 when the squash merge included the client-side change but lost
the server-side tool registration.

Fixes #200

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Jonathan Hefner 2026-01-09 15:41:04 -06:00
commit 996f028e7f

View file

@ -107,6 +107,30 @@ async function getMemoryStats(): Promise<MemoryStats> {
};
}
async function getStats(): Promise<SystemStats> {
const cpuSnapshots = getCpuSnapshots();
const cpuInfo = os.cpus()[0];
const memory = await getMemoryStats();
const uptimeSeconds = os.uptime();
return {
cpu: {
cores: cpuSnapshots,
model: cpuInfo?.model ?? "Unknown",
count: os.cpus().length,
},
memory,
system: {
hostname: os.hostname(),
platform: `${os.platform()} ${os.arch()}`,
arch: os.arch(),
uptime: uptimeSeconds,
uptimeFormatted: formatUptime(uptimeSeconds),
},
timestamp: new Date().toISOString(),
};
}
export function createServer(): McpServer {
const server = new McpServer({
name: "System Monitor Server",
@ -128,28 +152,27 @@ export function createServer(): McpServer {
_meta: { [RESOURCE_URI_META_KEY]: resourceUri },
},
async (): Promise<CallToolResult> => {
const cpuSnapshots = getCpuSnapshots();
const cpuInfo = os.cpus()[0];
const memory = await getMemoryStats();
const uptimeSeconds = os.uptime();
const stats: SystemStats = {
cpu: {
cores: cpuSnapshots,
model: cpuInfo?.model ?? "Unknown",
count: os.cpus().length,
},
memory,
system: {
hostname: os.hostname(),
platform: `${os.platform()} ${os.arch()}`,
arch: os.arch(),
uptime: uptimeSeconds,
uptimeFormatted: formatUptime(uptimeSeconds),
},
timestamp: new Date().toISOString(),
const stats = await getStats();
return {
content: [{ type: "text", text: JSON.stringify(stats) }],
structuredContent: stats,
};
},
);
// App-only tool for polling - used by the UI for periodic refresh
registerAppTool(
server,
"refresh-stats",
{
title: "Refresh Stats",
description: "Refresh system statistics (app-only, for polling)",
inputSchema: {},
outputSchema: SystemStatsSchema.shape,
_meta: { ui: { visibility: ["app"] } },
},
async (): Promise<CallToolResult> => {
const stats = await getStats();
return {
content: [{ type: "text", text: JSON.stringify(stats) }],
structuredContent: stats,