Google Workspace MCP Server
Allows creating Gmail drafts and sending plain-text emails via the Gmail API, with optional idempotency keys to prevent duplicate sends.
Allows appending plain text to the end of an existing Google Doc via the Google Docs API while preserving existing document content.
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., "@Google Workspace MCP Serversend an email to sarah@example.com saying the project is done"
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 Workspace MCP Server
Generic Model Context Protocol server that lets any MCP-compatible AI agent draft/send Gmail messages and append content to Google Docs.
What it does
Tool | Description |
| Create a Gmail draft (not sent) |
| Send a plain-text email (external side effect) |
| Append text to the end of an existing Google Doc |
The server is agent-agnostic: any MCP client can discover and call these tools.
Related MCP server: Google Services MCP Server
Architecture
AI Agent (MCP client)
│
▼
MCP Server (tools, validation, auth, errors, logs)
│
┌────┴────┐
▼ ▼
Gmail API Docs APILayers:
MCP tools — thin handlers with Zod schemas
Domain services — Gmail / Docs logic (mockable)
Auth — Google OAuth 2.0 + token persistence
Utils — validation, canonical errors, structured logging
See docs/architecture.md for the full design.
Prerequisites
Node.js 20+
A Google Cloud project with OAuth 2.0 credentials
Gmail API and Google Docs API enabled
Google Cloud setup
Open Google Cloud Console.
Create or select a project.
Enable APIs:
Gmail API
Google Docs API
Configure the OAuth consent screen (External or Internal).
Create OAuth client ID credentials:
Application type: Desktop app (recommended for local MCP)
or Web application with redirect URIhttp://localhost:3000/oauth2callback
Copy the Client ID and Client Secret.
OAuth scopes (requested automatically)
https://www.googleapis.com/auth/gmail.compose
https://www.googleapis.com/auth/gmail.send
https://www.googleapis.com/auth/documentsLocal setup
git clone <repository>
cd "MCP Server"
npm install
cp .env.example .envEdit .env:
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT_URI=http://localhost:3000/oauth2callback
GOOGLE_TOKEN_PATH=.tokens/google-tokens.json
MCP_API_KEY= # optional; when set, required on /mcp
LOG_LEVEL=infoAuthenticate once
npm run authOpen the printed URL, sign in with Google, and approve the scopes. Tokens are saved to GOOGLE_TOKEN_PATH (gitignored).
Run the server (stdio — local clients)
npm run devOr build and run stdio:
npm run build
npm run start:stdioRun the server (HTTP — Railway / remote clients)
npm run dev:httpOr:
npm run build
npm startHealth: GET /health → { "status": "ok" }
MCP: POST /mcp — if MCP_API_KEY is set, send Authorization: Bearer <key> or X-API-Key
Logs go to stderr (stdout is reserved for MCP JSON-RPC on stdio).
Connect an MCP client
Cursor (local stdio)
Add to MCP settings (example):
{
"mcpServers": {
"google-workspace": {
"command": "npx",
"args": ["tsx", "/absolute/path/to/MCP Server/src/index.ts"],
"env": {
"GOOGLE_CLIENT_ID": "your-client-id",
"GOOGLE_CLIENT_SECRET": "your-client-secret",
"GOOGLE_REDIRECT_URI": "http://localhost:3000/oauth2callback",
"GOOGLE_TOKEN_PATH": "/absolute/path/to/MCP Server/token.json"
}
}
}
}After npm run build, you can point command at node and args at dist/index.js.
Cursor (remote HTTP — Railway)
{
"mcpServers": {
"google-workspace": {
"url": "https://<service>.up.railway.app/mcp",
"headers": {
"Authorization": "Bearer <MCP_API_KEY>"
}
}
}
}Omit headers only if MCP_API_KEY is unset (not recommended for a public URL).
MCP Inspector
npx @modelcontextprotocol/inspector npx tsx src/index.tsFor HTTP:
npm run dev:http
# then point Inspector at http://localhost:3000/mcpDeploy on Railway
This repo includes railway.toml. Operational notes: docs/railway-deploy.md. Design checklist: docs/deployment-plan.md.
Setting | Value |
Builder | Nixpacks |
Build |
|
Start |
|
Health check |
|
Node |
|
Connect the GitHub repo in Railway and deploy from
main.Public MCP URL:
https://<service>.up.railway.app/mcpSet Variables (boot/
/healthwork without Google secrets; tools need them):
NODE_ENV=production
GOOGLE_CLIENT_ID=...
GOOGLE_CLIENT_SECRET=...
GOOGLE_TOKENS_JSON=... # full token.json as one JSON string
MCP_API_KEY=... # recommendedGenerate GOOGLE_TOKENS_JSON after local npm run auth:
node -e "console.log(JSON.stringify(JSON.parse(require('fs').readFileSync('token.json','utf8'))))"Smoke test:
curl -sS https://<service>.up.railway.app/healthRunbook — rotate secrets
Secret | Rotation |
| Generate a new key, update Railway Variables + client configs |
Google client secret | Rotate in Google Cloud Console, update |
Tokens revoked | Run |
Treat a public /mcp URL (especially without MCP_API_KEY) as full access to the linked Google account’s Gmail/Docs tools.
Available tools
gmail_draft_email
Creates a draft only — does not send.
{
"to": ["recipient@example.com"],
"cc": [],
"bcc": [],
"subject": "Email subject",
"body": "Email body"
}gmail_send_email
Sends immediately to external recipients and cannot be automatically undone.
{
"to": ["recipient@example.com"],
"subject": "Email subject",
"body": "Email body",
"idempotencyKey": "optional-unique-key"
}Optional idempotencyKey prevents duplicate sends when an agent retries the same operation.
google_docs_append_content
Appends plain text at the end of an existing document (preserves existing content).
{
"documentId": "1AbCdEfGhIjKlMnOp",
"content": "Text to append"
}The document ID is the long ID in the Docs URL:https://docs.google.com/document/d/<documentId>/edit
Example agent flows
Send email
User: Send an email to John saying the meeting moved to 4 PM.
Agent → gmail_send_emailAppend meeting notes
User: Add today's notes to the project Google Doc.
Agent → google_docs_append_contentError model
Tools return a JSON envelope:
{
"success": false,
"error": {
"code": "AUTHENTICATION_REQUIRED",
"message": "Google authentication is required.",
"retryable": false
}
}Common codes: AUTHENTICATION_REQUIRED, INVALID_EMAIL, DOCUMENT_NOT_FOUND, PERMISSION_DENIED, VALIDATION_ERROR, GOOGLE_API_ERROR, NETWORK_ERROR.
Security
Never commit
.env,credential.json, or token files.Tokens, client secrets, and
MCP_API_KEYare never logged.HTTP
/mcpis open unlessMCP_API_KEYis set (Authorization: BearerorX-API-Key).OAuth scopes are minimized to compose, send, and documents.
Prefer drafting (
gmail_draft_email) when send is not required.Use HTTPS redirect URIs for non-local deployments.
Testing
npm testUnit tests cover validation, MIME/Base64URL encoding, Docs append request construction, error mapping, and tool handlers with mocked services. No Google credentials are required for the default suite.
Troubleshooting
Issue | Fix |
| Run |
| Set/send |
| Confirm the signed-in account can edit the document |
| Check the document ID from the Docs URL |
OAuth redirect mismatch | Align |
Client cannot list tools | Confirm the server starts ( |
Scripts
Command | Purpose |
| Run MCP server over stdio via |
| Run Streamable HTTP server ( |
| Interactive Google OAuth login |
| Compile TypeScript to |
| Run compiled HTTP server ( |
| Run compiled stdio server ( |
| Run unit tests |
| Typecheck |
Future extensions
The layered layout supports adding tools such as gmail_search_emails, google_docs_create, Sheets, and Calendar without changing the MCP client contract.
License
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP server connecting AI agents to 100+ apps (Gmail, Slack, Notion, GitHub) via one-click OAuth.
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
Multiple Gmail accounts, editable Google Sheets & Docs for AI agents. Deny-by-default access rules.
Permissioned access to Gmail, Drive and Calendar via the user's own Google account
Related MCP Servers
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to send Gmail emails, create drafts, and append content to Google Docs through MCP tools. Provides secure OAuth-based integration with Google Workspace.205 npmMIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to send and draft Gmail emails and append content to Google Docs through standardized MCP tools.6 npmMIT
- AlicenseNot gradedqualityBmaintenanceEnables MCP-compatible AI agents to create Gmail drafts, send emails, and append content to Google Docs with OAuth-secured authentication.19 npmMIT
- FlicenseNot gradedqualityCmaintenanceEnables MCP-compatible AI agents to draft and send Gmail emails and append content to Google Docs without needing to understand Google's APIs.-