本项目是一个谷歌工作区 MCP 服务器,可实现邮件和日历的多种操作,如邮件的搜索、发送、标签修改,以及日历日程的查看、创建、更新和删除等功能。
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;
参考代码示例:
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"
}