Google Drive MCP增强版
用于Google Drive的全面模型上下文协议(MCP)服务器,具有增强的协作功能,包括完整的评论支持、建议和共享管理。
特性
核心能力
- 文件操作:搜索、列出、读取、创建、删除和移动文件
- 谷歌文件:读取和更新文档内容
- 谷歌表格:读取和更新电子表格数据
- 评论 ⭐: 创建、阅读、更新、删除、回复、解决文档和表格上的注释
- 建议:在Google Docs中创建、列出、接受和拒绝建议
- 共享:管理文件权限并创建可共享链接
关键差异
该实施方案通过提供以下功能,从现有的Google Drive MCP服务器中脱颖而出:
- ✅ 完整的评论支持 适用于Google文档和表格
- ✅ 注释锚定(文档中的文本选择,表格中的单元格引用)
- ✅ 带有回复的评论帖子
- ✅ 评论解决工作流程
- ✅ 全面的共享和权限管理
- ✅ 协同编辑建议跟踪
安装
先决条件
- Node.js 18或更高版本
- 启用了Drive、Docs和Sheets API的Google Cloud项目
- OAuth 2.0凭据(请参阅下面的安装指南)
安装依赖项
cd google-drive-mcp-enhanced
npm install构建
npm run build设置
1.创建谷歌云项目
- 首选 谷歌云控制台
- 创建新项目或选择现有项目
- 启用以下API:
- Google Drive API - 谷歌文档API - 谷歌网页API
2.创建OAuth 2.0凭据
- 导航到 API和服务>凭据
- 点击 创建凭据>OAuth 2.0客户端ID
- 根据提示配置同意屏幕
- 选择 桌面应用程序 作为应用程序类型
- 下载凭据JSON文件
3.设置环境变量
export GOOGLE_CLIENT_ID="your-client-id"
export GOOGLE_CLIENT_SECRET="your-client-secret"或者创建一个 .env 文件:
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret4.配置MCP客户端
添加到您的MCP客户端配置中(例如,Claude Desktop):
{
"mcpServers": {
"google-drive-enhanced": {
"command": "node",
"args": ["/path/to/google-drive-mcp-enhanced/dist/index.js"],
"env": {
"GOOGLE_CLIENT_ID": "your-client-id",
"GOOGLE_CLIENT_SECRET": "your-client-secret"
}
}
}
}5.首次运行-身份验证
首次运行时,服务器将:
- 打开Google OAuth浏览器
- 请您授权该应用程序
- 将令牌安全地保存到
~/.local/share/google-drive-mcp/tokens.json
可用工具
文件操作
gdrive_search
使用可选过滤器搜索文件。
{
"query": "meeting notes",
"mimeType": "application/vnd.google-apps.document",
"maxResults": 10
}gdrive_list_folder
列出文件夹的内容。
{
"folderId": "folder-id-here",
"pageSize": 50
}gdrive_read_file
读取文件元数据和内容。
{
"fileId": "file-id-here"
}gdrive_create_file
创建一个新文件。
{
"name": "New Document",
"mimeType": "application/vnd.google-apps.document",
"parentId": "folder-id"
}gdrive_delete_file
删除文件。
{
"fileId": "file-id-here"
}gdrive_move_file
将文件移动到其他文件夹。
{
"fileId": "file-id-here",
"newParentId": "folder-id"
}谷歌文档操作
gdocs_read
读取文档内容。
{
"documentId": "doc-id-here"
}gdocs_update
更新文档内容。
{
"documentId": "doc-id-here",
"text": "New content",
"startIndex": 1,
"endIndex": 10
}谷歌表格操作
gsheets_get_metadata
获取电子表格元数据。
{
"spreadsheetId": "sheet-id-here"
}gsheets_read
读取工作表数据。
{
"spreadsheetId": "sheet-id-here",
"range": "Sheet1!A1:D10"
}gsheets_update
更新图纸数据。
{
"spreadsheetId": "sheet-id-here",
"range": "Sheet1!A1:B2",
"values": [["Name", "Email"], ["John", "john@example.com"]]
}评论操作⭐
gdrive_create_comment
在文件上创建注释。对于文档,可以选择锚定到文本选择。对于图纸,锚定到单元格。
{
"fileId": "file-id-here",
"content": "This needs revision",
"startIndex": 10,
"endIndex": 50
}对于板材:
{
"fileId": "sheet-id-here",
"content": "Check this value",
"cellReference": "A1"
}gdrive_list_comments
列出文件中的所有注释。
{
"fileId": "file-id-here",
"resolvedOnly": false
}gdrive_get_comment
获取具体的评论详细信息。
{
"fileId": "file-id-here",
"commentId": "comment-id"
}gdrive_update_comment
更新评论内容。
{
"fileId": "file-id-here",
"commentId": "comment-id",
"content": "Updated comment text"
}gdrive_delete_comment
删除评论。
{
"fileId": "file-id-here",
"commentId": "comment-id"
}gdrive_reply_to_comment
向评论帖子添加回复。
{
"fileId": "file-id-here",
"commentId": "comment-id",
"content": "I agree with this"
}gdrive_resolve_comment
将评论标记为已解决。
{
"fileId": "file-id-here",
"commentId": "comment-id"
}gdrive_reopen_comment
重新打开已解决的评论。
{
"fileId": "file-id-here",
"commentId": "comment-id"
}共享操作
gdrive_share_file
与用户、组或域共享文件。
{
"fileId": "file-id-here",
"emailAddress": "user@example.com",
"type": "user",
"role": "writer",
"sendNotificationEmail": true,
"emailMessage": "Check out this document"
}gdrive_create_share_link
创建一个可共享的链接。
{
"fileId": "file-id-here",
"role": "reader"
}gdrive_list_permissions
列出文件的所有权限。
{
"fileId": "file-id-here"
}gdrive_update_permission
更新现有权限。
{
"fileId": "file-id-here",
"permissionId": "permission-id",
"role": "commenter"
}gdrive_remove_permission
删除权限。
{
"fileId": "file-id-here",
"permissionId": "permission-id"
}建议操作
gdocs_create_suggestion
在文档中创建建议。
{
"fileId": "doc-id-here",
"type": "insert",
"content": "suggested text",
"startIndex": 10
}gdocs_list_suggestions
列出待处理的建议。
{
"fileId": "doc-id-here"
}gdocs_accept_suggestion
接受一个建议。
{
"fileId": "doc-id-here",
"suggestionId": "suggestion-id"
}gdocs_reject_suggestion
拒绝建议。
{
"fileId": "doc-id-here",
"suggestionId": "suggestion-id"
}使用示例
看 示例.md 查看详细的使用示例。
安全
- OAuth令牌安全地存储在
~/.local/share/google-drive-mcp/tokens.json具有0600权限 - 过期时自动刷新令牌
- 用于增强OAuth安全性的PKCE流
故障排除
身份验证问题
- 确保GOOGLE_CLIENT_ID和GOOGLE_CLIEN_CRET设置正确
- 删除
~/.local/share/google-drive-mcp/tokens.json并重新验证 - 检查Google Cloud Console中是否启用了所有必需的API
权限错误
- 验证OAuth同意屏幕具有正确的范围
- 重新验证以授予缺失的权限
速率限制
- 服务器实现了指数回退的自动重试
- 如果达到速率限制,请考虑降低请求频率
许可证
麻省理工学院
贡献
欢迎投稿!请打开问题或拉取请求。
致谢
内置:
- @模型上下文协议/sdk -官方MCP SDK
- 谷歌蜜蜂 -谷歌API Node.js客户端
