/** * ┌─────────────────────────────────────────────────────────────────────────┐ * │ DETECT TEXT POSITION TOOL - MCP Tool Implementation │ * ├─────────────────────────────────────────────────────────────────────────┤ * │ Filename: detect-text-position.tool.ts │ * │ Language: TypeScript │ * │ MCP Server: PDF Operations Server │ * │ │ * │ Purpose: │ * │ Implements an MCP tool that detects precise text positions in PDF │ * │ pages using advanced OCR-level text extraction. Returns bounding │ * │ boxes, font information, and coordinates for each text element. │ * │ │ * │ Why this tool exists: │ * │ - Enables AI to find exact text locations in PDFs │ * │ - Supports intelligent watermark placement avoiding text │ * │ - Provides foundation for content-aware PDF operations │ * │ - Essential for accurate text-based positioning │ * │ │ * │ MCP Tool Information: │ * │ Tool Name: detect-text-position │ * │ Category: pdf-operations │ * │ Input: { filePath, pageNumber, searchQuery?, maxResults? } │ * │ Output: { textItems, totalTextItems, pageDimensions, etc. } │ * │ │ * │ Key Features: │ * │ - Extracts all text items with precise bounding boxes │ * │ - Provides font name and size for each text element │ * │ - Includes transformation matrices for rotated text │ * │ - Supports text search/filtering │ * │ - Returns text direction and styling information │ * │ - Uses PDF.js for highly accurate text positioning │ * │ │ * │ Algorithm: │ * │ Uses PDF.js getTextContent() API which provides: │ * │ 1. Character-level precision for text positioning │ * │ 2. Transformation matrices for coordinate calculations │ * │ 3. Font metadata (name, size, style) │ * │ 4. Handles rotated, scaled, and skewed text │ * │ │ * │ Dependencies: │ * │ - @modelcontextprotocol/sdk: MCP server SDK │ * │ - zod: Input validation and schema definition │ * │ - pdfjs-dist: Mozilla PDF.js for text extraction │ * │ - ../utils/text-position-utils: Text extraction functions │ * │ - ../utils/path-resolver: File path resolution │ * │ │ * │ Related Tools: │ * │ - analyze-pdf-page: Gets page dimensions for context │ * │ - add-pdf-watermark: Uses text positions for placement │ * │ │ * │ Security Considerations: │ * │ - Validates file paths to prevent traversal attacks │ * │ - Validates page numbers within document bounds │ * │ - Limits results to prevent memory exhaustion │ * │ - Sanitizes search queries │ * │ │ * │ Author: PDF MCP Team │ * │ Created: 2025-10-30 │ * │ Version: 1.0.0 │ * └─────────────────────────────────────────────────────────────────────────┘ */ import { z } from 'zod'; import type { TextPositionResult } from '../types.js'; /** * Zod schema for detect-text-position tool input validation */ export declare const DetectTextPositionInputSchema: { filePath: z.ZodString; pageNumber: z.ZodOptional; searchQuery: z.ZodOptional; maxResults: z.ZodOptional; }; /** * Zod schema for detect-text-position tool output */ export declare const DetectTextPositionOutputSchema: { filePath: z.ZodString; pageNumber: z.ZodNumber; textItems: z.ZodArray; transform: z.ZodArray; direction: z.ZodNumber; }, "strip", z.ZodTypeAny, { text: string; fontSize: number; fontName: string; bounds: { x: number; y: number; width: number; height: number; }; transform: number[]; direction: number; }, { text: string; fontSize: number; fontName: string; bounds: { x: number; y: number; width: number; height: number; }; transform: number[]; direction: number; }>, "many">; totalTextItems: z.ZodNumber; pageDimensions: z.ZodObject<{ width: z.ZodNumber; height: z.ZodNumber; rotation: z.ZodNumber; inchDimensions: z.ZodObject<{ width: z.ZodNumber; height: z.ZodNumber; }, "strip", z.ZodTypeAny, { width: number; height: number; }, { width: number; height: number; }>; mmDimensions: z.ZodObject<{ width: z.ZodNumber; height: z.ZodNumber; }, "strip", z.ZodTypeAny, { width: number; height: number; }, { width: number; height: number; }>; }, "strip", z.ZodTypeAny, { rotation: number; width: number; height: number; inchDimensions: { width: number; height: number; }; mmDimensions: { width: number; height: number; }; }, { rotation: number; width: number; height: number; inchDimensions: { width: number; height: number; }; mmDimensions: { width: number; height: number; }; }>; searchQuery: z.ZodOptional; filtered: z.ZodBoolean; }; /** * Detects text positions in a PDF page with OCR-level precision * * @param params - Detection parameters * @returns Complete text position analysis result * @throws Error if file cannot be processed or page number is invalid */ export declare function detectTextPosition(params: { filePath: string; pageNumber?: number | undefined; searchQuery?: string | undefined; maxResults?: number | undefined; }): Promise; /** * Tool handler for detect-text-position * Formats the result for MCP protocol */ export declare const detectTextPositionToolHandler: (params: { filePath: string; pageNumber?: number | undefined; searchQuery?: string | undefined; maxResults?: number | undefined; }) => Promise<{ content: { type: "text"; text: string; }[]; structuredContent: TextPositionResult; }>; //# sourceMappingURL=detect-text-position.tool.d.ts.map