get_group_agents
Retrieve all agents assigned to a specified Wazuh group. Filter by group ID, set pagination, and control result limit.
Instructions
List agents belonging to a specific Wazuh group
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| group_id | Yes | Group name/identifier (e.g., 'default', 'linux-servers') | |
| limit | No | Maximum number of agents to return (1-100) | |
| offset | No | Pagination offset |
Implementation Reference
- src/tools/groups.ts:63-123 (handler)The `get_group_agents` tool handler. Registers an MCP tool that accepts group_id (string), limit (number, default 25, max 100), and offset (number, default 0). Calls client.getGroupAgents() and returns a JSON response with agent details (id, name, ip, status, os_name, os_platform, version, last_keepalive), total count, limit, and offset. Includes error handling.
server.tool( "get_group_agents", "List agents belonging to a specific Wazuh group", { group_id: z .string() .describe("Group name/identifier (e.g., 'default', 'linux-servers')"), limit: z .number() .int() .min(1) .max(100) .default(25) .describe("Maximum number of agents to return (1-100)"), offset: z .number() .int() .min(0) .default(0) .describe("Pagination offset"), }, async ({ group_id, limit, offset }) => { try { const response = await client.getGroupAgents(group_id, { limit, offset }); const data = response.data; const result = { group_id, agents: data.affected_items.map((agent) => ({ id: agent.id, name: agent.name, ip: agent.ip, status: agent.status, os_name: agent.os?.name, os_platform: agent.os?.platform, version: agent.version, 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, }; } } ); - src/tools/groups.ts:66-83 (schema)Input schema for the get_group_agents tool using Zod validation: group_id (string), limit (integer, 1-100, default 25), offset (integer, min 0, default 0).
{ group_id: z .string() .describe("Group name/identifier (e.g., 'default', 'linux-servers')"), limit: z .number() .int() .min(1) .max(100) .default(25) .describe("Maximum number of agents to return (1-100)"), offset: z .number() .int() .min(0) .default(0) .describe("Pagination offset"), }, - src/index.ts:49-49 (registration)Registration call: registerGroupTools(server, client) is invoked in the main server setup, which registers the get_group_agents tool on the MCP server.
registerGroupTools(server, client); - src/client.ts:384-389 (helper)Client helper method getGroupAgents() that makes a GET request to /groups/{groupId}/agents on the Wazuh API, returning a paginated list of WazuhAgent objects.
async getGroupAgents( groupId: string, params: Record<string, string | number> = {} ): Promise<WazuhApiResponse<WazuhPaginatedData<WazuhAgent>>> { return this.get(`/groups/${groupId}/agents`, params); }