This document defines the refactor of zai-cli into a fully MCP‑native, LLM‑optimized CLI. The new CLI:
- Uses UTCP + MCP for all services, including Vision (stdio).
- Supports Code Mode for tool‑chaining via TypeScript.
- Provides tool discovery, schemas, and raw tool calls for perfect LLM alignment.
- Outputs data‑only by default for token efficiency, with optional JSON wrappers.
The goal is to make every MCP tool discoverable, debuggable, and safe for agent usage while preserving simple human UX.
- Full MCP coverage for Vision, Search, Reader, and ZRead.
- LLM‑first ergonomics: data‑only output, tool schemas, and chainable execution.
- Zero guesswork: explicit help, tool discovery, and a
doctorcommand. - Minimal surface area: one CLI that is both human‑friendly and agent‑friendly.
zai-cli
├── MCP Client (UTCP + MCP plugin)
│ ├── Vision (stdio via @z_ai/mcp-server)
│ ├── Search (HTTP)
│ ├── Reader (HTTP)
│ └── ZRead (HTTP)
└── Code Mode (UTCP Code Mode)
└── Executes TypeScript with tool calls
- Native MCP interoperability.
- Tool discovery (
listTools) for schema introspection. - Unified tool naming (
manual.server.tool). - Reliable session handling for both stdio and HTTP.
- Best tool‑chaining workflow for LLMs.
- TypeScript interface generation for all tools.
- Tool discovery + runtime introspection (
__interfaces).
All tools are registered under a single manual name:
zai.<server>.<tool>
Servers:
visionsearchreaderzread
Command: npx -y @z_ai/mcp-server@latest
Tools:
analyze_imageui_to_artifactextract_text_from_screenshotdiagnose_error_screenshotunderstand_technical_diagramanalyze_data_visualizationui_diff_checkanalyze_video
Endpoints:
https://api.z.ai/api/mcp/web_search_prime/mcp
https://api.z.ai/api/mcp/web_reader/mcp
https://api.z.ai/api/mcp/zread/mcp
zai-cli vision <cmd> <source> [prompt] [options]
zai-cli search <query> [options]
zai-cli read <url> [options]
zai-cli repo <cmd> <owner/repo> [args]
zai-cli tools [--full|--typescript]
zai-cli tool <name>
zai-cli call <tool> --json <payload>
zai-cli doctor
zai-cli code <run|eval|interfaces|prompt>
All commands emit the raw tool data to stdout, optimized for LLM consumption.
Use --output-format json or --output-format pretty:
{
"success": true,
"data": "...",
"timestamp": 1234567890
}Errors are JSON on stderr and include actionable help.
Z_AI_API_KEY
Z_AI_VISION_MCP_COMMAND
Z_AI_VISION_MCP_ARGS
Z_AI_VISION_MCP_CWD
Z_AI_VISION_MCP=0 # disable vision MCP
ZAI_OUTPUT_MODE=data|json|pretty
-
Central MCP configuration
- Single call template shared by UTCP + Code Mode.
-
Vision moved to MCP
- All 8 tools mapped directly to MCP tool calls.
-
Tool discovery + raw calls
tools,tool, andcallcommands.
-
Code Mode support
code run,code eval,code interfaces,code prompt.
-
Output overhaul
- Data‑only output by default, JSON wrapper optional.
-
Diagnostics
doctorcommand validates env + tool discovery.
- Vision tools:
analyze,ui-to-code,extract-text,diagnose-error,diagram,chart,diff,video
- Search:
searchwith domain + recency
- Reader:
readwith markdown + text
- ZRead:
repo tree,repo read,repo search
tools+tool(schema discovery)callwith explicit JSON payloadcode eval(tool chaining)doctor(env + tools)
- Add
--streamoption for streaming responses if MCP servers support it. - Add caching layer for search/read.
- Add “batch” mode for tool calls.
This refactor makes zai-cli fully MCP‑native, LLM‑optimized, and discoverable. All tool schemas are accessible, every endpoint is reachable through a stable interface, and the CLI now supports both direct tool calls and tool‑chaining via Code Mode.