Skip to main content
Glama

list_folders

Retrieve all email folders to organize and manage messages within the Mail MCP Server.

Instructions

List all email folders

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The list_folders method in FolderManager handles the IMAP list command to retrieve folders.
    def list_folders(self, directory: str = "", pattern: str = "*") -> list[str]:
        """
        List all folders matching the pattern.
    
        Uses IMAP LIST command to retrieve all mailboxes.
    
        Args:
            directory: Directory prefix (e.g., 'INBOX')
            pattern: Mailbox pattern (default '*' matches all)
    
        Returns:
            List of folder names
    
        Raises:
            FolderError: If the operation fails
    
        Example:
            >>> folders = manager.list_folders()
            >>> print(folders)
            ['INBOX', 'INBOX/Sent', 'INBOX/Drafts', 'Archive']
        """
        try:
            response = self._conn.list(directory, pattern)
    
            # 检查状态 (可能是 'OK' 或 b'OK')
            status = response[0]
            if status not in ("OK", b"OK"):
                error_msg = (
                    response[1][0].decode("utf-8", errors="replace")
                    if response[1]
                    else "Unknown error"
                )
                raise FolderError(f"Failed to list folders: {error_msg}")
    
            return self._parse_folder_list(response)
    
        except Exception as e:
            if isinstance(e, FolderError):
                raise
            raise FolderError(f"Failed to list folders: {str(e)}")

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/AdJIa/mail-mcp-server'

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