set_document_properties
Set metadata like title, author, and keywords in Microsoft Word documents to organize and identify files effectively.
Instructions
Set document properties and metadata.
Args: filepath: Path to the document title: Document title subject: Document subject author: Document author keywords: Document keywords comments: Document comments
Returns: Dictionary with status
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filepath | Yes | ||
| title | No | ||
| subject | No | ||
| author | No | ||
| keywords | No | ||
| comments | No |
Implementation Reference
- src/docx_mcp/server.py:541-597 (handler)The set_document_properties tool handler function is registered with @app.tool() and manages the updating of core document properties using the python-docx library.
@app.tool() def set_document_properties( filepath: str, title: Optional[str] = None, subject: Optional[str] = None, author: Optional[str] = None, keywords: Optional[str] = None, comments: Optional[str] = None, ) -> dict[str, Any]: """ Set document properties and metadata. Args: filepath: Path to the document title: Document title subject: Document subject author: Document author keywords: Document keywords comments: Document comments Returns: Dictionary with status """ logger.info( "Setting document properties", extra={"tool": "set_document_properties", "filepath": filepath}, ) try: doc = safe_open_document(filepath) props = doc.core_properties if title is not None: props.title = title if subject is not None: props.subject = subject if author is not None: props.author = author if keywords is not None: props.keywords = keywords if comments is not None: props.comments = comments safe_save_document(doc, filepath) logger.info("Document properties updated", extra={"filepath": filepath}) return { "status": "success", "filepath": filepath, "message": "Document properties updated", } except DocxMcpError as e: logger.warning( e.message, extra={"tool": "set_document_properties", "error_code": e.error_code}, ) return {"status": "error", "error": e.message, "error_code": e.error_code}