Google Drive文件管理API

提供容器化的REST API和Model Context Protocol (MCP)接口,用于管理Google Drive上的文件和文件夹。

  • by devgrunge
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 devgrunge/google-drive-mcp

使用说明

📁 Google Drive MCP集成

该项目提供了一个容器化的REST API和 模型上下文协议(MCP) 用于管理上的文件和文件夹的界面 Google 云端硬盘,使用 Node.js, TypeScript,以及 码头工人.


🚀 特性

  • 列出文件
  • 新建文件夹
  • 上传新文件
  • 更新现有文件
  • 公开MCP(模型上下文协议)集成的端点

设置

1.克隆存储库

git clone git@github.com:devgrunge/google-drive-mcp.git
cd google-drive-mcp

2.添加凭据

将credentials.json文件放在项目根目录中。这应该是Google Cloud控制台中的服务帐户密钥。

3.配置环境

创建.env文件:

PORT=3000

4.使用Docker构建和运行

docker build -t google-drive-mcp .
docker run -p 3000:3000 \
  --env-file .env \
  -v $(pwd)/credentials.json:/app/credentials.json \
  google-drive-mcp

⸻

API终点

GET/文件

列出Google Drive中的最新10个文件。

curl -X GET http://localhost:3000/files

⸻

POST/文件夹

创建一个新文件夹。

正文JSON:

{
  "name": "Nova Pasta"
}

例子:

curl -X POST http://localhost:3000/folder \
  -H "Content-Type: application/json" \
  -d '{"name":"Nova Pasta"}'

⸻

POST/上传

上传一个新文件。

正文JSON:

{
  "filename": "document.txt",
  "mimeType": "text/plain",
  "filepath": "/absolute/path/inside/container/document.txt"
}

例子:

curl -X POST http://localhost:3000/upload \
  -H "Content-Type: application/json" \
  -d '{"filename":"document.txt","mimeType":"text/plain","filepath":"/app/files/document.txt"}'

⸻

PUT/update/:id

更新现有文件的内容。

参数: •id:文件id(来自谷歌云端硬盘)

正文JSON:

{
  "filepath": "/absolute/path/inside/container/updated.txt",
  "mimeType": "text/plain"
}

例子:

curl -X PUT http://localhost:3000/update/1AbcD1234567 \
  -H "Content-Type: application/json" \
  -d '{"filepath":"/app/files/updated.txt","mimeType":"text/plain"}'

⸻

MCP集成

要将此API用作MCP服务器:

发现端点

GET/mcp/功能

返回可用工具和资源的列表。

调用工具

POST/mcp/invoke

正文JSON:

{
  "tool": "upload_file",
  "args": {
    "filename": "sample.txt",
    "mimeType": "text/plain",
    "filepath": "/app/files/sample.txt"
  }
}

每个工具名称都匹配一个端点函数(例如,list_files、create_folder等)。

⸻

📁 项目结构

src/
├── index.ts                  # Main entrypoint
├── app.ts                   # Express API
├── services/
│   └── googleDrive.service.ts
├── mcp/
│   └── server.ts            # MCP endpoint handlers
credentials.json
Dockerfile
.env
tsconfig.json