Skip to main content
Glama
marc-hanheide

PDF Redaction MCP Server

save_redacted_pdf

Apply redaction annotations to PDF documents and save the redacted version to a new file with '_redacted' appended to the original filename or a custom output path.

Instructions

Apply all redactions and save the redacted PDF.

This tool applies all pending redaction annotations to the PDF and saves it. By default, it saves to a new file with '_redacted' appended to the original filename.

Args: pdf_path: Path to the PDF file (must be already loaded) output_path: Optional custom output path. If not provided, saves as '<original_name>_redacted.pdf' ctx: MCP context for logging

Returns: Path to the saved redacted PDF

Raises: ToolError: If the PDF is not loaded or save fails

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYesPath to the loaded PDF file
output_pathNoOptional output path. If not provided, appends '_redacted' to the original filename

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function decorated with @mcp.tool that implements the save_redacted_pdf tool. It applies all pending redaction annotations to the loaded PDF document and saves it to a new file, either at a specified output_path or by appending '_redacted' to the original filename.
    @mcp.tool
    async def save_redacted_pdf(
        pdf_path: Annotated[str, Field(description="Path to the loaded PDF file")],
        output_path: Annotated[str | None, Field(
            description="Optional output path. If not provided, appends '_redacted' to the original filename"
        )] = None,
        ctx: Context = None
    ) -> str:
        """Apply all redactions and save the redacted PDF.
        
        This tool applies all pending redaction annotations to the PDF and saves it.
        By default, it saves to a new file with '_redacted' appended to the original
        filename.
        
        Args:
            pdf_path: Path to the PDF file (must be already loaded)
            output_path: Optional custom output path. If not provided, saves as
                        '<original_name>_redacted.pdf'
            ctx: MCP context for logging
            
        Returns:
            Path to the saved redacted PDF
            
        Raises:
            ToolError: If the PDF is not loaded or save fails
        """
        try:
            path = Path(pdf_path).resolve()
            path_str = str(path)
            
            await ctx.info(f"Saving redacted PDF: {path}")
            
            # Check if PDF is loaded
            if path_str not in _loaded_pdfs:
                raise ToolError(
                    f"PDF not loaded. Please load it first using load_pdf: {path}"
                )
            
            doc = _loaded_pdfs[path_str]
            
            # Determine output path
            if output_path:
                out_path = Path(output_path).resolve()
            else:
                # Append '_redacted' to the original filename
                out_path = path.parent / f"{path.stem}_redacted{path.suffix}"
            
            # Count total redactions before applying
            total_redactions = 0
            for page in doc:
                # Apply redactions on this page
                redact_count = page.apply_redactions()
                if redact_count:
                    total_redactions += 1  # Note: apply_redactions returns True if any were applied
            
            # Save the document
            doc.save(str(out_path))
            
            await ctx.info(f"Saved redacted PDF to: {out_path}")
            
            return (
                f"Successfully applied redactions and saved to: {out_path}\n"
                f"Redactions applied on {total_redactions} page(s)."
            )
            
        except ToolError:
            raise
        except Exception as e:
            await ctx.error(f"Failed to save redacted PDF: {str(e)}")
            raise ToolError(f"Failed to save redacted PDF: {str(e)}")
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes the mutation behavior ('apply all redactions and save'), default file naming convention, error conditions ('PDF not loaded or save fails'), and return value. However, it doesn't mention side effects like whether the original PDF is modified or if redactions are cleared after saving.

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

Conciseness5/5

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

The description is perfectly structured and front-loaded: the first sentence states the core purpose, followed by elaboration, parameter details, return value, and error handling. Every sentence adds value with zero redundancy, making it efficient and easy to parse.

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

Completeness5/5

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

Given the tool's moderate complexity (applying redactions and saving), no annotations, but a complete input schema (100% coverage) and an output schema (implied by 'Returns'), the description is fully adequate. It covers purpose, usage, parameters, returns, and errors, leaving no gaps for the agent to understand and invoke the tool correctly.

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

Parameters4/5

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

Schema description coverage is 100%, so the baseline is 3. The description adds meaningful context beyond the schema: it clarifies that 'pdf_path' refers to an 'already loaded' PDF (implying a prerequisite), explains the default naming convention for 'output_path' in more detail, and mentions 'ctx' as a logging context (though not in the schema). This extra semantic value justifies a score above baseline.

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 ('apply all redactions and save') and resource ('the redacted PDF'), distinguishing it from siblings like 'redact_area' or 'redact_text' which only create redactions, and 'list_applied_redactions' which only lists them. The verb+resource combination is precise and unambiguous.

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 provides clear context about when to use this tool ('apply all pending redaction annotations') and mentions prerequisites ('PDF must be already loaded'), but does not explicitly state when not to use it or name specific alternatives among the siblings. The context is helpful but lacks explicit exclusion guidance.

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