list_content_controls
Extract all content controls from a Microsoft Word document to identify editable regions, placeholders, and structured elements for document automation or analysis.
Instructions
List all content controls in a document.
Args: filepath: Path to the document
Returns: Dictionary with list of content controls
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes |
Implementation Reference
- src/docx_mcp/server.py:436-484 (handler)The implementation of the 'list_content_controls' tool, which extracts content controls (tags and titles) from a Word document.
def list_content_controls(filepath: str) -> dict[str, Any]: """ List all content controls in a document. Args: filepath: Path to the document Returns: Dictionary with list of content controls """ logger.info( "Listing content controls", extra={"tool": "list_content_controls", "filepath": filepath}, ) try: doc = safe_open_document(filepath) controls = [] # Find content controls in document for element in doc.element.body: # Look for content control elements sdt_elements = element.xpath(".//w:sdt") for sdt in sdt_elements: # Extract control properties properties = sdt.xpath(".//w:sdtPr") if properties: prop = properties[0] tag_elements = prop.xpath(".//w:tag") title_elements = prop.xpath(".//w:alias") ns_val = ( "{http://schemas.openxmlformats.org/wordprocessingml/" "2006/main}val" ) tag = tag_elements[0].get(ns_val, "") title = title_elements[0].get(ns_val, "") controls.append({ "tag": tag, "title": title, }) return { "status": "success", "filepath": filepath, "content_controls": controls, "count": len(controls), } - src/docx_mcp/server.py:435-435 (registration)The tool is registered using the @app.tool() decorator.
@app.tool()