Skip to main content
Glama
KazKozDev
by KazKozDev

Get Document Structure

get_document_structure

Extract the hierarchical structure of a Markdown document to navigate headings and elements efficiently.

Instructions

Parses the Markdown file and returns a tree of headings and elements. Use this first to navigate.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesAbsolute path to the .md file
depthNoMaximum depth of headings to return

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
structureNoTree of document elements

Implementation Reference

  • The primary handler function for the 'get_document_structure' tool. It delegates to the singleton EditTool instance's get_structure method.
    async def get_document_structure(file_path: str, depth: Optional[int] = None):
        return await _instance.get_structure(file_path, depth)
  • Schema definition in list_tools(), specifying input (file_path required, depth optional) and output (structure array).
    Tool(
        name="get_document_structure",
        title="Get Document Structure",
        description="Parses the Markdown file and returns a tree of headings and elements. Use this first to navigate.",
        inputSchema={
            "type": "object",
            "properties": {
                "file_path": {
                    "type": "string",
                    "description": "Absolute path to the .md file",
                    "examples": ["/path/to/document.md", "./README.md"],
                },
                "depth": {
                    "type": "integer",
                    "description": "Maximum depth of headings to return",
                    "default": 2,
                    "examples": [2, 3, 5],
                },
            },
            "required": ["file_path"],
            "additionalProperties": False,
        },
        outputSchema={
            "type": "object",
            "properties": {
                "structure": {
                    "type": "array",
                    "description": "Tree of document elements",
                }
            },
        },
    ),
  • Registration and dispatch logic in @app.call_tool(): invokes the handler and formats the CallToolResult.
    if name == "get_document_structure":
        res = await get_document_structure(file_path, arguments.get("depth", 2))
        result = {"structure": res}
        return CallToolResult(
            content=[TextContent(type="text", text=json.dumps(result, ensure_ascii=False, indent=2))],
            structuredContent=result,
            isError=False,
        )
  • Helper method in EditTool class implementing the core logic: loads cached Document and calls its get_structure method.
    async def get_structure(
        self, file_path: str, depth: Optional[int] = None
    ) -> List[dict]:
        doc = self.get_doc(file_path)
        return doc.get_structure(depth=depth)
Behavior3/5

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

With no annotations provided, the description carries the full burden. It discloses the tool's behavior as parsing and returning a tree, which implies a read-only operation without side effects, but lacks details on error handling, performance, or output format specifics. It adds some context with the navigation advice but is not comprehensive.

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

Conciseness5/5

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

The description is front-loaded with the core functionality in the first sentence and adds a concise usage tip in the second. Both sentences earn their place by providing essential information without redundancy, making it efficient and well-structured.

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

Completeness4/5

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

Given the tool's moderate complexity (parsing Markdown structure), no annotations, and the presence of an output schema (which handles return values), the description is reasonably complete. It covers purpose and usage but could improve by addressing behavioral aspects like error cases or limitations, though the output schema mitigates some gaps.

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?

Schema description coverage is 100%, so the schema fully documents both parameters (file_path and depth). The description adds no additional parameter semantics beyond what the schema provides, such as explaining how depth affects the tree structure or file_path validation, resulting in a baseline score.

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

Purpose5/5

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

The description clearly states the specific action ('parses the Markdown file') and the resource/result ('returns a tree of headings and elements'), distinguishing it from siblings like read_element or search_text by focusing on structural analysis rather than content reading or searching.

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

Usage Guidelines4/5

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

It provides explicit guidance to 'use this first to navigate,' indicating a primary use case for initial exploration of document structure. However, it does not specify when not to use it or name alternatives among siblings, such as read_element for content reading.

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/KazKozDev/markdown-editor-mcp-server'

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