Google云端文件管理服务

一个基于Go语言实现的MCP服务器,用于操作Google Drive、Google Docs、Google Slides和Google Sheets,提供文件搜索、内容读取和更新等功能。

  • by kitagry
  • Go
  • 本地部署
  • 更新于
在 GitHub 查看 kitagry/drive-mcp

使用说明

驱动MCP

用于Google Drive、Google文档、Google幻灯片和Google表格操作的MCP(模型上下文协议)服务器的Go实现。

特性

  • 搜索谷歌云端硬盘文件
  • 列出Google Drive文件夹中的文件
  • 阅读谷歌文档内容
  • 更新Google文档内容
  • 阅读谷歌幻灯片演示内容
  • 更新Google幻灯片演示文稿幻灯片
  • 阅读谷歌表格值
  • 更新Google表格值
  • 使用gcloud应用程序默认凭据进行身份验证

设置

先决条件

  • 转到1.21或更高版本
  • 谷歌云CLI(gcloud)
  • 启用Google Drive API、Google Docs API、Google Slides API和Google Sheets API的GCP项目

身份验证设置

  1. 启用Google Drive API、Google Docs API、Google Slides API和Google Sheets API
    • https://console.cloud.google.com/apis/library/drive.googleapis.com
    • https://console.cloud.google.com/apis/library/docs.googleapis.com
    • https://console.cloud.google.com/apis/library/slides.googleapis.com
    • https://console.cloud.google.com/apis/library/sheets.googleapis.com
  2. 运行gcloud身份验证:
gcloud auth application-default login --scopes=https://www.googleapis.com/auth/cloud-platform,https://www.googleapis.com/auth/drive
  1. 如果需要,设置配额项目环境变量:
export GOOGLE_CLOUD_QUOTA_PROJECT_ID=your-project-id

安装

go mod download

用法

运行MCP服务器

go build -o drive-mcp
./drive-mcp

可用工具

搜索文件

在谷歌云端硬盘中搜索文件。

参数:

  • query (必填):要搜索的文件名或关键字
  • maxResults (可选,默认值:10):要检索的最大文件数

例子:

{
  "name": "search_files",
  "arguments": {
    "query": "meeting notes",
    "maxResults": 5
  }
}

列表文件

列出Google Drive文件夹中的文件。

参数:

  • folderId (可选):列出文件的文件夹的ID。如果为空,则列出“我的驱动器”根目录中的文件
  • maxResults (可选,默认值:10):要检索的最大文件数

例子:

{
  "name": "list_files",
  "arguments": {
    "folderId": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
    "maxResults": 20
  }
}

示例(我的驱动器根目录):

{
  "name": "list_files",
  "arguments": {
    "maxResults": 10
  }
}

get_document

获取Google文档的内容。

参数:

  • documentId (必填):谷歌文档的ID

例子:

{
  "name": "get_document",
  "arguments": {
    "documentId": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms"
  }
}

update_document

更新Google文档的内容。

参数:

  • documentId (必填):谷歌文档的ID
  • content (必填):文档的新内容

例子:

{
  "name": "update_document",
  "arguments": {
    "documentId": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
    "content": "This is the new content for the document."
  }
}

get_resentation

获取Google幻灯片演示文稿的内容。

参数:

  • presentationId (必填):谷歌幻灯片演示文稿的ID

例子:

{
  "name": "get_presentation",
  "arguments": {
    "presentationId": "1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc"
  }
}

update_呈现

更新Google幻灯片演示文稿中的特定幻灯片。

参数:

  • presentationId (必填):谷歌幻灯片演示文稿的ID
  • slideIndex (可选,默认值:0):要更新的幻灯片索引(从0开始)
  • title (必填):幻灯片的标题
  • content (必填):幻灯片内容

例子:

{
  "name": "update_presentation",
  "arguments": {
    "presentationId": "1EAYk18WDjIG-zp_0vLm3CsfQh_i8eXc67Jo2O9C6Vuc",
    "slideIndex": 0,
    "title": "New Slide Title",
    "content": "This is the new content for the slide."
  }
}

get_spreadsheet

从谷歌电子表格中获取值。

参数:

  • spreadsheetId (必填):谷歌电子表格的ID
  • range (必填):要检索的范围(例如,'Sheet1!A1:C10')

例子:

{
  "name": "get_spreadsheet",
  "arguments": {
    "spreadsheetId": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
    "range": "Sheet1!A1:C10"
  }
}

update_spreadsheet

更新Google电子表格中的值。

参数:

  • spreadsheetId (必填):谷歌电子表格的ID
  • range (必填):要更新的范围(例如,“Sheet1!A1:C10”)
  • values (必填):要写入的二维值数组

例子:

{
  "name": "update_spreadsheet",
  "arguments": {
    "spreadsheetId": "1BxiMVs0XRA5nFMdKvBdBZjgmUUqptlbs74OgvE2upms",
    "range": "Sheet1!A1:C2",
    "values": [
      ["Name", "Age", "City"],
      ["John", "30", "Tokyo"]
    ]
  }
}

测试

go test -v

结构

  • drive.go -Google Drive、Docs、Slides和Sheets API操作实现
  • main.go -带有工具处理程序的MCP服务器入口点

许可证

麻省理工学院