apply_numbered_list
Add numbered list formatting to specific paragraphs in Word documents. Select paragraphs by index and choose from multiple numbering formats like 1, a, i, I, or A.
Instructions
Apply numbered list formatting to paragraphs.
Args: filepath: Path to the document paragraph_indices: List of paragraph indices to number number_format: Format for numbering ('1', 'a', 'i', 'I', 'A')
Returns: Dictionary with status
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | ||
| paragraph_indices | Yes | ||
| number_format | No | 1 |
Implementation Reference
- src/docx_mcp/server.py:760-813 (handler)The implementation of the apply_numbered_list tool, which applies numbered list formatting to specified paragraphs in a docx document.
@app.tool() def apply_numbered_list( filepath: str, paragraph_indices: list[int], number_format: str = "1", ) -> dict[str, Any]: """ Apply numbered list formatting to paragraphs. Args: filepath: Path to the document paragraph_indices: List of paragraph indices to number number_format: Format for numbering ('1', 'a', 'i', 'I', 'A') Returns: Dictionary with status """ logger.info( "Applying numbered list", extra={"tool": "apply_numbered_list", "filepath": filepath}, ) try: doc = safe_open_document(filepath) # Validate indices for idx in paragraph_indices: if idx < 0 or idx >= len(doc.paragraphs): raise InvalidParameterError("paragraph_indices", f"Index {idx} out of range") # Apply numbered formatting for idx in paragraph_indices: paragraph = doc.paragraphs[idx] paragraph.paragraph_format.left_indent = Inches(0.5) paragraph.style = "List Number" safe_save_document(doc, filepath) logger.info( f"Applied numbered list to {len(paragraph_indices)} paragraphs", extra={"filepath": filepath}, ) return { "status": "success", "filepath": filepath, "paragraphs_updated": len(paragraph_indices), "number_format": number_format, } except DocxMcpError as e: logger.warning(e.message, extra={"tool": "apply_numbered_list", "error_code": e.error_code}) return {"status": "error", "error": e.message, "error_code": e.error_code} except Exception as e: logger.error(f"Unexpected error applying numbered list: {str(e)}") return {"status": "error", "error": str(e)}