Skip to main content
Glama

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

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