get_audit_logs_by_category
Retrieve audit logs filtered by specific categories like authentication or user management from the MCP JSON Database Server for monitoring and compliance purposes.
Instructions
Belirli kategorideki audit logları getirir (Admin/Manager)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| token | Yes | JWT token | |
| category | Yes | Log kategorisi (authentication, user_management, data_access, permission, system, security) | |
| limit | No | Gösterilecek log sayısı (varsayılan: 100) |
Implementation Reference
- src/index.js:849-898 (handler)The main MCP tool handler for 'get_audit_logs_by_category'. Performs token validation and permission check, validates the category against AUDIT_CATEGORIES, calls the core getAuditLogsByCategory function, logs the access, and returns the filtered audit logs.case 'get_audit_logs_by_category': { const { token, category, limit = 100 } = args; try { const user = checkPermissionWithToken(token, PERMISSIONS.AUDIT_READ); // Geçerli kategori kontrolü const validCategories = Object.values(AUDIT_CATEGORIES); if (!validCategories.includes(category)) { return { content: [{ type: 'text', text: JSON.stringify({ success: false, message: 'Geçersiz kategori', validCategories }) }] }; } const logs = await getAuditLogsByCategory(category, limit); // Kategori bazlı audit log erişimini logla await auditLogger.dataAccessed(user.userId, user.role, 'audit_logs_by_category', { category, limit }); return { content: [{ type: 'text', text: JSON.stringify({ success: true, data: logs, category, total: logs.length, requestedBy: { id: user.userId, role: user.role } }, null, 2) }] }; } catch (error) { return { content: [{ type: 'text', text: JSON.stringify({ success: false, message: error.message, requiredPermission: PERMISSIONS.AUDIT_READ }) }] }; }
- src/index.js:332-340 (schema)Input schema definition for the 'get_audit_logs_by_category' tool, specifying parameters: token (required), category (required), limit (optional). Defines types and descriptions for MCP validation.inputSchema: { type: 'object', properties: { token: { type: 'string', description: 'JWT token' }, category: { type: 'string', description: 'Log kategorisi (authentication, user_management, data_access, permission, system, security)' }, limit: { type: 'number', description: 'Gösterilecek log sayısı (varsayılan: 100)' } }, required: ['token', 'category'] }
- src/index.js:329-341 (registration)Tool registration in the ListTools response. Registers 'get_audit_logs_by_category' with name, description, and input schema for MCP discovery.{ name: 'get_audit_logs_by_category', description: 'Belirli kategorideki audit logları getirir (Admin/Manager)', inputSchema: { type: 'object', properties: { token: { type: 'string', description: 'JWT token' }, category: { type: 'string', description: 'Log kategorisi (authentication, user_management, data_access, permission, system, security)' }, limit: { type: 'number', description: 'Gösterilecek log sayısı (varsayılan: 100)' } }, required: ['token', 'category'] } },
- src/audit.js:159-170 (helper)Core helper function that reads audit logs from file, filters by category, limits results, reverses for chronological order, and handles errors. Called by the main handler.export async function getAuditLogsByCategory(category, limit = 100) { try { const auditData = await readAuditLogs(); return auditData.logs .filter(log => log.category === category) .slice(-limit) .reverse(); } catch (error) { console.error('Kategori audit log hatası:', error); return []; } }
- src/audit.js:24-31 (helper)Constant defining valid audit log categories, used for validation in the tool handler.export const AUDIT_CATEGORIES = { AUTH: 'authentication', USER_MGMT: 'user_management', DATA_ACCESS: 'data_access', PERMISSION: 'permission', SYSTEM: 'system', SECURITY: 'security' };