document_processor
Process documents to import annotations, flatten content, perform OCR, rotate pages, add watermarks, apply redactions, and convert to multiple formats including PDF, images, JSON, and Office files.
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
| 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/index.ts:35-55 (registration)Registration of the 'document_processor' MCP tool with description, input schema (BuildAPIArgsSchema), and wrapper handler calling 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)}`) } }, )
- src/dws/build.ts:15-35 (handler)Core handler function 'performBuildCall' that processes document instructions, handles file/URL references, calls the Nutrient DWS build API, and returns the result or error.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-505 (schema)Input schema 'BuildAPIArgsSchema' for the tool, including 'instructions' (complex nested schema for parts, actions, output) 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.', ), }) export type BuildAPIArgs = z.infer<typeof BuildAPIArgsSchema>