Skip to main content
Glama
GongRzhe

Office Word MCP Server

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
NameRequiredDescriptionDefault
directoryNo.

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)}"
  • 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)

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/GongRzhe/Office-Word-MCP-Server'

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