dhis2_get_audit_summary
Retrieve summary statistics for audit logs and system usage from the DHIS2 MCP Server to monitor and analyze system activities effectively.
Instructions
Get summary statistics of audit log and system usage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:1423-1458 (handler)Handler for the 'dhis2_get_audit_summary' tool. Calls auditLogger.getAuditSummary(), logs the operation, and formats a comprehensive text summary including usage stats, session info, most used tools, and recent errors.case 'dhis2_get_audit_summary': const summary = auditLogger.getAuditSummary(); const permissionSummary = PermissionSystem.getPermissionSummary(userPermissions); auditLogger.log({ toolName: name, parameters: {}, outcome: 'success', dhis2Instance: dhis2Client?.baseURL, userId: currentUser?.username, executionTime: Date.now() - startTime }); return { content: [{ type: 'text', text: `📊 DHIS2 MCP Server Audit Summary 🔢 **Usage Statistics:** • Total Operations: ${summary.totalOperations} • Successful: ${summary.successCount} (${Math.round((summary.successCount / summary.totalOperations) * 100) || 0}%) • Errors: ${summary.errorCount} (${Math.round((summary.errorCount / summary.totalOperations) * 100) || 0}%) 👤 **Current Session:** • User: ${currentUser?.displayName || 'Unknown'} • Permission Level: ${permissionSummary.level} • Available Tools: ${PermissionSystem.filterToolsByPermissions(tools, userPermissions).length} of ${tools.length} • Connected to: ${dhis2Client?.baseURL || 'Not connected'} 🛠️ **Most Used Tools:** ${summary.mostUsedTools.slice(0, 5).map(tool => ` • ${tool.tool}: ${tool.count} times`).join('\n') || ' • No operations yet'} ${summary.recentErrors.length > 0 ? `⚠️ **Recent Errors:** ${summary.recentErrors.slice(0, 3).map(error => ` • ${error.toolName}: ${error.error}`).join('\n')}` : '✅ No recent errors'}` }] };
- src/audit-logger.ts:67-96 (helper)Core helper method that computes the audit summary: total operations, success/error counts, top 10 most used tools, and last 5 errors from the in-memory audit log.getAuditSummary(): { totalOperations: number; successCount: number; errorCount: number; mostUsedTools: Array<{ tool: string; count: number }>; recentErrors: AuditEntry[]; } { const toolUsage = new Map<string, number>(); this.entries.forEach(entry => { toolUsage.set(entry.toolName, (toolUsage.get(entry.toolName) || 0) + 1); }); const mostUsedTools = Array.from(toolUsage.entries()) .map(([tool, count]) => ({ tool, count })) .sort((a, b) => b.count - a.count) .slice(0, 10); const recentErrors = this.entries .filter(entry => entry.outcome === 'error') .slice(-5); return { totalOperations: this.entries.length, successCount: this.getSuccessCount(), errorCount: this.getErrorCount(), mostUsedTools, recentErrors }; }