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

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)
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.0.tar.gz (94.6 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.0-py3-none-any.whl (45.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mgs_cli-0.8.0.tar.gz
  • Upload date:
  • Size: 94.6 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.0.tar.gz
Algorithm Hash digest
SHA256 f706ac4b782c5c412907c3b8bc832e0c63ce25c84d1e46089859acf22a26a324
MD5 0cc5fb1e9ed64013d36c36270b939b5e
BLAKE2b-256 e754545cdb34f6ab41f90800ecf08599662a790bc73e09a14d57c3ed4a1b065e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mgs_cli-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 45.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4395f9295abcd957cd9735188380febbae63d8072c2c36b08d7580dc96e512c3
MD5 21e0a0c21a1381b04f66b0629672858e
BLAKE2b-256 79089217f5867871332c5110549a481cafd32dc8d6a6c35e178ed85f7e8ee535

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