Gmail推进MCP服务器
一个专门的MCP(模型上下文协议)服务器,用于通过Gmail集成自动化旅游推进电子邮件工作流程。
概述
该服务器为旅游经理和推进团队提供智能电子邮件解析和响应生成。它从场馆电子邮件中提取结构化数据,根据您的偏好起草专业回复,并维护可搜索的场馆通信历史。
特性
🎯 核心MCP工具
- parse_venue_email -智能电子邮件解析
- 提取场地细节、加载时间、技术规格 - 自动对电子邮件类型进行分类 - 识别停车、招待和乘客信息 - 返回具有置信度得分的结构化数据
- 起草_推进_回应 -自动生成响应
- 创建上下文感知的电子邮件草稿 - 适应电子邮件类型(加载、乘客、呼叫时间、停车) - 使用您的偏好和沟通风格 - 可以直接在Gmail中创建草稿
- search_venue_thread -历史电子邮件搜索
- 查找过去与场馆的通信 - 按场地名称和关键字搜索 - 提取历史前进的细节 - 参考以前的协议
📧 支持的电子邮件类型
- 加载确认 -时间、地点、设备
- 附加条款澄清 -酒店、饮食、技术规格
- 呼叫时间请求 -进度协调
- 停车证查询 -车辆物流
- 一般会场 -其他通信的包罗万象
快速开始
先决条件
- Python 3.10或更高版本
- 可访问API的Gmail帐户
- 启用Gmail API的谷歌云项目
安装
# Clone repository
git clone https://github.com/yourusername/gmail-advancing-mcp.git
cd gmail-advancing-mcp
# Install dependencies
pip install -r requirements.txt
# Copy environment template
cp .env.example .envGmail API设置
- 首选 谷歌云控制台
- 创建新项目或选择现有项目
- 启用Gmail API
- 创建OAuth 2.0凭据(桌面应用程序)
- 将凭据下载为
credentials.json - 放在项目根目录中或
credentials/目录
配置
编辑 .env 文件:
GMAIL_CREDENTIALS_PATH=credentials.json
GMAIL_TOKEN_PATH=token.json
MCP_SERVER_HOST=0.0.0.0
MCP_SERVER_PORT=8000
# Your advancing preferences
DEFAULT_LOAD_IN_TIME=14:00
DEFAULT_SOUND_CHECK_TIME=16:00
DEFAULT_PARKING_PASSES=5
DEFAULT_HOSPITALITY_REQUESTS="Vegetarian options, coffee, water"运行服务器
选项1:直接使用Python
python -m uvicorn gmail_advancing_mcp.server:app --host 0.0.0.0 --port 8000选项2:Docker
# Build and run
docker-compose up -d
# View logs
docker-compose logs -f
# Stop
docker-compose down首次运行将打开浏览器进行Gmail OAuth身份验证。
用法
MCP协议
服务器实现MCP协议,以便与兼容的客户端(Claude Desktop、Letta等)一起使用。
工具:parse_venue_email
{
"name": "parse_venue_email",
"arguments": {
"message_id": "gmail_message_id_here"
}
}答复:
{
"parsed_email": {...},
"email_type": "load_in_confirmation",
"confidence": 0.85,
"extracted_data": {
"venue_data": {
"venue_name": "The Roxy Theatre",
"load_in_time": "14:00:00",
"sound_check_time": "16:00:00",
"parking_passes_count": 5,
"stage_dimensions": "40' x 30' x 12'",
...
}
},
"summary": "..."
}工具:起草_推进_响应
{
"name": "draft_advancing_response",
"arguments": {
"venue_data": {...},
"email_type": "load_in_confirmation",
"preferences": {
"preferred_load_in_time": "14:00",
"standard_parking_passes": 5,
"communication_style": "professional",
"hospitality_requests": "Vegetarian options, coffee",
"dietary_restrictions": ["vegetarian"],
"signature": "Best,\nYour Name\nTour Manager"
},
"thread_id": "optional_gmail_thread_id"
}
}工具:search_venue_thread
{
"name": "search_venue_thread",
"arguments": {
"venue_name": "The Fillmore",
"query": "parking",
"max_results": 10
}
}REST API
MCP协议的替代方案-使用标准HTTP端点:
# Parse email
curl -X POST http://localhost:8000/api/parse_email \
-H "Content-Type: application/json" \
-d '{"message_id": "abc123"}'
# Draft response
curl -X POST http://localhost:8000/api/draft_response \
-H "Content-Type: application/json" \
-d '{
"venue_data": {...},
"email_type": "load_in_confirmation",
"preferences": {...}
}'
# Search threads
curl -X POST http://localhost:8000/api/search_thread \
-H "Content-Type: application/json" \
-d '{
"venue_name": "The Roxy",
"query": "load in"
}'Letta代理集成
看 LETTA_集成.md 有关详细的设置说明。
快速设置
- 安装letta:
pip install letta- 在Letta中配置MCP服务器:
添加到Letta的MCP配置(~/.letta/mcp_config.json):
{
"mcpServers": {
"gmail-advancing": {
"url": "http://localhost:8000",
"type": "http"
}
}
}- 使用工具创建Letta代理:
from letta import create_agent
agent = create_agent(
name="tour-advancing-assistant",
tools=["parse_venue_email", "draft_advancing_response", "search_venue_thread"],
mcp_servers=["gmail-advancing"]
)- 在对话中使用:
response = agent.send_message(
"Parse the latest email from The Roxy and draft a response confirming our 2pm load-in"
)建筑
gmail-advancing-mcp/
├── src/
│ └── gmail_advancing_mcp/
│ ├── server.py # FastAPI + MCP server
│ ├── tools/ # MCP tool implementations
│ │ ├── parse_venue_email.py
│ │ ├── draft_advancing_response.py
│ │ └── search_venue_thread.py
│ ├── schemas/ # Pydantic models
│ │ ├── venue_data.py # Venue data structures
│ │ └── email_types.py # Email classification
│ └── utils/ # Utilities
│ ├── gmail_client.py # Gmail API wrapper
│ └── email_parser.py # Email parsing logic
├── credentials/ # Gmail credentials (gitignored)
├── Dockerfile
├── docker-compose.yml
└── requirements.txt电子邮件架构示例
加载确认
{
"venue_name": "The Roxy Theatre",
"venue_contact": "John Smith",
"venue_email": "john@roxy.com",
"load_in_time": "14:00:00",
"load_in_address": "Rear entrance on Sunset Blvd",
"sound_check_time": "16:00:00",
"doors_time": "19:00:00",
"show_time": "20:00:00",
"parking_passes_count": 5,
"stage_dimensions": "40' x 30' x 12'",
"wifi_available": true,
"wifi_password": "roxy2024"
}附加条款澄清
{
"venue_name": "The Fillmore",
"clarification_topic": "Hospitality requirements",
"venue_questions": [
"Can we substitute chicken for turkey?",
"Is gluten-free bread acceptable?"
],
"dietary_restrictions": ["vegetarian", "gluten-free"]
}发展
运行测试
pytest tests/代码格式化
black src/
ruff check src/添加新的电子邮件模式
编辑 src/gmail_advancing_mcp/utils/email_parser.py:
VENUE_PATTERNS = {
'your_field': [
r'regex_pattern_1',
r'regex_pattern_2',
]
}故障排除
Gmail身份验证问题
# Remove old token and re-authenticate
rm token.json
# Restart server - will trigger OAuth flowDocker容器无法启动
# Check logs
docker-compose logs gmail-mcp-server
# Ensure credentials are mounted
ls credentials/在MCP客户端中找不到工具
确保服务器正在运行且可访问:
curl http://localhost:8000/health安全
- 从不提交凭据:
credentials.json和token.json被忽视了 - OAuth令牌:本地存储,自动刷新
- 码头工人:凭据作为卷装载,而不是烘焙到映像中
- API访问:考虑为生产部署添加身份验证
贡献
- 分叉存储库
- 创建特征分支(
git checkout -b feature/amazing-feature) - 提交更改(
git commit -m 'Add amazing feature') - 推送到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
MIT许可证-有关详细信息,请参阅许可证文件
支持
路线图
- \[\]显示日期的日历集成
- \[\]紧急会场电子邮件的短信通知
- \[\]与旅游管理平台集成
- \[\]改进电子邮件分类的机器学习
- \[\]多语言支持
- \[\]附件解析(阶段图、输入列表)
- \[\]自动跟踪提醒
______________________________________________________________________
内置于❤️ 面向旅游经理和前进团队
