Skip to main content
Glama
form-recognizer.ts2.27 kB
'use strict'; import { DocumentAnalysisClient, AzureKeyCredential, FormRecognizerRequestBody } from "@azure/ai-form-recognizer"; import { getConfig } from "../config/env"; import axios from "axios"; export const analyzeDocument = async (url: string, modelId?: 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); // Analyze the document const poller = await client.beginAnalyzeDocument( modelId || "prebuilt-document", 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(`Document analysis failed: ${errorMessage}`); } }; 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}`); } };

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Cognitive-Stack/orion-vision-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server