extract-form-data
Extract structured data from forms such as receipts, invoices, and ID documents using Azure Form Recognizer in Orion Vision MCP Server. Input a document URL and specify the form type for accurate analysis.
Instructions
Extracts structured data from forms using Azure Form Recognizer
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| formType | Yes | Type of form to analyze | |
| url | Yes | URL of the form document to analyze |
Implementation Reference
- src/tools/form-recognizer.ts:37-74 (handler)The core handler function that downloads the form from URL, maps formType to Azure model ID, analyzes it using Form Recognizer client, and returns JSON result.export const extractFormData = async (url: string, formType: string): Promise<string> => { const config = getConfig(); const client = new DocumentAnalysisClient( config.formRecognizerEndpoint, new AzureKeyCredential(config.formRecognizerKey) ); try { // Download the document from URL const response = await axios.get(url, { responseType: "arraybuffer" }); const buffer = Buffer.from(response.data); // Map form type to model ID const modelId = { receipt: "prebuilt-receipt", invoice: "prebuilt-invoice", idDocument: "prebuilt-idDocument", businessCard: "prebuilt-businessCard", custom: "prebuilt-document" }[formType]; if (!modelId) { throw new Error(`Invalid form type: ${formType}`); } // Analyze the form const poller = await client.beginAnalyzeDocument( modelId, buffer as FormRecognizerRequestBody ); const result = await poller.pollUntilDone(); return JSON.stringify(result, null, 2); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error'; throw new Error(`Form data extraction failed: ${errorMessage}`); } };
- src/types/tools.ts:20-23 (schema)Zod schema defining the input parameters: url (string URL) and formType (enum of supported form types).export const FormDataSchema = z.object({ url: z.string().url().describe("URL of the form document to analyze"), formType: z.enum(["receipt", "invoice", "idDocument", "businessCard", "custom"]).describe("Type of form to analyze"), });
- src/services/tools.ts:16-23 (registration)Tool configuration object in the tools array, specifying name, description, input schema, and execute function that delegates to the handler.{ name: "extract-form-data", description: "Extracts structured data from forms using Azure Form Recognizer", parameters: FormDataSchema, execute: async (args) => { return await extractFormData(args.url, args.formType); }, },
- src/index.ts:17-20 (registration)Loop that registers all tools from the config array into the FastMCP server using addTool method.// Register all tools tools.forEach((tool) => { (server.addTool as Tool)(tool); });