Skip to main content
Glama

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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sarathsp06/sourcesage'

If you have feedback or need assistance with the MCP directory API, please join our Discord server