Skip to main content
Glama

add_endnote_to_document

Insert an endnote into a specific paragraph of a Word document by providing the filename, paragraph index, and endnote text. Simplifies document annotation and referencing within Microsoft Word.

Instructions

Add an endnote to a specific paragraph in a Word document.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endnote_textYes
filenameYes
paragraph_indexYes

Implementation Reference

  • The primary handler function implementing the logic to add an endnote reference (dagger symbol) to a specified paragraph and append the endnote text to an 'Endnotes' section at the document end using python-docx.
    async def add_endnote_to_document(filename: str, paragraph_index: int, endnote_text: str) -> str: """Add an endnote to a specific paragraph in a Word document. Args: filename: Path to the Word document paragraph_index: Index of the paragraph to add endnote to (0-based) endnote_text: Text content of the endnote """ 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] # Add endnote reference last_run = paragraph.add_run() last_run.text = "†" # Unicode dagger symbol common for endnotes last_run.font.superscript = True # Check if endnotes section exists, if not create it endnotes_heading_found = False for para in doc.paragraphs: if para.text == "Endnotes:" or para.text == "ENDNOTES": endnotes_heading_found = True break if not endnotes_heading_found: # Add a page break before endnotes section doc.add_page_break() doc.add_heading("Endnotes:", level=1) # Add the endnote text endnote_para = doc.add_paragraph("† " + endnote_text) endnote_para.style = "Endnote Text" if "Endnote Text" in doc.styles else "Normal" doc.save(filename) return f"Endnote added to paragraph {paragraph_index} in {filename}" except Exception as e: return f"Failed to add endnote: {str(e)}"
  • FastMCP tool registration using @mcp.tool() decorator. This wrapper defines the tool's schema (parameters and docstring) for the MCP protocol and delegates execution to the implementation in footnote_tools.add_endnote_to_document.
    @mcp.tool() async def add_endnote_to_document(filename: str, paragraph_index: int, endnote_text: str): """Add an endnote to a specific paragraph in a Word document.""" return await footnote_tools.add_endnote_to_document(filename, paragraph_index, endnote_text)
  • Tool input schema defined by the function signature (filename: str, paragraph_index: int, endnote_text: str) and docstring in the MCP registration wrapper.
    async def add_endnote_to_document(filename: str, paragraph_index: int, endnote_text: str): """Add an endnote to a specific paragraph in a Word document.""" return await footnote_tools.add_endnote_to_document(filename, paragraph_index, endnote_text)

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/franlealp1/mcp-word'

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