Google Drive

Google Drive

用于从Google Drive读取数据和编辑Google Sheets的Model Context Protocol (MCP) Server。

概述

Google Drive MCP 服务器允许您:

  • 在 Google Drive 中搜索文件
  • 读取 Drive 文件内容
  • 读取和更新 Google Sheets

安装配置

1. 设置 Google Cloud 项目

1. 创建 Google Cloud 项目: https://console.cloud.google.com/projectcreate
2. 启用必要的 API:
   - Google Drive API
   - Google Sheets API 
   - Google Docs API
3. 配置 OAuth 同意屏幕 (测试用选择"内部")
4. 添加 OAuth 作用域:
   - https://www.googleapis.com/auth/drive.readonly
   - https://www.googleapis.com/auth/spreadsheets
5. 创建 OAuth 客户端 ID (桌面应用类型)

2. 配置服务器

1. 下载 OAuth 密钥文件并重命名为 gcp-oauth.keys.json
2. 创建配置目录 (例如: ~/.config/mcp-gdrive)
3. 将密钥文件放入配置目录
4. 创建 .env 文件:

GDRIVE_CREDS_DIR=/path/to/config/directory
CLIENT_ID=<您的客户端ID>
CLIENT_SECRET=<您的客户端密钥>

3. 构建并验证

1. 运行 npm run build 构建服务器
2. 执行 node ./dist/index.js 触发身份验证
3. 在浏览器中完成 OAuth 身份验证流程

使用方法

桌面应用集成

在应用程序的服务器配置中添加:

{
  "mcpServers": {
    "gdrive": {
      "command": "npx",
      "args": ["-y", "@isaacphi/mcp-gdrive"],
      "env": {
        "CLIENT_ID": "<CLIENT_ID>",
        "CLIENT_SECRET": "<CLIENT_SECRET>",
        "GDRIVE_CREDS_DIR": "/path/to/config/directory"
      }
    }
  }
}

可用工具

  1. gdrive_search - 搜索 Drive 文件

    • 输入: query, pageToken?, pageSize?
  2. gdrive_read_file - 读取文件内容

    • 输入: fileId
  3. gsheets_read - 读取电子表格数据

    • 输入: spreadsheetId, ranges?, sheetId?
  4. gsheets_update_cell - 更新单元格值

    • 输入: fileId, range, value

资源访问

通过 gdrive:///<file_id> 格式访问文件

许可证

本项目基于 MIT 许可证,包含 Anthropic, PBC 开发的代码。