Gmail MCP服务器📧
一个高性能的模型上下文协议(MCP)服务器,使AI助手能够安全地与Gmail交互。
✨ 特性
- 智能电子邮件检索:获取具有丰富元数据的未读邮件。
- 线程感知绘图:创建保持对话上下文的回复。
- 安全认证:具有令牌管理的强大OAuth 2.0实现。
- 企业级就绪:结构可扩展性和可维护性。
🏗️ 建筑
系统数据流
graph TD
User(["👤 User"]) |"Natural Language"| Claude(["🤖 Claude Desktop"])
subgraph "MCP Server (Local Machine)"
Claude |"JSON-RPC (stdio)"| Main["src/main.py"]
Main -->|Dispatch| Handler["src/handlers.py"]
Handler -->|Call| Client["src/client.py"]
end
Client |"HTTPS / OAuth 2.0"| Gmail(["☁️ Google Gmail API"])
style User fill:#f9f,stroke:#333
style Claude fill:#e1f5fe,stroke:#01579b
style Gmail fill:#fce4ec,stroke:#880e4f该项目遵循标准工程实践:
MLI/
├── src/
│ ├── main.py # Application Entry Point
│ ├── client.py # Gmail API Client
│ └── handlers.py # Request Handlers
├── config/ # Configuration & Credentials
├── tests/ # Unit Tests
└── requirements.txt # Dependencies🚀 快速开始
1.先决条件
- Python 3.8+
- 启用Gmail API的谷歌云项目
2.安装
# Clone and setup environment
python -m venv .venv
.venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt3.配置
- 放置您的谷歌云
credentials.json在config/. - 复制环境配置:
copy .env.example .env4.克劳德整合
添加到您的 克劳德桌面版 config(%APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"gmail": {
"command": "C:\\Path\\To\\MLI\\.venv\\Scripts\\python.exe",
"args": ["-m", "src.main"],
"cwd": "C:\\Path\\To\\MLI",
"env": {
"CREDENTIALS_PATH": "config/credentials.json",
"TOKEN_PATH": "config/token.json"
}
}
}
}🛠️ 用法
检查电子邮件:
“检查我的未读电子邮件”
答复草案:
“起草对\[姓名\]电子邮件的回复”
🛡️ 安全
- 凭据从不提交到版本控制。
- 令牌存储在本地
config/. - 您的机器和Google API之间直接进行通信。
