get_relationship_stats
Analyze Enhanced Index relationships to view total counts by type, identify most connected elements, and assess index health metrics.
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
- Executes the tool logic: retrieves relationship stats from EnhancedIndexManager, formats a detailed text response with index metadata, relationship counts, and top verb triggers, handles errors and security logging.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:134-144 (registration)Registers the 'get_relationship_stats' tool with the MCP server, defining its name, description, empty input schema, and handler that delegates to the server's getRelationshipStats method.{ 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() }
- Defines the input schema for the tool (empty object, no parameters required) and metadata.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: {}, }, },
- Computes raw relationship statistics (counts by type, totals) by iterating over all elements in the EnhancedIndex; called by EnhancedIndexManager.getRelationshipStats().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; }