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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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)}")
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It discloses that the tool frees resources and can raise a ToolError if the PDF is not loaded, which are useful behavioral traits. However, it lacks details on permissions, side effects, or rate limits that would be beneficial for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded with the main purpose. The structured sections (Args, Returns, Raises) are clear, but the repetition of parameter info in 'Args' slightly reduces efficiency, though it remains concise overall.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a simple close operation), no annotations, and the presence of an output schema, the description is fairly complete. It covers purpose, parameters, returns, and error conditions, though it could benefit from more behavioral context like resource management details.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents the 'pdf_path' parameter. The description repeats this information in the 'Args' section but does not add significant meaning beyond what the schema provides, such as format examples or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Close a loaded PDF') and resource ('free its resources'), distinguishing it from sibling tools like 'list_loaded_pdfs' or 'load_pdf'. It explicitly identifies what the tool does without being tautological.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying 'a loaded PDF' and mentioning the 'Raises' condition, which indicates when not to use it (if PDF is not loaded). However, it does not explicitly name alternatives or provide detailed exclusions beyond the error case.

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

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