这是一个用于 Google Workspace 服务的模型上下文协议(Model Context Protocol)服务器。该服务器提供了通过 MCP 协议与 Gmail 和 Google 日历进行交互的工具。
支持多个 Google 账户
Gmail 集成
日历集成
尝试使用您的AI助手执行以下示例提示:
克隆仓库:
git clone https://github.com/j3k0/mcp-google-workspace.git
cd mcp-google-workspace
安装依赖项:
npm install
构建TypeScript代码:
npm run build
Google Workspace(G Suite)API需要OAuth2授权。按照以下步骤设置身份验证:
创建OAuth2凭证:
http://localhost:4100/code用于本地开发)必需的OAuth2范围:
[
"openid",
"https://mail.google.com/",
"https://www.googleapis.com/auth/calendar",
"https://www.googleapis.com/auth/userinfo.email"
]
在项目根目录中创建一个.gauth.json文件,包含您的Google OAuth 2.0凭证:
{
"installed": {
"client_id": "your_client_id",
"project_id": "your_project_id",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "your_client_secret",
"redirect_uris": ["http://localhost:4100/code"]
}
}
创建一个.accounts.json文件以指定哪些Google账户可以使用该服务器:
{
"accounts": [
{
"email": "your.email@gmail.com",
"account_type": "personal",
"extra_info": "主要账户,带有家庭日历"
}
]
}
您可以指定多个账户。确保它们在您的Google认证应用中有访问权限。extra_info字段特别有用,您可以在此处添加您希望告知AI的有关账户的信息(例如,是否具有特定的日历)。
配置Claude Desktop以使用mcp-google-workspace服务器:
在MacOS上:编辑~/Library/Application\ Support/Claude/claude_desktop_config.json
在Windows上:编辑%APPDATA%/Claude/claude_desktop_config.json
{
"mcpServers": {
"mcp-google-workspace": {
"command": "<dir_to>/mcp-google-workspace/launch"
}
}
}
</details>
<details>
<summary>已发布的服务器配置</summary>
{
8 "mcpServers": {
"mcp-google-workspace": {
"command": "npx",
"args": [
"mcp-google-workspace"
]
}
}
}
</details>
启动服务器:
npm start
可选参数:
--gauth-file:OAuth2凭证文件路径(默认:./.gauth.json)--accounts-file:账户配置文件路径(默认:./.accounts.json)--credentials-dir:存储OAuth凭证的目录(默认:当前目录)服务器将启动并监听通过标准输入/输出的MCP命令。
对于每个账户的首次运行,它将:
.oauth2.{email}.json的文件中,以便将来使用gmail_list_accounts / calendar_list_accounts
gmail_query_emails
gmail_get_email
gmail_bulk_get_emails
gmail_create_draft
gmail_delete_draft
gmail_reply
gmail_get_attachment
gmail_bulk_save_attachments
gmail_archive / gmail_bulk_archive
calendar_list
calendar_get_events
calendar_create_event
calendar_delete_event
src/目录下的TypeScript中dist/目录mcp-google-workspace/
├── src/
│ ├── server.ts # 主服务器实现
│ ├── services/
│ │ └── gauth.ts # Google认证服务
│ ├── tools/
│ │ ├── gmail.ts # Gmail工具实现
│ │ └── calendar.ts # 日历工具实现
│ └── types/
│ └── tool-handler.ts # 公共类型和接口
├── .gauth.json # OAuth2凭证
├── .accounts.json # 账户配置
├── package.json # 项目依赖
└── tsconfig.json # TypeScript配置
npm run build:构建TypeScript代码npm start:启动服务器npm run dev:以开发模式启动,自动重新加载MIT许可证 - 详情见LICENSE文件