get_relationship_stats
Analyze Enhanced Index relationship statistics to identify total counts by type, most connected elements, and index health metrics for monitoring and optimization.
Instructions
Get statistics about the Enhanced Index relationships, including total counts by type, most connected elements, and index health metrics.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The primary handler for the get_relationship_stats tool. It retrieves relationship statistics from the EnhancedIndexManager, augments with index metadata and top verbs, formats a rich text response, and handles errors.async getRelationshipStats() { try { // Get the index with error handling await this.enhancedIndexManager.getIndex().catch(async (error) => { logger.error('Failed to get Enhanced Index, attempting rebuild', error); return this.enhancedIndexManager.getIndex({ forceRebuild: true }); }); // FIX: DMCP-SEC-006 - Add security audit logging SecurityMonitor.logSecurityEvent({ type: 'ELEMENT_CREATED', severity: 'LOW', source: 'EnhancedIndexHandler.getRelationshipStats', details: 'Enhanced Index statistics retrieved', additionalData: {} }); // Get stats const stats = await this.enhancedIndexManager.getRelationshipStats(); // Get the index for additional info const index = await this.enhancedIndexManager.getIndex(); // Format results let text = `${this.personaIndicator}📊 **Enhanced Index Statistics**\n\n`; text += `**Index Metadata:**\n`; text += `• Version: ${index.metadata.version}\n`; text += `• Last Updated: ${new Date(index.metadata.last_updated).toLocaleString()}\n`; text += `• Total Elements: ${index.metadata.total_elements}\n\n`; text += `**Relationship Statistics:**\n`; for (const [type, count] of Object.entries(stats)) { text += `• ${type}: ${count}\n`; } // Count verb triggers const verbCount = Object.keys(index.action_triggers || {}).length; text += `\n**Verb Triggers:** ${verbCount} verbs mapped\n`; // Show top verbs if any if (verbCount > 0) { const topVerbs = Object.entries(index.action_triggers) .sort((a, b) => b[1].length - a[1].length) .slice(0, 5); text += `**Top Action Verbs:**\n`; for (const [verb, elements] of topVerbs) { text += `• ${verb}: ${elements.length} elements\n`; } } return { content: [{ type: "text", text }] }; } catch (error: any) { ErrorHandler.logError('EnhancedIndexHandler.getRelationshipStats', error); return { content: [{ type: "text", text: `${this.personaIndicator}❌ Failed to get stats: ${SecureErrorHandler.sanitizeError(error).message}` }] }; } }
- src/server/tools/EnhancedIndexTools.ts:135-144 (registration)Tool registration defining the name, description, empty input schema, and handler delegation to server.getRelationshipStats().tool: { name: "get_relationship_stats", description: "Get statistics about the Enhanced Index relationships, including total counts by type, most connected elements, and index health metrics.", inputSchema: { type: "object", properties: {}, }, }, handler: () => server.getRelationshipStats() }
- Input schema for the tool: an empty object (no parameters required).inputSchema: { type: "object", properties: {}, },
- Core utility function that computes relationship statistics by iterating over all elements and counting relationships by type and totals. Called indirectly via EnhancedIndexManager.public getRelationshipStats(index: EnhancedIndex): Record<string, number> { const stats: Record<string, number> = { totalRelationships: 0, elementsWithRelationships: 0 }; // Count by relationship type for (const relType of Object.keys(RELATIONSHIP_TYPES)) { stats[relType] = 0; } for (const elements of Object.values(index.elements)) { for (const element of Object.values(elements)) { if (element.relationships) { stats.elementsWithRelationships++; for (const [relType, relations] of Object.entries(element.relationships)) { const count = relations.length; stats.totalRelationships += count; stats[relType] = (stats[relType] || 0) + count; } } } } return stats; }