Skip to main content
Glama
pablontiv
by pablontiv

validate_pdf

Check PDF file integrity and readability by validating its structure and content. Ensure accurate processing and extraction of data using the PDF Reader MCP Server.

Instructions

Validate PDF file integrity and readability

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the PDF file to validate

Implementation Reference

  • The main handler function for the 'validate_pdf' tool. It parses the input arguments using the Zod schema, creates a PDFProcessor instance, and calls its validatePDF method to perform the validation.
    export async function handleValidatePDF(args: unknown): Promise<ValidationResult> { try { const params = ValidatePDFParamsSchema.parse(args); const processor = new PDFProcessor(); return await processor.validatePDF(params.file_path); } catch (error) { const mcpError = handleError(error, typeof args === 'object' && args !== null && 'file_path' in args ? String(args.file_path) : undefined); throw new Error(JSON.stringify(mcpError)); } }
  • src/index.ts:39-46 (registration)
    Registration of the validatePDFTool in the MCP server's list tools response handler.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ extractTextTool, extractMetadataTool, extractPagesTool, validatePDFTool, ], }));
  • src/index.ts:83-91 (registration)
    Registration of the 'validate_pdf' tool call handler in the MCP server's call tool request handler, which invokes handleValidatePDF.
    case 'validate_pdf': return { content: [ { type: 'text', text: JSON.stringify(await handleValidatePDF(args), null, 2), }, ], };
  • Zod schema for validating the input parameters of the validate_pdf tool (file_path).
    export const ValidatePDFParamsSchema = z.object({ file_path: filePathValidation });
  • Core validation logic delegated to by the tool handler. Performs file validation, PDF parsing, and returns detailed ValidationResult.
    async validatePDF(filePath: string): Promise<ValidationResult> { try { await validatePDFFile(filePath); const buffer = await fs.readFile(filePath); const stats = await fs.stat(filePath); const pdfData = await withTimeout( pdf(buffer), this.config.processingTimeout ); return { is_valid: true, pdf_version: pdfData.version || '1.4', is_encrypted: false, // pdf-parse can handle basic PDFs is_readable: true, page_count: pdfData.numpages, file_size_bytes: stats.size }; } catch (error) { const stats = await fs.stat(filePath).catch(() => ({ size: 0 })); return { is_valid: false, is_encrypted: false, is_readable: false, error_message: error instanceof Error ? error.message : 'Unknown error', file_size_bytes: stats.size }; } }

Other Tools

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

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