Skip to main content
Glama

delete_footnote

Destructive

Remove a footnote and its reference from a DOCX document to clean up content and maintain formatting.

Instructions

Delete a footnote and its reference from the document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the DOCX file.
note_idYesFootnote ID to delete.

Implementation Reference

  • Core implementation of footnote deletion logic in docx-core.
    export async function deleteFootnote(
      documentXml: Document,
      zip: DocxZip,
      params: { noteId: number },
    ): Promise<void> {
      const { noteId } = params;
    
      const footnotesXml = await zip.readText('word/footnotes.xml');
      const footnotesDoc = parseXml(footnotesXml);
    
      const fnEl = findFootnoteById(footnotesDoc, noteId);
      if (!fnEl) throw new Error(`Footnote ID ${noteId} not found`);
      if (isReservedFootnote(fnEl)) throw new Error(`Cannot delete reserved footnote ID ${noteId}`);
    
      // Remove from footnotes.xml
      fnEl.parentNode?.removeChild(fnEl);
      zip.writeText('word/footnotes.xml', serializeXml(footnotesDoc));
    
      // Remove footnoteReference elements from document.xml
      const refs = documentXml.getElementsByTagNameNS(OOXML.W_NS, W.footnoteReference);
      const refsToRemove: Element[] = [];
    
      for (let i = 0; i < refs.length; i++) {
        const ref = refs.item(i) as Element;
        const idStr = getWAttr(ref, 'id');
        if (idStr && parseInt(idStr, 10) === noteId) {
          refsToRemove.push(ref);
        }
      }
    
      for (const ref of refsToRemove) {
        const run = ref.parentNode as Element | null;
        if (!run) continue;
    
        // Remove only the footnoteReference element, not the entire run
        run.removeChild(ref);
    
        // If the run is now empty (no visible content), remove it
        if (!hasVisibleContent(run)) {
          run.parentNode?.removeChild(run);
        }
      }
    }
  • MCP tool handler wrapper for deleting a footnote.
    export async function deleteFootnote(
      manager: SessionManager,
      params: {
        file_path?: string;
        note_id?: number;
      },
    ): Promise<ToolResponse> {
      const resolved = await resolveSessionForTool(manager, params, { toolName: 'delete_footnote' });
      if (!resolved.ok) return resolved.response;
      const { session, metadata } = resolved;
    
      if (params.note_id == null) {
        return err('MISSING_PARAMETER', 'note_id is required.', 'Provide the footnote ID to delete.');
      }
    
      try {
        await session.doc.deleteFootnote({ noteId: params.note_id });
    
        manager.markEdited(session);
        return ok(mergeSessionResolutionMetadata({
          note_id: params.note_id,
          file_path: manager.normalizePath(session.originalPath),
        }, metadata));
      } catch (e: unknown) {
        const msg = errorMessage(e);
        if (msg.includes('reserved')) {
          return err('RESERVED_TYPE', msg, 'Reserved footnotes (separator, continuationSeparator) cannot be deleted.');
        }
        if (msg.includes('Missing file in .docx: word/footnotes.xml')) {
          return err('NOTE_NOT_FOUND', `Footnote ID ${params.note_id} not found`, 'Use get_footnotes to list available footnotes.');
        }
        if (msg.includes('not found')) {
          return err('NOTE_NOT_FOUND', msg, 'Use get_footnotes to list available footnotes.');
        }
        return err('FOOTNOTE_ERROR', msg);
      }
    }
Behavior4/5

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

Adds valuable behavioral detail beyond annotations: specifies that the 'reference' in the text body is also removed, not just the note content. Annotations only indicate destructive=true, but description clarifies the cascade effect to document text. Could mention reversibility or return confirmation.

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?

Single sentence, front-loaded with action verb, zero waste. Every word earns its place: 'and its reference' is critical behavioral context, 'from the document' clarifies scope.

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?

Adequate for a focused 2-parameter destructive operation with good annotations. Missing explicit return value description (success confirmation vs void), but given no output schema exists and the operation is straightforward, the description covers the essential behavioral contract.

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 clear descriptions for both file_path and note_id. Description implicitly maps to these parameters ('document' = file_path, 'footnote' = note_id) but adds no syntax guidance, format examples, or constraints beyond what the schema already 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?

Clear specific verb (Delete) + resource (footnote and its reference) + scope (from the document). Distinguishes from siblings add_footnote/update_footnote/get_footnotes by specifying the destructive removal action.

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?

Lacks explicit when-to-use guidance or contrast with update_footnote (which presumably modifies content while keeping the reference). Usage is implied by the verb 'Delete' but no alternatives or prerequisites (like 'use after get_footnotes to find the ID') are mentioned.

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