Skip to main content
Glama
pietermyb

mcp-pdf-reader

open-pdf

Open PDF files from specified paths to enable reading and processing of document content within the MCP server environment.

Instructions

Open a PDF file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath to the PDF file

Implementation Reference

  • Handler for the 'open-pdf' tool: validates the PDF path, opens it with PyPDF2.PdfReader, generates a unique PDF ID, stores the reader and path in global dictionaries, notifies clients of resource changes, and returns a success message with PDF details.
    if name == "open-pdf":
        path = arguments.get("path")
        if not path:
            raise ValueError("Missing path")
    
        # Validate that the file exists and is a PDF
        if not os.path.exists(path):
            raise ValueError(f"File not found: {path}")
    
        try:
            # Try to open as PDF
            reader = PyPDF2.PdfReader(path)
    
            # Generate a unique ID
            pdf_id = base64.urlsafe_b64encode(os.path.abspath(path).encode()).decode()[:12]
    
            # Store the reader and path
            pdfs[pdf_id] = reader
            pdf_paths[pdf_id] = path
    
            # Notify clients that resources have changed
            await server.request_context.session.send_resource_list_changed()
    
            return [
                types.TextContent(
                    type="text",
                    text=f"Opened PDF '{os.path.basename(path)}' with {len(reader.pages)} pages. PDF ID: {pdf_id}",
                )
            ]
        except Exception as e:
            raise ValueError(f"Failed to open PDF: {str(e)}")
  • Registration of the 'open-pdf' tool in the handle_list_tools function, defining the tool name, description, and input schema requiring a 'path' parameter.
    types.Tool(
        name="open-pdf",
        description="Open a PDF file",
        inputSchema={
            "type": "object",
            "properties": {
                "path": {"type": "string", "description": "Path to the PDF file"},
            },
            "required": ["path"],
        },
    ),
  • JSON Schema for the 'open-pdf' tool input: requires a 'path' string parameter.
    inputSchema={
        "type": "object",
        "properties": {
            "path": {"type": "string", "description": "Path to the PDF file"},
        },
        "required": ["path"],
    },
  • Global state storage for opened PDFs: dictionaries holding PdfReader objects and file paths by PDF ID, used by the open-pdf handler.
    # Store opened PDF documents
    pdfs: Dict[str, PyPDF2.PdfReader] = {}
    pdf_paths: Dict[str, str] = {}  # Map of PDF IDs to their file paths
Behavior2/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. 'Open a PDF file' implies a read operation but lacks details on what 'open' entails—whether it loads the file into memory, displays it, returns a handle, or has side effects like locking the file. It doesn't address permissions, error handling, or performance considerations. While it hints at a non-destructive action, the description is too vague to provide meaningful behavioral context beyond the basic verb.

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 'Open a PDF file' is extremely concise—a single, front-loaded sentence with zero wasted words. It directly communicates the core action without unnecessary elaboration, making it easy for an agent to parse quickly. This efficiency is ideal for a simple tool, though it may trade off detail for brevity.

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

Completeness2/5

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

Given the tool's simplicity (1 parameter, no output schema, no annotations), the description is incomplete. It doesn't explain what happens after opening (e.g., returns a file handle, triggers a viewer) or address potential complexities like file format validation or error cases. While conciseness is high, the lack of behavioral and usage context makes it inadequate for an agent to fully understand the tool's role, especially with siblings available for related operations.

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?

The input schema has 100% description coverage, with the 'path' parameter fully documented in the schema. The description adds no additional semantic information about the parameter, such as path format examples (e.g., relative vs. absolute) or constraints. Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description doesn't compensate but also doesn't detract from the schema's clarity.

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

Purpose4/5

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

The description 'Open a PDF file' clearly states the action (open) and resource (PDF file), making the purpose immediately understandable. It doesn't explicitly differentiate from siblings like 'close-pdf' or 'get-pdf-page-text', but the verb 'open' implies initialization or access rather than closing or extraction, providing some implicit distinction. However, it lacks the specificity needed for a perfect score, such as clarifying what 'open' means in this context (e.g., loading for viewing vs. processing).

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., file must exist), exclusions (e.g., not for editing), or comparisons to siblings like 'pdf-to-text' for text extraction or 'get-pdf-page-count' for metadata. This leaves the agent to infer usage from the tool name alone, which is insufficient for effective tool selection in a multi-tool environment.

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/pietermyb/mcp-pdf-reader'

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