Skip to main content
Glama

gdrive-mcp

一个通过 Streamable HTTP 公开 Google Drive 文件夹的 MCP(Model Context Protocol)服务器,专为在 Vercel 上运行而构建,并托管在 GitHub 上。

它提供两个工具:

工具

描述

list_files

列出已配置的 Drive 文件夹中的文件/文件夹(可选搜索)

read_file

读取文本内容,自动导出 Google Docs/Sheets/Slides

架构

  • server.ts — Node.js HTTP 服务器入口(Streamable HTTP MCP 端点)。

  • src/mcp.ts — MCP 服务器定义 + 工具。

  • src/drive.ts — Google Drive 客户端,使用一个 服务账号。

身份验证通过 Google 服务账号 进行,且为只读(drive.readonly)。


Related MCP server: gdrive-mcp-server

1. Google Cloud 设置(服务账号)

  1. 前往 Google Cloud Console 并创建一个项目。

  2. 启用 Google Drive API:APIs & Services → Library → 搜索 "Google Drive API" -> 启用。

  3. 创建服务账号:IAM & Admin → Service Accounts -> Create Service Account。

  4. 为它创建 JSON 密钥:打开服务账号 -> Keys -> Add Key -> Create New Key -> JSON。下载该文件。

  5. 记下服务账号的 邮箱(格式像 name@project.iam.gserviceaccount.com)。

  6. 用该邮箱共享 Drive 文件夹:

    • 在 Google Drive 中打开你的文件夹 → 右键 → Share。

    • 粘贴服务账号的邮箱,授予其 查看者 权限。

  7. 复制文件夹 ID(即 URL 中 /folders/ 后面的部分)。


2. 本地设置

git clone <your-repo-url>
cd gdrive-mcp
npm install

创建一份 .env 文件(复制 .env.example):

DRIVE_FOLDER_ID=1XM-0CtgvW3PGDekC8qLa2ghxRyvTfjwD
GOOGLE_SERVICE_ACCOUNT_KEY=<base64 of service-account.json>

将服务账号密钥编码为 base64:

  • Linux/macOS:base64 -w0 service-account.json

  • PowerShell:[Convert]::ToBase64String([IO.File]::ReadAllBytes("service-account.json"))


3. 部署到 Vercel

选项 A — Vercel + GitHub(推荐)

  1. 将此仓库推送到 GitHub。

  2. 在 Vercel 中 → Add New → Project → 导入该 GitHub 仓库。

  3. 添加环境变量(DRIVE_FOLDER_ID、GOOGLE_SERVICE_ACCOUNT_KEY)。

  4. 部署。MCP 端点将是:

    https://<your-project>.vercel.app

选项 B — Vercel CLI

npm i -g vercel
vercel login
vercel env add DRIVE_FOLDER_ID
vercel env add GOOGLE_SERVICE_ACCOUNT_KEY
vercel --prod

4. 推送到 GitHub(首次)

git init
git add .
git commit -m "Add gdrive-mcp server"
git branch -M main
git remote add origin https://github.com/<you>/gdrive-mcp.git
git push -u origin main

5. 连接 MCP 客户端

使用 Streamable HTTP 传输方式,将你的客户端指向部署后的 URL。 示例 claude_desktop_config.json:

{
  "mcpServers": {
    "gdrive": {
      "type": "http",
      "url": "https://<your-project>.vercel.app"
    }
  }
}

使用通用 MCP 配置格式的客户端:

{
  "mcpServers": {
    "gdrive": {
      "url": "https://<your-project>.vercel.app"
    }
  }
}

该端点是无状态的,因此每个请求都会创建一个全新的传输——非常适合 serverless 场景。访问权限由 Google Drive 中对该服务账号的共享设置控制。

环境变量

变量

必需

描述

DRIVE_FOLDER_ID

是

Google Drive 文件夹 ID

GOOGLE_SERVICE_ACCOUNT_KEY

是

Base64 编码的服务账号 JSON 密钥

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    C
    maintenance
    A read-only Google Drive MCP server that allows searching files, reading file content (with auto-export for Google Docs, Sheets, Slides), and retrieving file metadata via OAuth authentication.
    13 npm
    2
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables MCP-compatible AI assistants to interact with a user's Google Drive, including listing, searching, reading, creating, updating, and deleting files, with authentication via Google OAuth.
    -
  • F
    license
    Not graded
    quality
    B
    maintenance
    A read-only MCP server that exposes a configured Google Drive folder to MCP clients, enabling them to list, search, and extract content from various file formats like Excel, CSV, PDF, DOCX, and images.
    -
  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables interacting with Google Drive folders through an MCP server, allowing listing, searching, and reading files using tools like list_files, search_files, get_file, and read_file.
    -