Skip to content
MoftgateMoftgate Docs
Product guide

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.

shell
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.

shell
mg --version
mg profile create prod https://center.example.local
mg profile use prod
mg profile list
mg profile delete staging
Deleting a profile
mg profile delete removes the profile and suggests running mg auth logout first so the token is revoked on the server, not just deleted locally.

Authentication#

  1. 1
    Point 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.

  2. 2
    Log 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.

  3. 3
    Verify the session

    mg auth status shows the active session and the organization the token belongs to.

  4. 4
    Log out when done

    mg auth logout revokes the token on the Center and deletes the local credentials for the profile.

shell
mg auth login
mg auth status
mg auth logout

Device Commands#

CommandDescriptionScope
mg device listLists 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 exportExports the device inventory as CSV for reporting or import into other tools.Read
shell
mg device list --os "Ubuntu" --status online
mg device inspect web-01
mg device export --limit all

Alert Commands#

CommandDescriptionScope
mg alert listLists 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
shell
mg alert list --device web-01 --status open
mg alert inspect a-4821
mg alert resolve a-4821 --yes

Script Commands#

CommandDescriptionScope
mg script listLists 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> --waitRuns a saved script on a device group and waits for results.Write
shell
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
Wait for the fleet
The --wait flag keeps the CLI attached until every targeted device reports a result, so group runs return a complete picture instead of a queued job.

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.

CommandDescriptionScope
mg run listLists 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
shell
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.

shell
mg device list -o json
mg device list --jq '.list[] | {id, hostname, status}'
mg device list --limit all --jq '.list | length'
FlagDescription
--versionPrints 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.
--yesSkips interactive confirmation on risky write operations.
--ca-bundle <path>Uses a custom CA bundle for on-premises self-signed certificates.
--insecureDisables 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.

CommandDescription
mg skill showPrints SKILL.md to stdout without installing it.
mg skill installWrites SKILL.md to ~/.agents/skills/moftgate/SKILL.md for user-level agents.
mg skill install --projectWrites 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.
shell
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
One token, two users
Your agent does not get a separate credential — it uses the token from mg auth login on the same profile. Every write action the agent performs is attributed to you in the Center audit log.

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.
Never disable verification in production
A CLI that skips TLS verification can be redirected to an attacker’s server and will hand it a valid token. Treat --insecure as a local-development escape hatch only.

Frequently Asked Questions#

Which platforms does mg run on?
mg is a single static binary for macOS, Linux, and Windows. It talks to your Moftgate Center over its API; no extra server or gateway is required.
Does mg need a separate license?
No. mg authenticates against your existing Center with a token from mg auth login. The first-year free tier (up to 200 endpoints) applies to CLI usage as well.
How do I script mg in CI pipelines?
Pass --yes to skip interactive confirmations and -o json (or --jq) for machine-readable output. Non-interactive shells never receive prompts.
What permission does an AI agent get?
Whatever the issuing user has. The token inherits the user’s role: read-only tokens can list and inspect, while write operations like alert resolve or script run require write scope.
Can mg reach an on-premises Center with a self-signed certificate?
Yes. Point mg at your private CA with --ca-bundle <path>. The --insecure flag disables verification entirely, but keep it to development environments.