extract-image
Extract structured data from images using a prompt, with options for URL or base64 inputs and JSON output format. Ideal for processing visual information into actionable insights.
Instructions
Extract structured data from images based on a prompt.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| images | Yes | Array of URLs or base64-encoded images | |
| inputMethod | Yes | Input method | |
| jsonMode | No | Return in JSON format | |
| prompt | Yes | Extraction prompt |
Implementation Reference
- src/index.ts:701-722 (handler)Handler function that executes the 'extract-image' tool logic by sending a POST request to the Dumpling AI API endpoint /api/v1/extract-image with the provided parameters.async ({ inputMethod, images, prompt, jsonMode }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch(`${NWS_API_BASE}/api/v1/extract-image`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ inputMethod, image: images[0], prompt, jsonMode, requestSource: "mcp", }), // Assuming single image for simplicity }); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; }
- src/index.ts:693-700 (schema)Zod input schema defining parameters for the 'extract-image' tool: inputMethod, images array, prompt, and optional jsonMode.{ inputMethod: z.enum(["url", "base64"]).describe("Input method"), images: z .array(z.string()) .describe("Array of URLs or base64-encoded images"), prompt: z.string().describe("Extraction prompt"), jsonMode: z.boolean().optional().describe("Return in JSON format"), },
- src/index.ts:689-723 (registration)Full registration of the 'extract-image' MCP tool using server.tool(), including name, description, input schema, and handler function.// Tool to extract from images server.tool( "extract-image", "Extract structured data from images based on a prompt.", { inputMethod: z.enum(["url", "base64"]).describe("Input method"), images: z .array(z.string()) .describe("Array of URLs or base64-encoded images"), prompt: z.string().describe("Extraction prompt"), jsonMode: z.boolean().optional().describe("Return in JSON format"), }, async ({ inputMethod, images, prompt, jsonMode }) => { const apiKey = process.env.DUMPLING_API_KEY; if (!apiKey) throw new Error("DUMPLING_API_KEY not set"); const response = await fetch(`${NWS_API_BASE}/api/v1/extract-image`, { method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ inputMethod, image: images[0], prompt, jsonMode, requestSource: "mcp", }), // Assuming single image for simplicity }); if (!response.ok) throw new Error(`Failed: ${response.status} ${await response.text()}`); const data = await response.json(); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] }; } );