Skip to main content
Glama

get_comments_by_author

Extract all comments written by a specific author from a Microsoft Word document to review or analyze their contributions.

Instructions

Extract comments from a specific author in a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
authorYes
filenameYes

Implementation Reference

  • Registration of the 'get_comments_by_author' MCP tool using FastMCP's @mcp.tool() decorator. This thin synchronous wrapper delegates execution to the async implementation in comment_tools.py.
    def get_comments_by_author(filename: str, author: str): """Extract comments from a specific author in a Word document.""" return comment_tools.get_comments_by_author(filename, author)
  • Core asynchronous handler implementing the tool logic: validates inputs, loads the DOCX document, extracts all comments, filters by author, and returns structured JSON response.
    async def get_comments_by_author(filename: str, author: str) -> str: """ Extract comments from a specific author in a Word document. Args: filename: Path to the Word document author: Name of the comment author to filter by Returns: JSON string containing filtered comments """ 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 not author or not author.strip(): return json.dumps({ 'success': False, 'error': 'Author name cannot be empty' }, indent=2) try: # Load the document doc = Document(filename) # Extract all comments all_comments = extract_all_comments(doc) # Filter by author author_comments = filter_comments_by_author(all_comments, author) # Return results return json.dumps({ 'success': True, 'author': author, 'comments': author_comments, 'total_comments': len(author_comments) }, indent=2) except Exception as e: return json.dumps({ 'success': False, 'error': f'Failed to extract comments: {str(e)}' }, indent=2)
  • Helper utility function that performs case-insensitive filtering of comments by author name. Called by the main handler.
    def filter_comments_by_author(comments: List[Dict[str, Any]], author: str) -> List[Dict[str, Any]]: """ Filter comments by author name. Args: comments: List of comment dictionaries author: Author name to filter by (case-insensitive) Returns: Filtered list of comments """ author_lower = author.lower() return [c for c in comments if c.get('author', '').lower() == author_lower]
  • Namespace export/registration of the get_comments_by_author function from comment_tools.py, making it available for import in main.py.
    from word_document_server.tools.comment_tools import ( get_all_comments, get_comments_by_author, get_comments_for_paragraph )

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