Skip to main content
Glama

add_comment

Destructive

Add comments or threaded replies to DOCX documents by anchoring to specific paragraphs or replying to existing comments for collaborative editing.

Instructions

Add a comment or threaded reply to a document. Provide target_paragraph_id + anchor_text for root comments, or parent_comment_id for replies.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the DOCX file.
target_paragraph_idNoParagraph ID to anchor the comment to (for root comments).
anchor_textNoText within the paragraph to anchor the comment to. If omitted, anchors to entire paragraph.
parent_comment_idNoParent comment ID for threaded replies.
authorYesComment author name.
textYesComment body text.
initialsNoAuthor initials (defaults to first letter of author name).

Implementation Reference

  • The addComment MCP tool handler, which manages session resolution and calls either session.doc.addCommentReply or session.doc.addComment.
    export async function addComment(
      manager: SessionManager,
      params: {
        file_path?: string;
        target_paragraph_id?: string;
        anchor_text?: string;
        parent_comment_id?: number;
        author: string;
        text: string;
        initials?: string;
      },
    ): Promise<ToolResponse> {
      const resolved = await resolveSessionForTool(manager, params, { toolName: 'add_comment' });
      if (!resolved.ok) return resolved.response;
      const { session, metadata } = resolved;
    
      try {
        // Reply mode: parent_comment_id provided
        if (params.parent_comment_id != null) {
          const result = await session.doc.addCommentReply({
            parentCommentId: params.parent_comment_id,
            author: params.author,
            text: params.text,
            initials: params.initials,
          });
          manager.markEdited(session);
          return ok(mergeSessionResolutionMetadata({
            comment_id: result.commentId,
            parent_comment_id: result.parentCommentId,
            mode: 'reply',
            file_path: manager.normalizePath(session.originalPath),
          }, metadata));
        }
    
        // Root comment mode: target_paragraph_id required
        if (!params.target_paragraph_id) {
          return err(
            'MISSING_PARAMETER',
            'Either target_paragraph_id (for root comments) or parent_comment_id (for replies) is required.',
            'Provide target_paragraph_id + optional anchor_text for root comments, or parent_comment_id for threaded replies.',
          );
        }
    
        const pid = params.target_paragraph_id;
        const pEl = session.doc.getParagraphElementById(pid);
        if (!pEl) {
          return err(
            'ANCHOR_NOT_FOUND',
            `Paragraph ID ${pid} not found in document`,
            'Use grep or read_file to find valid paragraph IDs.',
          );
        }
    
        let start = 0;
        let end: number;
    
        if (params.anchor_text) {
          // Find anchor_text within the paragraph
          const paraText = session.doc.getParagraphTextById(pid) ?? '';
          const match = findUniqueSubstringMatch(paraText, params.anchor_text);
    
          if (match.status === 'not_found') {
            return err(
              'TEXT_NOT_FOUND',
              `anchor_text '${params.anchor_text}' not found in paragraph ${pid}`,
              'Verify anchor_text is present in the target paragraph.',
            );
          }
          if (match.status === 'multiple') {
            return err(
              'MULTIPLE_MATCHES',
              `Found ${match.matchCount} matches for anchor_text in paragraph ${pid}`,
              'Provide more specific anchor_text for a unique match.',
            );
          }
    
          start = match.start;
          end = match.end;
        } else {
          // Anchor to entire paragraph
          const paraText = session.doc.getParagraphTextById(pid) ?? '';
          end = paraText.length;
        }
    
        const result = await session.doc.addComment({
          paragraphId: pid,
          start,
          end,
          author: params.author,
          text: params.text,
          initials: params.initials,
        });
    
        manager.markEdited(session);
        return ok(mergeSessionResolutionMetadata({
          comment_id: result.commentId,
          anchor_paragraph_id: pid,
          anchor_text: params.anchor_text ?? null,
          mode: 'root',
          file_path: manager.normalizePath(session.originalPath),
        }, metadata));
      } catch (e: unknown) {
        return err('COMMENT_ERROR', errorMessage(e));
      }
    }
Behavior4/5

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

Annotations declare destructiveHint=true and readOnlyHint=false; the description confirms the write nature via 'Add' and enriches this with behavioral details about threading mechanics and text anchoring that annotations don't cover. No contradictions with structured metadata.

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?

Two sentences total with zero redundancy. First sentence establishes purpose; second provides operational guidance. Front-loaded with the essential verb and no filler text.

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?

Given the 7-parameter complexity and lack of output schema, the description adequately covers the primary operational modes (root vs. reply) and anchoring behavior. Could improve by mentioning error conditions (e.g., mutually exclusive parameter sets) or return values, but sufficient for safe invocation.

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

Parameters4/5

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

With 100% schema coverage, baseline is 3. The description elevates this by explaining the semantic relationships between parameters—specifically that target_paragraph_id/anchor_text are for root comments while parent_comment_id is for replies—critical logic not expressed in the schema's isolated field descriptions.

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 opens with a specific verb ('Add') and clear resource ('comment or threaded reply'), distinguishing it from sibling tools like add_footnote. It explicitly scopes the operation to documents, differentiating from get_comments (read) and delete_comment (remove).

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

Usage Guidelines4/5

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

Provides explicit parameter-level guidance distinguishing root comments ('target_paragraph_id + anchor_text') from replies ('parent_comment_id'), effectively documenting the two primary usage patterns. Lacks explicit comparison to sibling tools like add_footnote, but the internal usage context is clearly defined.

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