Skip to main content
Glama

read_pdf_pages

Extract text content from specific pages of PDF files using local paths or URLs, with built-in caching for efficient document processing.

Instructions

Read content from PDF file for specified page range.

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

Note: Avoid reading too many pages at once (recommended: <50 pages) to prevent errors.

Args:
    pdf_file_path: Path to the PDF file or URL to PDF
    start_page: Starting page number (default: 1)
    end_page: Ending page number (default: 1)
    
Returns:
    Extracted text content from the specified pages

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_file_pathYes
start_pageNo
end_pageNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The `read_pdf_pages` tool implementation in `pdf_tools_mcp/server.py`. It handles input validation, path resolution (supporting local files and URLs), and delegates text extraction to the `extract_text_from_pdf` helper function.
    @mcp.tool()
    async def read_pdf_pages(pdf_file_path: str, start_page: int = 1, end_page: int = 1) -> str:
        """Read content from PDF file for specified page range.
        
        Supports both local file paths and URLs. For URLs, the PDF will be downloaded
        to a temporary directory and cached for future use.
        
        Note: Avoid reading too many pages at once (recommended: <50 pages) to prevent errors.
    
        Args:
            pdf_file_path: Path to the PDF file or URL to PDF
            start_page: Starting page number (default: 1)
            end_page: Ending page number (default: 1)
            
        Returns:
            Extracted text content from the specified pages
        """
        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)}"
        
        # Warning for large page ranges
        if end_page - start_page > 50:
            warning = "Warning: Reading more than 50 pages at once may cause performance issues or errors.\n"
        else:
            warning = ""
        
        try:
            # Read PDF file
            with open(actual_path, 'rb') as file:
                pdf_content = file.read()
            
            # Extract text using the original function
            result = extract_text_from_pdf(pdf_content, start_page, end_page)
            return warning + result if warning else result
            
        except FileNotFoundError:
            return f"Error: File not found '{actual_path}'"
        except PermissionError:
            return f"Error: No permission to read file '{actual_path}'"
        except Exception as e:
            return f"Error reading PDF file: {str(e)}"
Behavior4/5

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

Since no annotations are provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: support for local paths and URLs, downloading and caching for URLs, and a warning about page limits to prevent errors. This covers operational constraints and side effects, though it could add more on error handling or performance implications.

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 supporting details, usage notes, and parameter explanations. Every sentence adds value, such as the caching behavior and page limit warning, with no redundant or wasted text.

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, no annotations, and an output schema present (which handles return values), the description is complete enough. It covers purpose, usage, behaviors, and parameters, providing sufficient context for an agent to invoke the tool correctly without needing to explain return values explicitly.

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?

With 0% schema description coverage, the description compensates by explaining all three parameters: 'pdf_file_path' as path or URL, 'start_page' and 'end_page' as page numbers with defaults. It adds meaning beyond the bare schema by clarifying URL handling and default values, though it could detail format specifics like URL protocols or page numbering conventions.

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 verb 'read content from PDF file' and specifies the resource 'PDF file for specified page range', making the purpose explicit. It distinguishes from siblings like 'extract_pdf_pages', 'merge_pdfs', and 'search_pdf_content' by focusing on reading text content rather than extraction, merging, or searching operations.

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 when to use this tool: reading content from PDFs with local paths or URLs, and includes a recommendation to avoid reading too many pages (<50). However, it does not explicitly state when not to use it or name specific alternatives among the sibling tools, such as when to choose 'get_pdf_info' for metadata instead.

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