Skip to main content
Glama
imgtobase64-mcp-server

imgtobase64-mcp-server

by guiguito

imgtobase64-mcp-server

An MCP (Model Context Protocol) server that converts images to base64-encoded data. Designed for LLMs with vision capabilities that need images as base64 input.

Works with any MCP-compatible client — Claude Desktop, Claude Code, Cursor, and more — over stdio (local) or HTTP (remote/Docker).

Tools

image_url_to_base64

Fetch an image from a URL and convert it to base64.

Parameter

Type

Required

Description

url

string

Yes

Image URL to fetch

timeout_ms

number

No

Request timeout in ms (1000–120000, default 30000)

image_file_to_base64

Read a local image file and convert it to base64.

Parameter

Type

Required

Description

file_path

string

Yes

Path to the local image file

Response format

Both tools return a JSON object:

{
  "base64": "iVBORw0KGgo...",
  "mimeType": "image/png",
  "sizeBytes": 24680,
  "width": 800,
  "height": 600,
  "dataUri": "data:image/png;base64,iVBORw0KGgo..."
}

image_file_to_base64 also includes resolvedPath (the absolute path that was read).

width and height are extracted from image headers when possible (PNG, JPEG, GIF, BMP, WebP) without any native dependencies.

Supported formats

PNG, JPEG, GIF, WebP, BMP, SVG, TIFF, ICO, AVIF

MIME type is detected via magic bytes (file-type) with a fallback to file extension. Maximum file size is 20 MB.

Related MCP server: llm-vision-mcp

Getting started

Prerequisites

  • Node.js >= 20

Install and build

npm install
npm run build

Run locally (stdio)

node dist/index.js

Run locally (HTTP)

TRANSPORT=http node dist/index.js
# or
node dist/index.js --transport http

The server listens on http://0.0.0.0:3000 by default. Check with:

curl http://localhost:3000/health

Client configuration

Claude Desktop

Add to your Claude Desktop config (claude_desktop_config.json):

{
  "mcpServers": {
    "imgtobase64": {
      "command": "node",
      "args": ["/absolute/path/to/dist/index.js"]
    }
  }
}

Claude Code

claude mcp add imgtobase64 node /absolute/path/to/dist/index.js

Cursor

Add to .cursor/mcp.json:

{
  "mcpServers": {
    "imgtobase64": {
      "command": "node",
      "args": ["/absolute/path/to/dist/index.js"]
    }
  }
}

Remote (HTTP) clients

Point your client to http://<host>:3000/mcp. The server implements the Streamable HTTP transport with session management.

Docker

Docker Compose

docker compose up --build

Standalone

docker build -t imgtobase64-mcp-server .
docker run -p 3000:3000 imgtobase64-mcp-server

The Docker image:

  • Uses a multi-stage build (compile in builder, run with production deps only)

  • Runs as non-root user mcpuser

  • Defaults to HTTP transport on port 3000

  • Includes a health check at /health

Environment variables

Variable

Default

Description

TRANSPORT

stdio

Transport mode: stdio or http

PORT

3000

HTTP server port (HTTP mode only)

LOG_LEVEL

info

Log verbosity: debug, info, warn, error

The --transport CLI flag takes precedence over the TRANSPORT env var.

All logs are written to stderr (JSON format), keeping stdout clean for the MCP stdio protocol.

HTTP endpoints

Method

Path

Description

POST

/mcp

MCP protocol (initialize + tool calls)

GET

/mcp

SSE stream for notifications

DELETE

/mcp

Terminate a session

GET

/health

Health check

Development

npm run dev          # Watch mode (recompile on change)
npm run lint         # Check with Biome
npm run lint:fix     # Auto-fix lint/format issues
npm run inspect      # Open MCP Inspector

Project structure

src/
├── index.ts              # Entry point — transport selection (stdio/http)
├── server.ts             # McpServer creation + tool registration
├── tools/
│   ├── imageUrlToBase64.ts   # image_url_to_base64 tool
│   └── imageFileToBase64.ts  # image_file_to_base64 tool
└── utils/
    ├── imageUtils.ts     # MIME detection, base64 encoding, dimension parsing
    └── logger.ts         # stderr-only JSON logger

License

MIT

Available Tools

2 tools
image_file_to_base64A

Read a local image file and convert it to base64. Returns base64 data, MIME type, size, dimensions, resolved path, and a ready-to-use data URI.

Inputs: file_path (required).

image_url_to_base64A

Fetch an image from a URL and convert it to base64. Returns base64 data, MIME type, size, dimensions, and a ready-to-use data URI.

Inputs: url (required), timeout_ms.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 2 tools

    Disambiguation4/5

    The two tools are near-identical in function and differ only by input source (remote URL vs local file path), which the descriptions state clearly. An agent could plausibly hesitate over which to use if the source is ambiguous, but the split is logical and well-signposted.

    Naming Consistency5/5

    Both names follow the exact same pattern: image_<source>_to_base64. Verb/object ordering and casing are perfectly consistent.

    Tool Count4/5

    Two tools is thin in absolute terms but fits a narrowly scoped single-purpose server whose only job is producing base64 from images. Nothing extraneous is present, though the surface is close to the borderline of 'too few'.

    Completeness3/5

    The inbound direction is covered for both remote and local sources, but the inverse operation (base64 back to image) and batch/validation options are absent. For a one-directional converter this is acceptable, but it leaves notable functional gaps.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers