get_knowledge_statistics
Analyze and retrieve detailed statistics from a knowledge graph to understand its structure and metadata, supporting informed decision-making and insights.
Instructions
Get statistics about the knowledge graph.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- sourcesage/mcp_server.py:439-502 (handler)The handler function implementing the get_knowledge_statistics tool. It computes statistics on the knowledge graph (entities by type/language, relations, patterns, style conventions) and returns a formatted string report. Registered via @self.mcp.tool() decorator.def get_knowledge_statistics() -> str: """Get statistics about the knowledge graph.""" # Count entities by type entity_types = {} for entity in self.knowledge.entities.values(): entity_types[entity.entity_type] = ( entity_types.get(entity.entity_type, 0) + 1 ) # Count entities by language languages = {} for entity in self.knowledge.entities.values(): if entity.language: languages[entity.language] = languages.get(entity.language, 0) + 1 # Count relations by type relation_types = {} for relation in self.knowledge.relations.values(): relation_types[relation.relation_type] = ( relation_types.get(relation.relation_type, 0) + 1 ) # Count patterns by language pattern_languages = {} for pattern in self.knowledge.patterns.values(): if pattern.language: pattern_languages[pattern.language] = ( pattern_languages.get(pattern.language, 0) + 1 ) # Format output output = "Knowledge Graph Statistics:\n\n" output += f"Total Entities: {len(self.knowledge.entities)}\n" output += f"Total Relations: {len(self.knowledge.relations)}\n" output += f"Total Patterns: {len(self.knowledge.patterns)}\n" output += ( f"Total Style Conventions: {len(self.knowledge.style_conventions)}\n\n" ) if entity_types: output += "Entities by Type:\n" for entity_type, count in entity_types.items(): output += f"- {entity_type}: {count}\n" output += "\n" if languages: output += "Entities by Language:\n" for language, count in languages.items(): output += f"- {language}: {count}\n" output += "\n" if relation_types: output += "Relations by Type:\n" for relation_type, count in relation_types.items(): output += f"- {relation_type}: {count}\n" output += "\n" if pattern_languages: output += "Patterns by Language:\n" for language, count in pattern_languages.items(): output += f"- {language}: {count}\n" return output