Google MCP Server
Integrates with Google Docs and Gmail to append content to documents and create email drafts, requiring manual approval for each action.
README
Google MCP Server
A Python-based MCP-style server built with FastAPI that integrates with Google Docs and Gmail. Before running any action, the server requires manual approval in the terminal (Approve? (y/n)).
๐ Project Structure
google-mcp-server/
โโโ server.py # FastAPI app with tool endpoints & approval prompt
โโโ auth.py # Google OAuth authentication & token manager
โโโ docs_tool.py # Google Docs tool (appends content)
โโโ gmail_tool.py # Gmail tool (creates draft)
โโโ requirements.txt # Python dependencies
โโโ README.md # Setup and usage instructions
โโโ credentials.json # (NOT committed) OAuth 2.0 client secret credentials from Google Cloud Console
โโโ token.json # (NOT committed) Auto-generated user access/refresh token
โ๏ธ Features
- FastAPI Endpoints:
POST /append_to_doc: Appends text to the end of a Google Doc body.POST /create_email_draft: Creates a draft email in your Gmail drafts folder.
- Operator-in-the-loop Verification:
- Whenever an endpoint is hit, the server pauses, prints the payload, and prompts
Approve? (y/n)in the command line interface. - The API client waits and will receive a
200 OKon approval (y), or a403 Forbiddenon rejection (n).
- Whenever an endpoint is hit, the server pauses, prints the payload, and prompts
- Seamless Google OAuth2 Flow:
- Skips web authentication on subsequent runs if a valid
token.jsonalready exists.
- Skips web authentication on subsequent runs if a valid
๐ Setup Instructions
1. Prerequisites & Virtual Environment
Ensure you have Python 3.10+ installed.
# Clone or navigate to the project directory
cd google-mcp-server
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install the dependencies
pip install -r requirements.txt
2. Configure Google Cloud Console
To interact with the APIs, you must download a client secrets credentials file:
- Open the Google Cloud Console.
- Create a new Google Cloud Project (or select an existing one).
- Enable the Google Docs API and Gmail API:
- Go to APIs & Services > Library.
- Search for Google Docs API and click Enable.
- Search for Gmail API and click Enable.
- Configure the OAuth Consent Screen:
- Go to APIs & Services > OAuth consent screen.
- Select External (or Internal if you are within a Google Workspace organization) and click Create.
- Fill in the required fields (App Name, User support email, Developer contact information).
- Under Scopes, you can add or skip (the app requests scopes dynamically).
- Under Test Users, add the Google email address you plan to authenticate with.
- Create OAuth 2.0 Client Credentials:
- Go to APIs & Services > Credentials.
- Click Create Credentials and select OAuth client ID.
- Select Desktop App as the Application Type.
- Set a name (e.g.,
Google MCP Server Desktop Client) and click Create.
- Download the Client Secret:
- In the Credentials list, find your new Client ID under OAuth 2.0 Client IDs.
- Click the Download JSON icon on the right.
- Rename the downloaded file to
credentials.jsonand save it directly in thegoogle-mcp-server/directory.
๐ Initial Authentication
Before running the server, you can optionally test and run the OAuth authentication flow standalone to create token.json:
python auth.py
This will automatically open your default web browser. Log in with your test Google account, accept the security warnings (as this is your own developer app), and authorize the requested permissions for Docs and Gmail.
Once completed, a file named token.json will be saved in the directory, allowing future executions to run headlessly.
๐ข Running the Server
Start the server using uvicorn or by running the script directly:
python server.py
The server will launch at http://127.0.0.1:8000.
๐งช Testing the Endpoints
Keep the server running and open a new terminal window to execute test requests using curl.
Test 1: Append text to a Google Doc
Replace YOUR_DOCUMENT_ID with the ID of a Google Document you own and have edit access to (from the document URL: https://docs.google.com/document/d/YOUR_DOCUMENT_ID/edit).
curl -X POST "http://127.0.0.1:8000/append_to_doc" \
-H "Content-Type: application/json" \
-d "{\"doc_id\": \"YOUR_DOCUMENT_ID\", \"content\": \"\nHello from the Google MCP-style Server!\"}"
Terminal prompt response:
- In the server terminal, you will see:
================================================== PENDING OPERATOR APPROVAL Action: append_to_doc Payload: doc_id: YOUR_DOCUMENT_ID content: \nHello from the Google MCP-style Server! ================================================== Approve? (y/n): - Type
yand press Enter. - The API client will receive:
{ "status": "success", "message": "Text successfully appended to Google Doc", "documentId": "YOUR_DOCUMENT_ID", "response": { ... } } - Verify the new line in your Google Doc!
Test 2: Create a Gmail Email Draft
curl -X POST "http://127.0.0.1:8000/create_email_draft" \
-H "Content-Type: application/json" \
-d "{\"to\": \"recipient@example.com\", \"subject\": \"FastAPI MCP Server Test\", \"body\": \"This email draft was generated using the Python Google API server integration with console-based approval validation.\"}"
Terminal prompt response:
- In the server terminal, approve the request by typing
yand pressing Enter. - Go to Gmail Drafts in your browser and verify the new draft is created.
- Try sending another request and typing
nto reject it. Verify that the server returns a403 Forbiddenresponse:{ "detail": "Action rejected by user." }
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.