Skip to main content
Glama

read_pdf_pages

Extract text from a PDF by specifying a page range. Provide the file path and start page; optionally set an end page. Returns the text content from those pages.

Instructions

Extract text from specific pages or page range in a PDF

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the PDF file
startPageYesStarting page number (1-indexed)
endPageNoEnding page number (optional, defaults to startPage)

Implementation Reference

  • src/index.ts:56-77 (registration)
    Tool registration: defines the 'read_pdf_pages' tool with input schema requiring filePath and startPage, with optional endPage.
    {
      name: 'read_pdf_pages',
      description: 'Extract text from specific pages or page range in a PDF',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Absolute path to the PDF file',
          },
          startPage: {
            type: 'number',
            description: 'Starting page number (1-indexed)',
          },
          endPage: {
            type: 'number',
            description: 'Ending page number (optional, defaults to startPage)',
          },
        },
        required: ['filePath', 'startPage'],
      },
    },
  • Handler: dispatches the 'read_pdf_pages' tool call, constructs a PageRange from args, and delegates to extractTextFromPages() from pdf-tools.ts.
    case 'read_pdf_pages': {
      const { filePath, startPage, endPage } = args as {
        filePath: string;
        startPage: number;
        endPage?: number;
      };
      
      const pageRange: PageRange = {
        start: startPage,
        end: endPage ?? undefined,
      };
      
      const text = await extractTextFromPages(filePath, pageRange);
      
      return {
        content: [
          {
            type: 'text',
            text,
          },
        ],
      };
    }
  • Helper function that performs the actual PDF page text extraction using PDFParse, reading specified pages by number range.
    export async function extractTextFromPages(
      filePath: string,
      pageRange: PageRange
    ): Promise<string> {
      try {
        const dataBuffer = await fs.readFile(filePath);
        const parser = new PDFParse({ data: dataBuffer });
        
        // Get text from specific pages
        const start = pageRange.start;
        const end = pageRange.end || pageRange.start;
        
        // Create array of page numbers
        const pages: number[] = [];
        for (let i = start; i <= end; i++) {
          pages.push(i);
        }
        
        const result = await parser.getText({ partial: pages });
        await parser.destroy();
        
        return result.text;
      } catch (error) {
        throw new Error(`Failed to extract pages: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • Schema: PageRange type defining start and optional end page numbers used by the extractTextFromPages function.
    export interface PageRange {
      start: number;
      end?: number | undefined;
    }
Behavior2/5

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

No annotations provided. Description does not disclose how invalid page numbers are handled, whether images are excluded, or any side effects. Minimal behavioral context.

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?

Single, clear sentence that is front-loaded and concise. Could be slightly expanded for context but adequate for a simple tool.

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?

No output schema or description of return format. Does not explain error handling or boundary conditions for pages. Incomplete for a tool with 3 parameters.

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 coverage is 100%, so parameters are described in the schema. The description adds no extra meaning beyond the schema, meeting 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?

Description clearly states the action (extract text) and scope (specific pages or page range). It distinguishes from sibling 'read_pdf' which likely reads entire PDF.

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?

No explicit guidance on when to use vs alternatives like 'read_pdf' or 'search_pdf'. No mention of limitations or prerequisites.

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

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