mg CLI
Manage devices, alerts, scripts, and runs from the terminal — and give your AI agent the same controls via SKILL.md.
What mg CLI Is#
mg is the command-line interface for Moftgate Center. It is a single static binary for macOS, Linux, and Windows that talks to your Center over its API. Anything you do in the console — listing devices, triaging alerts, running scripts, tracking runs — is available as a command.
mg is designed for two audiences at once: operators who prefer the terminal, and AI agents that drive the same commands through a generated SKILL.md file.
mg auth login mg device list --group Servers --limit 3 mg alert list --severity critical
Installation and Profiles#
Profiles let one mg binary talk to multiple Centers — your production Center, a staging environment, or a customer tenant. Each profile stores a URL and its own credentials.
mg --version mg profile create prod https://center.example.local mg profile use prod mg profile list mg profile delete staging
Authentication#
- 1Point a profile at your Center
Run mg profile create <name> <url> to register the Center URL, then select it with mg profile use <name>. Multiple profiles let you switch between production, staging, or customer tenants.
- 2Log in through the browser
mg auth login opens a browser approval flow. After you approve, a token is issued to the CLI and stored locally under the active profile.
- 3Verify the session
mg auth status shows the active session and the organization the token belongs to.
- 4Log out when done
mg auth logout revokes the token on the Center and deletes the local credentials for the profile.
mg auth login mg auth status mg auth logout
Device Commands#
| Command | Description | Scope |
|---|---|---|
| mg device list | Lists devices. Filters: --group, --tag, --status, --os. | Read |
| mg device inspect <id|hostname> | Shows a single device’s details: OS, agent version, last seen, posture score. | Read |
| mg device export | Exports the device inventory as CSV for reporting or import into other tools. | Read |
mg device list --os "Ubuntu" --status online mg device inspect web-01 mg device export --limit all
Alert Commands#
| Command | Description | Scope |
|---|---|---|
| mg alert list | Lists alerts. Filters: --device, --severity, --status. | Read |
| mg alert inspect <id> | Shows a single alert’s details and evidence. | Read |
| mg alert resolve <id> | Marks an alert as resolved. Prompts for confirmation unless --yes is passed. | Write |
mg alert list --device web-01 --status open mg alert inspect a-4821 mg alert resolve a-4821 --yes
Script Commands#
| Command | Description | Scope |
|---|---|---|
| mg script list | Lists scripts registered in the Center script library. | Read |
| mg script run --command "…" --device <id> | Runs an ad-hoc command on a single device. | Write |
| mg script run --script <name> --group <g> --wait | Runs a saved script on a device group and waits for results. | Write |
mg script list mg script run --command "journalctl -u nginx --no-pager -n 50" --device web-01 mg script run --script "Restart nginx" --group Web --wait
Run Commands#
Every script execution — ad-hoc or saved — produces a run. Runs are the audit trail for what was executed, where, and with what result.
| Command | Description | Scope |
|---|---|---|
| mg run list | Lists active and completed runs. | Read |
| mg run inspect <id> | Shows run detail with per-action status. | Read |
| mg run cancel <id> | Cancels a run in progress. | Write |
| mg run retry <id> | Retries the failed actions of a run. | Write |
mg run list --status failed mg run inspect r-9042 mg run retry r-9042 --yes
Output Formats and Global Flags#
List commands print a colored, human-readable table by default. Pass -o json for machine-readable output, or --jq to project fields directly — jq output implies JSON. mg device export produces CSV.
mg device list -o json
mg device list --jq '.list[] | {id, hostname, status}'
mg device list --limit all --jq '.list | length'| Flag | Description |
|---|---|
| --version | Prints the mg CLI version and exits. Useful for verifying the install or reporting issues. |
| --profile <name> | Runs the command against a specific profile instead of the default. |
| -o, --output <fmt> | Output format: json or table. Table is the default. |
| --jq <filter> | Applies a jq filter to the output. Implies JSON output. |
| --limit <n|all> | Items per page. Default: 100. Use all to stream the full result set. |
| --page <n> | Page number for paginated list commands. |
| --yes | Skips interactive confirmation on risky write operations. |
| --ca-bundle <path> | Uses a custom CA bundle for on-premises self-signed certificates. |
| --insecure | Disables TLS verification. Development only — never use in production. |
Using mg with AI Agents#
mg ships with a built-in skill generator. SKILL.md teaches coding agents — Claude Code, Codex, Gemini, and others that read the .agents/skills convention — how to authenticate, which commands exist, and which flags to use.
| Command | Description |
|---|---|
| mg skill show | Prints SKILL.md to stdout without installing it. |
| mg skill install | Writes SKILL.md to ~/.agents/skills/moftgate/SKILL.md for user-level agents. |
| mg skill install --project | Writes SKILL.md to ./.agents/skills/moftgate/SKILL.md inside the current project. |
| mg skill describe <command> | Shows detail for a single command: usage, flags, examples, jq recipes. |
mg skill install # user level: ~/.agents/skills/moftgate/SKILL.md mg skill install --project # repo level: ./.agents/skills/moftgate/SKILL.md mg skill describe script run
Security and TLS#
- Tokens are issued per profile through the browser approval flow and revoked with mg auth logout.
- Write operations (alert resolve, script run, run cancel/retry) require write scope on the issuing user.
- Risky operations ask for interactive confirmation; --yes skips the prompt for CI and automation.
- For on-premises Centers with self-signed certificates, pass --ca-bundle <path> instead of disabling verification.
- --insecure disables TLS verification entirely. It exists for development — never point it at a production Center.