Skip to main content
Glama

get_pdf_info

Extract basic PDF metadata including page count from local files or URLs, with automatic caching for online documents.

Instructions

Get basic information about a PDF file including page count.

Supports both local file paths and URLs. For URLs, the PDF will be downloaded
to a temporary directory and cached for future use.

Args:
    pdf_file_path: Path to the PDF file or URL to PDF
    
Returns:
    Basic information about the PDF file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_file_pathYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The `get_pdf_info` tool handler, which retrieves basic metadata and page count from a PDF file.
    @mcp.tool()
    async def get_pdf_info(pdf_file_path: str) -> str:
        """Get basic information about a PDF file including page count.
        
        Supports both local file paths and URLs. For URLs, the PDF will be downloaded
        to a temporary directory and cached for future use.
    
        Args:
            pdf_file_path: Path to the PDF file or URL to PDF
            
        Returns:
            Basic information about the PDF file
        """
        try:
            # Resolve path (download if URL, validate if local path)
            actual_path = resolve_path(pdf_file_path)
            
            # Validate local path if not URL
            if not is_url(pdf_file_path):
                is_valid, error_msg = validate_path(pdf_file_path)
                if not is_valid:
                    return error_msg
        
        except Exception as e:
            return f"Error resolving path: {str(e)}"
        
        try:
            with open(actual_path, 'rb') as file:
                pdf_reader = PyPDF2.PdfReader(file)
                
                # Get all needed information within the with block
                total_pages = len(pdf_reader.pages)
                info = pdf_reader.metadata
                
                result = "PDF file information:\n"
                result += f"Total pages: {total_pages}\n"
                
                if info:
                    result += f"Title: {info.get('/Title', 'Unknown')}\n"
                    result += f"Author: {info.get('/Author', 'Unknown')}\n"
                    result += f"Creator: {info.get('/Creator', 'Unknown')}\n"
                    result += f"Creation date: {info.get('/CreationDate', 'Unknown')}\n"
                
                return result
            
        except FileNotFoundError:
            return f"Error: File not found '{actual_path}'"
        except Exception as e:
            return f"Error getting PDF information: {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 key behaviors: it's a read-only operation (implied by 'Get'), supports multiple input types, and includes caching for URLs. It could improve by mentioning error handling or performance limits, but covers essential traits well.

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 well-structured and front-loaded with the core purpose, followed by usage details and parameter/return sections. Every sentence adds value without redundancy, making it efficient and easy to parse for an AI agent.

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 low complexity (1 parameter), no annotations, and the presence of an output schema (which handles return values), the description is complete enough. It covers purpose, usage context, parameter semantics, and behavioral traits, leaving no critical gaps for effective tool invocation.

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?

The input schema has 0% description coverage, so the description must compensate. It adds meaningful semantics by explaining that 'pdf_file_path' can be a local path or URL, and clarifies the caching behavior for URLs. This goes beyond the schema's basic type definition, though it could detail format constraints or examples.

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 tool's purpose with a specific verb ('Get') and resource ('basic information about a PDF file'), including the key detail of page count. It distinguishes itself from siblings like 'extract_pdf_pages' or 'search_pdf_content' by focusing on metadata retrieval rather than content manipulation or searching.

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 for usage by specifying it supports both local file paths and URLs, with caching behavior for URLs. However, it does not explicitly state when to use this tool versus alternatives like 'search_pdf_info' or other siblings, leaving some ambiguity in tool selection.

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/lockon-n/pdf-tools-mcp'

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