Skip to main content
Glama
Sofias-ai

SharePoint MCP Server

by Sofias-ai

Delete_Document

Remove specific documents from SharePoint directories by specifying folder and file names, enabling precise document management and cleanup.

Instructions

Delete a document from a SharePoint directory

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_nameYes
folder_nameYes

Implementation Reference

  • Registration of the 'Delete_Document' tool using the @mcp.tool decorator, specifying the tool name and description.
    @mcp.tool(name="Delete_Document", description="Delete a document from a SharePoint directory")
  • The handler function 'delete_document' that implements the core logic for deleting a SharePoint document. It checks if the file exists, deletes it using the SharePoint CSOM API, and returns success/error responses. Includes input schema via type hints (folder_name: str, file_name: str).
    @_handle_sp_operation
    async def delete_document(folder_name: str, file_name: str):
        """Delete a document from a directory"""
        logger.info(f"Deleting document {file_name} from folder {folder_name}")
        
        # Check if file exists and delete
        file = sp_context.web.get_file_by_server_relative_url(_get_path(folder_name, file_name))
        sp_context.load(file, ["Exists"])
        sp_context.execute_query()
        
        if not file.exists:
            return {"success": False, "message": f"File {file_name} does not exist in folder {folder_name}"}
        
        file.delete_object()
        sp_context.execute_query()
        return {"success": True, "message": f"File {file_name} deleted successfully"}
  • Helper decorator applied to the delete_document handler for standardized SharePoint error handling and logging.
    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 by delete_document to construct the full SharePoint server-relative path for the target document.
    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?

No annotations are provided, so the description carries the full burden of behavioral disclosure. 'Delete' implies a destructive, irreversible mutation, but the description doesn't state whether this requires specific permissions, what happens on success/failure, if there's a confirmation step, or any rate limits. For a destructive tool with zero annotation coverage, 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 that states the core purpose without unnecessary words. It is appropriately sized and front-loaded, with every word earning its place. No structural issues or redundancy are present.

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, 2 parameters with 0% schema coverage, no annotations, and no output schema, the description is incomplete. It lacks critical context like behavioral traits, parameter details, error handling, and output expectations. For a deletion tool, this minimal description poses risks for correct agent invocation.

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

Parameters2/5

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

Schema description coverage is 0%, so the schema provides no parameter descriptions. The description mentions 'document' and 'SharePoint directory', which loosely maps to file_name and folder_name, but adds no details on format (e.g., case sensitivity, path structure), constraints, or examples. With 2 undocumented parameters, the description fails to compensate for the coverage gap.

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 ('a document from a SharePoint directory'), making the purpose immediately understandable. It distinguishes from siblings like Delete_Folder by specifying 'document' rather than 'folder', though it doesn't explicitly contrast them. The description is specific but lacks explicit sibling differentiation for a full score.

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 no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., document must exist), exclusions (e.g., cannot delete system files), or when to choose other tools like Update_Document or Delete_Folder. Without any usage context, the agent must infer when this tool is appropriate.

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