@zleap-ai/sag-cli is the official command-line client for SAG knowledge bases. From your terminal it lets you:
- Sign in to and validate a running SAG instance;
- Inspect sources and document processing status, and search knowledge directly;
- Verify the local Docker SAG knowledge-base MCP and wire it into Codex and Claude Code with a single command.
- You already have a SAG instance (local Docker or remote HTTP) and want to query, diagnose, and expose it to coding agents from the terminal.
- You are developing or operating SAG and need diagnostics such as
doctorandmcp test. - You want to use SAG for retrieval inside Codex or Claude Code without hand-writing an MCP config.
| Task | Requirement |
|---|---|
| Install and run the CLI | Node.js ≥ 20.19 |
| Sign in and search via the HTTP API | A reachable SAG origin (e.g. http://localhost:8000) |
| Use the local Docker token-less path | Docker CLI, with a SAG API container running sag_api.mcp.server locally |
| Wire into Codex | Codex CLI (≥ 0.145) installed |
| Wire into Claude Code | Claude Code (≥ 2.1) installed |
How to sign in: sag auth login --name "Your name" is for the default SAG_AUTH_MODE=local. With password mode, sign in through the SAG web UI first, then provide the issued token to the CLI through SAG_TOKEN. The CLI prefers the OS credential store (macOS Keychain, Windows Credential Manager, Linux Secret Service).
npm install --global @zleap-ai/sag-cli
sag --help
sag versionThe CLI offers two independent paths. Pick one based on your situation.
Requires a SAG API container running locally in Docker. The CLI discovers the container, talks to it over stdio MCP via docker exec, and never needs the JWT.
# 1. Verify the local Docker SAG MCP works
sag mcp test
# 2. Wire it into an agent (either or both)
sag agent connect codex
sag agent connect claude-code
# 3. Check status any time
sag agent statusScope to a single source with --source-id:
sag mcp test --source-id <source-id>
sag agent connect codex --source-id <source-id>Preview the plan with --dry-run before writing anything:
sag agent connect codex --dry-runUndo an integration:
sag agent disconnect codexAuthenticate and search against SAG's HTTP API directly.
# 1. Register a SAG instance
sag profile add local http://localhost:8000
sag profile use local
# 2. Sign in through SAG's existing login API
sag auth login --name "Your name"
sag auth status
# 3. Health check and browse
sag doctor
sag source list
sag document status --source <source-id>
# 4. Search
sag search "how to wire MCP" --source <source-id> --top-k 5A profile stores only scheme://host[:port]. The /api/v1 prefix is added by the CLI — do not put it in the URL yourself.
sag version
sag auth login | status | logout
sag profile add | list | use | show | remove
sag doctor
sag source list | get | status
sag document list | get | status
sag search <query>
sag outline <document-id>
sag grep <pattern>
sag read <document-id>
sag get-entity <name>
sag mcp test
sag agent list
sag agent connect <codex | claude-code>
sag agent status [codex | claude-code]
sag agent disconnect <codex | claude-code>
Common examples:
sag profile list --json
sag source get <source-id>
sag document list --source <source-id>
sag search "how to wire MCP" --source <source-id> --strategy multi
sag mcp test --container sag-api-1 --timeout 15000
sag agent connect claude-code --name sag-knowledge-local--profile <name> Select a profile
--url <origin> Override the SAG origin for one command
--json Emit stable JSON (schema: sag.cli.v1)
--quiet Print only the essential value
--yes Confirm a safe local configuration operation
Priority: CLI flag > environment variable > current profile > local default probe.
SAG_URL=http://localhost:8000
SAG_TOKEN=<jwt>
SAG_PROFILE=localProfile storage locations:
| Platform | Path |
|---|---|
| macOS | ~/Library/Application Support/sag-cli/config.yaml |
| Linux | $XDG_CONFIG_HOME/sag-cli/config.yaml or ~/.config/sag-cli/config.yaml |
| Windows | %APPDATA%\sag-cli\config.yaml |
Agent-integration managed state is kept in managed-connections.yaml (mode 0600). Do not edit it by hand.
- SAG CLI never writes the JWT into agent configuration. The local Docker path needs no token at all.
- The default MCP entry name is
sag-knowledge-<profile>, orsag-knowledge-localwhen no profile is active. - The CLI only removes MCP entries it created whose fingerprint is unchanged. Same-name user entries and external edits block overwrite and delete.
--dry-runshows the plan only;--yesskips confirmation but never skips conflict checks.
Under --json, both success and failure use a fixed schema:
{ "schema": "sag.cli.v1", "ok": true, "data": {} }{
"schema": "sag.cli.v1",
"ok": false,
"error": { "code": "AUTH_REQUIRED", "message": "No SAG token is configured" }
}Tokens never appear in JSON, logs, or error output. Full error and exit codes live in the CLI architecture docs.