dhis2_get_audit_log
Retrieve audit logs of all MCP operations performed on the DHIS2 MCP Server. Specify the number of recent entries to monitor and analyze system activities effectively.
Instructions
Retrieve audit log of all MCP operations performed
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of recent entries to return (default: 50, max: 1000) |
Implementation Reference
- src/index.ts:1394-1421 (handler)Handler for 'dhis2_get_audit_log' tool: destructures limit parameter (default 50), calls auditLogger.getAuditTrail(), logs the operation, formats audit entries into a readable text response with emojis and details.case 'dhis2_get_audit_log': const { limit = 50 } = args as { limit?: number }; const auditEntries = auditLogger.getAuditTrail(Math.min(limit, 1000)); // Log successful audit retrieval auditLogger.log({ toolName: name, parameters: { limit }, outcome: 'success', dhis2Instance: dhis2Client?.baseURL, userId: currentUser?.username, executionTime: Date.now() - startTime }); return { content: [{ type: 'text', text: `📋 Audit Log (${auditEntries.length} entries)\n\n` + auditEntries.map(entry => `🕐 ${entry.timestamp}\n` + `🛠️ Tool: ${entry.toolName}\n` + `👤 User: ${entry.userId || 'unknown'}\n` + `${entry.outcome === 'success' ? '✅' : '❌'} Result: ${entry.outcome}${entry.error ? ` - ${entry.error}` : ''}\n` + `⏱️ Duration: ${entry.executionTime || 0}ms\n` + `📍 Instance: ${entry.dhis2Instance || 'N/A'}\n` ).join('\n') }] };
- src/audit-logger.ts:54-57 (helper)Core helper method getAuditTrail() from AuditLogger class that provides the recent audit entries used by the tool handler.getAuditTrail(limit?: number): AuditEntry[] { const entries = limit ? this.entries.slice(-limit) : this.entries; return [...entries]; // Return copy to prevent mutation }
- src/audit-logger.ts:110-112 (helper)Global singleton instance 'auditLogger' exported and used throughout the codebase, including by the tool handler.} // Global audit logger instance