document_processor
Process document files with annotations, OCR, page rotation, watermarking, and redaction. Export outputs in PDF, images, JSON, or Office formats using the Nutrient DWS MCP Server.
Instructions
Processes documents using Nutrient DWS Processor API. Reads from and writes to file system or sandbox (if enabled).
Features: • Import XFDF annotations • Flatten annotations • OCR processing • Page rotation • Watermarking (text/image) • Redaction creation and application
Output formats: PDF, PDF/A, images (PNG, JPEG, WebP), JSON extraction, Office (DOCX, XLSX, PPTX)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instructions | Yes | Build instructions. | |
| outputPath | Yes | A path to the output file to. (if required) Resolves to sandbox path if enabled, otherwise resolves to the local file system. |
Implementation Reference
- src/dws/build.ts:15-35 (handler)Implements the core handler logic for the 'document_processor' tool by processing build instructions, handling file references and URLs, calling the Nutrient DWS build API, and managing file or JSON responses.export async function performBuildCall(instructions: Instructions, outputFilePath: string): Promise<CallToolResult> { const { instructions: adjustedInstructions, fileReferences } = await processInstructions(instructions) if (fileReferences.size === 0) { return createErrorResponse('Error: No valid files or urls found in instructions') } try { // We resolve the output path first to fail early const resolvedOutputPath = await resolveWriteFilePath(outputFilePath) const response = await makeApiBuildCall(adjustedInstructions, fileReferences) if (adjustedInstructions.output?.type === 'json-content') { return handleJsonContentResponse(response) } else { return handleFileResponse(response, resolvedOutputPath, 'File processed successfully using build API') } } catch (e: unknown) { return handleApiError(e) } }
- src/schemas.ts:496-503 (schema)Defines the Zod schema BuildAPIArgsSchema used for input validation of the 'document_processor' tool, including instructions and outputPath.export const BuildAPIArgsSchema = z.object({ instructions: InstructionsSchema.describe('Build instructions.'), outputPath: z .string() .describe( 'A path to the output file to. (if required) Resolves to sandbox path if enabled, otherwise resolves to the local file system.', ), })
- src/index.ts:35-55 (registration)Registers the 'document_processor' MCP tool with the McpServer, specifying its description, input schema from BuildAPIArgsSchema.shape, and handler delegating to performBuildCall.'document_processor', `Processes documents using Nutrient DWS Processor API. Reads from and writes to file system or sandbox (if enabled). Features: • Import XFDF annotations • Flatten annotations • OCR processing • Page rotation • Watermarking (text/image) • Redaction creation and application Output formats: PDF, PDF/A, images (PNG, JPEG, WebP), JSON extraction, Office (DOCX, XLSX, PPTX)`, BuildAPIArgsSchema.shape, async ({ instructions, outputPath }) => { try { return performBuildCall(instructions, outputPath) } catch (error) { return createErrorResponse(`Error: ${error instanceof Error ? error.message : String(error)}`) } }, )