Skip to main content
Glama
Sofias-ai

SharePoint MCP Server

by Sofias-ai

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
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the folder must be empty, which is a critical constraint, but fails to address permissions, irreversibility, error handling, or response format. For a destructive operation, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste—it states the action, resource, and key constraint directly. It's appropriately sized and front-loaded, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's destructive nature, lack of annotations, no output schema, and 0% schema coverage, the description is incomplete. It misses critical details like permissions, error cases, and return values, which are essential for safe and effective use in a SharePoint context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate, but it adds no parameter details beyond what's implied by the tool name. The single parameter 'folder_path' is undocumented in both schema and description, leaving its format and semantics unclear. Baseline 3 is given as it minimally meets expectations without adding value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Delete') and resource ('an empty folder from SharePoint'), making the purpose immediately understandable. It distinguishes from siblings like Delete_Document by specifying folder deletion, though it doesn't explicitly contrast with all alternatives.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal guidance—it specifies the folder must be empty, but offers no explicit when-to-use rules, prerequisites, or comparisons to alternatives like Delete_Document. This leaves the agent with insufficient context for optimal tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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