list_available_documents
Retrieve available .docx files from a directory to identify documents for editing or processing in Microsoft Word.
Instructions
List all .docx files in the specified directory.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory | No | . |
Implementation Reference
- Core implementation of the tool: asynchronously lists all .docx files in the specified directory, including their sizes in KB.async def list_available_documents(directory: str = ".") -> str: """List all .docx files in the specified directory. Args: directory: Directory to search for Word documents """ try: if not os.path.exists(directory): return f"Directory {directory} does not exist" docx_files = [f for f in os.listdir(directory) if f.endswith('.docx')] if not docx_files: return f"No Word documents found in {directory}" result = f"Found {len(docx_files)} Word documents in {directory}:\n" for file in docx_files: file_path = os.path.join(directory, file) size = os.path.getsize(file_path) / 1024 # KB result += f"- {file} ({size:.2f} KB)\n" return result except Exception as e: return f"Failed to list documents: {str(e)}"
- word_document_server/main.py:119-122 (registration)Registers the list_available_documents tool with the FastMCP server using the @mcp.tool() decorator, providing a synchronous wrapper around the async implementation.@mcp.tool() def list_available_documents(directory: str = "."): """List all .docx files in the specified directory.""" return document_tools.list_available_documents(directory)