Google Drive文件管理服务

一个基于FastMCP的Google Drive集成服务,提供文件列表、搜索、读写Google Docs等功能,支持服务账号认证和分页处理。

  • by festusev
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 festusev/google_drive_mcp

使用说明

Google Drive MCP服务器

使用FastMCP构建的用于Google Drive集成的模型上下文协议(MCP)服务器。提供用于读取、写入、搜索和列出Google Drive文件的工具,重点是Google文档操作。

特性

  • 文件操作:在Google Drive中列出和搜索文件,并进行分页
  • 文档阅读:通过分页和标签选择阅读谷歌文档内容
  • 公文写作:使用选项卡选择和范围操作写入谷歌文档
  • 认证:Google Drive API访问的服务帐户身份验证
  • 分页:高效处理大型文档和文件列表

设置

1.安装依赖项

uv sync

2.Google API设置

  1. 转到 谷歌云控制台
  2. 创建新项目或选择现有项目
  3. 启用Google Drive API和Google Docs API
  4. 创建服务帐户并生成密钥
  5. 下载服务帐户密钥文件并将其另存为 service-account-key.json 在项目根中
  6. 使用服务帐户电子邮件共享您要访问的任何Google Drive文件/文件夹

3.运行服务器

python -m google_drive_mcp.server

不需要身份验证流程-服务帐户将使用密钥文件自动进行身份验证。

可用工具

list_files

列出Google Drive中的文件,并可选择过滤和分页。

参数:

  • folder_id (可选):用于列出文件的文件夹ID(默认:root)
  • page_size (可选):每页文件数(默认值:50,最大值:100)
  • page_token (可选):分页标记
  • mime_type (可选):按MIME类型筛选(例如,“application/vnd.google-apps.document”)

search_files

使用查询语法在Google Drive中搜索文件。

参数:

  • query:搜索查询(例如,'名称包含“报告”')
  • page_size (可选):每页文件数(默认值:50,最大值:100)
  • page_token (可选):分页标记

read_document

从带有分页的Google Docs文档中读取内容。

参数:

  • document_id:谷歌文档文档ID
  • tab_id (可选):要读取的特定选项卡ID
  • start_index (可选):起始字符索引(默认值:0)
  • length (可选):要读取的字符数(默认值:5000,最大值:10000)

write_document

将内容写入Google Docs文档。

参数:

  • document_id:谷歌文档文档ID
  • content:要写的内容
  • tab_id (可选):要写入的特定选项卡ID
  • insert_index (可选):索引插入内容的位置(默认:结束)
  • replace_start (可选):开始内容替换索引
  • replace_end (可选):内容替换的结束索引

使用示例

搜索谷歌文档

# Search for documents containing "report"
search_files(query='name contains "report" and mimeType="application/vnd.google-apps.document"')

使用分页功能读取文档

# Read first 5000 characters
read_document(document_id="your_doc_id")

# Read next 5000 characters
read_document(document_id="your_doc_id", start_index=5000)

写入特定选项卡

# Write to a specific tab in a document
write_document(
    document_id="your_doc_id",
    content="Hello, World!",
    tab_id="your_tab_id"
)

发展

项目结构

google_drive_mcp/
├── __init__.py
├── auth.py          # Google Drive authentication
└── server.py        # FastMCP server implementation

在发展中奔跑

# Install in development mode
uv pip install -e .

# Run the server
python -m google_drive_mcp.server

许可证

该项目根据MIT许可证获得许可。