Back to MCP directory
publicPublicdnsLocal runtime

google-workspace-mcp-server-by-itc

基于Google Workspace的MCP服务器项目,提供Gmail和日历功能的API接口,支持邮件管理、日程操作等功能。

article

README

🚀 谷歌工作区 MCP 服务器

本项目是一个谷歌工作区 MCP 服务器,可实现邮件和日历的多种操作,如邮件的搜索、发送、标签修改,以及日历日程的查看、创建、更新和删除等功能。

🚀 快速开始

必要条件

  1. 安装 Node.js 和 npm。
  2. 配置 Google Workspace 开发者凭据。
  3. 确保已启用 Gmail API 和 Calendar API。

设置步骤

项目初始化

npm init -y

安装依赖项

npm install express cors @google/googleapis

创建配置文件

创建 config.js

const config = {
    google: {
        clientId: 'YOUR_CLIENT_ID',
        clientSecret: 'YOUR_CLIENT_SECRET',
        refreshToken: 'YOUR_REFRESH_TOKEN'
    }
};

module.exports = config;

实现 API 调用

参考代码示例:

const {google} = require('googleapis');
const config = require('./config');

function gmailApiCall() {
    const auth = new google.auth.OAuth2(config.google.clientId, 
                                       config.google.clientSecret,
                                       config.google.refreshToken);
    // 实现具体的 API 调用逻辑
}

function calendarApiCall() {
    const auth = new google.auth.OAuth2(config.google.clientId,
                                       config.google.clientSecret,
                                       config.google.refreshToken);
    // 实现具体的日历 API 调用逻辑
}

项目构建

npm run build

运行命令

npm start

✨ 主要特性

邮件操作

  • 最近邮件列表:获取最近未读邮件列表。
{
    "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"]
}

日历操作

  • 查看日程安排:查看指定时间范围内的日程。
{
    "maxResults": 10,
    "timeMin": "2024-01-01T00:00:00Z",
    "timeMax": "2024-12-31T23:59:59Z"
}
  • 创建日程:创建新的日程安排。
{
    "summary": "团队会议",
    "location": "会议室",
    "description": "每周同步",
    "start": "2024-01-24T10:00:00Z",
    "end": "2024-01-24T11:00:00Z",
    "attendees": ["colleague@example.com"]
}
  • 更新日程:更新已有日程的信息。
{
    "eventId": "event_id",
    "summary": "更新后的会议标题",
    "location": "虚拟会议室",
    "start": "2024-01-24T11:00:00Z",
    "end": "2024-01-24T12:00:00Z"
}
  • 删除日程:删除指定日程。
{
    "eventId": "event_id"
}

📚 详细文档

常见问题排查

  • 无法启动服务?:检查端口是否被占用或配置文件是否有误。
  • API 请求失败?:确保凭据有效且网络连接正常。
  • 日志信息不足?:启用详细日志记录以获取更多调试信息。

文档参考

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client