Skip to main content

MCP server for ZhipuAI GLM — chat, text embeddings, translation, and vision

Project description

glm-mcp

MCP server for ZhipuAI GLM — exposes chat, text embeddings, translation, and vision to Claude Code (and any MCP-compatible client) via the OpenAI-compatible API.

Tools

Tool Description
glm_chat Text completion — default model glm-4-flash, pass model= to use any GLM chat model (e.g. glm-5). Supports single-turn and multi-turn (messages= parameter). Auto-fallback on transient errors (429/503/timeout/connection) via auto_fallback=True (default). Use avoid_peak_hours=True to pre-emptively switch during peak hours (UTC+8 14:00–18:00).
glm_embed Text embeddings — default model embedding-3, pass model= to override
glm_usage_summary Query token usage from ~/.glm-mcp/usage.jsonl. Parameters: days (default 7), model (optional filter). Returns period, total tokens, by_tool, by_model.
glm_translate Pure single-language translation — default model glm-4.7. Parameters: text, target_lang ("ja", "zh", "en"), source_lang (default "auto"), style ("formal" or "casual", default "formal"). Outputs ONLY the target language, solving the mixed Chinese–Japanese output problem common with general LLMs.
glm_vision Multimodal image analysis — default model glm-4v-plus. Parameters: image_url (HTTP/HTTPS URL or Base64 string), prompt, detail ("auto", "low", "high"), max_tokens (default 2048). Auto-fallback to glm-4v on 429/503/timeout. Bare Base64 strings are automatically prefixed with data:image/png;base64,.

Quick Start

Install via uvx (recommended)

uvx glm-mcp

Add to Claude Code

Add to ~/.claude.json:

{
  "mcpServers": {
    "glm-mcp": {
      "type": "stdio",
      "command": "uvx",
      "args": ["glm-mcp"],
      "env": {
        "GLM_API_KEY": "your_api_key_here"
      }
    }
  }
}

Get your API key at https://open.bigmodel.cn/.

Run from source

git clone https://github.com/sky-zhang01/glm-mcp
cd glm-mcp
uv sync
GLM_API_KEY=your_key uv run glm-mcp

Environment Variables

Variable Required Default Description
GLM_API_KEY Yes ZhipuAI API key
GLM_BASE_URL No https://open.bigmodel.cn/api/paas/v4/ API endpoint override
GLM_MCP_LOG_DIR No ~/.glm-mcp/ Directory for usage.jsonl token log

Token Usage Logging

Each tool call appends a JSON line to ~/.glm-mcp/usage.jsonl:

{"timestamp": "...", "tool": "glm_chat", "model": "glm-4-flash", "input_tokens": 13, "output_tokens": 15, "fallback_used": false, "original_model": null, "fallback_reason": null}

When fallback is triggered:

{"timestamp": "...", "tool": "glm_chat", "model": "glm-4.7", "input_tokens": 13, "output_tokens": 15, "fallback_used": true, "original_model": "GLM-5", "fallback_reason": "429"}

Development

uv sync --dev
uv run pytest --cov=glm_mcp --cov-report=term-missing

License

MIT

Project details


Download files

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

Source Distribution

glm_mcp-0.6.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

glm_mcp-0.6.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file glm_mcp-0.6.0.tar.gz.

File metadata

  • Download URL: glm_mcp-0.6.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 glm_mcp-0.6.0.tar.gz
Algorithm Hash digest
SHA256 963e511b4c8de761a265b75fc6e2dd7b984e31c317d03730d41c1ab09c92da30
MD5 bcbc287c6725ffcd399eea4804c56667
BLAKE2b-256 9d2461fef5dd2583c0ce33e7d3ca61dde49ac713ab9713662c6327cb865bb565

See more details on using hashes here.

File details

Details for the file glm_mcp-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: glm_mcp-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","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 glm_mcp-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b5a92b624ce9697dcc77844ba031b251aa9210d9ff1c2ecef77d7aff5138a7c1
MD5 e487cf65071c08f971bae3d7f809195a
BLAKE2b-256 2197e50362ed91b91157d78a901f1cd7a64cadd79c58db786d11fefdd5786f51

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 Pingdom Monitoring Sentry Error logging StatusPage Status page