Skip to main content
Glama

clear_formatting

Destructive

Remove specific formatting like bold, italic, underline, highlight, color, or font from paragraphs in DOCX files to clean up document appearance.

Instructions

Clear specific run-level formatting (bold, italic, underline, highlight, color, font) from paragraphs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the DOCX file.
paragraph_idsNoParagraph IDs to clear formatting from. If omitted, clears from all paragraphs.
clear_highlightNoRemove highlight formatting.
clear_boldNoRemove bold formatting.
clear_italicNoRemove italic formatting.
clear_underlineNoRemove underline formatting.
clear_colorNoRemove font color.
clear_fontNoRemove font family and size.

Implementation Reference

  • The main handler function for the `clear_formatting` MCP tool, which resolves the session and removes specified formatting elements (bold, italic, underline, color, font, highlight) from paragraphs in a DOCX document.
    export async function clearFormatting(
      manager: SessionManager,
      params: {
        file_path?: string;
        paragraph_ids?: string[];
        clear_highlight?: boolean;
        clear_bold?: boolean;
        clear_italic?: boolean;
        clear_underline?: boolean;
        clear_color?: boolean;
        clear_font?: boolean;
      },
    ): Promise<ToolResponse> {
      try {
        const resolved = await resolveSessionForTool(manager, params, { toolName: 'clear_formatting' });
        if (!resolved.ok) return resolved.response;
        const { session, metadata } = resolved;
    
        const { nodes } = session.doc.buildDocumentView({ includeSemanticTags: false });
        const pids = params.paragraph_ids ?? nodes.map((n) => n.id);
        let modifiedCount = 0;
    
        for (const pid of pids) {
          const pEl = session.doc.getParagraphElementById(pid);
          if (!pEl) continue;
    
          const rElems = Array.from(pEl.getElementsByTagNameNS(OOXML.W_NS, W.r));
          let pModified = false;
    
          for (const r of rElems) {
            const rPr = r.getElementsByTagNameNS(OOXML.W_NS, W.rPr).item(0);
            if (!rPr) continue;
    
            if (params.clear_highlight) {
              const highlights = Array.from(rPr.getElementsByTagNameNS(OOXML.W_NS, W.highlight));
              if (highlights.length > 0) {
                for (const h of highlights) h.parentNode?.removeChild(h);
                pModified = true;
              }
            }
    
            if (params.clear_bold) {
              const bolds = Array.from(rPr.getElementsByTagNameNS(OOXML.W_NS, W.b));
              if (bolds.length > 0) {
                for (const b of bolds) b.parentNode?.removeChild(b);
                pModified = true;
              }
            }
    
            if (params.clear_italic) {
              const italics = Array.from(rPr.getElementsByTagNameNS(OOXML.W_NS, W.i));
              if (italics.length > 0) {
                for (const i of italics) i.parentNode?.removeChild(i);
                pModified = true;
              }
            }
    
            if (params.clear_underline) {
              const underlines = Array.from(rPr.getElementsByTagNameNS(OOXML.W_NS, W.u));
              if (underlines.length > 0) {
                for (const u of underlines) u.parentNode?.removeChild(u);
                pModified = true;
              }
            }
    
            if (params.clear_color) {
              const colors = Array.from(rPr.getElementsByTagNameNS(OOXML.W_NS, W.color));
              if (colors.length > 0) {
                for (const c of colors) c.parentNode?.removeChild(c);
                pModified = true;
              }
            }
    
            if (params.clear_font) {
              const fonts = Array.from(rPr.getElementsByTagNameNS(OOXML.W_NS, W.rFonts));
              const sizes = Array.from(rPr.getElementsByTagNameNS(OOXML.W_NS, W.sz));
              const csSizes = Array.from(rPr.getElementsByTagNameNS(OOXML.W_NS, W.szCs));
              if (fonts.length > 0 || sizes.length > 0 || csSizes.length > 0) {
                for (const f of fonts) f.parentNode?.removeChild(f);
                for (const s of sizes) s.parentNode?.removeChild(s);
                for (const s of csSizes) s.parentNode?.removeChild(s);
                pModified = true;
              }
            }
          }
          if (pModified) modifiedCount++;
        }
    
        if (modifiedCount > 0) {
          manager.markEdited(session);
        }
    
        return ok(mergeSessionResolutionMetadata({
          success: true,
          file_path: manager.normalizePath(session.originalPath),
          paragraphs_modified: modifiedCount,
        }, metadata));
      } catch (e: any) {
        return err('CLEAR_FORMATTING_ERROR', `Failed to clear formatting: ${e.message}`);
      }
    }
Behavior3/5

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

Annotations indicate destructiveHint=true, and the description clarifies what gets destroyed (specific formatting types). However, it lacks details about reversibility, whether this affects direct formatting or styles, and if changes are immediate or require a save operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the action verb. It packs the essential scope and examples without redundancy, though the density of parenthetical examples slightly reduces readability.

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

Completeness3/5

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

Given the comprehensive schema and presence of destructive annotations, the description is minimally adequate. However, for a destructive file-modification tool, it should ideally mention the scoping behavior (all paragraphs vs specific IDs) or file state requirements.

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?

With 100% schema description coverage, the schema already fully documents all 8 parameters. The description provides a helpful summary list of formatting types (bold, italic, etc.) that maps to the boolean flags, but does not add semantic information beyond what the schema already provides.

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 specific action (Clear) and target (run-level formatting including bold, italic, underline, highlight, color, font from paragraphs). It distinguishes from content-focused siblings like replace_text or insert_paragraph by explicitly mentioning formatting removal, though it could better differentiate from format_layout.

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. It does not mention prerequisites (like opening the file first), when clearing is preferable to applying new formatting, or that omitting paragraph_ids affects all paragraphs.

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