⚡ 快速入门指南-Gmail和Drive MCP
🎯 目标
通过漂亮的Streamlit界面访问您的Gmail和Google Drive数据。
______________________________________________________________________
📦 步骤1:安装(2分钟)
# Install dependencies
pip install -r requirements.txt______________________________________________________________________
🔐 步骤2:获取谷歌凭据(5分钟)
A.创建项目
- 首选https://console.cloud.google.com/
- 点击“新建项目”→ Name:
gmail-drive-mcp→ 创建
B.启用API
- 转到“API和服务”→ “图书馆”
- 搜索和 启用:
- Gmail API - Google Drive API
C.创建OAuth凭据
- “API和服务”→ “凭据”
- “创建凭据”→ “OAuth客户端ID”
- 第一次?点击“配置同意屏幕”:
- 用户类型: 外部 - 应用程序名称: Gmail Drive MCP - 添加两次电子邮件(支持+开发人员) - 作用域:添加以下URL:
https://www.googleapis.com/auth/gmail.readonly
https://www.googleapis.com/auth/drive.readonly- 测试用户:添加您的Gmail - 保存
- 现在“创建凭据”→ “OAuth客户端ID”:
- 类型: 桌面应用 - 姓名: Gmail Drive Desktop - 下载JSON
- 将下载的文件重命名为
credentials.json
- 将其放入您的项目文件夹中
______________________________________________________________________
🚀 步骤3:首次运行和身份验证(2分钟)
# This will open browser for authentication
python gmail_drive_rest.py发生了什么:
- ✅ 浏览器自动打开
- ✅ 使用您的Google帐户登录
- ✅ 点击“允许”
- ✅
token.json已创建(您的访问令牌) - ✅ 服务器在端口8000上启动
让这个终端继续运行!
______________________________________________________________________
🎨 步骤4:打开Streamlit UI(1分钟)
新航站楼:
streamlit run gmail_drive_ui.py访问权限: http://localhost:8501
______________________________________________________________________
🎉 你完了!
您现在可以做什么:
📊 仪表板选项卡:
- 查看收件箱计数
- 查看垃圾邮件计数
- 查看驱动器文件总数
- 查看存储使用情况
- 最近的电子邮件和文件
📧 Gmail管理器选项卡:
- 按标签统计电子邮件
- 列出最近的电子邮件
- 搜索电子邮件(例如。,
from:boss@company.com)
📁 驱动器管理器选项卡:
- 统计所有文件
- 列出最近的文件
- 按名称搜索文件
- 检查存储配额
______________________________________________________________________
🔧 故障排除
“未找到credentials.json”
→ 从谷歌云控制台下载,重命名,放入项目文件夹
“访问被阻止”
→ 确保同时启用Gmail API和Drive API
浏览器无法打开
→ 从终端复制URL并粘贴到浏览器中
“无效授权”
→ 删除 token.json 并再次运行以重新进行身份验证
Streamlit中的连接错误
→ 确保 gmail_drive_rest.py 仍在另一个终端中运行
______________________________________________________________________
📁 文件结构
your-project/
├── credentials.json ← Download from Google
├── token.json ← Auto-generated after auth
├── requirements.txt
├── gmail_drive_mcp.py ← MCP Server (for Claude)
├── gmail_drive_rest.py ← REST API (run this!)
├── gmail_drive_ui.py ← Streamlit UI (run this!)
└── .gitignore______________________________________________________________________
🎓 后续步骤
与Claude Desktop一起使用:
- 运行MCP服务器:
python gmail_drive_mcp.py- 添加到Claude配置(
~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"gmail-drive": {
"command": "python",
"args": ["/full/path/to/gmail_drive_mcp.py"]
}
}
}- 重新启动克劳德桌面
- 问克劳德:
- “我有多少封电子邮件?” - “在我的电子邮件中搜索约翰的消息” - “我的驱动器中有多少个文件?”
______________________________________________________________________
⚡ 快速命令参考
# Install
pip install -r requirements.txt
# Run REST API (Terminal 1)
python gmail_drive_rest.py
# Run Streamlit (Terminal 2)
streamlit run gmail_drive_ui.py
# Run MCP for Claude (Alternative)
python gmail_drive_mcp.py______________________________________________________________________
🔒 安全提醒
永远不要将这些文件提交到Git:
- ❌ credentials.json
- ❌ token.json
它们包含您的私钥!已添加到 .gitignore ✅
______________________________________________________________________
🎯 总结
| 终端 | 命令 | 目的 |
|---|---|---|
| 1 | python gmail_drive_rest.py | REST API服务器 |
| 2 | streamlit run gmail_drive_ui.py | Web界面 |
访问UI: http://localhost:8501
就是这样! 🎉
