Skip to main content
Glama

clear_formatting

Destructive

Remove selected formatting types (bold, italic, underline, highlight, color, font) from paragraphs in a DOCX file. Optionally target specific paragraphs.

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 'clearFormatting' that clears run-level formatting (bold, italic, underline, highlight, color, font) from paragraphs. It resolves the session, iterates over target paragraphs, removes the specified formatting elements from run properties (rPr), and marks the session as edited.
    import { SessionManager } from '../session/manager.js';
    import { ok, err, type ToolResponse } from './types.js';
    import { resolveSessionForTool, mergeSessionResolutionMetadata } from './session_resolution.js';
    import { OOXML, W } from '@usejunior/docx-core';
    
    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}`);
      }
    }
  • The tool registration definition in the catalog. Defines the 'clear_formatting' tool name, description, input schema (file_path, paragraph_ids, clear_highlight, clear_bold, clear_italic, clear_underline, clear_color, clear_font), and annotations (destructiveHint: true).
    {
      name: 'clear_formatting',
      description:
        'Clear specific run-level formatting (bold, italic, underline, highlight, color, font) from paragraphs.',
      input: z.object({
        ...FILE_FIELD,
        paragraph_ids: z.array(z.string()).optional().describe('Paragraph IDs to clear formatting from. If omitted, clears from all paragraphs.'),
        clear_highlight: z.boolean().optional().describe('Remove highlight formatting.'),
        clear_bold: z.boolean().optional().describe('Remove bold formatting.'),
        clear_italic: z.boolean().optional().describe('Remove italic formatting.'),
        clear_underline: z.boolean().optional().describe('Remove underline formatting.'),
        clear_color: z.boolean().optional().describe('Remove font color.'),
        clear_font: z.boolean().optional().describe('Remove font family and size.'),
      }),
      annotations: { readOnlyHint: false, destructiveHint: true },
    },
  • The case handler in the server's tool dispatch that routes 'clear_formatting' requests to the clearFormatting function.
    case 'clear_formatting':
      return await clearFormatting(sessions, args as Parameters<typeof clearFormatting>[1]);
  • Import of clearFormatting from the tools module in the server entry point.
    import { clearFormatting } from './tools/clear_formatting.js';
  • The ToolResponse type and helper functions (ok/err) used by clearFormatting for returning results.
    export type ToolResponse =
      | { success: true; [key: string]: unknown }
      | { success: false; error: { code: string; message: string; hint?: string }; [key: string]: unknown };
    
    export function ok(extra: Record<string, unknown> = {}): ToolResponse {
      return { success: true, ...extra };
    }
    
    export function err(code: string, message: string, hint?: string): ToolResponse {
      return { success: false, error: { code, message, hint } };
    }
Behavior3/5

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

Annotations already indicate this is a destructive write operation (readOnlyHint=false, destructiveHint=true). The description adds the specific formatting types but does not disclose other behaviors (e.g., effect on all paragraphs if paragraph_ids omitted) beyond what the schema provides.

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 one concise sentence, immediately stating the core action and list of formatting types. No redundant information.

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?

For a destructive mutation tool with 8 parameters and no output schema, the description is minimal. It covers the basic action but lacks explanation of return value, default behavior for omitted paragraph_ids, and potential side-effects beyond what annotations provide.

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 description coverage is 100%, so baseline is 3. The description adds the term 'run-level formatting' which offers minor additional context, but does not explain parameter behavior (e.g., default for paragraph_ids) beyond schema 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 clearly states the verb 'clear' and the resource 'run-level formatting' with a specific list (bold, italic, underline, highlight, color, font), distinguishing it from sibling tools like format_layout or replace_text.

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?

No guidance is provided on when to use this tool versus alternatives, nor are any prerequisites or exclusions mentioned. The description merely states the action without context.

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