Skip to main content
Glama

get_comments

Read-only

Retrieve all comments from a DOCX document, including threaded replies and associated details like author, date, and paragraph location.

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 that resolves the session, calls doc.getComments(), maps comments to MCP-friendly format, and returns them with file path metadata.
    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));
      }
    }
  • Output schema for a comment returned by the MCP tool, with fields mapped to snake_case for MCP compatibility.
    type McpComment = {
      id: number;
      author: string;
      date: string | null;
      initials: string;
      text: string;
      anchored_paragraph_id: string | null;
      replies: McpComment[];
    };
  • Recursive helper to convert a core Comment to an MCP-friendly McpComment, limiting reply depth to 10.
    function mapComment(c: Comment, depth = 0): McpComment {
      return {
        id: c.id,
        author: c.author,
        date: c.date || null,
        initials: c.initials,
        text: c.text,
        anchored_paragraph_id: c.anchoredParagraphId,
        replies: depth < MAX_REPLY_DEPTH ? c.replies.map((r) => mapComment(r, depth + 1)) : [],
      };
    }
  • Tool catalog registration for get_comments: defines name, description, input schema (file_path only), and read-only annotations.
    {
      name: 'get_comments',
      description:
        'Get all comments from the document with IDs, authors, dates, text, and anchored paragraph IDs. Includes threaded replies. Read-only.',
      input: z.object({
        ...FILE_FIELD,
      }),
      annotations: { readOnlyHint: true, destructiveHint: false },
    },
  • Core implementation that parses word/comments.xml, resolves anchored paragraph IDs from commentRangeStart elements, builds reply thread trees from commentsExtended.xml, and returns only root-level (non-reply) comments.
    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 indicate readOnlyHint=true and destructiveHint=false. The description adds behavioral details about the output content (IDs, authors, dates, text, anchored paragraph IDs, threaded replies), which goes beyond annotations without contradiction.

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 two sentences, front-loading the key information (what it gets and the fields). Every sentence adds value without being verbose.

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

Completeness5/5

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

Given no output schema, the description adequately describes the return values (IDs, authors, dates, text, anchored paragraph IDs, threaded replies). This is sufficient for a simple tool with one required parameter.

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 a single parameter (file_path) described in schema. The description does not add further parameter semantics beyond what the schema provides, so baseline score of 3 is appropriate.

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?

The description clearly states the tool retrieves all comments with specific fields (IDs, authors, dates, text, anchored paragraph IDs) and includes threaded replies. It also indicates read-only nature, distinguishing it from sibling tools 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 through stating the tool gets comments and is read-only, but does not explicitly mention when to use or avoid this tool, nor provide alternatives among siblings.

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