griffin31-m365-mcp
README.md
# Griffin31 M365 MCP
**Safe Microsoft 365 admin from your AI assistant. Read freely, change only with approval, always with a backup.**
An open-source [Model Context Protocol](https://modelcontextprotocol.io) server by [Griffin31](https://www.griffin31.com) for Microsoft Entra ID, Conditional Access, Intune, SharePoint and Microsoft Defender, built on Microsoft Graph.
> [!IMPORTANT]
> **Status: skeleton, not production-ready.** This is a starter kit. The safety core works and is tested (tenant isolation, two-step approval, backups and restore, two auth modes), but it ships with only a few example tools. We run a much larger, heavily customized version ourselves. Rather than publish our personal setup, we're opening the core so we can build the rest together. **Contributions are welcome.** See [CONTRIBUTING.md](CONTRIBUTING.md) and the [roadmap](#roadmap).
>
> Try it in a test tenant first. Read [SECURITY.md](SECURITY.md) before you point it at a production tenant.
## Why another M365 MCP server?
Most Graph MCP servers give an AI model one powerful token and hope for the best. This one is built around how a careful admin actually works:
| Principle | How it's enforced |
|---|---|
| **One tenant per session** | The server is pinned to one tenant ID. Every tool call must name that tenant, and every token's `tid` claim is checked. The token cache, backups and audit log live in that tenant's own folder. |
| **Read and write are different identities** | Certificate mode uses **two app registrations**. The read-only app handles every read. The admin app's key isn't even loaded until an approved change is applied. If the read app ever holds a write permission, the server refuses to use it. |
| **No change without a human yes** | Changes take two steps. A `*_plan_*` tool returns a **change ID and a diff** and writes nothing. `change_apply` needs that ID **and** `confirm=true`. Plans are single-use, expire after 15 minutes, and are refused if the object changed in the meantime. |
| **Backup before every write** | The current object's JSON is saved to a local backups folder *before* the write. If the backup can't be written, nothing is changed. `backup_plan_restore` undoes a change, and the undo goes through the same approval gate. |
| **Writes are off by default** | Write tools aren't even registered unless you set `G31_ALLOW_WRITES=true`. |
## Quick start
Requirements: Node.js 20+ and a Microsoft 365 tenant where you can register apps (use a test tenant first).
```bash
git clone https://github.com/griffin31-public/griffin31-m365-mcp.git
cd griffin31-m365-mcp
npm install
npm test # runs against a mock Graph, no tenant needed
npm run build
```
1. Create the app registrations and certificates: [docs/setup-app-registrations.md](docs/setup-app-registrations.md).
2. Copy `.env.example` (or `config.example.json`) and fill in your own values.
3. Add the server to your MCP client.
**Claude Code**
```bash
claude mcp add griffin31-m365 \
-e G31_TENANT_ID=<TENANT_ID> \
-e G31_READ_CLIENT_ID=<READ_APP_CLIENT_ID> \
-e G31_READ_CERT_PATH=/secure/path/read.pem \
-- node /path/to/griffin31-m365-mcp/dist/index.js
```
**Claude Desktop and other clients** (`mcpServers` JSON)
```json
{
"mcpServers": {
"griffin31-m365": {
"command": "node",
"args": ["/path/to/griffin31-m365-mcp/dist/index.js"],
"env": {
"G31_TENANT_ID": "<TENANT_ID>",
"G31_READ_CLIENT_ID": "<READ_APP_CLIENT_ID>",
"G31_READ_CERT_PATH": "/secure/path/read.pem"
}
}
}
}
```
To enable changes, also set `G31_ALLOW_WRITES=true`, `G31_ADMIN_CLIENT_ID` and `G31_ADMIN_CERT_PATH`. To manage a second tenant, add a **second server entry** with its own tenant ID and apps. One process never serves two tenants.
## Configuration
Set these as environment variables, or put them in a JSON file and point `G31_M365_CONFIG` at it. Environment variables override the file.
| Variable | Meaning |
|---|---|
| `G31_TENANT_ID` | Tenant ID (GUID). Required. Domains and placeholders are rejected. |
| `G31_AUTH_MODE` | `certificate` (default, app-only) or `delegated` (signed-in admin). |
| `G31_READ_CLIENT_ID`, `G31_READ_CERT_PATH` | Read-only app and its PEM (certificate + private key). `G31_READ_KEY_PATH` if the key is a separate file. `G31_READ_KEY_PASSPHRASE` for an encrypted key. |
| `G31_ADMIN_CLIENT_ID`, `G31_ADMIN_CERT_PATH` | Admin app (same pattern as the read app). Only needed when writes are on. |
| `G31_DELEGATED_CLIENT_ID`, `G31_DELEGATED_FLOW` | Delegated mode: public client app ID; `device_code` (default) or `interactive`. |
| `G31_ALLOW_WRITES` | `true` registers the plan/apply tools. Default `false`. |
| `G31_CHANGE_TTL_MINUTES` | How long a plan stays valid (default 15, max 120). |
| `G31_DATA_DIR` | Token cache, backups, audit log. Default `~/.griffin31-m365-mcp`, one sub-folder per tenant. |
## Tools
Every tenant-bound tool takes a required `tenantId`, which must match the pinned tenant.
**Read** (read-only app or read scopes)
| Tool | What it does |
|---|---|
| `session_info` | Pinned tenant, auth mode, whether writes are on, whether the admin credential is loaded. |
| `auth_sign_in` | *Delegated mode.* Starts a device-code sign-in and returns the code to show the user. |
| `entra_list_users` | Users (`$filter` supported). |
| `entra_list_groups` | Groups (`$filter` supported). |
| `ca_list_policies` / `ca_get_policy` | Conditional Access policies: summary list, or one policy in full. |
| `intune_list_compliance_policies` | Device compliance policies. |
| `intune_list_device_configurations` | Device configuration profiles (template-based). |
| `sharepoint_get_tenant_settings` | Tenant-wide SharePoint and OneDrive settings (sharing capability and more). |
| `defender_get_secure_score` | Latest Microsoft Secure Score and percentage, with per-control scores on request. |
| `defender_list_incidents` | Microsoft Defender XDR incidents. |
| `backup_list` | Backups taken before changes. |
**Write** (only when `G31_ALLOW_WRITES=true`)
| Tool | What it does |
|---|---|
| `ca_plan_create_policy` | Plans a new CA policy. It defaults to **report-only** unless you set a state. |
| `ca_plan_update_policy` | Plans a partial update to a CA policy. |
| `ca_plan_set_policy_state` | Plans setting a CA policy to on, off or report-only. |
| `intune_plan_update_compliance_policy` | Plans a partial update to a compliance policy. |
| `backup_plan_restore` | Plans the undo of an earlier change from its backup. |
| `change_list` / `change_discard` | Shows or drops pending plans. |
| `change_apply` | Applies a plan. Needs `changeId` and `confirm=true`. |
Plan tools also return **warnings**, for example when a CA policy targets all users with no exclusions (break-glass lock-out risk), blocks access, or is set to enforce right away.
Exact Microsoft Graph permissions for each tool and mode are in [docs/permissions.md](docs/permissions.md).
## Safety model
```
plan tool ──read app──▶ Graph GET → change ID + diff + warnings (nothing written)
│
human reviews the diff, says yes
│
change_apply(changeId, confirm=true)
├─ load admin credential (first time only)
├─ re-read object, refuse if it changed since the plan
├─ save backup JSON (refuse to continue if this fails)
├─ PATCH / POST / DELETE
└─ re-read and verify, write audit record
```
- **Tenant pinning:** `tenant.json` in the tenant's folder, a `tenantId` argument on every call, and a `tid` check on every token.
- **Least privilege:** the read app holds read permissions only, and the server checks this. The admin app holds just the write permissions the write tools need.
- **Audit:** every plan outcome (applied, failed, discarded, expired) is written to `<data dir>/tenants/<tenant id>/changes/`.
- **Local secrets:** certificates and keys stay on your machine. Backups can contain tenant configuration, so treat that folder as sensitive.
Details and threat model: [SECURITY.md](SECURITY.md).
## Roadmap
The core is the hard part. Each item below is mostly one well-scoped tool plus a permission row and a test, which makes them good first contributions:
- **Entra:** get a user or group, group members, directory role assignments, PIM eligibility, named locations, authentication methods policy, sign-in and audit logs.
- **Conditional Access:** what-if evaluation, policy templates, export/import of a baseline.
- **Intune:** settings catalog policies, endpoint security policies, assignments, update rings, apps; `intune_plan_update_device_configuration`.
- **SharePoint:** site search and per-site sharing, `sharepoint_plan_update_tenant_settings`.
- **Defender:** alerts (`alerts_v2`), secure score control profiles, advanced hunting.
- **Exchange Online:** a separate, isolated module (it isn't Graph).
- **Platform:** a certificate in the OS keychain instead of a PEM file, an HTTP transport with auth, change approval through a second person, packaging on npm.
Open an issue before you start on a big one, so we can agree on the shape.
## Check your tenant against these controls
This server lets an assistant read and change settings. It doesn't tell you **which** settings matter. [Griffin31](https://www.griffin31.com) continuously checks your Microsoft 365 tenant against a large catalog of security recommendations (Conditional Access, Intune, Defender, SharePoint, Exchange and more), maps them to frameworks such as CIS, and tells you what to fix first.
**[Check your tenant at www.griffin31.com →](https://www.griffin31.com)**
## Related: Argus
Also from Griffin31: **Argus**. Website: [argus.griffin31.com](https://argus.griffin31.com). Source: [github.com/griffin31-public/argus](https://github.com/griffin31-public/argus).
## Contributing
Issues and pull requests are welcome. Read [CONTRIBUTING.md](CONTRIBUTING.md) first. In short: every tool lists its exact permissions, tests run without a tenant, and no real IDs or secrets ever go into the repo.
## License
[MIT](LICENSE) © Griffin31 and contributors.
Microsoft, Microsoft 365, Entra, Intune, SharePoint and Defender are trademarks of the Microsoft group of companies. This project is not affiliated with or endorsed by Microsoft.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues