Skip to main content
Glama

get_agent_stats

Retrieve CPU, memory, and disk usage statistics for a specified Wazuh agent to monitor its resource health.

Instructions

Get system statistics (CPU, memory, disk) for a specific Wazuh agent

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agent_idYesAgent identifier (e.g., '001')

Implementation Reference

  • The handler function for the 'get_agent_stats' tool. It accepts an agent_id, verifies the agent exists, calls client.getAgentStats(), and returns CPU, memory, and disk statistics.
      async ({ agent_id }) => {
        try {
          // Verify agent exists
          const agentResponse = await client.getAgent(agent_id);
          const agents = agentResponse.data.affected_items;
    
          if (agents.length === 0) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({ error: `Agent '${agent_id}' not found` }),
                },
              ],
              isError: true,
            };
          }
    
          const agent = agents[0];
          const statsResponse = await client.getAgentStats(agent_id);
          const stats = statsResponse.data.affected_items[0] ?? {};
    
          const result = {
            agent_id: agent.id,
            agent_name: agent.name,
            cpu: stats.cpu,
            memory: stats.memory,
            disk: stats.disk,
          };
    
          return {
            content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify({
                  error: error instanceof Error ? error.message : String(error),
                }),
              },
            ],
            isError: true,
          };
        }
      }
    );
  • The schema definition for 'get_agent_stats' including the tool name, description, and Zod schema requiring an agent_id string.
    server.tool(
      "get_agent_stats",
      "Get system statistics (CPU, memory, disk) for a specific Wazuh agent",
      {
        agent_id: z
          .string()
          .describe("Agent identifier (e.g., '001')"),
      },
  • The registerAgentTools function registers the 'get_agent_stats' tool (along with 'list_agents' and 'get_agent') on the MCP server. Called from src/index.ts:39.
    export function registerAgentTools(
      server: McpServer,
      client: WazuhClient
    ): void {
      server.tool(
        "list_agents",
        "List all Wazuh agents with optional status filtering",
        {
          status: z
            .enum(["active", "disconnected", "never_connected", "pending"])
            .optional()
            .describe(
              "Filter by agent status: active, disconnected, never_connected, or pending"
            ),
          limit: z
            .number()
            .int()
            .min(1)
            .max(100)
            .default(10)
            .describe("Maximum number of agents to return (1-100)"),
          offset: z
            .number()
            .int()
            .min(0)
            .default(0)
            .describe("Pagination offset"),
          sort: z
            .string()
            .optional()
            .describe("Sort field with direction prefix (e.g., '-name', '+id')"),
        },
        async ({ status, limit, offset, sort }) => {
          try {
            const params: Record<string, string | number> = { limit, offset };
            if (status) params.status = status;
            if (sort) params.sort = sort;
    
            const response = await client.getAgents(params);
            const data = response.data;
    
            const result = {
              agents: data.affected_items.map((agent) => ({
                id: agent.id,
                name: agent.name,
                ip: agent.ip,
                status: agent.status,
                group: agent.group,
                os_name: agent.os?.name,
                os_version: agent.os?.version,
                os_platform: agent.os?.platform,
                version: agent.version,
                manager: agent.manager,
                node_name: agent.node_name,
                date_add: agent.dateAdd,
                last_keepalive: agent.lastKeepAlive,
              })),
              total: data.total_affected_items,
              limit,
              offset,
            };
    
            return {
              content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }],
            };
          } catch (error) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({
                    error: error instanceof Error ? error.message : String(error),
                  }),
                },
              ],
              isError: true,
            };
          }
        }
      );
    
      server.tool(
        "get_agent",
        "Get detailed information about a specific Wazuh agent by ID",
        {
          agent_id: z
            .string()
            .describe("Agent identifier (e.g., '001')"),
        },
        async ({ agent_id }) => {
          try {
            const response = await client.getAgent(agent_id);
            const agents = response.data.affected_items;
    
            if (agents.length === 0) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: JSON.stringify({ error: `Agent '${agent_id}' not found` }),
                  },
                ],
                isError: true,
              };
            }
    
            const agent = agents[0];
            const result = {
              id: agent.id,
              name: agent.name,
              ip: agent.ip,
              status: agent.status,
              group: agent.group,
              os_name: agent.os?.name,
              os_version: agent.os?.version,
              os_platform: agent.os?.platform,
              version: agent.version,
              manager: agent.manager,
              node_name: agent.node_name,
              date_add: agent.dateAdd,
              last_keepalive: agent.lastKeepAlive,
              register_ip: agent.registerIP,
            };
    
            return {
              content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }],
            };
          } catch (error) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({
                    error: error instanceof Error ? error.message : String(error),
                  }),
                },
              ],
              isError: true,
            };
          }
        }
      );
    
      server.tool(
        "get_agent_stats",
        "Get system statistics (CPU, memory, disk) for a specific Wazuh agent",
        {
          agent_id: z
            .string()
            .describe("Agent identifier (e.g., '001')"),
        },
        async ({ agent_id }) => {
          try {
            // Verify agent exists
            const agentResponse = await client.getAgent(agent_id);
            const agents = agentResponse.data.affected_items;
    
            if (agents.length === 0) {
              return {
                content: [
                  {
                    type: "text" as const,
                    text: JSON.stringify({ error: `Agent '${agent_id}' not found` }),
                  },
                ],
                isError: true,
              };
            }
    
            const agent = agents[0];
            const statsResponse = await client.getAgentStats(agent_id);
            const stats = statsResponse.data.affected_items[0] ?? {};
    
            const result = {
              agent_id: agent.id,
              agent_name: agent.name,
              cpu: stats.cpu,
              memory: stats.memory,
              disk: stats.disk,
            };
    
            return {
              content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }],
            };
          } catch (error) {
            return {
              content: [
                {
                  type: "text" as const,
                  text: JSON.stringify({
                    error: error instanceof Error ? error.message : String(error),
                  }),
                },
              ],
              isError: true,
            };
          }
        }
      );
    }
  • The getAgentStats() method on WazuhClient that calls the Wazuh API endpoint GET /agents/{agentId}/stats/agent.
    async getAgentStats(
      agentId: string
    ): Promise<WazuhApiResponse<WazuhPaginatedData<WazuhAgentStats>>> {
      return this.get(`/agents/${agentId}/stats/agent`);
    }
  • The WazuhAgentStats TypeScript interface defining the shape of the stats data (cpu with usage_percent/load_average/cores, memory with total/used/free/percent, disk array with path/total/used/free/percent).
    export interface WazuhAgentStats {
      cpu?: {
        usage_percent?: number;
        load_average?: number[];
        cores?: number;
      };
      memory?: {
        total_bytes?: number;
        used_bytes?: number;
        free_bytes?: number;
        usage_percent?: number;
      };
      disk?: Array<{
        path?: string;
        total_bytes?: number;
        used_bytes?: number;
        free_bytes?: number;
        usage_percent?: number;
      }>;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It only states purpose but does not disclose behavioral traits like read-only nature, authentication requirements, or rate limits. Minimal behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

A single concise sentence that is front-loaded with the key information. No wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The tool has no output schema, and the description does not hint at the output structure or fields. For a simple stats tool, it is adequate but could provide more context on what the returned statistics look like.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with a single parameter 'agent_id' described as 'Agent identifier (e.g., '001')'. The description adds no extra meaning beyond the schema, so baseline 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Get', the resource 'system statistics (CPU, memory, disk)', and the scope 'for a specific Wazuh agent'. This distinguishes it well from sibling tools like get_agent (general info) or get_agent_os (OS specific).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies use when needing stats for a specific agent but does not provide explicit when-to-use or alternatives. With many sibling get_agent_* tools, no guidance on selection is given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/solomonneas/wazuh-mcp'

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