Skip to main content
Glama

pdf_extract_text

Read-onlyIdempotent

Extract text from PDF files with page range control for efficient content analysis and data processing.

Instructions

Extract text content from a PDF file. Returns first 10 pages by default to avoid exceeding LLM context limits. Use the 'pages' parameter for specific pages.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the PDF file
pagesNoPage range, e.g. '1-5' or '1,3,5'. Defaults to first 10 pages.

Implementation Reference

  • The `pdf_extract_text` tool is registered and implemented within `src/tools/read.ts`. The implementation validates the input path and file size, determines the page range, extracts the text using a service, and returns the result or an error message.
    server.registerTool(
      "pdf_extract_text",
      {
        description:
          "Extract text content from a PDF file. Returns first 10 pages by default to avoid exceeding LLM context limits. Use the 'pages' parameter for specific pages.",
        inputSchema: z
          .object({
            filePath: z.string().max(4096).describe("Absolute path to the PDF file"),
            pages: z
              .string()
              .max(256)
              .optional()
              .describe(
                "Page range, e.g. '1-5' or '1,3,5'. Defaults to first 10 pages."
              ),
          })
          .strict(),
        annotations: {
          readOnlyHint: true,
          destructiveHint: false,
          idempotentHint: true,
          openWorldHint: false,
        },
      },
      async ({ filePath, pages }) => {
        try {
          const resolvedPath = await validatePdfPath(filePath);
          await validateFileSize(resolvedPath);
    
          const totalPages = await getPdfPageCount(resolvedPath);
    
          let pageIndices: number[];
          let extractedLabel: string;
    
          if (pages) {
            pageIndices = parsePageRange(pages, totalPages);
            extractedLabel = pages;
          } else {
            const count = Math.min(DEFAULT_EXTRACT_PAGES, totalPages);
            pageIndices = Array.from({ length: count }, (_, i) => i);
            extractedLabel = count === 1 ? "1" : `1-${count}`;
          }
    
          const result = await extractPdfText(resolvedPath, pageIndices);
    
          const response: Record<string, unknown> = {
            totalPages,
            extractedPages: extractedLabel,
            pages: result.pages,
          };
    
          if (result.pages.length < totalPages) {
            response.note = `Showing pages ${extractedLabel} of ${totalPages}. Request specific pages for more.`;
          }
    
          return toolSuccess(response);
        } catch (error) {
          return toolError(
            error instanceof Error ? error.message : String(error)
          );
        }
      }
    );
Behavior4/5

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

Annotations declare readOnlyHint=true and idempotentHint=true; the description adds crucial behavioral context about the 10-page default limit and its rationale (LLM context limits), which is not inferable from the annotations. No contradictions with annotations.

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?

Two sentences efficiently structured: first states purpose, second explains default behavior and parameter usage. Every sentence earns its place with zero redundancy or filler.

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

Completeness4/5

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

Appropriately complete for a read-only extraction tool with good annotations and full schema coverage. Mentions return behavior (first 10 pages) despite lacking an output schema. Minor gap: could mention output format (plain text) or handling of image-based PDFs.

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?

With 100% schema description coverage, the schema already fully documents both filePath and pages parameters. The description adds usage guidance for the pages parameter but does not add semantic meaning (syntax, format examples) beyond what the schema already provides, warranting the baseline score.

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 opens with a specific verb ('Extract') and resource ('text content from a PDF file'), clearly distinguishing this from siblings like pdf_create, pdf_add_watermark, or pdf_get_metadata which handle creation, modification, or metadata rather than text extraction.

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?

Provides clear context about the default 10-page limitation to avoid LLM context limits and explicitly states when to use the 'pages' parameter ('for specific pages'). However, it lacks explicit guidance on when to choose this over alternatives like pdf_get_metadata or error handling for encrypted files.

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/AryanBV/pdf-toolkit-mcp'

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