Google Drive MCP服务器
Google Drive的模型上下文协议(MCP)服务器,使搜索、阅读和提取文档中的信息变得更加容易,例如,在填写表单时快速检索所需的详细信息。 它使用FastMCP构建,使用Google OAuth进行身份验证,并支持OCR处理扫描的PDF和图像
______________________________________________________________________
✨ 特性
- 🔍 搜索:按名称、类型或内容查询Google Drive中的文件。
- 📂 阅读:获取并显示文件内容(文本、PDF、图像)。
- 🔑 安全认证:使用Google OAuth 2.0进行身份验证。
- ⚡ MCP就绪:轻松集成到MCP客户端。
______________________________________________________________________
项目结构
.
├── src/
│ ├── server.py # Entry point, starts the FastMCP server
│ ├── tools.py # MCP tools (gdrive_search, read_file, etc.)
│ ├── auth.py # Google OAuth / service account handling
│ ├── file_utils.py # Helpers for reading Drive files, PDFs, images
│ └── config.py # Config (scopes, constants)
├── pyproject.toml / requirements.txt
├── README.md
└── .gitignore
______________________________________________________________________
认证
有 两种身份验证模式:
- OAuth客户端(交互式)
- 建议用于本地测试/个人使用。 - 需要 credentials.json 从谷歌云控制台。将它们存储在~/credentials文件夹中。 - 首次运行时,系统会提示您通过浏览器登录。
- 服务帐户(服务器到服务器)
- 用于自动化部署。 - 需要服务帐户密钥JSON。 - 服务帐户必须有权访问驱动器文件(与其电子邮件共享文件/文件夹)。
敏感文档:本地不存储文件内容;
______________________________________________________________________
🛠 MCP工具
目前实施:
gdrive_search(query: str)\
在谷歌云端硬盘中搜索文件。返回元数据(id、name、mimeType)。
read_file(file_id: str)\
下载并返回文件内容。
- Text → 以字符串形式返回。 - PDFs → 提取文本(如果是基于文本的)或OCR(如果是扫描的)。 - 图像→ OCR文本提取。
______________________________________________________________________
本地运行
与诗歌
poetry install
poetry run python src/server.py
## Configuring MCP Desktop Claude
To connect this server with **MCP Desktop (Claude)**, update your Claude config file (usually located at `~/.mcp/config.json`) to include the `gdrive` server.
Example config snippet:
{ "mcpServers": { "gdrive": { "command": "poetry", "args": [ "run", "python", "src/server.py" ], "env": { "GOOGLE_APPLICATION_CREDENTIALS": "credentials.json" } } } }````
