### Start MCP Image Extractor Server Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/integration.md Use this command to start the MCP Image Extractor server. Ensure Node.js and npm are installed. ```bash npm start ``` -------------------------------- ### Install Smithery CLI Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/smithery.md Install the Smithery CLI globally using npm. This is a prerequisite for interacting with Smithery. ```bash npm install -g smithery-cli ``` -------------------------------- ### Manual Installation and Configuration Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/README.md Steps for cloning the repository, installing dependencies, building the project, and linking it globally. Includes the .cursor/mcp.json configuration for a globally linked command. ```bash git clone https://github.com/ifmelate/mcp-image-extractor.git cd mcp-image-extractor npm install npm run build npm link ``` ```json { "mcpServers": { "image-extractor": { "command": "mcp-image-extractor", "disabled": false } } } ``` -------------------------------- ### Example: Extract Image from Local File Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/README.md Example prompt for Claude to extract an image from a local file path. Claude will automatically use the `extract_image_from_file` tool. ```text Please extract the image from this local file: images/photo.jpg ``` -------------------------------- ### Cursor IDE: NPX Configuration Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/mcp_configuration.md Automatically start the image extractor server using npx within Cursor IDE. This is the recommended setup. ```json { "servers": [ { "name": "Image Extractor", "command": "npx", "args": ["-y", "mcp-image-extractor"], "enabled": true, "env": { "PORT": "8000", "MAX_IMAGE_SIZE": "10485760" } } ] } ``` -------------------------------- ### Example: Extract Image from URL Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/README.md Example prompt for Claude to extract an image from a given URL. Claude will automatically use the `extract_image_from_url` tool. ```text Please extract the image from this URL: https://example.com/image.jpg ``` -------------------------------- ### Claude Desktop: NPX Configuration Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/mcp_configuration.md Automatically start the image extractor server using npx. This is the recommended method for Claude Desktop. ```json { "mcpServers": { "image-extractor": { "command": "npx", "args": ["-y", "mcp-image-extractor"], "env": { "PORT": "8000", "MAX_IMAGE_SIZE": "10485760" } } } } ``` -------------------------------- ### Example Prompt for Claude Desktop Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/integration.md Use this prompt format in Claude Desktop to request image analysis using the configured MCP server. Replace '[URL to screenshot]' with the actual screenshot URL. ```text Please analyze this screenshot: [URL to screenshot] ``` -------------------------------- ### Example Prompt for Cursor IDE Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/integration.md Use this prompt format in Cursor IDE to trigger image analysis via the integrated MCP server. Replace '[URL to image]' with the actual image URL. ```text Can you analyze this image for me? [URL to image] ``` -------------------------------- ### Install MCP Image Extractor via Local Path Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/README.md Configure your .cursor/mcp.json to use a locally installed package. This is useful for troubleshooting 'Failed to create client' errors. ```json { "mcpServers": { "image-extractor": { "command": "node", "args": ["/full/path/to/mcp-image-extractor/dist/index.js"], "disabled": false } } } ``` -------------------------------- ### Install MCP Image Extractor with npx Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/README.md Use this JSON configuration in your .cursor/mcp.json to automatically install and use the latest version of the image extractor without global installation. ```json { "mcpServers": { "image-extractor": { "command": "npx", "args": [ "-y", "mcp-image-extractor" ] } } } ``` -------------------------------- ### Register MCP Image Extractor for Claude Desktop Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Register the server in Claude Desktop's configuration file so it can be spawned on demand using `npx`. This example shows how to set environment variables for the extractor. ```json { "mcpServers": { "image-extractor": { "command": "npx", "args": ["-y", "mcp-image-extractor"], "env": { "MAX_IMAGE_SIZE": "10485760", "MAX_IMAGE_DIMENSION": "512" } } } } ``` -------------------------------- ### Claude Desktop: Node Configuration Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/mcp_configuration.md Start the image extractor server directly using Node.js. Allows specifying script path and environment variables. ```json { "mcpServers": { "image-extractor": { "command": "node", "args": ["path/to/mcp-image-extractor/dist/index.js"], "env": { "PORT": "8000", "MAX_IMAGE_SIZE": "10485760", "ALLOWED_DOMAINS": "example.com,trusted-domain.org" } } } } ``` -------------------------------- ### Development and Testing Commands Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt This section provides essential commands for developing and testing the MCP Image Extractor. It includes instructions for installing dependencies, running the application in development mode using `ts-node`, compiling the project, and executing tests, including a CI mode that enforces snapshot and coverage requirements. ```bash # Install dependencies npm install # Run in dev mode (ts-node, no compile step) npm run dev # Compile to dist/ npm run build # Run all tests npm test # Run tests in CI mode (fails on snapshots/missing coverage) npm run test:ci ``` ```bash # Test files cover: # tests/file-tests.test.ts — extractImageFromFile # tests/url-tests.test.ts — extractImageFromUrl # tests/base64-tests.test.ts — extractImageFromBase64 # tests/compression.test.ts — processImage pipeline # tests/ssrf.test.ts — isPrivateIP + checkSSRFRisk # tests/image-utils.test.ts — shared utilities # tests/index.test.ts — MCP server wiring ``` -------------------------------- ### Cursor IDE: Node Configuration Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/mcp_configuration.md Start the image extractor server directly using Node.js within Cursor IDE. Specify the script path and environment variables. ```json { "servers": [ { "name": "Image Extractor", "command": "node", "args": ["path/to/mcp-image-extractor/dist/index.js"], "enabled": true, "env": { "PORT": "8000", "MAX_IMAGE_SIZE": "10485760", "ALLOWED_DOMAINS": "example.com,trusted-domain.org" } } ] } ``` -------------------------------- ### extractImageFromBase64 Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Decodes a base64 string, validates size against MAX_IMAGE_SIZE, uses the mime_type hint to guide sharp format detection, then processes through the unified pipeline. ```APIDOC ## Function: extractImageFromBase64 ### Description Decodes a base64 string, validates size against `MAX_IMAGE_SIZE`, uses the `mime_type` hint to guide `sharp` format detection, then processes through the unified pipeline. Useful for clipboard screenshots or images generated in memory. ### Parameters #### Request Body - **base64** (string) - Required - The base64 encoded image string. - **mime_type** (string) - Optional - A hint for the image's MIME type (default is "image/png"). ### Request Example ```typescript import { extractImageFromBase64 } from './src/image-utils'; const raw = fs.readFileSync('/tmp/diagram.jpg'); const base64Input = raw.toString('base64'); const result = await extractImageFromBase64({ base64: base64Input, mime_type: 'image/jpeg' }); ``` ### Response #### Success Response - **content** (Array) - An array containing metadata and image data. - **type** (string) - 'text' for metadata, 'image' for image data. - **text** (string) - JSON string of image metadata (width, height, format, size, etc.). - **data** (string) - Base64 encoded image data. - **mimeType** (string) - MIME type of the image. #### Response Example ```json { "was_resized": true } ``` #### Error Response - **isError** (boolean) - true if an error occurred. - **content** (Array) - An array containing error information. - **type** (string) - 'text' for error message. - **text** (string) - Descriptive error message. #### Error Example ``` Error: Image size exceeds maximum allowed size of 10485760 bytes ``` ``` -------------------------------- ### Fetch and Process Remote Image with extractImageFromUrl Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Use this function to fetch an image from a URL. It includes SSRF validation and applies an image processing pipeline. Ensure the URL starts with http:// or https:// and is not on an allowlist if enforced. ```typescript import { extractImageFromUrl } from './src/image-utils'; // Fetch and process a remote image const result = await extractImageFromUrl({ url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png' }); if (result.isError) { const err = result.content[0] as { type: 'text'; text: string }; console.error(err.text); // Possible errors: // "Error: URL must start with http:// or https://" // "Error: IP address "192.168.1.1" is not allowed (private/internal range)" // "Error: Hostname "internal.corp" resolves to a private/internal IP address" // "Error: Domain example.com is not in the allowed domains list" } else { const meta = JSON.parse((result.content[0] as { type: 'text'; text: string }).text); console.log(meta); // { width: 280, height: 280, format: "png", size: 12048, // original_width: 280, original_height: 280, was_resized: false } } ``` -------------------------------- ### Docker Deployment and Run Commands Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt These commands demonstrate how to build a Docker image for the MCP Image Extractor and how to run it. The `docker run` command shows how to set environment variables for configuration, such as `MAX_IMAGE_DIMENSION`, `URL_FETCH_TIMEOUT_MS`, and `ALLOWED_DOMAINS`. ```dockerfile # Build and run the server in a container # Dockerfile is included in the repository root ``` ```bash # Build docker build -t mcp-image-extractor . # Run (stdio mode — attach to MCP host via stdin/stdout) docker run -i --rm \ -e MAX_IMAGE_DIMENSION=768 \ -e URL_FETCH_TIMEOUT_MS=15000 \ -e ALLOWED_DOMAINS=cdn.myapp.io,assets.example.com \ mcp-image-extractor ``` -------------------------------- ### Deploy to Smithery Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/smithery.md Deploy your project to Smithery.ai using the npm script. Alternatively, use the Smithery CLI directly. ```bash npm run smithery:deploy ``` ```bash smithery deploy ``` -------------------------------- ### Build Project for Deployment Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/smithery.md Build your project using npm scripts before deployment. This ensures your code is ready for packaging and distribution. ```bash npm run build ``` -------------------------------- ### Log in to NPM Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/smithery.md Log in to your npm account using the npm CLI. This is required before publishing packages. ```bash npm login ``` -------------------------------- ### Claude Desktop: URL Configuration Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/mcp_configuration.md Configure the image extractor server using a direct URL. This method requires manual server startup. ```json { "mcpServers": { "image-extractor": { "url": "http://localhost:8000" } } } ``` -------------------------------- ### Docker Build and Run Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/README.md Commands to build the Docker image for the MCP Image Extractor and run it as a container, exposing port 8000. ```bash docker build -t mcp-image-extractor . docker run -p 8000:8000 mcp-image-extractor ``` -------------------------------- ### Publish Package to NPM Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/smithery.md Publish your project to npm using the npm CLI. This makes your MCP server available via npx. ```bash npm publish ``` -------------------------------- ### Cursor IDE: URL Configuration Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/mcp_configuration.md Configure the image extractor server with a direct URL for Cursor IDE. Ensure the server is running manually. ```json { "servers": [ { "name": "Image Extractor", "url": "http://localhost:8000", "enabled": true } ] } ``` -------------------------------- ### Build and Run Commands for MCP Image Extractor Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/CLAUDE.md Common npm commands for building, running, and testing the MCP Image Extractor project. Use `npm run dev` for direct development with ts-node. ```bash npm run build # Compile TypeScript → dist/ (also chmod +x dist/index.js) npm run dev # Run directly via ts-node (no build step) npm start # Run compiled server from dist/ npm run lint # ESLint on .ts files npm test # Jest tests (--no-cache) ``` -------------------------------- ### Cursor IDE: Full Path Node Configuration Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/mcp_configuration.md Use the full path to the Node.js executable for Cursor IDE configuration, useful with Node version managers. ```json { "servers": [ { "name": "Image Extractor", "command": "/home/username/.nvm/versions/node/v20.11.0/bin/node", "args": ["/absolute/path/to/mcp-image-extractor/dist/index.js"], "enabled": true } ] } ``` -------------------------------- ### Claude Desktop: Full Path NPX Configuration Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/mcp_configuration.md Use the full path to npx for Claude Desktop configuration, especially when using Node version managers like nvm. ```json { "mcpServers": { "image-extractor": { "command": "/home/username/.nvm/versions/node/v20.11.0/bin/npx", "args": ["-y", "mcp-image-extractor"], "env": { "PORT": "8000" } } } } ``` -------------------------------- ### Log in to Smithery Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/smithery.md Log in to your Smithery.ai account using the Smithery CLI. This authenticates your CLI session. ```bash smithery login ``` -------------------------------- ### Cursor IDE Server Configuration (URL) Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/smithery.md Configure Cursor IDE to use a deployed Smithery server via its URL. This enables integration with your remote MCP server. ```json { "servers": [ { "name": "Image Extractor", "url": "https://your-smithery-url.smithery.ai", "enabled": true } ] } ``` -------------------------------- ### Claude Desktop Server Configuration (URL) Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/docs/smithery.md Configure Claude Desktop to use a deployed Smithery server via its URL. This allows Claude Desktop to connect to your remote MCP server. ```json { "mcpServers": { "image-extractor": { "url": "https://your-smithery-url.smithery.ai" } } } ``` -------------------------------- ### extract_image_from_file Tool Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt This tool reads an image from the local filesystem, processes it through a resize and compression pipeline, and returns both JSON metadata and the optimized base64 image. It handles errors for non-existent files, size limits, and decoding issues. ```APIDOC ## Tool: `extract_image_from_file` ### Description Reads an image from the local filesystem, runs it through the resize/compress pipeline, and returns both JSON metadata and the optimized base64 image. Returns `isError: true` if the file does not exist, exceeds `MAX_IMAGE_SIZE`, or cannot be decoded by `sharp`. ### Usage Example ```typescript import { extractImageFromFile } from './src/image-utils'; // Basic usage const result = await extractImageFromFile({ file_path: '/screenshots/test.png' }); if (result.isError) { const errText = result.content[0] as { type: 'text'; text: string }; console.error('Failed:', errText.text); // e.g. "Error: File /screenshots/test.png does not exist" } else { // content[0] — JSON metadata text block const meta = JSON.parse((result.content[0] as { type: 'text'; text: string }).text); console.log(meta); // { // width: 512, height: 400, // format: "png", size: 48200, // original_width: 1920, original_height: 1080, // was_resized: true // } // content[1] — base64 image block ready for LLM vision input const img = result.content[1] as { type: 'image'; data: string; mimeType: string }; console.log(img.mimeType); // "image/png" // img.data — base64 string of the processed image } ``` ``` -------------------------------- ### Image Processing Pipeline Overview Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt This illustrates the internal behavior of the `processImage` function, which is automatically called by extraction tools. It outlines the steps for reading metadata, resizing based on `MAX_IMAGE_DIMENSION`, applying format-specific compression, and the structure of the returned `ProcessedImage` object. The `MAX_IMAGE_DIMENSION` can be overridden at startup. ```typescript // Internal pipeline behavior (illustrative — not a public export) // Called automatically by all three extract* functions. // Step 1: Read metadata with sharp // Step 2: If width or height > MAX_IMAGE_DIMENSION, resize with fit:'inside' // Step 3: Apply format-specific compression: // JPEG/JPG → quality 80 // PNG → quality 80, compressionLevel 9 // WebP → quality 80 // AVIF → quality 80 // TIFF → quality 80 // other → pass-through // Step 4: Return ProcessedImage: // { // buffer: Buffer, // final compressed bytes // width: number, // final width // height: number, // final height // format: string, // sharp-detected format name (e.g. "jpeg") // size: number, // final byte length // wasResized: boolean, // originalWidth: number, // originalHeight: number // } // Override MAX_IMAGE_DIMENSION at startup: // MAX_IMAGE_DIMENSION=1024 npx mcp-image-extractor ``` -------------------------------- ### MCP Image Extractor Configuration (.env) Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Environment variables control the runtime behavior of the MCP Image Extractor. Adjust these values in a `.env` file to customize settings like maximum input size, image dimensions, and URL fetch timeouts. ```bash # .env — all values shown are defaults MAX_IMAGE_SIZE=10485760 # Max accepted input size in bytes (10 MB) MAX_IMAGE_DIMENSION=512 # Max width/height after resize (px) URL_FETCH_TIMEOUT_MS=30000 # HTTP timeout for URL extraction (ms) ALLOWED_DOMAINS= # Comma-separated domain allowlist; empty = all domains allowed # Example: ALLOWED_DOMAINS=example.com,cdn.myapp.io ``` -------------------------------- ### Running a Single Test File with Jest Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/CLAUDE.md Execute a specific test file using npx and Jest. The `--no-cache` flag ensures tests run with the latest code. ```bash npx jest tests/compression.test.ts --no-cache ``` -------------------------------- ### Register MCP Image Extractor for Cursor IDE Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Configure Cursor IDE to use the MCP Image Extractor by adding its registration details to the `.cursor/mcp.json` file. ```json { "mcpServers": { "image-extractor": { "command": "npx", "args": ["-y", "mcp-image-extractor"] } } } ``` -------------------------------- ### checkSSRFRisk Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Async full-URL SSRF check. Returns a descriptive error string if the URL is risky, or `null` if it is safe to fetch. ```APIDOC ## Function: checkSSRFRisk ### Description Async full-URL SSRF check. Returns a descriptive error string if the URL is risky, or `null` if it is safe to fetch. Performs DNS pre-resolution for hostnames to catch internal services hidden behind public-looking names. ### Parameters #### Path Parameters - **url** (string) - Required - The URL to check for SSRF risks. ### Request Example ```typescript import { checkSSRFRisk } from './src/image-utils'; const safe = await checkSSRFRisk('https://cdn.example.com/photo.jpg'); console.log(safe); // null const priv = await checkSSRFRisk('http://192.168.1.50/logo.png'); console.log(priv); // 'IP address "192.168.1.50" is not allowed (private/internal range)' ``` ### Response #### Success Response - **return value** (string | null) - A descriptive error string if the URL is risky, or `null` if it is safe to fetch. ``` -------------------------------- ### extractImageFromUrl Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Fetches an image from an HTTP/HTTPS URL, performs SSRF validation, optionally enforces the ALLOWED_DOMAINS allowlist, then applies the same resize/compress pipeline as the file tool. ```APIDOC ## Function: extractImageFromUrl ### Description Fetches an image from an HTTP/HTTPS URL, performs SSRF validation, optionally enforces the `ALLOWED_DOMAINS` allowlist, then applies the same resize/compress pipeline as the file tool. ### Parameters #### Request Body - **url** (string) - Required - The URL of the image to fetch. ### Request Example ```typescript import { extractImageFromUrl } from './src/image-utils'; const result = await extractImageFromUrl({ url: 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/280px-PNG_transparency_demonstration_1.png' }); ``` ### Response #### Success Response - **content** (Array) - An array containing metadata and image data. - **type** (string) - 'text' for metadata, 'image' for image data. - **text** (string) - JSON string of image metadata (width, height, format, size, etc.). - **data** (string) - Base64 encoded image data. - **mimeType** (string) - MIME type of the image. #### Response Example ```json { "width": 280, "height": 280, "format": "png", "size": 12048, "original_width": 280, "original_height": 280, "was_resized": false } ``` #### Error Response - **isError** (boolean) - true if an error occurred. - **content** (Array) - An array containing error information. - **type** (string) - 'text' for error message. - **text** (string) - Descriptive error message. #### Error Example ``` Error: URL must start with http:// or https:// ``` ``` -------------------------------- ### extract_image_from_file Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/README.md Extracts an image from a local file and converts it to base64. Images are automatically resized to optimal dimensions (max 512x512) for LLM analysis. ```APIDOC ## extract_image_from_file ### Description Extracts an image from a local file and converts it to base64. All images are automatically resized to optimal dimensions (max 512x512) for LLM analysis to limit the size of the base64 output and optimize context window usage. ### Parameters #### Path Parameters - **file_path** (string) - Required - Path to the local image file ``` -------------------------------- ### Perform Full URL SSRF Check with checkSSRFRisk Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Asynchronously checks a URL for SSRF risks, returning an error string if risky or null if safe. It performs DNS pre-resolution to detect internal services behind public hostnames. ```typescript import { checkSSRFRisk } from './src/image-utils'; // Safe URL — returns null const safe = await checkSSRFRisk('https://cdn.example.com/photo.jpg'); console.log(safe); // null // Direct private IP — returns error string const priv = await checkSSRFRisk('http://192.168.1.50/logo.png'); console.log(priv); // 'IP address "192.168.1.50" is not allowed (private/internal range)' // Localhost — returns error string const local = await checkSSRFRisk('http://localhost:3000/image'); console.log(local); // 'Hostname "localhost" is not allowed' // Hostname resolving to internal IP — returns error string const dns = await checkSSRFRisk('http://internal.corp/img.png'); console.log(dns); // 'Hostname "internal.corp" resolves to a private/internal IP address' ``` -------------------------------- ### extract_image_from_base64 Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/README.md Processes a base64-encoded image for LLM analysis. Images are automatically resized to optimal dimensions (max 512x512) for LLM analysis. ```APIDOC ## extract_image_from_base64 ### Description Processes a base64-encoded image for LLM analysis. All images are automatically resized to optimal dimensions (max 512x512) for LLM analysis to limit the size of the base64 output and optimize context window usage. ### Parameters #### Path Parameters - **base64** (string) - Required - Base64-encoded image data - **mime_type** (string) - Optional - MIME type of the image (default: "image/png") ``` -------------------------------- ### extract_image_from_url Source: https://github.com/ifmelate/mcp-image-extractor/blob/main/README.md Extracts an image from a URL and converts it to base64. Images are automatically resized to optimal dimensions (max 512x512) for LLM analysis. ```APIDOC ## extract_image_from_url ### Description Extracts an image from a URL and converts it to base64. All images are automatically resized to optimal dimensions (max 512x512) for LLM analysis to limit the size of the base64 output and optimize context window usage. ### Parameters #### Path Parameters - **url** (string) - Required - URL of the image to extract ``` -------------------------------- ### Extract Image from File using TypeScript Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Use the `extractImageFromFile` function to process an image from the local filesystem. It returns JSON metadata and a base64-encoded image. Handle potential errors by checking the `isError` flag. ```typescript import { extractImageFromFile } from './src/image-utils'; // Basic usage const result = await extractImageFromFile({ file_path: '/screenshots/test.png' }); if (result.isError) { const errText = result.content[0] as { type: 'text'; text: string }; console.error('Failed:', errText.text); // e.g. "Error: File /screenshots/test.png does not exist" } else { // content[0] — JSON metadata text block const meta = JSON.parse((result.content[0] as { type: 'text'; text: string }).text); console.log(meta); // { // width: 512, height: 400, // format: "png", size: 48200, // original_width: 1920, original_height: 1080, // was_resized: true // } // content[1] — base64 image block ready for LLM vision input const img = result.content[1] as { type: 'image'; data: string; mimeType: string }; console.log(img.mimeType); // "image/png" // img.data — base64 string of the processed image } ``` -------------------------------- ### isPrivateIP Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Synchronously checks whether an IPv4 or IPv6 address falls into any private, loopback, link-local, or CGNAT range. ```APIDOC ## Function: isPrivateIP ### Description Synchronously checks whether an IPv4 or IPv6 address falls into any private, loopback, link-local, or CGNAT range. Used internally by `checkSSRFRisk` and exported for direct unit testing. ### Parameters #### Path Parameters - **ip** (string) - Required - The IP address to check. ### Request Example ```typescript import { isPrivateIP } from './src/image-utils'; console.log(isPrivateIP('127.0.0.1')); // true console.log(isPrivateIP('8.8.8.8')); // false ``` ### Response #### Success Response - **return value** (boolean) - `true` if the IP address is private, `false` otherwise. ``` -------------------------------- ### Extract Image from Base64 String with extractImageFromBase64 Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Use this function to decode and process a base64 encoded image string. It validates image size and uses the mime_type hint for format detection. Useful for images from clipboard or memory. ```typescript import * as fs from 'fs'; import { extractImageFromBase64 } from './src/image-utils'; // Read a file and convert to base64 for demonstration const raw = fs.readFileSync('/tmp/diagram.jpg'); const base64Input = raw.toString('base64'); const result = await extractImageFromBase64({ base64: base64Input, mime_type: 'image/jpeg' // default is "image/png" if omitted }); if (result.isError) { const err = result.content[0] as { type: 'text'; text: string }; console.error(err.text); // "Error: Invalid base64 string - Decoded to empty buffer" // "Error: Image size exceeds maximum allowed size of 10485760 bytes" } else { const meta = JSON.parse((result.content[0] as { type: 'text'; text: string }).text); const img = result.content[1] as { type: 'image'; data: string; mimeType: string }; console.log(meta.was_resized, img.mimeType); // true "image/jpeg" } ``` -------------------------------- ### Check if IP Address is Private with isPrivateIP Source: https://context7.com/ifmelate/mcp-image-extractor/llms.txt Synchronously checks if an IPv4 or IPv6 address falls within private, loopback, link-local, or CGNAT ranges. This utility is used internally for SSRF risk assessment. ```typescript import { isPrivateIP } from './src/image-utils'; // Private / blocked ranges console.log(isPrivateIP('127.0.0.1')); // true — loopback console.log(isPrivateIP('10.0.0.1')); // true — RFC 1918 console.log(isPrivateIP('172.16.5.1')); // true — RFC 1918 console.log(isPrivateIP('192.168.1.100')); // true — RFC 1918 console.log(isPrivateIP('169.254.1.1')); // true — link-local console.log(isPrivateIP('100.64.0.1')); // true — CGNAT console.log(isPrivateIP('::1')); // true — IPv6 loopback console.log(isPrivateIP('::ffff:127.0.0.1')); // true — IPv4-mapped loopback console.log(isPrivateIP('fd00::1')); // true — IPv6 ULA // Public / allowed console.log(isPrivateIP('8.8.8.8')); // false console.log(isPrivateIP('2001:4860:4860::8888')); // false — Google public DNS ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.