SuperAPI AI Directory

glm-mcp

Run GLM (Zhipu/Z.ai) as a sub-agent in Claude Code or GitHub Copilot with its own read/write/edit/run loop, Opus-vs-GLM routing and diff/dry-run oversight.

Open website

About this tool

glm-mcp is an MCP server that uses GLM (Zhipu / Z.ai) as a low-cost delegate for AI coding clients. Its positioning is: let an expensive primary model (Claude Opus, Copilot's default model, or Codex) handle orchestration and review, while GLM takes on the actual coding work and is billed at cheap GLM token rates. Because GLM provides an Anthropic-compatible /v1/messages endpoint, it can be embedded directly into any tool that already supports the Anthropic protocol. The repository wraps it as an MCP server with four tools and provides one-click installers for Claude Code, GitHub Copilot, and Codex, with the same server driving all versions.

Purpose and how it works: the user gives a task to the primary agent; the primary agent delegates via glm_agent, passing in a goal and an absolute working directory (workdir). The server's router picks a GLM model (peak-hour aware) and calls Z.ai's /v1/messages endpoint; cost preference keeps GLM as the default option. GLM runs its own agent loop (read_file / write_file / edit_file / list_dir / run_bash), working directly against the user's repository, then ends with a summary. The server returns a concise summary plus a GLM STATS block (model, token counts, estimated cost) to the primary agent. The primary agent reviews; every GLM call is also appended to the usage.jsonl ledger.

Token economics note: delegated work is billed at GLM token rates (about 10x cheaper), and the primary model only pays for orchestration and review. To get close to a 100% GLM share, you need to use the all-GLM launcher (claude/glm-code.mjs), because in mixed mode the primary agent carries session context every turn, and that context is the lower bound of its token share.

Live progress: glm_agent streams MCP progress notifications while running, including the current iteration, token count, and tok/s, displayed live in Claude Code and mapped to VS Code Copilot's tool.execution_progress. This heartbeat also keeps long calls alive on clients that reset their timeout based on progress; canceling a run stops GLM promptly (partial changes are shown and can be rolled back). max_tokens defaults to auto (no limit or a lenient setting; the orchestrating agent can pass a number to limit a given call). The server uses idle/stall timeouts (GLM_STALL_TIMEOUT_MS, default 2 minutes), so turns that are actively streaming are not truncated. If a very long run is still canceled by a client tool-call timeout, you can raise MCP_TOOL_TIMEOUT / CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUT.

Installation (by version): (a) Claude Code: installs globally by default (user level): the MCP server, a glm subagent with the full toolset, a PreToolUse auto-routing hook, and an optional glm-code all-GLM launcher. Restart Claude Code, then run glm_status to confirm api_key_loaded: true. See claude/README.md for details. (b) GitHub Copilot / VS Code: in agent mode, install the MCP server, a GLM custom agent (subagent), a PreToolUse auto-routing hook, and a delegation instructions file. Reload the VS Code window, open Copilot Chat in Agent mode, and start the glm server. See copilot/README.md for details. Installing the published Codex package: installs the Codex MCP registration, a glm custom agent, the glm-delegate skill, and a suggested UserPromptSubmit / PreToolUse hook. Configure a 30-minute timeout for GLM tools, and prompt before change-type calls. Restart Codex, review the hooks with /hooks, then run glm_status. See codex/README.md for details. (d) Any MCP client / Glama / Docker: the standalone glm-mcp package — Cursor, Windsurf, Claude Desktop, Glama and the like require no installer. In container scenarios, the Dockerfile at the repository root runs the same server. The server can start and respond to MCP introspection without a key; set GLM_API_KEY only when actually making GLM calls.

Version overview and parity: all three versions expose the same four tools and one sub-agent, using the same server underneath. Codex uses its native custom agent, skills, and hook interfaces; its hooks are advisory only and must be trusted by the user. Only Claude comes with a separate glm-code all-GLM launcher. All switches are in .env (already git-ignored). Version locations: Claude ~/.claude/glm-mcp/.env (set at install time); Copilot ~/.glm-mcp/glm-mcp/.env; Codex ~/.codex/glm-mcp/.env. Codex sets tool_timeout_sec = 1800 because its default MCP tool timeout is 60 seconds. For a fully annotated reference, see claude/glm-mcp/.env.example.

Peak-aware routing and cost: China peak hours are 14:00–18:00 (UTC+8). The glm-5.x series has a surcharge during peak (about 3x peak / 2x off-peak), so when auto lands on a glm-5.x model during peak, the router assigns less work to GLM; if a model without a surcharge is listed (for example GLM_PEAK_MODEL=glm-5.2,glm-4.7), the router will prefer it during peak, and GLM can still be used normally. In either case, the cost preference keeps GLM as the default—even during peak it is still cheaper than the main model. The following cases stay on the main model: sensitive/confidential code, visual input, parallel fan-out, 128K context, latency-sensitive loops, and heavily dependency-laden tool loops (the router's hard override).

Proving GLM was actually used: the usage.jsonl ledger—every GLM call is appended to disk with model + input_tokens + output_tokens. Claude: ~/.claude/glm-mcp/usage.jsonl; Copilot: ~/.glm-mcp/glm-mcp/usage.jsonl. Independent of the Z.ai dashboard. glm_status prints the cumulative ledger totals (call count, tokens, per-model counts). After each glm_agent run, it prints a === GLM STATS === block: model, delegated tokens, iteration count, changed files, estimated cost relative to Opus. If the ledger is empty, GLM was never called—the work ran on the main model.

Supervision and safety: dry_run: true on glm_agent—GLM proposes a full diff and writes nothing; apply it after approval. After each real glm_agent run, it prints a Git checkpoint rollback line (when workdir is a git repository), so it can be undone with one command. Key isolation—GLM_API_KEY exists only in the git-ignored .env and is never written into the npm package (scripts/publish-server.mjs scans every package for .env / usage.jsonl / node_modules and errors out explicitly if found). Data residency—GLM traffic goes to Z.ai servers located in China. Keep confidential and regulated code on the main model; the router's sensitive flag forces it to stay on the main model.

Development / CI: CI (see .github/workflows/ci.yml) runs: syntax checks on the server and every installer/hook/script; a keyless stdio smoke test (scripts/smoke-stdio.mjs) that asserts the four-tool MCP handshake with no key on disk; a Docker introspection test (piping initialize into the built image); and an npm-pack secret scan (scripts/publish-server.mjs). PRs are welcome—see CONTRIBUTING.md.

License: MIT © djerok · Official repository:https://github.com/djerok/glm-mcp