document_signer
Digitally sign PDF files with CMS/PKCS#7 or CAdES signatures. Customize appearance, position, and metadata for visible or invisible signatures using Nutrient DWS MCP Server.
Instructions
Digitally signs PDF files using Nutrient DWS Sign API. Reads from and writes to file system or sandbox (if enabled).
Signature types: • CMS/PKCS#7 (standard digital signatures) • CAdES (advanced electronic signatures)
Appearance options: • Visible or invisible signatures • Multiple display modes (signature only, description only, or both) • Customizable elements (signer name, reason, location, date) • Support for watermarks and custom graphics
Positioning: • Place on specific page coordinates • Use existing signature form fields
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | The path to the file to be signed. Resolves to sandbox path if enabled, otherwise resolves to the local file system. | |
| graphicImagePath | No | The path to the graphic image to be used as part of the signature's appearance. Optional. Resolves to sandbox path if enabled, otherwise resolves to the local file system. | |
| outputPath | Yes | A path to the output file to. Resolves to sandbox path if enabled, otherwise resolves to the local file system. | |
| signatureOptions | No | Options for creating the digital signature. If not provided, defaults will be used. | |
| watermarkImagePath | No | The path to the watermark image to be used as part of the signature's appearance. Optional. Resolves to sandbox path if enabled, otherwise resolves to the local file system. |
Implementation Reference
- src/dws/sign.ts:13-45 (handler)Main handler function that implements the document signing logic by preparing FormData with file and options, calling the Nutrient DWS Sign API, and handling the response.export async function performSignCall( filePath: string, outputFilePath: string, signatureOptions: SignatureOptions = { signatureType: 'cms', flatten: false }, watermarkImagePath?: string, graphicImagePath?: string, ): Promise<CallToolResult> { try { // We resolve the output path first to fail early const resolvedOutputPath = await resolveWriteFilePath(outputFilePath) const formData = new FormData() await addFileToFormData(formData, 'file', filePath) if (signatureOptions) { formData.append('data', JSON.stringify(signatureOptions)) } if (watermarkImagePath) { await addFileToFormData(formData, 'watermark', watermarkImagePath) } if (graphicImagePath) { await addFileToFormData(formData, 'graphic', graphicImagePath) } const response = await callNutrientApi('sign', formData) return handleFileResponse(response, resolvedOutputPath, 'File signed successfully') } catch (e: unknown) { return handleApiError(e) } }
- src/schemas.ts:107-133 (schema)Zod schema defining the input arguments for the document_signer tool, including filePath, signatureOptions, optional images, and outputPath.export const SignAPIArgsSchema = z.object({ filePath: z .string() .describe( 'The path to the file to be signed. Resolves to sandbox path if enabled, otherwise resolves to the local file system.', ), signatureOptions: CreateDigitalSignatureSchema.optional().describe( 'Options for creating the digital signature. If not provided, defaults will be used.', ), watermarkImagePath: z .string() .optional() .describe( "The path to the watermark image to be used as part of the signature's appearance. Optional. Resolves to sandbox path if enabled, otherwise resolves to the local file system.", ), graphicImagePath: z .string() .optional() .describe( "The path to the graphic image to be used as part of the signature's appearance. Optional. Resolves to sandbox path if enabled, otherwise resolves to the local file system.", ), outputPath: z .string() .describe( 'A path to the output file to. Resolves to sandbox path if enabled, otherwise resolves to the local file system.', ), })
- src/index.ts:57-82 (registration)Registers the 'document_signer' MCP tool with description, input schema from SignAPIArgsSchema, and thin wrapper handler delegating to performSignCall.server.tool( 'document_signer', `Digitally signs PDF files using Nutrient DWS Sign API. Reads from and writes to file system or sandbox (if enabled). Signature types: • CMS/PKCS#7 (standard digital signatures) • CAdES (advanced electronic signatures) Appearance options: • Visible or invisible signatures • Multiple display modes (signature only, description only, or both) • Customizable elements (signer name, reason, location, date) • Support for watermarks and custom graphics Positioning: • Place on specific page coordinates • Use existing signature form fields`, SignAPIArgsSchema.shape, async ({ filePath, signatureOptions, watermarkImagePath, graphicImagePath, outputPath }) => { try { return performSignCall(filePath, outputPath, signatureOptions, watermarkImagePath, graphicImagePath) } catch (error) { return createErrorResponse(`Error: ${error instanceof Error ? error.message : String(error)}`) } }, )
- src/dws/sign.ts:54-62 (helper)Helper function to add files (like watermark or graphic images) to the FormData for the API request.export async function addFileToFormData(formData: FormData, fieldName: string, filePath: string) { try { const validatedPath = await resolveReadFilePath(filePath) const fileBuffer = await fs.promises.readFile(validatedPath) formData.append(fieldName, fileBuffer, { filename: path.basename(validatedPath) }) } catch (error) { throw Error(`Error with ${fieldName} image: ${error instanceof Error ? error.message : String(error)}`) } }