Skip to main content
Glama

get_document_outline

Extract the hierarchical structure of a Word document to analyze headings, sections, and content organization. Input a filename to retrieve the document outline in clear, structured format.

Instructions

Get the structure of a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes

Implementation Reference

  • The primary handler function for the get_document_outline MCP tool. Ensures .docx extension for local files, calls get_document_structure utility, and returns the structure as JSON.
    async def get_document_outline(filename: str) -> str:
        """Get the structure of a Word document from local path or URL.
    
        Args:
            filename: Path or URL to the Word document
        """
        # Only add .docx extension for local paths, not URLs
        if not is_url(filename):
            filename = ensure_docx_extension(filename)
    
        structure = get_document_structure(filename)
        return json.dumps(structure, indent=2)
  • MCP tool registration in the main server file. Wraps the document_tools.get_document_outline function and registers it with FastMCP using the @mcp.tool() decorator.
    @mcp.tool()
    async def get_document_outline(filename: str):
        """Get the structure of a Word document."""
        return await document_tools.get_document_outline(filename)
  • Core utility function that loads the document (handling local paths and URLs), parses paragraphs with index, preview text, and style, and tables with dimensions and preview data, returning a structured dictionary used by the tool handler.
    def get_document_structure(doc_path: str) -> Dict[str, Any]:
        """Get the structure of a Word document from local path or URL."""
        doc, error, is_temp, temp_path = load_document_from_path_or_url(doc_path)
    
        if error:
            return {"error": error}
    
        try:
            structure = {
                "paragraphs": [],
                "tables": []
            }
    
            # Get paragraphs
            for i, para in enumerate(doc.paragraphs):
                structure["paragraphs"].append({
                    "index": i,
                    "text": para.text[:100] + ("..." if len(para.text) > 100 else ""),
                    "style": para.style.name if para.style else "Normal"
                })
    
            # Get tables
            for i, table in enumerate(doc.tables):
                table_data = {
                    "index": i,
                    "rows": len(table.rows),
                    "columns": len(table.columns),
                    "preview": []
                }
    
                # Get sample of table data
                max_rows = min(3, len(table.rows))
                for row_idx in range(max_rows):
                    row_data = []
                    max_cols = min(3, len(table.columns))
                    for col_idx in range(max_cols):
                        try:
                            cell_text = table.cell(row_idx, col_idx).text
                            row_data.append(cell_text[:20] + ("..." if len(cell_text) > 20 else ""))
                        except IndexError:
                            row_data.append("N/A")
                    table_data["preview"].append(row_data)
    
                structure["tables"].append(table_data)
    
            return structure
        except Exception as e:
            return {"error": f"Failed to get document structure: {str(e)}"}
        finally:
            # Clean up temp file if needed
            if is_temp and temp_path:
                cleanup_temp_file(temp_path)
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action but doesn't describe what 'structure' includes (e.g., headings, sections, tables), whether it's read-only or has side effects, or any permissions or limitations. This is inadequate for a tool with no annotation coverage.

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 a single, efficient sentence with no wasted words. It's front-loaded and appropriately sized for the tool's apparent simplicity, making it easy to parse quickly.

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

Completeness2/5

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

Given the lack of annotations, low schema coverage, and no output schema, the description is incomplete. It doesn't explain what 'structure' means in practice, how results are returned, or any behavioral traits, making it insufficient for an AI agent to use the tool effectively without guesswork.

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 no parameter information beyond the input schema, which has 0% description coverage for the single parameter 'filename'. Since schema coverage is low, the description should compensate but doesn't, leaving the parameter's meaning and format unspecified. The baseline is adjusted due to the coverage gap.

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 verb 'Get' and the resource 'structure of a Word document', making the purpose understandable. However, it doesn't distinguish this tool from sibling tools like 'get_document_info' or 'get_document_text', which also retrieve document information but focus on different aspects.

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 no guidance on when to use this tool versus alternatives. With siblings like 'get_document_info' and 'get_document_text', there's no indication of what 'structure' entails or how it differs from other document retrieval tools, leaving usage context unclear.

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

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/franlealp1/mcp-word'

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