Skip to main content
Glama
mcp-workspace-admin

mcp-workspace-admin

by keyserfaty
README.md
<div align="center">

# ๐Ÿ”‘ mcp-workspace-admin

**A [Model Context Protocol](https://modelcontextprotocol.io) server for Google Workspace Admin operations.**
Let AI agents manage domains, mailboxes, and DKIM โ€” no browser required.

<br/>

[![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-3776AB?style=flat-square&logo=python&logoColor=white)](https://python.org)
[![License: MIT](https://img.shields.io/badge/license-MIT-22c55e?style=flat-square)](LICENSE)
[![MCP](https://img.shields.io/badge/MCP-compatible-8b5cf6?style=flat-square)](https://modelcontextprotocol.io)
[![Google Admin SDK](https://img.shields.io/badge/Google_Admin_SDK-4285F4?style=flat-square&logo=google&logoColor=white)](https://developers.google.com/admin-sdk)

</div>

---

## โœจ Overview

`mcp-workspace-admin` exposes Google Workspace Admin operations as MCP tools, making it trivial for AI agents and Claude Code workflows to:

- ๐ŸŒ **Add & verify domains** โ€” programmatically add domains to your Workspace and retrieve the DNS verification token
- ๐Ÿ‘ค **Manage mailboxes** โ€” create users, list accounts, and reset passwords
- ๐Ÿ” **Set up DKIM** โ€” generate keys and inject records into DNS

Originally built for **cold email infrastructure automation**: buy domains โ†’ add to Workspace โ†’ create sending mailboxes โ†’ configure DNS โ€” all in a single agent workflow, zero manual steps.

---

## ๐Ÿ“‹ Prerequisites

1. A **Google Workspace** account (any tier)
2. A **Google Cloud project** with the [Admin SDK API](https://console.cloud.google.com/apis/library/admin.googleapis.com) enabled
3. A **Service Account** with domain-wide delegation configured
4. Python 3.11+

---

## ๐Ÿš€ Setup

### 1. Create a Service Account

In [Google Cloud Console](https://console.cloud.google.com) โ†’ **IAM & Admin โ†’ Service Accounts**:

1. Create a new service account (e.g. `workspace-admin-mcp`)
2. Click the account โ†’ **Keys โ†’ Add Key โ†’ JSON** โ†’ download the file
3. Note the **Client ID** from the service account details page

### 2. Grant Domain-Wide Delegation

In [Google Workspace Admin](https://admin.google.com) โ†’ **Security โ†’ API controls โ†’ Domain-wide delegation**:

1. Click **Add new**
2. Enter the service account's **Client ID**
3. Add these OAuth scopes:

```
https://www.googleapis.com/auth/admin.directory.domain,
https://www.googleapis.com/auth/admin.directory.user,
https://www.googleapis.com/auth/gmail.settings.sharing
```

4. Click **Authorize**

### 3. Install

```bash
git clone https://github.com/keyserfaty/mcp-workspace-admin
cd mcp-workspace-admin

python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate

pip install -e .
```

### 4. Configure Environment

```bash
export GOOGLE_SERVICE_ACCOUNT_JSON="/path/to/service-account-key.json"
export GOOGLE_WORKSPACE_ADMIN_EMAIL="admin@yourdomain.com"
```

---

## โš™๏ธ MCP Configuration

Add to your `~/.claude.json` (or project `.mcp.json`):

```json
{
  "mcpServers": {
    "workspace-admin": {
      "type": "stdio",
      "command": "/path/to/.venv/bin/python",
      "args": ["/path/to/mcp-workspace-admin/server.py"],
      "env": {
        "GOOGLE_SERVICE_ACCOUNT_JSON": "/path/to/service-account-key.json",
        "GOOGLE_WORKSPACE_ADMIN_EMAIL": "admin@yourdomain.com"
      }
    }
  }
}
```

---

## ๐Ÿ› ๏ธ Tools Reference

### Domain Management

| Tool | Description | Key Parameters |
|------|-------------|----------------|
| `add_domain` | Add a domain to Workspace; returns the DNS verification TXT record | `domain: str` |
| `get_domain_status` | Check if a domain is verified | `domain: str` |
| `list_domains` | List all domains in the account | โ€” |

**Typical domain onboarding flow:**

```python
# 1. Add domain โ†’ get verification token
result = add_domain("example.com")
# โ†’ inject result["txt_record"] into DNS at @ as TXT

# 2. Poll until verified (DNS propagation: ~1โ€“5 min)
status = get_domain_status("example.com")
# โ†’ status["verified"] == True once propagated
```

---

### User / Mailbox Management

| Tool | Description | Key Parameters |
|------|-------------|----------------|
| `create_user` | Create a new Workspace mailbox | `email`, `first_name`, `last_name`, `password` |
| `list_users` | List users, optionally filtered by domain | `domain?: str`, `max_results?: int` |
| `reset_password` | Reset a user's password | `email`, `new_password`, `force_change?: bool` |

---

### DKIM

| Tool | Description | Key Parameters |
|------|-------------|----------------|
| `generate_dkim_key` | Generate a DKIM signing key | `domain: str`, `key_length?: int` |
| `get_dkim_record` | Retrieve the DKIM TXT record name and Admin console link | `domain: str` |
| `enable_dkim` | Instructions to activate DKIM signing | `domain: str` |

> โš ๏ธ **DKIM limitation** โ€” see below.

---

## โš ๏ธ Known Limitations

### DKIM cannot be fully automated via API

Google's public REST APIs do not expose DKIM key generation, retrieval, or activation endpoints. The three DKIM tools return the correct DNS record name and a direct link to the Admin console page instead of performing the action programmatically.

**Manual steps required for DKIM:**

```
Google Workspace Admin Console
  โ†’ Apps โ†’ Google Workspace โ†’ Gmail โ†’ Authenticate email
  โ†’ Select domain โ†’ Generate new record
  โ†’ Copy the TXT value โ†’ inject into DNS at google._domainkey.<domain>
  โ†’ Wait ~30โ€“60 min for DNS propagation
  โ†’ Click "Start authentication"
```

PRs that automate this via browser automation (e.g. Playwright) are very welcome.

---

## ๐Ÿค– Example Agent Workflow

This server is designed to power cold email infrastructure automation. A full agent flow:

```
1. Purchase domain via registrar API (e.g. Porkbun)
2. add_domain("newdomain.com")                 โ† workspace-admin MCP
3. Inject verification TXT into registrar DNS
4. Poll get_domain_status() until verified
5. create_user("hello@newdomain.com", ...)     โ† workspace-admin MCP
6. create_user("info@newdomain.com", ...)      โ† workspace-admin MCP
7. Add SPF / DMARC records via registrar API
8. DKIM setup (see limitation above)
9. Connect mailboxes to sending platform for warmup
```

---

## ๐Ÿ“ Project Structure

```
mcp-workspace-admin/
โ”œโ”€โ”€ server.py          # MCP server & tool definitions
โ”œโ”€โ”€ auth.py            # Google service account auth helpers
โ”œโ”€โ”€ pyproject.toml     # Package metadata & dependencies
โ””โ”€โ”€ README.md
```

---

## ๐Ÿค Contributing

Contributions welcome โ€” especially:

- **DKIM automation** via Playwright/browser automation fallback
- **Send-as alias** management
- **Group / mailing list** management
- **Suspend / restore user** tools

```bash
git checkout -b feature/your-feature
# make changes
git commit -m "feat: describe your change"
git push origin feature/your-feature
# open a PR
```

---

## ๐Ÿ“„ License

MIT ยฉ [Karen Serfaty](https://github.com/keyserfaty)

---

<div align="center">
<sub>Built for use with <a href="https://claude.ai/claude-code">Claude Code</a> ยท Powered by <a href="https://modelcontextprotocol.io">Model Context Protocol</a></sub>
</div>