Skip to main content

mcp-glm-ocr

                                  _                                 
 _ __ ___   ___ _ __         __ _| |_ __ ___         ___   ___ _ __ 
| '_ ` _ \ / __| '_ \ _____ / _` | | '_ ` _ \ _____ / _ \ / __| '__|
| | | | | | (__| |_) |_____| (_| | | | | | | |_____| (_) | (__| |   
|_| |_| |_|\___| .__/       \__, |_|_| |_| |_|      \___/ \___|_|   
               |_|          |___/                                   

Free OCR & vision for any AI coding client, powered by GLM-4.6V-Flash.

mcp-glm-ocr is an MCP server that gives OCR and image-understanding capabilities to AI clients that cannot process images themselves (Claude Code, Claude Desktop, Cursor, Cline, OpenCode, and any other MCP-compatible client).

Under the hood it sends the image to GLM-4.6V-Flash, z.ai's vision-language model, which is completely free (input and output). The model reads the image and returns text, so your text-only client gets full vision capabilities at zero cost.

Why this exists: z.ai's official vision MCP server is exclusive to paid GLM Coding Plan subscribers. This one works with a plain free z.ai account.

Tools

Tool Description
ocr_image(image) Extract all text from an image (screenshots, photos, receipts, document pages).
describe_image(image) Detailed description of what an image shows.
analyze_image(image, prompt) Answer a custom question about an image (charts, tables, diagrams, UI screenshots, math...).

All tools accept:

  • a local file path (absolute, or relative to the client's working directory), e.g. demo.png
  • an http(s) URL, e.g. https://example.com/photo.jpg
  • a file:// URL or a data: URL

Requirements

  • Python 3.10+ (or just uv)
  • A free z.ai API key

Get a free API key

  1. Go to https://z.ai/model-api and create an account (or log in).
  2. Create an API key at https://z.ai/manage-apikey/apikey-list.
  3. GLM-4.6V-Flash costs nothing to use.

Installation & configuration

1. Claude Code

claude mcp add glm-ocr --env ZAI_API_KEY=your_key -- uvx mcp-glm-ocr

Then in any conversation:

> what does demo.png say?
> read the text from receipt.jpg
> describe this image: ~/Pictures/screenshot.png
> analyze this chart: chart.png — what is the trend?

2. Claude Desktop

Add to claude_desktop_config.json:

{
  "mcpServers": {
    "glm-ocr": {
      "command": "uvx",
      "args": ["mcp-glm-ocr"],
      "env": { "ZAI_API_KEY": "your_key" }
    }
  }
}

3. Cursor

In .cursor/mcp.json at the root of your project:

{
  "mcpServers": {
    "glm-ocr": {
      "command": "uvx",
      "args": ["mcp-glm-ocr"],
      "env": { "ZAI_API_KEY": "your_key" }
    }
  }
}

4. Cline (VS Code)

In Cline settings → MCP servers:

{
  "mcpServers": {
    "glm-ocr": {
      "command": "uvx",
      "args": ["mcp-glm-ocr"],
      "env": { "ZAI_API_KEY": "your_key" }
    }
  }
}

5. OpenCode

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "glm-ocr": {
      "type": "local",
      "command": ["uvx", "mcp-glm-ocr"],
      "environment": { "ZAI_API_KEY": "your_key" }
    }
  }
}

Without uv (pip / Docker)

pip install mcp-glm-ocr
mcp-glm-ocr          # requires ZAI_API_KEY env var
docker run --rm -i -e ZAI_API_KEY=your_key mcp-glm-ocr

Environment variables

Variable Default Description
ZAI_API_KEY Required. Your z.ai API key. Z_AI_API_KEY is also accepted.
ZAI_MODEL glm-4.6v-flash Model to use. Switch to glm-4.6v for higher quality (paid), or glm-ocr for a dedicated cheap OCR model.
ZAI_BASE_URL https://api.z.ai/api/paas/v4/ API base URL. Lets you point at a proxy or self-hosted gateway.
ZAI_TIMEOUT 120 HTTP timeout in seconds.
ZAI_MAX_TOKENS 4096 Max output tokens per call.
ZAI_MAX_IMAGE_MB 15 Max local image size in MB (larger files are rejected).

Development

uv sync --all-groups        # install deps + dev deps
uv run pytest -q            # unit tests (no network, no API key)
uv run python scripts/smoke_stdio.py   # boots the real stdio MCP server, lists tools
uv run mcp-glm-ocr          # run the server locally (needs ZAI_API_KEY)
uv run mcp-glm-ocr --version
uv run python scripts/banner.py   # print the banner in color (terminal)

# real end-to-end call against the z.ai API (needs a real key).
# Omitting the image uses the bundled test fixture (tests/fixtures/test_image.png):
ZAI_API_KEY=your_key uv run python scripts/live_test.py
ZAI_API_KEY=your_key uv run python scripts/live_test.py path/to/your/image.png

How it works

  1. The client model calls ocr_image / describe_image / analyze_image.
  2. The server resolves the image (local file → base64 data: URL, or passthrough for URLs).
  3. It calls POST /chat/completions on the z.ai OpenAI-compatible API with model glm-4.6v-flash.
  4. The text answer is returned to the client model.

Limitations

  • Images only (no video). Video is out of scope for this free model.
  • Free tier has rate limits set by z.ai; check the rate limits docs.
  • Very large images are rejected by default (ZAI_MAX_IMAGE_MB=15).

Releasing (maintainer)

Option A: tag a version and let GitHub Actions build and publish automatically:

git tag v0.1.0 && git push --tags

Prerequisite: create a PyPI API token at https://pypi.org/manage/account/token/ and store it as the PYPI secret in the GitHub repo settings.

Option B: publish manually:

uv build                          # build sdist + wheel
uv publish                        # push to PyPI (requires a PyPI token)

After publishing, users install with uvx mcp-glm-ocr or pip install mcp-glm-ocr. Remember to bump version in pyproject.toml and src/mcp_glm_ocr/__init__.py for each release.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_glm_ocr-0.1.0.tar.gz (356.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_glm_ocr-0.1.0-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file mcp_glm_ocr-0.1.0.tar.gz.

File metadata

  • Download URL: mcp_glm_ocr-0.1.0.tar.gz
  • Upload date:
  • Size: 356.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mcp_glm_ocr-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bdc4580f15835950bfb4e85ad4e96db9c3de0917360990320c4cc895808f22e9
MD5 740b1962e7a8fc3ff5d75382675ae254
BLAKE2b-256 b4f5cca248b2304386dcc3524cffea34bed4ae7acd8d344ea2a9b6aa9402bcd1

See more details on using hashes here.

File details

Details for the file mcp_glm_ocr-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_glm_ocr-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mcp_glm_ocr-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f2d0bf861658e706ff4ebac3adf5a4cfac4b499a4ea1209e44959b116c9e183d
MD5 f79cb96160f1df9dd37a9ba59ca6cf35
BLAKE2b-256 af6fe8cf4337004e9e40ca55ada8109febfa6c1ee2d9ebed806c9e9351cd202c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page