Skip to main content
Glama

get_document_stats

Analyze and retrieve detailed statistics, structure, and insights from a loaded document using a specified document identifier, enabling efficient document management and navigation.

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

Implementation Reference

  • The handler function for the 'get_document_stats' tool, decorated with @mcp.tool() for registration. It computes and returns document statistics including total nodes, headings, paragraphs, token count, and heading level distribution using the DocumentNavigator instance.
    @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

Other Tools

Related 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