Skip to main content
Glama
stevereiner
by stevereiner

delete_node

Remove documents or folders from Alfresco content management system by specifying the node ID, with options for permanent deletion or temporary removal.

Instructions

Delete a document or folder from Alfresco.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
node_idYes
permanentNo

Implementation Reference

  • Core handler function implementing the delete_node tool logic: validates input, ensures Alfresco connection, retrieves node info, performs deletion (to trash or permanent), handles errors, and returns formatted confirmation with progress reporting via MCP context.
    async def delete_node_impl(
        node_id: str, 
        permanent: bool = False,
        ctx: Optional[Context] = None
    ) -> str:
        """Delete a document or folder from Alfresco.
        
        Args:
            node_id: Node ID to delete
            permanent: Whether to permanently delete (bypass trash)
            ctx: MCP context for progress reporting
        
        Returns:
            Deletion confirmation
        """
        if ctx:
            delete_type = "permanently delete" if permanent else "move to trash"
            await ctx.info(f"Preparing to {delete_type}: {node_id}")
            await ctx.info("Validating deletion request...")
            await ctx.report_progress(0.1)
        
        if not node_id.strip():
            return safe_format_output("❌ Error: node_id is required")
        
        try:
            await ensure_connection()
            from ...utils.connection import get_client_factory
            
            # Get client factory and create core client (working pattern from test)
            client_factory = await get_client_factory()
            core_client = client_factory.create_core_client()
            
            # Clean the node ID (remove any URL encoding or extra characters)
            clean_node_id = node_id.strip()
            if clean_node_id.startswith('alfresco://'):
                # Extract node ID from URI format
                clean_node_id = clean_node_id.split('/')[-1]
            
            logger.info(f"Attempting to delete node: {clean_node_id}")
            
            if ctx:
                await ctx.report_progress(0.7)
            
            # Get node information first to validate it exists (working pattern from test)
            node_response = core_client.nodes.get(clean_node_id)
            
            if not hasattr(node_response, 'entry'):
                return safe_format_output(f"❌ Failed to get node information for: {clean_node_id}")
            
            node_info = node_response.entry
            filename = getattr(node_info, 'name', f"document_{clean_node_id}")
            
            # Use the working high-level API pattern from test script
            core_client.nodes.delete(clean_node_id)
            
            status = "permanently deleted" if permanent else "moved to trash"
            logger.info(f"✅ Node {status}: {filename}")
            
            if ctx:
                await ctx.report_progress(1.0)
            return safe_format_output(f"""✅ **Deletion Complete**
    
    📄 **Node**: {node_info.name}
    🗑️ **Status**: {status.title()}
    {"⚠️ **WARNING**: This action cannot be undone" if permanent else "ℹ️ **INFO**: Can be restored from trash"}
    
    🆔 **Node ID**: {clean_node_id}""")
            
        except Exception as e:
            error_msg = f"ERROR: Deletion failed: {str(e)}"
            if ctx:
                await ctx.error(error_msg)
            logger.error(f"Deletion failed: {e}")
            return error_msg 
  • Registration of the 'delete_node' MCP tool using FastMCP @mcp.tool decorator. Defines tool name, input parameters (serving as schema: node_id (str), permanent (bool, default False), ctx (Context)), docstring, and delegates to the core implementation delete_node_impl.
    @mcp.tool
    async def delete_node(
        node_id: str, 
        permanent: bool = False,
        ctx: Context = None
    ) -> str:
        """Delete a document or folder from Alfresco."""
        return await delete_node_impl(node_id, permanent, ctx)
  • Input schema inferred from function signature in the registered tool: required node_id (string), optional permanent (boolean, defaults to False indicating move to trash), optional ctx for MCP context.
    async def delete_node(
        node_id: str, 
        permanent: bool = False,
        ctx: Context = None
    ) -> str:
        """Delete a document or folder from Alfresco."""
        return await delete_node_impl(node_id, permanent, ctx)

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/stevereiner/python-alfresco-mcp-server'

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