Google Drive MCP Server
文件
Google Drive MCP Server
🔥 热度:5

Google Drive 无缝集成

DeepSeek 导航网:Google Drive MCP Server 一个强大的模型上下文协议(MCP)服务器,提供与 Google Drive 的无缝集成,允许 AI 模型在 Google Drive 中搜索、列出和读取文件。

🚀 功能

工具

使用强大的全文搜索功能在您的 Google Drive 中搜索文件。

  • 输入
    {
      "query": "string (您的搜索查询)"
    }
    
  • 输出:文件列表包含:
    • 文件名
    • MIME 类型
    • 文件 ID
    • 最后修改时间
    • 文件大小

2. gdrive_read_file

直接使用 Google Drive 文件 ID 读取文件内容。

  • 输入
    {
      "file_id": "string (Google Drive 文件 ID)"
    }
    
  • 输出:具有适当格式转换的文件内容

自动文件格式处理

服务器智能处理不同的 Google Workspace 文件类型:

  • 📝 Google 文档 → Markdown
  • 📊 Google 表格 → CSV
  • 📊 Google 演示文稿 → 纯文本
  • 🎨 Google 绘图 → PNG
  • 📄 文本/JSON 文件 → UTF-8 文本
  • 📦 其他文件 → Base64 编码

🛠️ 开始使用

前提条件

  • Node.js (v16 或更高版本)
  • npm 或 yarn
  • 一个 Google Cloud 项目
  • 一个 Google Workspace 或个人 Google 账户

详细的 Google Cloud 设置

  1. 创建 Google Cloud 项目
    • 访问 Google Cloud Console
    • 点击“新建项目”
    • 输入项目名称(例如:“MCP GDrive Server”)
    • 点击“创建”
    • 等待项目创建完成并选择该项目
  2. 启用 Google Drive API
    • 转到 API 库
    • 搜索“Google Drive API”
    • 点击“Google Drive API”
    • 点击“启用”
    • 等待 API 启用完成
  3. 配置 OAuth 同意屏幕
    • 导航至 OAuth 同意屏幕
    • 选择用户类型:
      • 如果您使用的是 Google Workspace ,请选择“内部”
      • 对于个人 Google 账户,请选择“外部”
    • 点击“创建”
    • 填写必填字段:
      • 应用名称:“MCP GDrive Server”
      • 用户支持电子邮件:您的电子邮件
      • 开发者联系电子邮件:您的电子邮件
    • 点击“保存并继续”
    • 在“范围”页面上:
      • 点击“添加或删除范围”
      • 添加 https://www.googleapis.com/auth/drive.readonly
      • 点击“更新”
    • 点击“保存并继续”
    • 查看摘要并点击“返回仪表板”
  4. 创建 OAuth 客户端 ID
    • 转到 凭据
    • 点击顶部的“创建凭据”
    • 选择“OAuth 客户端 ID”
    • 选择应用程序类型:“桌面应用”
    • 名称:“MCP GDrive Server Desktop Client”
    • 点击“创建”
    • 在弹出窗口中:
      • 点击“下载 JSON”
      • 保存文件
      • 点击“确定”
  5. 在项目中设置凭据
    # 创建凭据目录
    mkdir credentials
    # 移动并重命名下载的 JSON 文件
    mv path/to/downloaded/client_secret_*.json credentials/gcp-oauth.keys.json

安装

# Clone the repository
git clone https://github.com/felores/gdrive-mcp-server.git
cd gdrive-mcp-server
# Install dependencies
npm install

# Build the project
npm run build

身份验证

  1. 创建一个凭据目录并将您的 OAuth 密钥放入其中:
    mkdir credentials
    # 将下载的 OAuth JSON 文件移动到凭据目录,并命名为 gcp-oauth.keys.json
  2. 运行身份验证命令:
    node dist/index.js auth
  3. 在浏览器中完成 OAuth 流程
  4. 凭据将保存在 credentials/.gdrive-server-credentials.json 中

🔧 使用方法

作为命令行工具

# Start the server
node dist/index.js

与桌面应用程序集成

将以下配置添加到您的应用程序服务器设置中:

{
  "mcpServers": {
    "gdrive": {
      "command": "node",
      "args": ["path/to/gdrive-mcp-server/dist/index.js"],
      "env": {
        "GOOGLE_APPLICATION_CREDENTIALS": "path/to/gdrive-mcp-server/credentials/gcp-oauth.keys.json",
        "MCP_GDRIVE_CREDENTIALS": "path/to/gdrive-mcp-server/credentials/.gdrive-server-credentials.json"
      }
    }
  }
}

将 path/to/gdrive-mcp-server 替换为实际的安装目录路径。

示例用法

  1. 搜索文件
    // 搜索包含“季度报告”的文档
    const result = await gdrive_search({ query: "quarterly report" });
    
  2. 读取文件内容
    // 使用其 ID 读取特定文件
    const contents = await gdrive_read_file({ file_id: "your-file-id" });
    

🔒 安全性

  • 所有敏感凭证都存储在 credentials 目录中
  • OAuth 凭证和令牌被排除在版本控制之外
  • 对 Google Drive 的只读访问
  • 安全的 OAuth 2.0 认证流程

🤝 贡献

欢迎贡献!请随时提交 Pull Request 。

📝 许可证

此 MCP 服务器基于 MIT 许可证发布。详情请参见 LICENSE 文件。

🔍 故障排查

如果您遇到问题:

  1. 验证您的 Google Cloud Project 设置
  2. 确保启用了所有必需的 OAuth 范围
  3. 检查凭证是否正确放置在 credentials 目录中
  4. 验证 Google Drive 中的文件权限和访问权限

相关推荐