Gmail MCP Server
Enables sending Gmail emails through natural language via Claude Desktop by exposing a FastAPI endpoint wrapped with MCP support.
README
Gmail MCP Server (FastAPI + Claude Desktop)
This project is a minimal Gmail MCP server built with FastAPI. It exposes a /send-email/ HTTP endpoint and an MCP tool that can be called from MCP‑aware clients like Claude Desktop, so you can send real Gmail emails just by chatting with an AI assistant.
The flow is:
- FastAPI app provides a
POST /send-email/endpoint that sends email via the Gmail API. fastapi-mcpwraps the app and exposes an MCP endpoint at/mcp.- Claude Desktop connects to the MCP server and calls the email tool when you ask it to send an email.
1. Project structure
Key files:
mcp_server.py– FastAPI app with/send-email/and MCP wrapper.send_email.py– Gmail API helper functions (OAuth, MIME message creation, sending).test_gmail_auth.py– One‑time script to perform Gmail OAuth and createtoken.json.requirements.txt– Python dependencies.
Not in Git (must be provided by each user):
credentials.json– Google OAuth client secrets downloaded from Google Cloud.token.json– Gmail access/refresh tokens generated locally after you runtest_gmail_auth.py.
2. Prerequisites
Before you start, install:
- Python 3.11+
- Node.js (for
npx– used by Claude Desktop to run the MCP bridge) - Claude Desktop (latest version from Anthropic’s website)
- A Google account with access to Gmail
Clone the repo: git clone https://github.com/TushaarKD/Kalpesh_MCP_Project.git cd Kalpesh_MCP_Project
3. Set up Python environment
Create and activate a virtual environment:
python -m venv venv .\venv\Scripts\Activate.ps1
Install dependencies: pip install -r requirements.txt
This installs FastAPI, Uvicorn, Gmail API libraries, fastapi-mcp, etc.
4. Enable Gmail API and get credentials
- Go to the Google Cloud Console and create a project (or use an existing one).
- In APIs & Services → Library, enable the Gmail API for your project.
- In APIs & Services → Credentials, create credentials:
- Type: OAuth client ID
- Application type: Desktop app
- Download the
credentials.jsonfile and place it in the root of this project (same folder asmcp_server.py). - Make sure
credentials.jsonis not committed to Git; it is in.gitignore.
5. Run Gmail OAuth once (test_gmail_auth.py)
With the venv active and credentials.json in place:
python test_gmail_auth.py
What this does:
- If
token.jsondoes not exist, it opens a browser window for Google login and consent. - After you approve access, it saves
token.jsonin the project root. - Subsequent runs reuse or refresh this token without asking you to log in again.
Both credentials.json and token.json are local to your machine and should never be committed.
6. Start the Gmail MCP server
Start the FastAPI + MCP server:
uvicorn mcp_server:app --reload
By default this runs on http://127.0.0.1:8000.
6.1 Test the HTTP API (optional but recommended)
Open Swagger UI:
- Go to
http://localhost:8000/docsin your browser. - Find
POST /send-email/. - Click Try it out and use a JSON body like:
{ "to_email": "your-recipient@example.com", "subject": "MCP Gmail test", "body": "Hello from the Gmail MCP FastAPI server!" }
Click Execute. You should see a success response and receive an email at the target address.
You can do the same from curl:
curl -X POST "http://127.0.0.1:8000/send-email/" -H "Content-Type: application/json" -d '{ "to_email": "your-recipient@example.com", "subject": "MCP Gmail test via curl", "body": "Hello from the Gmail MCP FastAPI server (curl)." }'
7. MCP endpoint
The MCP server is exposed at:
http://localhost:8000/mcp
If you open that URL in a browser, you will see a JSON‑RPC error like:
{"jsonrpc":"2.0","id":"server-error","error":{"code":-32600,"message":"Not Acceptable: Client must accept text/event-stream"}}
This is expected. MCP over HTTP uses Server‑Sent Events, so it requires special headers. MCP clients (like Claude Desktop) handle this for you.
8. Connect to Claude Desktop
Claude Desktop needs a local MCP process that speaks MCP over stdio. We use a small bridge called mcp-remote (run via npx) which forwards between Claude Desktop and your HTTP MCP server.
8.1 Install Node.js
If you don’t have Node.js, install the latest LTS from the official website. This gives you npm and npx.
8.2 Edit claude_desktop_config.json
Claude Desktop stores its config in claude_desktop_config.json. On Windows it is typically located at:
C:\Users<YourUser>\AppData\Roaming\Claude\claude_desktop_config.json
In Claude Desktop:
- Open Settings → Developer → Edit Config to open this file.
- Add the following block under
"mcpServers"(merge with existing content if needed):
{ "mcpServers": { "gmail-mcp": { "command": "npx", "args": [ "-y", "mcp-remote", "http://localhost:8000/mcp", "--transport", "http-only" ] } } }
gmail-mcpis the name of this MCP server as seen by Claude.commandandargsstart a local bridge process that connects Claude Desktop to your HTTP MCP endpoint.
Save the file.
8.3 Restart Claude Desktop
- Quit Claude Desktop completely (including tray icon).
- Start Claude Desktop again so it reloads the config.
- Ensure your FastAPI server is still running (
uvicorn mcp_server:app --reload).
In a new chat, Claude should now be able to use the gmail-mcp server.
9. Using the Gmail MCP tool from Claude
With everything running:
- Open a new Claude Desktop chat.
- Ask something like:
“Use the gmail-mcp server to send an email to
your-recipient@example.comwith subjectTest from Claude MCPand bodyHello from my local Gmail MCP server.”
Claude will:
- Discover the
gmail-mcptools. - Call the tool that maps to
POST /send-email/withto_email,subject, andbody. - Your FastAPI logs should show the email being sent.
- You should receive the email at the recipient address.
10. Security notes
- Do not commit
credentials.jsonortoken.jsonto Git. - Only run this server on your own machine or in a secure environment; it has the power to send email from your Gmail account.
- For demos, use a dedicated Gmail account if possible.
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.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
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.