get_agent_os
Retrieve operating system information collected from a Wazuh agent using its agent ID.
Instructions
Get operating system information collected from a Wazuh agent
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agent_id | Yes | Agent identifier (e.g., '001') |
Implementation Reference
- src/tools/syscollector.ts:17-43 (handler)The handler function that executes the 'get_agent_os' tool logic. It receives the agent_id, calls client.getAgentOs(agent_id), extracts affected_items, and returns formatted JSON response with error handling.
async ({ agent_id }) => { try { const response = await client.getAgentOs(agent_id); const items = response.data.affected_items; const result = { agent_id, os: items[0] ?? null, }; 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/syscollector.ts:12-16 (schema)Input schema for the 'get_agent_os' tool. It defines a single required parameter 'agent_id' as a string with description 'Agent identifier (e.g., '001')'.
{ agent_id: z .string() .describe("Agent identifier (e.g., '001')"), }, - src/tools/syscollector.ts:9-44 (registration)The tool is registered via server.tool('get_agent_os', ...) inside the registerSyscollectorTools function. The registration includes the tool name, description, input schema (agent_id), and the handler callback.
server.tool( "get_agent_os", "Get operating system information collected from a Wazuh agent", { agent_id: z .string() .describe("Agent identifier (e.g., '001')"), }, async ({ agent_id }) => { try { const response = await client.getAgentOs(agent_id); const items = response.data.affected_items; const result = { agent_id, os: items[0] ?? null, }; 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/index.ts:45-45 (registration)The registerSyscollectorTools function is invoked from the main index.ts file, wiring up the syscollector tools (including get_agent_os) to the MCP server.
registerSyscollectorTools(server, client); - src/client.ts:304-308 (helper)The WazuhClient.getAgentOs method is the helper that makes the actual API call to the Wazuh /syscollector/{agent_id}/os endpoint and returns parsed response data.
async getAgentOs( agentId: string ): Promise<WazuhApiResponse<WazuhPaginatedData<WazuhOsInfo>>> { return this.get(`/syscollector/${agentId}/os`); }