Skip to main content
Glama
GongRzhe

Office Word MCP Server

get_all_comments

Extract all comments from a Microsoft Word document to review feedback, track changes, or analyze document collaboration.

Instructions

Extract all comments from a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes

Implementation Reference

  • Primary handler function for the get_all_comments tool. Loads the Word document, extracts all comments using the core helper, handles errors, and returns a JSON-formatted response.
    async def get_all_comments(filename: str) -> str:
        """
        Extract all comments from a Word document.
        
        Args:
            filename: Path to the Word document
            
        Returns:
            JSON string containing all comments with metadata
        """
        filename = ensure_docx_extension(filename)
        
        if not os.path.exists(filename):
            return json.dumps({
                'success': False,
                'error': f'Document {filename} does not exist'
            }, indent=2)
        
        try:
            # Load the document
            doc = Document(filename)
            
            # Extract all comments
            comments = extract_all_comments(doc)
            
            # Return results
            return json.dumps({
                'success': True,
                'comments': comments,
                'total_comments': len(comments)
            }, indent=2)
            
        except Exception as e:
            return json.dumps({
                'success': False,
                'error': f'Failed to extract comments: {str(e)}'
            }, indent=2)
  • MCP tool registration using @mcp.tool() decorator. This is the entry point handler that delegates to the implementation in comment_tools.
    @mcp.tool()
    def get_all_comments(filename: str):
        """Extract all comments from a Word document."""
        return comment_tools.get_all_comments(filename)
  • Core helper function that performs the low-level extraction of all comments from the docx Document object, handling both direct comments part and fallback methods.
    def extract_all_comments(doc: DocumentType) -> List[Dict[str, Any]]:
        """
        Extract all comments from a Word document.
        
        Args:
            doc: The Document object to extract comments from
            
        Returns:
            List of dictionaries containing comment information
        """
        comments = []
        
        # Access the document's comment part if it exists
        try:
            # Get the document part
            document_part = doc.part
            
            # Find comments part through relationships
            comments_part = None
            for rel_id, rel in document_part.rels.items():
                if 'comments' in rel.reltype and 'comments' == rel.reltype.split('/')[-1]:
                    comments_part = rel.target_part
                    break
            
            if comments_part:
                # Extract comments from the comments part using proper xpath syntax
                comment_elements = comments_part.element.xpath('.//w:comment')
                
                for idx, comment_element in enumerate(comment_elements):
                    comment_data = extract_comment_data(comment_element, idx)
                    if comment_data:
                        comments.append(comment_data)
            
            # If no comments found, try alternative approach
            if not comments:
                # Fallback: scan paragraphs for comment references
                comments = extract_comments_from_paragraphs(doc)
        
        except Exception as e:
            # If direct access fails, try alternative approach
            comments = extract_comments_from_paragraphs(doc)
        
        return comments
  • Export of the get_all_comments function from comment_tools module, making it available for import.
    from word_document_server.tools.comment_tools import (
        get_all_comments, get_comments_by_author, get_comments_for_paragraph
    )
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 mentions extraction but doesn't specify output format, error handling, permissions needed, or whether it's read-only or destructive. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 that directly states the tool's function without unnecessary words. It's front-loaded and wastes no space, 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 complexity of extracting comments (which could involve structured data), no annotations, no output schema, and low schema coverage, the description is insufficient. It doesn't explain what 'extract' entails—e.g., format, pagination, or error cases—leaving the agent with incomplete context for proper use.

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 implies a 'filename' parameter is needed for the Word document, but with 0% schema description coverage, it doesn't add details like file path format, supported extensions, or handling of non-existent files. Since there's only one parameter, the baseline is higher, but the description doesn't fully compensate for the lack of schema documentation.

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 action ('Extract') and resource ('all comments from a Word document'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_comments_by_author' or 'get_comments_for_paragraph', which would require a 5.

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 like 'get_comments_by_author' or 'get_comments_for_paragraph', nor does it mention prerequisites or context for usage. It merely states what the tool does without indicating appropriate scenarios.

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/GongRzhe/Office-Word-MCP-Server'

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