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 operations, freeing memory and preventing file lock issues.

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 closes the specified loaded PDF document, removes it from the in-memory store, clears associated redaction tracking, and logs the action. The function signature provides input validation schema via Annotated types. The @mcp.tool decorator registers it as an MCP tool.
    @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