使用说明
Gmail MCP服务器
模型上下文协议(MCP)服务器,提供与Gmail API交互的工具。此服务器使您能够通过MCP接口以编程方式管理电子邮件。
特性
Gmail工具
list_emails:使用可选过滤功能列出收件箱中最近的电子邮件search_emails:使用Gmail查询语法进行高级电子邮件搜索send_email:发送支持CC和BCC的新电子邮件modify_email:修改电子邮件标签(存档、垃圾箱、标记已读/未读)
先决条件
- Node.js:安装Node.js版本14或更高版本
- 谷歌云控制台设置:
- 首选 谷歌云控制台
- 创建新项目或选择现有项目
- 启用Gmail API:
- 转到“API和服务”>“库”
- 搜索并启用“Gmail API”
- 设置OAuth 2.0凭据:
- 转到“API和服务”>“凭据”
- 点击“创建凭据”>“OAuth客户端ID”
- 选择“Web应用程序”
- 将“授权重定向URI”设置为包括:
http://localhost:3001/code - 记下客户端ID和客户端密码
安装说明
-
克隆并安装:
git clone https://github.com/yourusername/google-gmail-mcp-server.git cd google-gmail-mcp-server npm install -
创建OAuth凭据: 创建一个
credentials.json根目录中的文件:{ "web": { "client_id": "YOUR_CLIENT_ID", "client_secret": "YOUR_CLIENT_SECRET", "redirect_uris": ["http://localhost:3001/code"], "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token" } } -
获取刷新令牌:
node get-refresh-token.js这将:
- 打开浏览器进行Google OAuth身份验证
- 请求以下权限:
https://www.googleapis.com/auth/gmail.modifyhttps://www.googleapis.com/auth/gmail.send
- 将凭据保存到
token.json - 在控制台中显示刷新令牌
-
配置MCP设置: 将服务器配置添加到MCP设置文件中:
- 对于VSCode Claude扩展:
~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json - 对于Claude桌面应用程序:
~/Library/Application Support/Claude/claude_desktop_config.json
将此添加到
mcpServers对象:{ "mcpServers": { "google-gmail": { "command": "node", "args": ["/path/to/google-gmail-server/build/index.js"], "env": { "GOOGLE_ACCESS_TOKEN": "your_access_token", } } } } - 对于VSCode Claude扩展:
-
构建并运行:
npm run build
使用示例
Gmail操作
-
列出最近的电子邮件:
{ "maxResults": 5, "query": "is:unread" } -
搜索电子邮件:
{ "query": "from:example@gmail.com has:attachment", "maxResults": 10 } -
发送电子邮件:
{ "to": "recipient@example.com", "subject": "Hello", "body": "Message content", "cc": "cc@example.com", "bcc": "bcc@example.com" } -
修改电子邮件:
{ "id": "message_id", "addLabels": ["UNREAD"], "removeLabels": ["INBOX"] }
许可证
麻省理工学院
