MCP-Style Server — Google Docs & Gmail Integration
Allows creating draft emails in a user's Gmail account by specifying recipient, subject, and body, enabling AI agents to compose email drafts without sending them (with human approval before execution).
Allows appending text content to a specified Google Doc by document ID, enabling AI agents to add content to existing documents in a user's Google Docs account (with human approval before execution).
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., "@MCP-Style Server — Google Docs & Gmail IntegrationDraft an email to sarah@example.com with subject 'Project' and body 'Deadline is Friday'"
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.
MCP-Style Server — Google Docs & Gmail Integration
A lightweight Python server that exposes Google Docs and Gmail operations as MCP-style tool endpoints via FastAPI. Every action requires explicit human approval in the terminal before execution.
Features
Append to Google Doc — Append text content to any Google Doc you have access to.
Create Gmail Draft — Create a draft email in your Gmail account.
Human-in-the-Loop — Every action is printed to the terminal and requires
y/napproval.OAuth 2.0 — Secure authentication via Google's OAuth 2.0 flow.
Related MCP server: Google MCP Server
Prerequisites
Python 3.9+
Google Cloud Project with the following APIs enabled:
Google Docs API
Gmail API
OAuth 2.0 Client Credentials (
credentials.json) downloaded from the Google Cloud Console.
Setup
1. Clone the repository
git clone <repo-url>
cd MCP_server2. Create a virtual environment (recommended)
python -m venv venv
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate3. Install dependencies
pip install -r requirements.txt4. Add your credentials
Place your Google OAuth client secrets file in the project root. The server is pre-configured to look for the credentials file by its downloaded name. If you renamed it, update the CREDENTIALS_FILE path in auth.py.
5. Run the server
python server.pyOn the first run, a browser window will open asking you to sign in and grant permissions. After approval, a token.json file is created and subsequent runs will not require browser login.
Usage
Append to a Google Doc
curl -X POST http://127.0.0.1:8000/append_to_doc \
-H "Content-Type: application/json" \
-d '{"doc_id": "YOUR_DOC_ID", "content": "Hello from MCP server!"}'Check the terminal running the server — you'll see:
============================================================
ACTION: append_to_doc
============================================================
{
"doc_id": "YOUR_DOC_ID",
"content": "Hello from MCP server!"
}
============================================================
Approve? (y/n):Type y to approve and execute, or n to reject.
Create a Gmail Draft
curl -X POST http://127.0.0.1:8000/create_email_draft \
-H "Content-Type: application/json" \
-d '{"to": "recipient@example.com", "subject": "Test", "body": "Hello!"}'API Reference
POST /append_to_doc
Field | Type | Description |
doc_id | string | Google Doc ID (from the URL) |
content | string | Text content to append |
Response (200):
{ "status": "success", "message": "Content appended to document.", "doc_id": "..." }POST /create_email_draft
Field | Type | Description |
to | string | Recipient email address |
subject | string | Email subject line |
body | string | Email body text |
Response (200):
{ "status": "success", "message": "Draft created successfully.", "draft_id": "..." }Error Responses
Status | Meaning |
403 | Action rejected by operator |
401 | Authentication error |
422 | Invalid request payload |
502 | Google API error |
500 | Internal server error |
Project Structure
MCP_server/
├── server.py → FastAPI app with tool endpoints
├── auth.py → Google OAuth 2.0 authentication
├── docs_tool.py → Google Docs tool (append content)
├── gmail_tool.py → Gmail tool (create draft)
├── requirements.txt → Python dependencies
├── Procfile → Railway deployment config
├── README.md → This file
├── .gitignore → Git ignore rules
└── docs/
├── problemStatement.md
└── architecture.mdDeploy to Railway
Prerequisites
A Railway account (free tier available)
The project pushed to GitHub (see Setup above)
Google OAuth
token.jsongenerated locally (run the server once locally first)
Step 1: Create a New Project on Railway
Go to railway.app and log in.
Click "New Project" → "Deploy from GitHub Repo".
Select your repository:
nikhil1102-ai/custom_mcp_server.Railway will auto-detect the
Procfileand configure the start command.
Step 2: Configure Environment Variables
In your Railway project dashboard, go to Variables and add:
Variable | Value | Description |
|
| Auto-approve actions (no terminal in cloud) |
|
| Bind to all interfaces (required by Railway) |
| (contents of token.json) | OAuth token for Google APIs (see Step 3) |
Note: Railway automatically sets the
PORTvariable — you do not need to add it manually.
Step 3: Set Up Google OAuth Token
Since Railway has no browser for the OAuth consent flow, you must generate token.json locally first:
Run the server locally once:
python server.pyMake any API call (e.g., append to doc) — this triggers the OAuth browser flow.
Complete the consent in your browser —
token.jsonis created.Copy the token contents:
# Windows (PowerShell) Get-Content token.json # macOS/Linux cat token.jsonPaste the entire JSON into the
GOOGLE_TOKEN_JSONRailway variable.
Alternative: You can also upload
token.jsonandcredentials.jsonas Railway volume mounts if your plan supports it.
Step 4: Handle Credentials in Production
For Railway, the credentials.json and token.json files need to be provided via environment variables since they can't be committed to git. Update auth.py to read from env vars by adding this pattern (optional enhancement):
import json
import os
# If GOOGLE_TOKEN_JSON env var is set, write it to token.json on startup
token_env = os.getenv("GOOGLE_TOKEN_JSON")
if token_env and not os.path.exists("token.json"):
with open("token.json", "w") as f:
f.write(token_env)Step 5: Deploy
Push your code to GitHub:
git add . git commit -m "Add Railway deployment support" git push origin mainRailway will auto-deploy from the
mainbranch.Once deployed, Railway provides a public URL like:
https://your-app-name.up.railway.app
Step 6: Test the Deployed API
# Replace with your Railway URL
curl -X POST https://your-app-name.up.railway.app/append_to_doc \
-H "Content-Type: application/json" \
-d '{"doc_id": "YOUR_DOC_ID", "content": "Hello from Railway!"}'
curl -X POST https://your-app-name.up.railway.app/create_email_draft \
-H "Content-Type: application/json" \
-d '{"to": "test@example.com", "subject": "Test", "body": "Deployed!"}'Railway Environment Summary
Setting | Value |
Start Command |
|
Build Command |
|
Port | Auto-assigned by Railway via |
Health Check |
|
Security Notes
credentials.jsonandtoken.jsonare excluded from version control via.gitignore.The server binds to
127.0.0.1(localhost) by default — it is not exposed to the network.On Railway, set
AUTO_APPROVE=truesince there is no terminal for manual approval.Only
documentsandgmail.composeOAuth scopes are requested.For production, consider adding API key authentication to protect your endpoints.
This server cannot be deployed
Maintenance
Related MCP Connectors
Permissioned access to Gmail, Drive and Calendar via the user's own Google account
OAuth 2.1 short-link tools for AI agents with scoped tokens, approvals, audit logs, and revocation.
Multiple Gmail accounts, editable Google Sheets & Docs for AI agents. Deny-by-default access rules.
Your workspace as agent tools — docs, canvases, slides, sheets, projects, tickets, and a shell.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables appending text to Google Docs and creating Gmail drafts with interactive approval via terminal.-
- FlicenseNot gradedqualityDmaintenanceEnables appending text to Google Docs and creating Gmail drafts, with interactive terminal approval before each action.-
- FlicenseNot gradedqualityDmaintenanceEnables appending content to Google Docs and creating email drafts in Gmail via FastAPI endpoints.-
- FlicenseNot gradedqualityCmaintenanceEnables interaction with Google Docs and Gmail, allowing users to append text to documents and create email drafts with explicit approval prompts.-