Skip to main content
Glama
GongRzhe

Office Word MCP Server

get_comments_for_paragraph

Extract comments for a specific paragraph in a Word document to review feedback or track changes efficiently.

Instructions

Extract comments for a specific paragraph in a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
paragraph_indexYes

Implementation Reference

  • Main asynchronous handler implementing the tool logic: loads document, validates inputs, extracts and filters comments for the specified paragraph, includes paragraph text context, returns structured JSON response.
    async def get_comments_for_paragraph(filename: str, paragraph_index: int) -> str:
        """
        Extract comments for a specific paragraph in a Word document.
        
        Args:
            filename: Path to the Word document
            paragraph_index: Index of the paragraph (0-based)
            
        Returns:
            JSON string containing comments for the specified paragraph
        """
        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)
        
        if paragraph_index < 0:
            return json.dumps({
                'success': False,
                'error': 'Paragraph index must be non-negative'
            }, indent=2)
        
        try:
            # Load the document
            doc = Document(filename)
            
            # Check if paragraph index is valid
            if paragraph_index >= len(doc.paragraphs):
                return json.dumps({
                    'success': False,
                    'error': f'Paragraph index {paragraph_index} is out of range. Document has {len(doc.paragraphs)} paragraphs.'
                }, indent=2)
            
            # Extract all comments
            all_comments = extract_all_comments(doc)
            
            # Filter for the specific paragraph
            from word_document_server.core.comments import get_comments_for_paragraph as core_get_comments_for_paragraph
            para_comments = core_get_comments_for_paragraph(all_comments, paragraph_index)
            
            # Get the paragraph text for context
            paragraph_text = doc.paragraphs[paragraph_index].text
            
            # Return results
            return json.dumps({
                'success': True,
                'paragraph_index': paragraph_index,
                'paragraph_text': paragraph_text,
                'comments': para_comments,
                'total_comments': len(para_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 via FastMCP @mcp.tool() decorator in the main server file, defining input parameters and docstring, delegating execution to the handler in comment_tools.
    def get_comments_for_paragraph(filename: str, paragraph_index: int):
        """Extract comments for a specific paragraph in a Word document."""
        return comment_tools.get_comments_for_paragraph(filename, paragraph_index)
    # New table column width tools
  • Core helper function that filters a list of comments to return only those associated with the given paragraph_index.
    def get_comments_for_paragraph(comments: List[Dict[str, Any]], paragraph_index: int) -> List[Dict[str, Any]]:
        """
        Get all comments for a specific paragraph.
        
        Args:
            comments: List of all comments
            paragraph_index: Index of the paragraph
            
        Returns:
            Comments for the specified paragraph
        """
        return [c for c in comments if c.get('paragraph_index') == paragraph_index]
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states 'extract comments' which implies a read-only operation, but doesn't specify whether this requires file access permissions, what format comments are returned in, if there are rate limits, or error handling for invalid paragraph indices. For a tool with zero annotation coverage, this leaves significant behavioral gaps.

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, focused sentence that efficiently communicates the core functionality without unnecessary words. It's appropriately sized for a simple tool and front-loads the essential information immediately.

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?

For a tool with 2 parameters, 0% schema coverage, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what 'extract' means in practice, what format comments are returned in, or how paragraph indexing works. Given the lack of structured data support, the description should provide more operational context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage for both parameters, the description provides no additional semantic information about 'filename' (e.g., path requirements, supported formats) or 'paragraph_index' (e.g., zero-based vs one-based indexing, valid range). The description mentions 'specific paragraph' but doesn't clarify how paragraph identification works, failing to compensate for the schema 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 action ('extract comments') and target resource ('for a specific paragraph in a Word document'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_all_comments' or 'get_comments_by_author', which would require more specific scope clarification.

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_all_comments' or 'get_comments_by_author'. There's no mention of prerequisites, context, or comparison with sibling tools, leaving the agent to infer usage scenarios independently.

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