Skip to main content
Glama

get_document_stats

Analyze document structure and extract statistics from loaded documents to understand content organization and key metrics.

Instructions

Get statistics about a loaded document.

Args:
    doc_id: Document identifier

Returns:
    Document statistics and structure info

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doc_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'get_document_stats' tool, decorated with @mcp.tool() for registration. It retrieves document statistics including node counts, headings, paragraphs, token counts, and heading level breakdown using the DocumentNavigator.
    @mcp.tool()
    def get_document_stats(doc_id: str) -> str:
        """Get statistics about a loaded document.
    
        Args:
            doc_id: Document identifier
    
        Returns:
            Document statistics and structure info
        """
        document = navigator.get_document(doc_id)
        if not document:
            return f"Document '{doc_id}' not found"
    
        headings = []
        paragraphs = []
        if document.index:
            headings = [node for node in document.index.values() if node.type == "heading"]
            paragraphs = [
                node for node in document.index.values() if node.type == "paragraph"
            ]
    
        stats = f"Document: {doc_id}\n"
        stats += f"Total nodes: {len(document.index) if document.index else 0}\n"
        stats += f"Headings: {len(headings)}\n"
        stats += f"Paragraphs: {len(paragraphs)}\n"
    
        # Token statistics
        token_stats = navigator.get_document_tokens(doc_id)
        if token_stats:
            stats += f"Total tokens: {token_stats['total_tokens']}\n"
            # stats += f"Content tokens: {token_stats['content_tokens']}\n"
    
        # Heading level breakdown
        level_counts = {}
        for heading in headings:
            level = heading.level or 0
            level_counts[level] = level_counts.get(level, 0) + 1
    
        if level_counts:
            stats += "Heading levels:\n"
            for level in sorted(level_counts.keys()):
                stats += f"  H{level}: {level_counts[level]}\n"
    
        return stats
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool retrieves 'statistics and structure info,' but lacks details on what specific statistics are included, whether it's a read-only operation, potential errors (e.g., if the document isn't loaded), or performance considerations. This leaves significant gaps in understanding the tool's behavior beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded: the first sentence clearly states the purpose, followed by structured 'Args' and 'Returns' sections. While efficient, the 'Returns' section is vague ('Document statistics and structure info'), and the overall text could be more informative without sacrificing brevity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (one parameter) and the presence of an output schema, the description is minimally adequate. It covers the basic purpose and parameters but lacks depth in usage guidelines and behavioral details. The output schema likely handles return values, so the description's vagueness there is acceptable, but overall completeness is limited.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds minimal meaning beyond the input schema: it defines 'doc_id' as 'Document identifier,' which is slightly more informative than the schema's 'Doc Id' title. However, with 0% schema description coverage and only one parameter, the baseline is high, and this small addition doesn't fully compensate for the lack of detail (e.g., format or source of the identifier).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get statistics about a loaded document.' It specifies the verb ('Get') and resource ('loaded document'), making the function evident. However, it doesn't explicitly differentiate from siblings like 'get_outline' or 'list_documents,' which might provide overlapping or related information, so it falls short of a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal guidance: it implies usage when statistics about a loaded document are needed, but offers no explicit advice on when to use this tool versus alternatives like 'list_documents' or 'search_document.' There's no mention of prerequisites (e.g., the document must be loaded first) or exclusions, leaving the agent to infer context from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/shenyimings/DocNav-MCP'

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