Skip to main content
Glama

Delete_Folder

Remove empty folders from SharePoint by specifying the folder path using the MCP server integration, streamlining document and folder management.

Instructions

Delete an empty folder from SharePoint

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
folder_pathYes

Implementation Reference

  • Registers the Delete_Folder tool using the @mcp.tool decorator.
    @mcp.tool(name="Delete_Folder", description="Delete an empty folder from SharePoint")
  • The main handler function for the Delete_Folder tool. It checks if the folder exists and is empty before deleting it using SharePoint API.
    async def delete_folder(folder_path: str): """Delete an empty folder from SharePoint""" logger.info(f"Deleting folder: {folder_path}") # Get folder and check if it exists and is empty full_path = _get_path(folder_path) folder = sp_context.web.get_folder_by_server_relative_url(full_path) sp_context.load(folder) sp_context.load(folder.files) sp_context.load(folder.folders) sp_context.execute_query() if not hasattr(folder, 'exists') or not folder.exists: return {"success": False, "message": f"Folder '{folder_path}' does not exist"} if len(folder.files) > 0: return {"success": False, "message": f"Folder contains {len(folder.files)} files"} if len(folder.folders) > 0: return {"success": False, "message": f"Folder contains {len(folder.folders)} subfolders"} # Delete the empty folder folder.delete_object() sp_context.execute_query() return {"success": True, "message": f"Folder '{folder_path}' deleted successfully"}
  • Helper decorator applied to the handler for error handling in SharePoint operations.
    def _handle_sp_operation(func): """Decorator for SharePoint operations with error handling""" @wraps(func) async def wrapper(*args, **kwargs): try: return await func(*args, **kwargs) except Exception as e: logger.error(f"Error in {func.__name__}: {str(e)}") return {"success": False, "message": f"Operation failed: {str(e)}"} return wrapper
  • Helper function used to construct the full SharePoint path for the folder.
    def _get_path(folder: str = "", file: Optional[str] = None) -> str: """Construct SharePoint path from components""" path = f"{SHP_DOC_LIBRARY}/{folder}".rstrip('/') return f"{path}/{file}" if file else path

Other Tools

Related Tools

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/Sofias-ai/mcp-sharepoint'

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