Merge pull request #227 from jonathanhefner/system-monitor-refresh-stats-tool
Add missing `refresh-stats` tool to `system-monitor-server`
This commit is contained in:
commit
6d2d4b22b6
2 changed files with 44 additions and 20 deletions
|
|
@ -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,
|
||||
|
|
|
|||
1
package-lock.json
generated
1
package-lock.json
generated
|
|
@ -5590,6 +5590,7 @@
|
|||
"version": "4.53.3",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/estree": "1.0.8"
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue