Skip to main content

mgs — One CLI for Microsoft 365

mgs is a fast Python CLI for Microsoft 365 — built for humans and AI agents. It builds its command surface dynamically from Microsoft Graph's CSDL metadata and covers Outlook mail & calendar, OneDrive/SharePoint files, Teams, Excel, OneNote, and directory users. It is the Microsoft counterpart to the gws Google Workspace CLI.

  • Structured JSON output on every command
  • --dry-run on every write; OData --select/--filter/--top/...; --page-all
  • Zero-setup browser login (Entra ID via MSAL); mgs schema <service> introspection
  • ~33 ms local overhead; one runtime dependency (msal)
  • Generated agent skills (SKILL.md + AGENTS.md) so any agent can drive it

Install

Requires Python 3.10+. The package is mgs-cli; the command it installs is mgs. Easiest via uv or pipx:

uv tool install mgs-cli        # or: pipx install mgs-cli   → provides the `mgs` command

Run without installing: uvx --from mgs-cli mgs --help.

From source:

git clone https://github.com/mr-illu-minati/mgs-cli && cd mgs-cli
uv tool install .                       # installs the `mgs` command globally
# or, for development:
uv sync && uv run mgs --help            # and: uv run pytest

Update with uv tool upgrade mgs-cli, remove with uv tool uninstall mgs-cli.

Quick start

mgs auth login                                   # browser sign-in (Entra ID)
mgs mail +triage --max 5
mgs calendar +agenda --week --timezone America/Toronto
mgs files +upload ./report.pdf --to /Documents
mgs mail +send --to you@example.com --subject Hi --body "It works"
mgs schema mail                                  # introspect a service

Login works out of the box: mgs ships its own registered multi-tenant Entra app ("mgs CLI"), so mgs auth login needs no setup. Organizations can bring their own app via MGS_CLIENT_ID. For unattended/server/CI use, set MGS_AUTH for app-only auth (client secret, workload identity federation, or managed identity). Details, scopes, and admin consent: docs/auth-production.md.

Commands

mail      list get create update delete  +send +read +reply +reply-all +forward +triage +watch
calendar  list get create update delete  +agenda +insert
files     list get create update delete  +upload +download
teams     list get create update delete  +send +channels +chats
excel     list get create update delete  +read +append
onenote   list get create update delete  +write
users     list get create update delete
auth login|logout|status   ·   schema <service>   ·   skills install   ·   generate-skills

Every service also accepts bound actions (e.g. mgs mail move <id> --json '{...}') and raw bodies via --json / --params. Discover anything with mgs <service> --help and mgs schema <service>.

Target mailbox (--mailbox)

By default commands run against the signed-in user (/me/). The global --mailbox <upn> flag retargets any command to another user's mailbox/drive/calendar (/users/<upn>/):

mgs mail +triage --mailbox assistant@contoso.com          # delegated: shared-mailbox access
MGS_AUTH=secret mgs mail list --mailbox user@contoso.com  # app-only: required (no /me/ context)

In app-only mode /me/ has no meaning, so a mailbox is required: pass --mailbox, or set MGS_DEFAULT_MAILBOX as a fallback. Without either, mgs fails fast with a usage error instead of sending a doomed Graph call. MGS_MAILBOX is the env twin of the flag (flag wins).

Related: mgs mail +send accepts --from <address> to send as a mailbox alias (requires the tenant's SendFromAliasEnabled) or another mailbox (requires Send As rights), and --header 'X-Name: value' (repeatable) for custom internet headers — Graph requires the X- name prefix.

Using mgs with AI agents (any platform)

mgs ships a generated, agent-agnostic skill set — no platform lock-in.

Install skills into a project

mgs skills install --dir /path/to/repo   # default targets: claude + agents
mgs skills install --target all          # claude + agents
mgs skills install --target cursor       # Cursor only
mgs skills install --global              # write to global skill dirs (~/.claude/skills etc.)
mgs skills install --prune               # also remove stale mgs-* skills from a previous version

The command is idempotent — re-running it when nothing changed reports added: 0. It never touches skill directories that don't start with mgs-.

Target directories

--target project dir global dir loaded by
claude (default) .claude/skills ~/.claude/skills Claude Code, GitHub Copilot, OpenCode
agents (default) .agents/skills ~/.agents/skills Cursor, OpenCode
cursor .cursor/skills ~/.cursor/skills Cursor
opencode .opencode/skills ~/.config/opencode/skills OpenCode

AGENTS.md

AGENTS.md at the repo root is the single agent-agnostic entry point read automatically by Codex, Cursor, Gemini CLI, Amp, Claude Code, and others. Generate or update it with:

mgs generate-skills --out skills   # writes skills/AGENTS.md; copy or symlink to repo root

The committed AGENTS.md at the root of this repo is kept up to date.

Low-level primitive

mgs generate-skills --out skills   # writes skills/<name>/SKILL.md + SKILLS.md + AGENTS.md

The recipient needs mgs installed and mgs auth login done once.

Performance

The 2.7 MB Graph $metadata is parsed at most once per 24 h and cached as compact per-EntityType JSON, so a typical command loads a few-KB file. MSAL is imported only when a token must be acquired or refreshed; a valid cached token skips it entirely.

Environment variables

Variable Purpose
MGS_TOKEN Pre-obtained Graph access token (highest priority)
MGS_CLIENT_ID / MGS_TENANT_ID Bring-your-own Entra app + tenant (default tenant: common)
MGS_SCOPES Delegated Graph scopes to request at login (space/comma-separated; default: all). Handy with a minimal BYO app.
MGS_CONFIG_DIR Config dir override (default ~/.config/mgs)
MGS_NO_BROWSER Use device-code login instead of the browser (headless/CI)
MGS_AUTH Auth mode: delegated (default), app-only, secret, workload, managed-identity — for unattended/server/CI use (details)
MGS_MAILBOX Target mailbox UPN for /me/-style commands (env twin of the global --mailbox flag)
MGS_DEFAULT_MAILBOX Fallback mailbox in app-only mode when --mailbox/MGS_MAILBOX is not given
AZURE_CLIENT_SECRET / MGS_CLIENT_SECRET App-only client secret (service principal)
AZURE_CLIENT_CERTIFICATE_PATH App-only certificate (PEM)
AZURE_FEDERATED_TOKEN_FILE App-only workload identity federation (OIDC) token file
AZURE_CLIENT_ID / AZURE_TENANT_ID Standard fallbacks

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mgs_cli-0.8.2.tar.gz (99.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mgs_cli-0.8.2-py3-none-any.whl (48.1 kB view details)

Uploaded Python 3

File details

Details for the file mgs_cli-0.8.2.tar.gz.

File metadata

  • Download URL: mgs_cli-0.8.2.tar.gz
  • Upload date:
  • Size: 99.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mgs_cli-0.8.2.tar.gz
Algorithm Hash digest
SHA256 7a3be9f0ca4b5422b8549bf17a867ef263cae10f3d2668fdd60add38ae8ff3cf
MD5 5701b0266caf4b74f360c58a1ff72057
BLAKE2b-256 14dc2fcc570fcfe11c1e8832b8253760646e9c77cf0cded7e1cbcecdea35430a

See more details on using hashes here.

File details

Details for the file mgs_cli-0.8.2-py3-none-any.whl.

File metadata

  • Download URL: mgs_cli-0.8.2-py3-none-any.whl
  • Upload date:
  • Size: 48.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mgs_cli-0.8.2-py3-none-any.whl
Algorithm Hash digest
SHA256 300317ef9d8d3d2f50ce0847ca2cc392310e69b5ab7a56a77a520ebf95b5238c
MD5 edb610fad5b3102a71facf467bad6d27
BLAKE2b-256 f0fa2176a737892164f8c58d630556aa02e02622df0d1d15d8a5d27e11e2c9cd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page