GAM MCP Server
The GAM MCP Server provides 13 administrative tools for managing Google Workspace via service account impersonation (Domain-Wide Delegation), covering users, groups, Gmail, Drive, and Sheets.
User & Group Management
Create user accounts with optional auto-generated passwords
Move users between Organizational Units or re-parent OU hierarchies
Sync Google Group memberships by computing and applying membership diffs
List users, groups, and group members with pagination (JSON or CSV output)
Gmail Compliance & Auditing
Search any user's mailbox using Gmail query syntax (returns metadata + snippets)
Fetch full details of a specific email, including recursively decoded MIME body parts
Bulk delete emails matching a query (defaults to dry-run with sample previews)
Drive Security Auditing
List Drive file metadata across user, domain, or Shared Drives
Stream permissions audits to local files (CSV or JSONL) in a memory-safe manner
Sheets Integration
Export local CSV audit files to Google Sheets in 2000-row chunks
Read worksheet ranges to feed data into administrative automation workflows
Safety Features: All mutating tools default to dry-run mode; a read-only mode blocks all writes; output paths are allowlisted and symlink-rejected.
Provides tools for searching, fetching, and bulk deleting emails within a Google Workspace domain, with features like MIME decoding, pagination, and dry-run support for bulk operations.
Offers file listing and permission auditing across user, domain, or shared drives, with memory-safe streaming to disk for large audits.
Enables exporting audit data from CSV to Google Sheets in safe chunks, and reading sheet ranges for administrative automation, with CSV injection defense.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@GAM MCP Server create a new user for John Doe"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Google Apps Manager (GAM) TypeScript Model Context Protocol (MCP) Server
A high-performance, secure, memory-safe Model Context Protocol (MCP) server that implements Google Workspace administrative controls (Directory, Gmail, Drive, Sheets) via Domain-Wide Delegation (DWD) service account impersonation.
Designed as a modern TypeScript alternative to traditional GAM scripts, this server provides a structured, schema-validated toolset that integrates with any Model Context Protocol host (such as Antigravity or Claude Desktop).
Core Architectural Features
Resilient Rate-Limiting: API requests are wrapped in exponential backoff with fractional randomized jitter. The retry classifier distinguishes retryable (
429,5xx,403/quotaExceeded, networkECONNRESET/ETIMEDOUT/etc.) from non-retryable errors (400,403/forbidden,403/insufficientPermissions), and honorsRetry-Afterheaders when the server provides one.Stream-to-Disk Operations:
StreamDiskWriterpipes large search and audit responses line-by-line directly to local files at0600permissions, bypassing standard V8 heap limits to prevent Node.js Out-Of-Memory (OOM) crashes.Concurrency-Limitation Gates: A strict write-concurrency queue limited to maximum 5 active operations for Directory mutations, and 10 concurrent Drive audit list pages.
Token-Scrubbing Filter: Globally intercepts
stdoutandstderrto mask access tokens (ya29.*), refresh tokens (1//0*), ID tokens (eyJ*.*.*), and PEM private key blocks before any bytes are flushed. Idempotent.POSIX Security Guard: Validates service account key file permissions on startup, emitting a high-visibility security warning if the key is world- or group-accessible. Called exactly once at startup.
Path Allowlist: All tool I/O paths (audit outputs, CSV imports) are resolved under
GAM_MCP_OUTPUT_DIR(or cwd if unset). Paths that escape the root are rejected, as are any paths whose ancestry contains a symlink.CSV Injection Defense: Spreadsheet-bound output prefixes leading
=,+,-,@,\t,\rwith a single quote per OWASP guidance, preventing formula injection when audits are opened in Excel or Sheets.JWT Client Cache: DWD JWT instances are cached per
(subject, scopes)so the underlyinggoogle-auth-libraryaccess-token cache is reused across many calls within a single audit.Multi-line CSV Reader: The Sheets exporter correctly joins records that span multiple physical lines (RFC 4180 §2.6).
Structured Logging: A stderr-only logger emits human-readable text in
testmode and single-line JSON inprodmode (set viaNODE_ENVorGAM_MCP_ENV). Log level is gated via--log-level/GAM_MCP_LOG_LEVEL.
Related MCP server: google-workspace-mcp
Tool Catalog (13 Administrative Tools)
Directory & Group Management
gam_admin_create_user: Creates user accounts.passwordis optional — if omitted, a cryptographically secure 32-character base64url password (~192 bits of entropy) is generated and returned ONCE in the response.gam_admin_update_ou: Moves a user or re-parents an OU. Requires explicittargetType: 'user' | 'ou'(no auto-detection from@).gam_admin_sync_group_members: Computes membership diffs and syncs concurrently up to the 5-concurrency write limit. If a group's membership exceeds theMAX_PAGES_LIMITread cap, the diff would be computed against partial membership: a dry-run returnstruncated: truewith a warning, and a real sync is refused to avoid a destructive partial sync.gam_admin_print_users: Paginated user listing (up toMAX_PAGES_LIMITpages) in CSV or JSON.gam_admin_print_groups: Paginated group listing in CSV or JSON.gam_admin_print_group_members: Paginated active-member listing in CSV or JSON.
Gmail Compliance & Mail Auditing
gam_gmail_search_messages: Searches a mailbox and returns metadata + snippets of the first N results in CSV or JSON.gam_gmail_get_message: Fetches details for a single email, decoding base64url MIME parts recursively (depth-capped at 20).gam_gmail_bulk_delete: Batch deletes emails matching a query in chunks of 1000 IDs (Gmail's API limit). Default dry-run shows up to 15 sample previews. When more messages match than can be enumerated within theMAX_PAGES_LIMITpage cap, the response setstruncated: trueand the message instructs you to re-run (or narrow the query) to delete the remainder.
Drive Security Auditing
gam_drive_list_files: Lists file metadata. Acceptscorpora: 'user' | 'domain' | 'drive' | 'allDrives'to widen the search scope (useallDrivesfor Shared Drives).gam_drive_audit_permissions: Memory-safe permission audit. Streams flattened rows to a file underGAM_MCP_OUTPUT_DIRwith the inherited-ancestry cache active across the run. Also acceptscorpora.
Sheets & Reports
gam_export_audit_to_sheets: Streams a local CSV (which MUST live underGAM_MCP_OUTPUT_DIR) to a Sheet tab in safe 2000-row chunks. Auto-creates missing tabs.gam_read_admin_sheet: Reads a worksheet range to feed targeting data back into administrative automation runs.
Note: Gmail, Drive, and Sheets tools no longer accept adminUserEmail — the DWD impersonation subject is always the named mailbox/Drive/Sheet owner (userEmail).
Google Workspace Setup (Domain-Wide Delegation)
To authorize this service account, a Google Workspace Super-Admin must configure Domain-Wide Delegation (DWD) inside the Google Workspace Admin Console.
1. Create a Service Account in GCP
Go to the Google Cloud Console.
Create or select a project (e.g.,
gam-mcp).Enable the following APIs:
Admin SDK API (
admin.googleapis.com)Gmail API (
gmail.googleapis.com)Google Drive API (
drive.googleapis.com)Google Sheets API (
sheets.googleapis.com)
Navigate to IAM & Admin > Service Accounts and create a Service Account (e.g.,
gam-mcp-sa).Generate and download a JSON credentials key. Save it securely.
Set secure POSIX file permissions:
chmod 0600 ~/secrets/oauth2service.jsonNote the Client ID (Unique ID) of the service account.
2. Configure Domain-Wide Delegation (DWD)
Log into the Google Workspace Admin Console as a Super Admin.
Go to Security > Access and data control > API controls.
Under Domain-wide delegation, click Manage Domain Wide Delegation.
Click Add new, enter the Client ID, and paste these OAuth scopes:
https://www.googleapis.com/auth/admin.directory.user, https://www.googleapis.com/auth/admin.directory.group, https://www.googleapis.com/auth/admin.directory.group.member, https://www.googleapis.com/auth/admin.directory.orgunit, https://www.googleapis.com/auth/drive.readonly, https://www.googleapis.com/auth/gmail.readonly, https://mail.google.com/, https://www.googleapis.com/auth/spreadsheets, https://www.googleapis.com/auth/spreadsheets.readonly(
https://mail.google.com/is only required forgam_gmail_bulk_delete.)Save the delegation.
Installation & Local Execution
Requires Node.js 20+ LTS (enforced via package.json engines).
cd gam-mcp
npm install
npm run build
npm run test # unit + integrationConfiguration
The server resolves settings in this precedence order (highest wins):
CLI flags (see below)
Environment variables
Config file (
--config <path>)Built-in defaults
CLI flags
gam-mcp-server [options] [credentials.json]
OPTIONS:
-c, --credentials <path> Service-account JSON key file.
--config <path> Path to a key=value (or key: value) config file.
--log-level <level> error | warn | info | debug
--read-only Block all mutating tool invocations.
--dry-run Treat mutating tools as dry-runs by default.
-h, --help Show help and exit.
-v, --version Show version and exit.Environment variables
Variable | Purpose |
| Path to the service-account JSON key. |
| Same, but standard GCP env var. |
| Path to a config file (same format as |
|
|
|
|
| Allowlist root for tool I/O. Defaults to cwd. |
|
|
A template is provided in .env.example.
Config file format
Lines are key = value or key: value. # and ; introduce comments.
credentials = /Users/me/secrets/oauth2service.json
log_level = info
read_only = false
output_dir = /Users/me/gam-mcp-auditsConnecting to an MCP Host
Claude Desktop
~/Library/Application Support/Claude/claude_desktop_config.json (macOS):
{
"mcpServers": {
"gam-mcp": {
"command": "node",
"args": [
"/Users/yourname/src/gam-mcp/build/index.js",
"--log-level", "info"
],
"env": {
"GAM_MCP_CREDENTIALS": "/Users/yourname/secrets/oauth2service.json",
"GAM_MCP_OUTPUT_DIR": "/Users/yourname/gam-mcp-audits"
}
}
}
}Antigravity
Register the server inside your Antigravity MCP registry, ensuring the absolute path to build/index.js is correct.
Security & Data Safety Standards
Read-Only Command Gate: When enabled (via
--read-onlyorGAM_MCP_READ_ONLY), all mutating operations are blocked at the executor level. Dry-runs still proceed.Fail-Safe Dry-Runs: All mutating tools default to
dryRun: true. Bulk delete additionally surfaces 15 sample previews on dry-run.Stderr-Only Logging: The MCP stdio transport requires a pristine stdout. The logger writes ONLY to stderr; stdout is reserved for JSON-RPC.
Token Scrubbing: Every byte written to stdout/stderr is scanned for known token patterns and masked.
Output Path Allowlist: Audit writes and CSV imports cannot escape
GAM_MCP_OUTPUT_DIR. Symlink-bearing paths are rejected. Files are created with mode0600.Closed-By-Default Error Policy: Errors are returned to MCP callers as text content with
isError: true; full stack traces (includingcausechains) go to stderr atdebug/warnlevels.
Project files
File | Purpose |
| Original developer specification (historical roadmap). |
| This file (operational reference). |
| Live status tracker. |
| Architectural design notes. |
| Verification log per release. |
| Environment template. |
License
MIT.
Available Tools
13 toolsgam_admin_create_userA
Creates a new user account in the Google Workspace directory. If password is omitted on a non-dry-run, a secure random password is generated and returned ONCE in the response.
Inputs: givenName (required), familyName (required), primaryEmail (required), adminUserEmail (required), +3 more.
gam_admin_print_group_membersB
Lists active members of a group, paginating until exhaustion.
Inputs: groupEmail (required), adminUserEmail (required), format.
gam_admin_print_groupsA
Lists groups, paginating until exhaustion (capped at MAX_PAGES_LIMIT pages).
Inputs: adminUserEmail (required), format.
gam_admin_print_usersB
Lists user profiles, paginating until exhaustion (capped at MAX_PAGES_LIMIT pages).
Inputs: adminUserEmail (required), query, format, orgUnitPath.
gam_admin_sync_group_membersA
Synchronizes a Google Group's membership against a target list, adding/removing concurrently.
Inputs: groupEmail (required), targetMembers (required), adminUserEmail (required), dryRun.
gam_admin_update_ouA
Moves a user to a different OU or re-parents an OU. The caller MUST set targetType explicitly.
Inputs: targetKey (required), targetType (required), orgUnitPath (required), adminUserEmail (required), +1 more.
gam_drive_audit_permissionsC
Memory-safe Drive permissions audit. Streams results to a local file under GAM_MCP_OUTPUT_DIR (or cwd if unset).
Inputs: userEmail (required), outputPath (required), query, format, +3 more.
gam_drive_list_filesC
Lists Drive file metadata matching a server-side query.
Inputs: query (required), userEmail (required), format, corpora, +1 more.
gam_export_audit_to_sheetsB
Streams a local CSV audit to a Google Sheet tab in safe 2000-row chunks. CSV path must live under GAM_MCP_OUTPUT_DIR.
Inputs: csvPath (required), sheetName (required), userEmail (required), spreadsheetId (required), +2 more.
gam_gmail_bulk_deleteA
Purges emails matching a query in bulk. Defaults to dry-run with samples.
Inputs: query (required), userEmail (required), dryRun.
gam_gmail_get_messageA
Fetches details of a single email including recursively decoded body content.
Inputs: messageId (required), userEmail (required).
gam_gmail_search_messagesB
Searches a mailbox and returns metadata + snippets. The mailbox owner (userEmail) is the DWD impersonation subject.
Inputs: query (required), userEmail (required), format, maxResults.
gam_read_admin_sheetC
Reads a worksheet range to feed administrative execution scripts.
Inputs: range (required), userEmail (required), spreadsheetId (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 13 tools
Each tool targets a distinct Google service and operation (Admin, Drive, Gmail, Sheets), with no overlapping functionality. Tools like `gam_admin_print_groups` and `gam_admin_print_group_members` are clearly differentiated by object type.
All tools follow a consistent `gam_<service>_<action>[_<object>]` pattern in snake_case, using descriptive verbs like create, print, sync, update, audit, list, export, and read.
With 13 tools covering Admin, Drive, Gmail, and Sheets operations, the tool count is well-scoped for a Google Workspace administration server—neither too sparse nor overly heavy.
The tool set covers common admin tasks like user creation, group management, drive auditing, and Gmail operations. Minor gaps exist, such as missing user deletion or group creation, but core workflows are well-supported.
Maintenance
Related MCP Connectors
Hosted MCP for Google Workspace, Atlassian and Notion: one OAuth, per-user accounts, write access.
Read and edit GA4, Search Console and Google Tag Manager from any MCP client. 29 tools.
One OAuth connector for your team's remote MCP servers, with Tool Packs, guardrails and logs.
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables interaction with Google Workspace (Drive, Docs, Sheets, Gmail) via MCP tools, using OAuth credentials stored locally or inline.-
- FlicenseNot gradedqualityDmaintenanceEnables multi-user access to Google Workspace services (Gmail, Calendar, Docs, Sheets, Slides, Drive) via remote MCP with OAuth 2.1 authentication.-
- AlicenseAqualityCmaintenanceEnables AI assistants to access and manage Google Drive, Sheets, Docs, Calendar, and Gmail through OAuth2-authenticated MCP tools.271MIT
- FlicenseNot gradedqualityBmaintenanceEnables AI assistants to access and manage Google Workspace services such as Gmail, Drive, Docs, Sheets, Calendar, and Slides through the MCP protocol, with built-in OAuth 2.0 authentication and read/write tool support.-