Google Drive MCP Server

by felores
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Enables reading and conversion of Google Docs to Markdown format for AI processing.

  • Allows AI models to search, list, and read files directly from Google Drive with support for various file formats and intelligent conversion.

  • Provides access to Google Sheets files with automatic conversion to CSV format.

Google Drive MCP 服务器

强大的模型上下文协议 (MCP) 服务器,可与 Google Drive 无缝集成,让 AI 模型能够从 Google Drive 搜索、列出和读取文件。

🚀 功能

工具

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

  • 输入
    { "query": "string (your search query)" }
  • 输出:文件列表,内容如下:
    • 文件名
    • MIME 类型
    • 文件 ID
    • 上次修改时间
    • 文件大小

2. gdrive_read_file

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

  • 输入
    { "file_id": "string (Google Drive file 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 服务器”
      • 用户支持电子邮件:您的电子邮件
      • 开发者联系邮箱:您的邮箱
    • 点击“保存并继续”
    • 在“范围”页面上:
      • 点击“添加或删除范围”
      • 添加https://www.googleapis.com/auth/drive.readonly
      • 点击“更新”
    • 点击“保存并继续”
    • 查看摘要并点击“返回仪表板”
  4. 创建 OAuth 客户端 ID
    • 前往凭证
    • 点击顶部的“创建凭证”
    • 选择“OAuth 客户端 ID”
    • 选择应用程序类型:“桌面应用程序”
    • 名称:“MCP GDrive 服务器桌面客户端”
    • 点击“创建”
    • 在弹出窗口中:
      • 点击“下载 JSON”
      • 保存文件
      • 点击“确定”
  5. 在项目中设置凭据
    # Create credentials directory mkdir credentials # Move and rename the downloaded JSON file 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 # Move your downloaded OAuth JSON file to the credentials directory as 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. 搜索文件
    // Search for documents containing "quarterly report" const result = await gdrive_search({ query: "quarterly report" });
  2. 读取文件内容
    // Read a specific file using its ID const contents = await gdrive_read_file({ file_id: "your-file-id" });

🔒 安全

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

🤝 贡献

欢迎贡献代码!欢迎提交 Pull 请求。

📝 许可证

此 MCP 服务器采用 MIT 许可证。详情请参阅许可证文件。

🔍 故障排除

如果您遇到问题:

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

📚 其他资源

-
security - not tested
A
license - permissive license
-
quality - not tested

支持与 Google Drive 集成以列出、读取和搜索文件,支持各种文件类型并自动导出 Google Workspace 文件。

  1. 🚀 Features
    1. Tools
    2. Automatic File Format Handling
  2. 🛠️ Getting Started
    1. Prerequisites
    2. Detailed Google Cloud Setup
    3. Installation
    4. Authentication
  3. 🔧 Usage
    1. As a Command Line Tool
    2. Integration with Desktop App
    3. Example Usage
  4. 🔒 Security
    1. 🤝 Contributing
      1. 📝 License
        1. 🔍 Troubleshooting
          1. 📚 Additional Resources
            ID: lgoestmwtn