Gmail MCP Server

Gmail MCP Server

Enables sending Gmail emails through natural language via Claude Desktop by exposing a FastAPI endpoint wrapped with MCP support.

Category
访问服务器

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:

  1. FastAPI app provides a POST /send-email/ endpoint that sends email via the Gmail API.
  2. fastapi-mcp wraps the app and exposes an MCP endpoint at /mcp.
  3. 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 create token.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 run test_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

  1. Go to the Google Cloud Console and create a project (or use an existing one).
  2. In APIs & Services → Library, enable the Gmail API for your project.
  3. In APIs & Services → Credentials, create credentials:
    • Type: OAuth client ID
    • Application type: Desktop app
  4. Download the credentials.json file and place it in the root of this project (same folder as mcp_server.py).
  5. Make sure credentials.json is 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.json does not exist, it opens a browser window for Google login and consent.
  • After you approve access, it saves token.json in 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/docs in 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:

  1. Open Settings → Developer → Edit Config to open this file.
  2. 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-mcp is the name of this MCP server as seen by Claude.
  • command and args start a local bridge process that connects Claude Desktop to your HTTP MCP endpoint.

Save the file.

8.3 Restart Claude Desktop

  1. Quit Claude Desktop completely (including tray icon).
  2. Start Claude Desktop again so it reloads the config.
  3. 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:

  1. Open a new Claude Desktop chat.
  2. Ask something like:

“Use the gmail-mcp server to send an email to your-recipient@example.com with subject Test from Claude MCP and body Hello from my local Gmail MCP server.”

Claude will:

  • Discover the gmail-mcp tools.
  • Call the tool that maps to POST /send-email/ with to_email, subject, and body.
  • 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.json or token.json to 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.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选