get_pdf_metadata
Retrieve the title, author, creation date, and other metadata from a PDF file by providing its absolute path.
Instructions
Extract metadata information from a PDF file (title, author, creation date, etc.)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Absolute path to the PDF file |
Implementation Reference
- src/index.ts:42-55 (registration)Tool registration: defines the 'get_pdf_metadata' tool with name, description, and inputSchema (accepts filePath).
{ name: 'get_pdf_metadata', description: 'Extract metadata information from a PDF file (title, author, creation date, etc.)', inputSchema: { type: 'object', properties: { filePath: { type: 'string', description: 'Absolute path to the PDF file', }, }, required: ['filePath'], }, }, - src/index.ts:204-216 (handler)Tool handler: when 'get_pdf_metadata' is called, it extracts filePath, calls extractMetadata(filePath), and returns the metadata as JSON.
case 'get_pdf_metadata': { const { filePath } = args as { filePath: string }; const metadata = await extractMetadata(filePath); return { content: [ { type: 'text', text: JSON.stringify(metadata, null, 2), }, ], }; } - src/pdf-tools.ts:42-63 (helper)The actual implementation: extractMetadata() reads the PDF file, parses it with PDFParse, extracts metadata (title, author, subject, creator, producer, creationDate, modificationDate, keywords, totalPages), and returns it.
export async function extractMetadata(filePath: string): Promise<PDFMetadata> { try { const dataBuffer = await fs.readFile(filePath); const parser = new PDFParse({ data: dataBuffer }); const result = await parser.getInfo(); await parser.destroy(); return { title: result.info?.Title, author: result.info?.Author, subject: result.info?.Subject, creator: result.info?.Creator, producer: result.info?.Producer, creationDate: result.info?.CreationDate, modificationDate: result.info?.ModDate, keywords: result.info?.Keywords, totalPages: result.total, }; } catch (error) { throw new Error(`Failed to extract metadata: ${error instanceof Error ? error.message : String(error)}`); } } - src/types.ts:4-14 (schema)Type definition: PDFMetadata interface defines the shape of the metadata returned by the tool.
export interface PDFMetadata { title?: string; author?: string; subject?: string; creator?: string; producer?: string; creationDate?: string; modificationDate?: string; keywords?: string; totalPages?: number; }