Skip to main content
Glama

read_pdf

Extract all text from a PDF file by specifying its absolute path. Optionally include PDF metadata. Solves the need to get text content from PDF documents.

Instructions

Extract all text content from a PDF file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesAbsolute path to the PDF file
includeMetadataNoWhether to include PDF metadata in the response

Implementation Reference

  • The core handler function 'extractTextFromPDF' that reads a PDF file and extracts all text content along with metadata (title, author, subject, etc.) and page count. This is the actual implementation called when 'read_pdf' is invoked.
    export async function extractTextFromPDF(filePath: string): Promise<PDFExtractionResult> {
      try {
        const dataBuffer = await fs.readFile(filePath);
        const parser = new PDFParse({ data: dataBuffer });
        const textResult = await parser.getText();
        const infoResult = await parser.getInfo();
        await parser.destroy();
    
        const metadata: PDFMetadata = {
          title: infoResult.info?.Title,
          author: infoResult.info?.Author,
          subject: infoResult.info?.Subject,
          creator: infoResult.info?.Creator,
          producer: infoResult.info?.Producer,
          creationDate: infoResult.info?.CreationDate,
          modificationDate: infoResult.info?.ModDate,
          keywords: infoResult.info?.Keywords,
          totalPages: infoResult.total,
        };
    
        return {
          text: textResult.text,
          metadata,
          pageCount: infoResult.total,
        };
      } catch (error) {
        throw new Error(`Failed to read PDF: ${error instanceof Error ? error.message : String(error)}`);
      }
    }
  • The PDFExtractionResult interface defines the return type of the read_pdf handler, containing text, optional metadata, and pageCount.
    export interface PDFExtractionResult {
      text: string;
      metadata?: PDFMetadata;
      pageCount: number;
    }
  • src/index.ts:22-41 (registration)
    Tool registration definition for 'read_pdf' in the TOOLS array, including its name, description, and inputSchema (filePath required, includeMetadata optional).
    const TOOLS: Tool[] = [
      {
        name: 'read_pdf',
        description: 'Extract all text content from a PDF file',
        inputSchema: {
          type: 'object',
          properties: {
            filePath: {
              type: 'string',
              description: 'Absolute path to the PDF file',
            },
            includeMetadata: {
              type: 'boolean',
              description: 'Whether to include PDF metadata in the response',
              default: false,
            },
          },
          required: ['filePath'],
        },
      },
  • The CallToolRequestSchema handler case for 'read_pdf' in the main server - dispatches to extractTextFromPDF and formats the response based on includeMetadata flag.
    case 'read_pdf': {
      const { filePath, includeMetadata } = args as {
        filePath: string;
        includeMetadata?: boolean;
      };
      
      const result = await extractTextFromPDF(filePath);
      
      if (includeMetadata) {
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      }
      
      return {
        content: [
          {
            type: 'text',
            text: result.text,
          },
        ],
      };
    }
  • The PDFMetadata interface defines the metadata structure returned as part of the read_pdf result.
    export interface PDFMetadata {
      title?: string;
      author?: string;
      subject?: string;
      creator?: string;
      producer?: string;
      creationDate?: string;
      modificationDate?: string;
      keywords?: string;
      totalPages?: number;
    }
Behavior2/5

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

No annotations are provided, so the description must carry behavioral disclosure. It only states 'extract', implying a read operation, but does not mention potential pitfalls (e.g., large files, access rights) or that it reads the entire file.

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 a single, front-loaded sentence without any superfluous information. Every word earns its place.

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?

With no output schema and no annotations, the description omits crucial context like return format, error handling, behavior with large files, or whether metadata can be included. Two parameters are documented but the tool's overall behavior is underspecified.

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?

Input schema has 100% coverage with clear descriptions for both parameters. The description adds no additional meaning beyond what the schema already provides, meeting the 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?

The description 'Extract all text content from a PDF file' clearly states the verb (extract), resource (PDF text), and scope (all), distinguishing it from sibling tools like extract_pdf_image or get_pdf_metadata.

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 guidance on when to use this tool versus alternatives like read_pdf_pages or search_pdf. The description lacks when-not scenarios or alternative suggestions.

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