Skip to main content
Glama
marc-hanheide

PDF Redaction MCP Server

close_pdf

Release system resources by closing a loaded PDF file after completing redaction tasks in the PDF Redaction MCP Server.

Instructions

Close a loaded PDF and free its resources.

Args: pdf_path: Path to the PDF file to close ctx: MCP context for logging

Returns: Confirmation message

Raises: ToolError: If the PDF is not loaded

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYesPath to the PDF file to close

Implementation Reference

  • The handler function for the 'close_pdf' tool. It takes a PDF path, checks if it's loaded, closes the fitz.Document, removes it from the global _loaded_pdfs dictionary, clears associated redactions tracking, logs the action, and returns a success message. Raises ToolError if not loaded or on failure.
    @mcp.tool
    async def close_pdf(
        pdf_path: Annotated[str, Field(description="Path to the PDF file to close")],
        ctx: Context = None
    ) -> str:
        """Close a loaded PDF and free its resources.
        
        Args:
            pdf_path: Path to the PDF file to close
            ctx: MCP context for logging
            
        Returns:
            Confirmation message
            
        Raises:
            ToolError: If the PDF is not loaded
        """
        try:
            path = Path(pdf_path).resolve()
            path_str = str(path)
            
            if path_str not in _loaded_pdfs:
                raise ToolError(f"PDF not loaded: {path}")
            
            # Close the document
            _loaded_pdfs[path_str].close()
            del _loaded_pdfs[path_str]
            
            # Also clear redaction tracking for this PDF
            if path_str in _applied_redactions:
                del _applied_redactions[path_str]
            
            await ctx.info(f"Closed PDF: {path}")
            
            return f"Successfully closed PDF: {path}"
            
        except ToolError:
            raise
        except Exception as e:
            await ctx.error(f"Failed to close PDF: {str(e)}")
            raise ToolError(f"Failed to close PDF: {str(e)}")

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/marc-hanheide/redact_mcp'

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