Skip to main content
Glama

get_comments

Read-only

Extract all comments from DOCX files including text, authors, dates, IDs, and threaded replies to analyze feedback and track document revisions.

Instructions

Get all comments from the document with IDs, authors, dates, text, and anchored paragraph IDs. Includes threaded replies. Read-only.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the DOCX file.

Implementation Reference

  • MCP tool handler for 'get_comments', which resolves the session and calls session.doc.getComments().
    export async function getComments(
      manager: SessionManager,
      params: { file_path?: string },
    ): Promise<ToolResponse> {
      const resolved = await resolveSessionForTool(manager, params, { toolName: 'get_comments' });
      if (!resolved.ok) return resolved.response;
      const { session, metadata } = resolved;
    
      try {
        const comments = await session.doc.getComments();
        return ok(mergeSessionResolutionMetadata({
          comments: comments.map((c) => mapComment(c)),
          file_path: manager.normalizePath(session.originalPath),
        }, metadata));
      } catch (e: unknown) {
        return err('COMMENT_ERROR', errorMessage(e));
      }
    }
  • Core implementation that parses the OOXML comment structure and threads replies.
    export async function getComments(zip: DocxZip, documentXml: Document): Promise<Comment[]> {
      const commentsText = await zip.readTextOrNull('word/comments.xml');
      if (!commentsText) return [];
    
      const commentsDoc = parseXml(commentsText);
      const commentEls = commentsDoc.getElementsByTagNameNS(OOXML.W_NS, W.comment);
      if (commentEls.length === 0) return [];
    
      // Build a map of commentId → { paraId, Comment }
      const byParaId = new Map<string, Comment>();
      const byId = new Map<number, Comment>();
    
      for (let i = 0; i < commentEls.length; i++) {
        const el = commentEls.item(i) as Element;
        const idStr = el.getAttributeNS(OOXML.W_NS, 'id') ?? el.getAttribute('w:id');
        const id = idStr ? parseInt(idStr, 10) : -1;
        if (id < 0) continue;
    
        const author = el.getAttributeNS(OOXML.W_NS, 'author') ?? el.getAttribute('w:author') ?? '';
        const date = el.getAttributeNS(OOXML.W_NS, 'date') ?? el.getAttribute('w:date') ?? '';
        const initials = el.getAttributeNS(OOXML.W_NS, 'initials') ?? el.getAttribute('w:initials') ?? '';
    
        // Extract text from <w:t> elements, skipping annotationRef runs
        const text = extractCommentText(el);
    
        // Get paraId from first <w:p> child
        const paras = el.getElementsByTagNameNS(OOXML.W_NS, W.p);
        let paragraphId: string | null = null;
        if (paras.length > 0) {
          const p = paras.item(0) as Element;
          paragraphId = p.getAttributeNS(OOXML.W14_NS, 'paraId') ?? p.getAttribute('w14:paraId') ?? null;
        }
    
        const comment: Comment = {
          id,
          author,
          date,
          initials,
          text,
          paragraphId,
          anchoredParagraphId: null,
          replies: [],
        };
    
        byId.set(id, comment);
        if (paragraphId) byParaId.set(paragraphId, comment);
      }
    
      // Resolve anchoredParagraphId by scanning documentXml for commentRangeStart elements
      const rangeStarts = documentXml.getElementsByTagNameNS(OOXML.W_NS, W.commentRangeStart);
      for (let i = 0; i < rangeStarts.length; i++) {
        const rs = rangeStarts.item(i) as Element;
        const cidStr = rs.getAttributeNS(OOXML.W_NS, 'id') ?? rs.getAttribute('w:id');
        if (!cidStr) continue;
        const cid = parseInt(cidStr, 10);
        const comment = byId.get(cid);
        if (!comment) continue;
    
        // Walk up to find enclosing <w:p>
        let parent = rs.parentNode;
        while (parent && parent.nodeType === 1) {
          const pel = parent as Element;
          if (pel.localName === W.p && pel.namespaceURI === OOXML.W_NS) {
            comment.anchoredParagraphId = getParagraphBookmarkId(pel);
            break;
          }
          parent = parent.parentNode;
        }
      }
    
      // Build thread tree from commentsExtended.xml
      const extText = await zip.readTextOrNull('word/commentsExtended.xml');
      if (extText) {
        const extDoc = parseXml(extText);
        const exEls = extDoc.getElementsByTagNameNS(OOXML.W15_NS, 'commentEx');
        for (let i = 0; i < exEls.length; i++) {
          const ex = exEls.item(i) as Element;
          const childParaId = ex.getAttributeNS(OOXML.W15_NS, 'paraId') ?? ex.getAttribute('w15:paraId');
          const parentParaId = ex.getAttributeNS(OOXML.W15_NS, 'paraIdParent') ?? ex.getAttribute('w15:paraIdParent');
          if (!childParaId || !parentParaId) continue;
    
          const child = byParaId.get(childParaId);
          const parentComment = byParaId.get(parentParaId);
          if (child && parentComment) {
            parentComment.replies.push(child);
          }
        }
      }
    
      // Collect root-level comments (those not appearing as anyone's reply)
      const replyParaIds = new Set<string>();
      if (extText) {
        const extDoc = parseXml(extText);
        const exEls = extDoc.getElementsByTagNameNS(OOXML.W15_NS, 'commentEx');
        for (let i = 0; i < exEls.length; i++) {
          const ex = exEls.item(i) as Element;
          const childParaId = ex.getAttributeNS(OOXML.W15_NS, 'paraId') ?? ex.getAttribute('w15:paraId');
          const parentParaId = ex.getAttributeNS(OOXML.W15_NS, 'paraIdParent') ?? ex.getAttribute('w15:paraIdParent');
          if (childParaId && parentParaId) {
            replyParaIds.add(childParaId);
          }
        }
      }
    
      const roots: Comment[] = [];
      for (const comment of byId.values()) {
        if (!comment.paragraphId || !replyParaIds.has(comment.paragraphId)) {
          roots.push(comment);
        }
      }
    
      return roots;
    }
Behavior4/5

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

Annotations already declare readOnlyHint=true, but the description reinforces this with 'Read-only' and adds crucial behavioral context about the return structure (field names and threaded replies) that compensates for the missing output schema. No contradictions with annotations.

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?

Three sentences total: first establishes action and return payload, second adds threading detail, third confirms safety. Every word earns its place with zero redundancy. Perfectly front-loaded with the essential action.

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?

For a single-parameter read operation, the description adequately compensates for the missing output schema by enumerating return fields and threading behavior. Could explicitly mention return format (array/list) but otherwise complete.

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 coverage is 100% with file_path fully documented. The description references 'the document' which implicitly maps to the parameter, but adds no additional semantics (path formats, relative vs absolute) beyond what the schema provides. Baseline 3 appropriate for high schema coverage.

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?

Description uses specific verb 'Get' with clear resource 'comments', specifies scope 'all', and details exactly what data is returned (IDs, authors, dates, text, anchored paragraph IDs). The mention of 'threaded replies' distinguishes its output format from siblings like add_comment or delete_comment.

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

Usage Guidelines3/5

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

The description implies usage by stating it retrieves all comments with specific fields, but does not explicitly state when to use this versus alternatives (e.g., 'use this to read comments before calling delete_comment') or provide exclusion criteria.

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/UseJunior/safe-docx'

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