Skip to main content
Glama

system_performance

Monitor and analyze macOS system performance, including CPU, memory, disk, and network usage. View current stats, historical data, or optimize resources for efficient operation.

Instructions

Monitor system performance and analyze resource usage

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesType of performance analysis
metricNoSpecific metric to analyze
timeRangeNoTime range for historical data (e.g., '1h', '24h', '7d')

Implementation Reference

  • The main handler function `performanceMonitor` that implements the core logic for the `system_performance` tool. It handles different actions: 'current' for current metrics, 'history' for historical data, 'processes' for top processes, and 'optimize' for optimization suggestions. Uses database for storage and caching.
    export async function performanceMonitor( params: SystemPerformanceParams ): Promise<PerformanceResult> { try { const db = initDatabase(); switch (params.action) { case "current": { const metrics = await getCurrentMetrics(); storeMetrics(db, metrics); if (!params.metric || params.metric === "all") { return { status: "success", data: metrics }; } // Return specific metric const filteredMetrics: SystemMetrics = { ...metrics, cpu: params.metric === "cpu" ? metrics.cpu : {} as any, memory: params.metric === "memory" ? metrics.memory : {} as any, disk: params.metric === "disk" ? metrics.disk : {} as any, network: params.metric === "network" ? metrics.network : {} as any, }; return { status: "success", data: filteredMetrics }; } case "history": { const timeRange = params.timeRange || "1h"; const historicalData = getHistoricalMetrics(db, timeRange); if (params.metric && params.metric !== "all") { // Filter historical data by metric const filtered = historicalData; return { status: "success", data: filtered }; } return { status: "success", data: historicalData }; } case "processes": { const cacheKey = createCacheKey("processes", { metric: params.metric }); const processes = await processListCache.get(cacheKey, async () => { const procs = await getTopProcesses(); if (params.metric && params.metric !== "all") { // Sort by specific metric return procs.sort((a, b) => { switch (params.metric) { case "cpu": return b.cpu - a.cpu; case "memory": return b.memory - a.memory; default: return 0; } }); } return procs; }); return { status: "success", data: processes }; } case "optimize": { const suggestions = await analyzeForOptimizations(); return { status: "success", data: suggestions }; } default: return { status: "error", error: "Invalid action" }; } } catch (error) { return { status: "error", error: error instanceof Error ? error.message : String(error), }; } }
  • src/index.ts:42-64 (registration)
    Tool registration entry for `system_performance` in the tools list provided to the MCP server, including name, description, and input schema definition.
    name: "system_performance", description: "Monitor system performance and analyze resource usage", inputSchema: { type: "object", properties: { action: { type: "string", enum: ["current", "history", "processes", "optimize"], description: "Type of performance analysis", }, timeRange: { type: "string", description: "Time range for historical data (e.g., '1h', '24h', '7d')", }, metric: { type: "string", enum: ["cpu", "memory", "disk", "network", "all"], description: "Specific metric to analyze", }, }, required: ["action"], }, },
  • Zod validation schema `SystemPerformanceSchema` used to parse and validate input parameters for the `system_performance` tool in the dispatch handler.
    const SystemPerformanceSchema = z.object({ action: z.enum(["current", "history", "processes", "optimize"]), timeRange: z.string().optional(), metric: z.enum(["cpu", "memory", "disk", "network", "all"]).optional(), });
  • TypeScript interface defining the input parameters `SystemPerformanceParams` used by the handler function.
    export interface SystemPerformanceParams { action: "current" | "history" | "processes" | "optimize"; timeRange?: string; metric?: "cpu" | "memory" | "disk" | "network" | "all"; }
  • Dispatch handler case in the main server request handler that parses arguments using the schema and calls the `performanceMonitor` implementation.
    case "system_performance": { const params = SystemPerformanceSchema.parse(args); const result = await performanceMonitor(params); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tornikegomareli/macos-tools-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server