Skip to main content
Glama

read_section

Extract specific sections from documents by providing document and section identifiers to retrieve targeted content with subsections for focused analysis.

Instructions

Read content of a specific document section.

Args:
    doc_id: Document identifier
    section_id: Section ID from outline (e.g., 'h1_0', 'h2_1')

Returns:
    Section content with subsections

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
doc_idYes
section_idYes

Implementation Reference

  • server.py:70-82 (handler)
    MCP tool handler for 'read_section'. Decorated with @mcp.tool(), handles input parameters, strips '#' from section_id if present, and delegates to Navigator.read_section. This is the entry point for the tool.
    @mcp.tool()
    def read_section(doc_id: str, section_id: str) -> str:
        """Read content of a specific document section.
    
        Args:
            doc_id: Document identifier
            section_id: Section ID from outline (e.g., 'h1_0', 'h2_1')
    
        Returns:
            Section content with subsections
        """
    
        return navigator.read_section(doc_id, section_id.strip("#"))
  • Core helper method in Navigator class that retrieves the document, finds the specified section node, collects content from the node and all its descendants recursively, and joins them into a string. Handles error cases for missing document or section.
    def read_section(self, doc_id: str, section_id: str) -> str:
        """Read specified section content."""
        document = self.get_document(doc_id)
        if not document:
            return f"Document '{doc_id}' not found"
    
        # Get the node and return its content with subsections
        node = document.get_node(section_id)
        if not node:
            return f"Section '{section_id}' not found"
    
        content = [node.content] if node.content else []
    
        def collect_content(n: DocumentNode) -> None:
            for child in n.children:
                if child.content:
                    content.append(child.content)
                collect_content(child)
    
        collect_content(node)
        return "\n".join(content)
  • server.py:70-70 (registration)
    The @mcp.tool() decorator registers the read_section function as an MCP tool.
    @mcp.tool()

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