Skip to main content
Glama
Theorhd
by Theorhd

read_pdf

Extract text content from PDF files stored on disk. Provide the file path to retrieve readable text from PDF documents.

Instructions

Read a PDF file from disk and return its text content

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesAbsolute or relative path to the PDF file

Implementation Reference

  • Handler for the 'read_pdf' tool that validates the file path, reads the PDF file, parses it using the 'pdf-parse' library, and returns the extracted text content.
    case "read_pdf": {
      const { file_path } = args as any;
    
      if (!file_path || typeof file_path !== 'string') {
        throw new Error('file_path is required and must be a string');
      }
    
      const resolvedPath = path.resolve(file_path);
    
      const isAllowed = ALLOWED_DIRS.some(allowedDir => resolvedPath.startsWith(path.resolve(allowedDir)));
      if (!isAllowed) {
        throw new Error(`file_path must be inside allowed directories: ${ALLOWED_DIRS.join(', ')}`);
      }
    
      const data = await fs.readFile(resolvedPath);
        let pdfParse: any;
        try {
          const require = createRequire(import.meta.url);
          pdfParse = require('pdf-parse');
      } catch (e) {
        throw new Error('Dependency "pdf-parse" is not installed. Please run `npm install pdf-parse` in pdftools-mcp');
      }
    
      const parsed: any = await pdfParse(data);
    
      return {
        content: [
          {
            type: 'text',
            text: parsed.text || ''
          }
        ]
      };
    }
  • index.ts:159-172 (registration)
    Registration of the 'read_pdf' tool in the tools list, including name, description, and input schema definition.
    {
      name: "read_pdf",
      description: "Read a PDF file from disk and return its text content",
      inputSchema: {
        type: "object",
        properties: {
          file_path: {
            type: "string",
            description: "Absolute or relative path to the PDF file"
          }
        },
        required: ["file_path"]
      }
    }
  • Input schema for the 'read_pdf' tool defining the required 'file_path' parameter.
    inputSchema: {
      type: "object",
      properties: {
        file_path: {
          type: "string",
          description: "Absolute or relative path to the PDF file"
        }
      },
      required: ["file_path"]
    }
  • TypeScript type definitions for the 'pdf-parse' library used in the read_pdf handler.
    declare module 'pdf-parse' {
      import { Buffer } from 'buffer';
    
      export default function pdfParse(data: Buffer | Uint8Array | string): Promise<{
        numpages?: number;
        numrender?: number;
        info?: any;
        metadata?: any;
        version?: string;
        text: string;
        textAsHtml?: string;
      }>;
    }
Behavior2/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 states the tool reads from disk and returns text content, but doesn't mention error handling (e.g., what happens if the file doesn't exist or isn't a PDF), performance characteristics, or any limitations (e.g., file size constraints, text extraction accuracy). This leaves significant gaps for a tool that interacts with the filesystem.

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, efficient sentence that states exactly what the tool does. It's front-loaded with the core action and includes the key details (source and output). There's no wasted language or unnecessary elaboration.

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

Completeness3/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 (filesystem interaction, PDF parsing) and lack of annotations/output schema, the description is minimally adequate. It covers the basic operation but lacks details about error conditions, performance, or output format beyond 'text content'. For a tool with no structured safety or output information, more behavioral context would be helpful.

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 description coverage is 100%, so the schema already fully documents the single parameter 'file_path'. The description doesn't add any parameter-specific information beyond what's in the schema. According to the rules, with high schema coverage, the baseline is 3 even with no param info in the description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/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 specific verb ('Read') and resource ('PDF file'), and specifies what it returns ('text content'). It doesn't explicitly distinguish from sibling tools, which are all PDF generators rather than readers, so it's clear but lacks explicit sibling differentiation.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling tools (all PDF generators) or any other context for usage decisions. The agent must infer usage from the tool name and description alone.

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/Theorhd/Pdftools-mcp'

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