Skip to main content
Glama
GongRzhe

Office Word MCP Server

add_footnote_to_document

Add explanatory notes or citations to specific paragraphs in Microsoft Word documents to provide references and additional context.

Instructions

Add a footnote to a specific paragraph in a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filenameYes
paragraph_indexYes
footnote_textYes

Implementation Reference

  • MCP tool registration for 'add_footnote_to_document' using @mcp.tool() decorator. This is the entrypoint handler called by the MCP server, which delegates execution to the implementation in footnote_tools.
    @mcp.tool()
    def add_footnote_to_document(filename: str, paragraph_index: int, footnote_text: str):
        """Add a footnote to a specific paragraph in a Word document."""
        return footnote_tools.add_footnote_to_document(filename, paragraph_index, footnote_text)
  • Core implementation of the tool logic. This async function adds a footnote to the specified paragraph using python-docx, attempting native footnote addition first and falling back to manual superscript and section creation if needed.
    async def add_footnote_to_document(filename: str, paragraph_index: int, footnote_text: str) -> str:
        """Add a footnote to a specific paragraph in a Word document.
        
        Args:
            filename: Path to the Word document
            paragraph_index: Index of the paragraph to add footnote to (0-based)
            footnote_text: Text content of the footnote
        """
        filename = ensure_docx_extension(filename)
        
        # Ensure paragraph_index is an integer
        try:
            paragraph_index = int(paragraph_index)
        except (ValueError, TypeError):
            return "Invalid parameter: paragraph_index must be an integer"
        
        if not os.path.exists(filename):
            return f"Document {filename} does not exist"
        
        # Check if file is writeable
        is_writeable, error_message = check_file_writeable(filename)
        if not is_writeable:
            return f"Cannot modify document: {error_message}. Consider creating a copy first."
        
        try:
            doc = Document(filename)
            
            # Validate paragraph index
            if paragraph_index < 0 or paragraph_index >= len(doc.paragraphs):
                return f"Invalid paragraph index. Document has {len(doc.paragraphs)} paragraphs (0-{len(doc.paragraphs)-1})."
            
            paragraph = doc.paragraphs[paragraph_index]
            
            # In python-docx, we'd use paragraph.add_footnote(), but we'll use a more robust approach
            try:
                footnote = paragraph.add_run()
                footnote.text = ""
                
                # Create the footnote reference
                reference = footnote.add_footnote(footnote_text)
                
                doc.save(filename)
                return f"Footnote added to paragraph {paragraph_index} in {filename}"
            except AttributeError:
                # Fall back to a simpler approach if direct footnote addition fails
                last_run = paragraph.add_run()
                last_run.text = "¹"  # Unicode superscript 1
                last_run.font.superscript = True
                
                # Add a footnote section at the end if it doesn't exist
                found_footnote_section = False
                for p in doc.paragraphs:
                    if p.text.startswith("Footnotes:"):
                        found_footnote_section = True
                        break
                
                if not found_footnote_section:
                    doc.add_paragraph("\n").add_run()
                    doc.add_paragraph("Footnotes:").bold = True
                
                # Add footnote text
                footnote_para = doc.add_paragraph("¹ " + footnote_text)
                footnote_para.style = "Footnote Text" if "Footnote Text" in doc.styles else "Normal"
                
                doc.save(filename)
                return f"Footnote added to paragraph {paragraph_index} in {filename} (simplified approach)"
        except Exception as e:
            return f"Failed to add footnote: {str(e)}"
  • Re-exports the add_footnote_to_document function from footnote_tools.py for convenient imports in other modules.
    # Footnote tools
    from word_document_server.tools.footnote_tools import (
        add_footnote_to_document, add_endnote_to_document,
        convert_footnotes_to_endnotes_in_document, customize_footnote_style
    )
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'Add a footnote' implies a write/mutation operation, the description doesn't address important behavioral aspects like: whether this modifies the original file or creates a copy, what permissions are required, how errors are handled, or what the response looks like. For a mutation tool with zero annotation coverage, this is a significant gap.

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 a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for what it communicates and is front-loaded with the core functionality.

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

Completeness2/5

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

For a mutation tool with 3 parameters, 0% schema coverage, no annotations, and no output schema, the description is incomplete. It doesn't address behavioral implications, parameter details, error handling, or what happens after the operation. Given the complexity of document editing and the many sibling tools, more context is needed for effective tool selection and use.

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

Parameters2/5

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

With 0% schema description coverage and 3 undocumented parameters, the description provides minimal parameter guidance. It mentions 'specific paragraph' which hints at paragraph_index, and 'footnote' which hints at footnote_text, but doesn't explain what filename expects (path? document name?), how paragraph_index works (0-based? 1-based?), or any constraints on footnote_text. The description doesn't adequately compensate for the complete lack of schema documentation.

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 action ('Add a footnote') and target ('to a specific paragraph in a Word document'), providing a specific verb+resource combination. However, it doesn't explicitly distinguish this tool from its many sibling footnote tools (like add_endnote_to_document, add_footnote_after_text, etc.), which would require more specific differentiation.

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 its many alternatives. With multiple sibling tools for footnotes and related document operations, there's no indication of when this specific 'add_footnote_to_document' is appropriate versus other footnote tools or general document editing tools.

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/GongRzhe/Office-Word-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server