/** * ┌─────────────────────────────────────────────────────────────────────────┐ * │ TYPE DEFINITIONS - PDF MCP Server │ * ├─────────────────────────────────────────────────────────────────────────┤ * │ Filename: types.ts │ * │ Language: TypeScript │ * │ MCP Server: PDF Operations Server │ * │ │ * │ Purpose: │ * │ Defines all TypeScript types and interfaces used throughout the │ * │ PDF MCP server, including PDF data structures, tool schemas, and │ * │ utility types for type-safe PDF operations. │ * │ │ * │ Why this file exists: │ * │ - Provides centralized type definitions for entire server │ * │ - Ensures type safety across all PDF operations │ * │ - Enables IDE autocomplete and type checking │ * │ - Documents data structures and their purposes │ * │ │ * │ Dependencies: │ * │ - pdf-parse: PDF parsing library types │ * │ │ * │ Author: PDF MCP Team │ * │ Created: 2025-10-29 │ * │ Version: 1.0.0 │ * └─────────────────────────────────────────────────────────────────────────┘ */ /** * Represents parsed PDF data returned by pdf-parse library */ export interface PDFData { /** Total number of pages in the PDF */ numpages: number; /** Number of pages actually rendered during parsing */ numrender: number; /** PDF document metadata (title, author, etc.) */ info: PDFInfo; /** Additional metadata object */ metadata: Record | null; /** PDF.js version used for parsing */ version: string; /** Extracted text content from all pages */ text: string; } /** * PDF metadata information */ export interface PDFInfo { /** Document title */ Title?: string; /** Document author */ Author?: string; /** Document subject */ Subject?: string; /** Document keywords */ Keywords?: string; /** Creating application */ Creator?: string; /** PDF producer */ Producer?: string; /** Creation date */ CreationDate?: string; /** Modification date */ ModDate?: string; /** PDF version */ PDFFormatVersion?: string; /** Whether document is encrypted */ IsAcroFormPresent?: boolean; /** Whether document is linearized */ IsLinearized?: boolean; /** Whether document is tagged */ IsXFAPresent?: boolean; } /** * Result from counting PDF pages */ export interface PageCountResult { [key: string]: unknown; /** Total number of pages */ pageCount: number; /** File path that was analyzed */ filePath: string; } /** * Result from extracting PDF text */ export interface TextExtractionResult { [key: string]: unknown; /** Extracted text content */ text: string; /** Number of characters extracted */ characterCount: number; /** Number of pages processed */ pageCount: number; /** File path that was analyzed */ filePath: string; } /** * Result from extracting PDF metadata */ export interface MetadataExtractionResult { [key: string]: unknown; /** Document title */ title: string; /** Document author */ author: string; /** Document subject */ subject: string; /** Creation date */ creationDate: string; /** Modification date */ modificationDate: string; /** Total number of pages */ pageCount: number; /** PDF version */ pdfVersion: string; /** File path that was analyzed */ filePath: string; } /** * Result from summarizing PDF content */ export interface SummaryResult { [key: string]: unknown; /** Generated summary text */ summary: string; /** Number of pages summarized */ pageCount: number; /** Original text length in characters */ originalLength: number; /** Summary length in characters */ summaryLength: number; /** File path that was analyzed */ filePath: string; } /** * Result from answering questions about PDF */ export interface QuestionAnswerResult { [key: string]: unknown; /** Answer to the question */ answer: string; /** The original question */ question: string; /** Relevant context from PDF */ context: string; /** File path that was analyzed */ filePath: string; } /** * Watermark position presets */ export type WatermarkPosition = 'top-left' | 'top-right' | 'top-center' | 'bottom-left' | 'bottom-right' | 'bottom-center' | 'center' | 'custom'; /** * Text alignment options */ export type TextAlignment = 'left' | 'center' | 'right'; /** * RGB color representation */ export interface RGBColor { /** Red component (0-1) */ r: number; /** Green component (0-1) */ g: number; /** Blue component (0-1) */ b: number; } /** * Watermark configuration options */ export interface WatermarkConfig { /** Text to display as watermark */ text: string; /** Position preset or custom coordinates */ position: WatermarkPosition; /** Custom X coordinate (used when position is 'custom') */ x?: number; /** Custom Y coordinate (used when position is 'custom') */ y?: number; /** Font size in points */ fontSize?: number; /** Text color in RGB (0-1 range) */ color?: RGBColor; /** Opacity (0-1, where 0 is fully transparent and 1 is fully opaque) */ opacity?: number; /** Rotation angle in degrees */ rotation?: number; /** Margin from edges in points */ margin?: number; /** Font to use for the watermark text */ font?: string; /** Style of the font (e.g., bold, italic) */ style?: string; } /** * Header/Footer configuration options */ export interface HeaderFooterConfig { /** Header text (supports variables: {page}, {totalPages}, {date}, {title}) */ headerText?: string; /** Footer text (supports variables: {page}, {totalPages}, {date}, {title}) */ footerText?: string; /** Text alignment */ alignment?: TextAlignment; /** Font size in points */ fontSize?: number; /** Text color in RGB (0-1 range) */ color?: RGBColor; /** Margin from top/bottom edges in points */ margin?: number; /** Page range to apply to (e.g., [1, 5] for pages 1-5, or undefined for all pages) */ pageRange?: [number, number]; } /** * Result from adding watermark to PDF */ export interface WatermarkResult { [key: string]: unknown; /** Path to the output PDF with watermark */ outputPath: string; /** Number of pages watermarked */ pagesProcessed: number; /** Original file path */ originalPath: string; /** Watermark configuration used */ config: WatermarkConfig; } /** * Result from adding header/footer to PDF */ export interface HeaderFooterResult { [key: string]: unknown; /** Path to the output PDF with header/footer */ outputPath: string; /** Number of pages processed */ pagesProcessed: number; /** Original file path */ originalPath: string; /** Header/footer configuration used */ config: HeaderFooterConfig; } /** * PDF page dimensions and layout information */ export interface PageDimensions { /** Page width in points (1 point = 1/72 inch) */ width: number; /** Page height in points */ height: number; /** Page rotation in degrees (0, 90, 180, 270) */ rotation: number; /** Page dimensions in inches */ inchDimensions: { width: number; height: number; }; /** Page dimensions in millimeters */ mmDimensions: { width: number; height: number; }; } /** * PDF page margins (if detectable) */ export interface PageMargins { /** Top margin in points */ top: number; /** Bottom margin in points */ bottom: number; /** Left margin in points */ left: number; /** Right margin in points */ right: number; /** Whether margins were detected or estimated */ detected: boolean; } /** * Bounding box for text or content */ export interface BoundingBox { /** X coordinate of top-left corner */ x: number; /** Y coordinate of top-left corner */ y: number; /** Width of the bounding box */ width: number; /** Height of the bounding box */ height: number; } /** * Complete page analysis result */ export interface PageAnalysisResult { [key: string]: unknown; /** File path analyzed */ filePath: string; /** Page number analyzed */ pageNumber: number; /** Page dimensions and layout */ dimensions: PageDimensions; /** Estimated or detected margins */ margins: PageMargins; /** Content bounding box (area with actual content) */ contentBox?: BoundingBox; /** MediaBox (physical page boundary) */ mediaBox: { x: number; y: number; width: number; height: number; }; /** CropBox (visible page area), if different from MediaBox */ cropBox?: { x: number; y: number; width: number; height: number; }; } /** * Text item with position information */ export interface TextItem { /** The text content */ text: string; /** Font name */ fontName: string; /** Font size in points */ fontSize: number; /** Text bounding box with precise coordinates */ bounds: BoundingBox; /** Text transformation matrix [a, b, c, d, e, f] */ transform: number[]; /** Text direction (0 = horizontal, 90 = vertical, etc.) */ direction: number; } /** * Text position detection result */ export interface TextPositionResult { [key: string]: unknown; /** File path analyzed */ filePath: string; /** Page number analyzed */ pageNumber: number; /** Array of all text items with positions */ textItems: TextItem[]; /** Total number of text items found */ totalTextItems: number; /** Page dimensions for context */ pageDimensions: PageDimensions; /** Search query used (if filtering was applied) */ searchQuery?: string; /** Whether results were filtered */ filtered: boolean; } /** * Single text replacement specification */ export interface TextReplacementSpec { /** Page number where text should be replaced (1-indexed) */ pageNumber: number; /** Original text to find and replace */ originalText: string; /** New text to insert */ replacementText: string; /** Bounding box of the text to replace (from detect-text-position) */ bounds: BoundingBox; /** Font name to use (defaults to Helvetica if not specified) */ fontName?: string; /** Font size in points (from detect-text-position) */ fontSize?: number; /** Text color in RGB (0-1 range), defaults to black */ color?: RGBColor; /** Text rotation angle in degrees (from detect-text-position) */ rotation?: number; /** Background color to cover old text (defaults to white) */ backgroundColor?: RGBColor; } /** * Text replacement configuration options */ export interface TextReplacementConfig { /** Array of text replacements to perform */ replacements: TextReplacementSpec[]; /** Whether to preserve original fonts when possible */ preserveFonts?: boolean; /** Whether to preserve original colors when possible */ preserveColors?: boolean; /** Output file path (defaults to input_with_replacements.pdf) */ outputPath?: string; /** Whether to create a backup of the original file */ createBackup?: boolean; } /** * Result from replacing text in PDF */ export interface TextReplacementResult { [key: string]: unknown; /** Path to the output PDF with replacements */ outputPath: string; /** Number of replacements made */ replacementCount: number; /** Number of pages modified */ pagesModified: number; /** Original file path */ originalPath: string; /** Details of each replacement made */ replacements: Array<{ pageNumber: number; originalText: string; replacementText: string; success: boolean; error?: string; }>; } /** * Context types for text replacement * Determines how text should be handled during replacement */ export type ContextType = 'name' | 'email' | 'plain_text' | 'identifier' | 'unknown'; /** * Context detection result for a text occurrence */ export interface TextContext { /** Type of context detected */ type: ContextType; /** Full text containing the search term (e.g., "Ramya Lakhani" for name) */ fullText: string; /** Components extracted from the context (including delimiters like dots, spaces, @ signs) */ components: string[]; /** Index where search term starts in fullText */ startIndex: number; /** Index where search term ends in fullText */ endIndex: number; /** Pattern that matched the context */ pattern?: string; /** Confidence score for context detection (0-1) */ confidence: number; /** Optional metadata with additional context information */ metadata?: { /** For emails: local part before @ */ localPart?: string; /** For emails: domain after @ */ domain?: string; /** For emails: components of local part */ localComponents?: string[]; /** Additional context-specific data */ [key: string]: any; }; } /** * Result from context-aware text replacement validation */ export interface ContextAwareReplacementPreview { /** Original occurrence found */ original: { text: string; context: TextContext; pageNumber: number; bounds: BoundingBox; }; /** Replacement that will be applied */ replacement: { text: string; preservesContext: boolean; warning?: string; }; /** Whether the replacement is safe to apply */ safe: boolean; /** Explanation of the replacement logic */ explanation: string; } /** * Enhanced text replacement result with context awareness */ export interface ContextAwareReplacementResult extends TextReplacementResult { /** Whether validation passed */ validationPassed: boolean; /** Context information for each replacement */ contextDetails: Array<{ pageNumber: number; context: TextContext; preview: ContextAwareReplacementPreview; }>; /** Summary of context types found */ contextSummary: { names: number; emails: number; plainText: number; identifiers: number; unknown: number; }; } //# sourceMappingURL=types.d.ts.map