Gmail MCP 服务器是一个基于 Model Context Protocol (MCP) 的工具,它提供了与 Gmail API 交互的能力。借助 MCP 接口,用户可以对电子邮件进行编程管理,极大地提升了邮件管理的效率和灵活性。
Gmail MCP 服务器为用户提供了便捷的方式来管理 Gmail 邮件。通过 MCP 接口,用户可以轻松地列出、搜索、发送和修改邮件。
list_emails:可列出收件箱中的近期邮件,并且支持可选过滤功能,方便用户快速定位所需邮件。search_emails:支持使用 Gmail 查询语法进行高级邮件搜索,满足用户多样化的搜索需求。send_email:能够发送新邮件,同时支持 CC 和 BCC 功能,方便进行多人邮件沟通。modify_email:可以修改邮件标签,如将邮件存档、移动到垃圾邮件箱、标记为已读或未读等。http://localhost:3001/code。克隆和安装:
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"
}
}
获取 Refresh Token:
node get-refresh-token.js
这将:
https://www.googleapis.com/auth/gmail.modifyhttps://www.googleapis.com/auth/gmail.sendtoken.json。配置 MCP 设置: 将服务器配置添加到你的 MCP 设置文件中:
~/Library/Application Support/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json~/Library/Application Support/Claude/claude_desktop_config.json在 mcpServers 对象中添加:
{
"mcpServers": {
"google-gmail": {
"command": "node",
"args": ["/path/to/google-gmail-mcp-server/index.js"],
"env": {}
}
}
}
运行服务器:
npm start
{
"command": "_gmail.list_emails",
"args": {
"userId": "me"
},
"response": {
"data": {
"messages": []
}
}
}
{
"command": "_gmail.search_emails",
"args": {
"userId": "me",
"query": "inbox is:unread label:important"
},
"response": {
"data": {
"messages": []
}
}
}
{
"command": "_gmail.send_email",
"args": {
"userId": "me",
"email": {
"to": "recipient@example.com",
"subject": "Test Email",
"bodyText": "This is a test email."
}
},
"response": {
"data": {
"id": "string"
}
}
}
{
"command": "_gmail.modify_email",
"args": {
"userId": "me",
// 原文档此处未完整,保持原样
}
}