使用说明
Google Drive MCP服务器
一个模型上下文协议(MCP)服务器,为Claude和其他AI助手提供对Google Drive文件的安全、文件夹范围的访问。该服务器允许AI助手从选定的Google Drive文件夹中读取、处理和分析文件,并提供全面的文件格式支持。
特性
- 文件夹范围安全:仅限于单个选定的Google Drive文件夹访问
- 综合文件处理:支持PDF、Word、Excel、PowerPoint、CSV、HTML、XML、ZIP存档等
- 智能内容处理:大文件的智能分块和摘要
- 交互式设置:通过浏览器集成轻松选择文件夹
- 档案处理:提取和分析ZIP文件内容
- 文件概述:获取大型文档的结构化摘要
支持的文件格式
| 格式 | 扩展 | 处理 |
|---|---|---|
.pdf |
文本提取 | |
| Word文档 | .docx, .doc |
全文内容 |
| Excel电子表格 | .xlsx, .xls |
JSON结构化数据 |
| PowerPoint | .pptx, .ppt |
幻灯片文本提取 |
| 文本文件 | .txt, .csv |
直接内容 |
| HTML | .html, .htm |
文本提取 |
| XML | .xml |
结构化JSON |
| JSON | .json |
格式化输出 |
| ZIP档案 | .zip |
内容提取和分析 |
| MS项目 | .mpp |
有限的文本提取 |
先决条件
- Python 3.8+
- 谷歌云项目 启用驱动器API
- 克劳德桌面 或兼容的MCP客户端
安装说明
第一步:谷歌云设置
- 首选 谷歌云控制台
- 创建新项目或选择现有项目
- 启用Google Drive API:
- 导航到“API和服务”>“库”
- 搜索“Google Drive API”
- 点击“启用”
步骤2:创建OAuth凭据
- 转到“API和服务”>“凭据”
- 点击“创建凭据”>“OAuth客户端ID”
- 选择“桌面应用程序”
- 将其命名为“Google Drive MCP服务器”
- 下载凭据JSON文件
- 将其重命名为
credentials.json并将其放置在项目目录中
步骤3:安装依赖项
# Clone or download the project
cd gdrive_mcp_server
# Install basic requirements
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client
# Install optional file processing libraries (recommended)
pip install -r requirements_optional.txt
步骤4:初始设置和身份验证
# Run initial setup to authenticate and select folder
python gdrive_mcp_server.py --setup
这将:
- 打开浏览器进行谷歌身份验证
- 允许您选择要访问的Google Drive文件夹
- 保存配置以备将来使用
步骤5:配置Claude桌面
将服务器添加到Claude Desktop配置文件中:
视窗: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"gdrive": {
"command": "python",
"args": ["c:\\Users\\shank\\projects\\github\\gdrive_mcp_server\\gdrive_mcp_server.py"],
"env": {
"GOOGLE_CREDENTIALS_FILE": "c:\\Users\\shank\\projects\\github\\gdrive_mcp_server\\credentials.json",
"GOOGLE_TOKEN_FILE": "c:\\Users\\shank\\projects\\github\\gdrive_mcp_server\\token.json"
}
}
}
}
重要:更新路径以匹配您的实际项目位置。
步骤6:重新启动克劳德桌面
关闭并重新启动Claude Desktop以加载新的MCP服务器。
用法
配置后,您可以在Claude中使用这些命令:
列出文件
List all files in my Google Drive folder
分析文档
Get the content of file ID: [file_id]
流程档案
Extract and analyze the ZIP file with ID: [file_id]
获取文档概述
Give me an overview of the large document with ID: [file_id]
搜索和筛选
List files containing "budget" in the name
可用工具
| 工具 | 说明 |
|---|---|
list_gdrive_files |
列出所选文件夹中的文件 |
get_gdrive_file |
下载并处理文件内容 |
get_gdrive_file_metadata |
获取文件信息 |
get_current_folder_info |
显示所选文件夹详细信息 |
extract_and_analyze_archive |
处理ZIP存档 |
get_file_chunk |
获取大文件的特定部分 |
get_document_overview |
获取结构化文档摘要 |
get_file_processing_info |
检查文件格式支持 |
安全功能
- 文件夹范围界定:访问仅限于预选文件夹
- 无写访问权限:为安全起见,只读操作
- 文件验证:确保文件在允许的范围内
- OAuth身份验证:安全的Google身份验证流程
故障排除
身份验证问题
# Re-run setup to re-authenticate
python gdrive_mcp_server.py --setup
缺少的依赖
# Install all optional dependencies
pip install -r requirements_optional.txt
文件处理错误
- 检查是否支持文件格式
- 确保文件未损坏
- 请先尝试使用较小的文件
Claude连接问题
- 验证中的路径
claude_desktop_config.json - 检查Python是否在您的系统PATH中
- 配置更改后重新启动Claude Desktop
测试
测试服务器功能:
# Run comprehensive tests
python test_server.py
# Choose option 1 for full test or option 2 for specific file testing
文件结构
gdrive_mcp_server/
├── gdrive_mcp_server.py # Main MCP server
├── file_processor.py # File format processing
├── rag_processor.py # Document chunking and search
├── test_server.py # Testing utilities
├── requirements_optional.txt # Optional dependencies
├── test_requirements.txt # Basic requirements
├── credentials.json # Your Google OAuth credentials
├── token.json # Generated auth token
└── gdrive_folder_config.json # Folder selection config
高级配置
更改所选文件夹
python gdrive_mcp_server.py --setup
环境变量
GOOGLE_CREDENTIALS_FILE:credentials.json的路径GOOGLE_TOKEN_FILE:token.json的路径
自定义文件处理
编辑 file_processor.py 添加对其他文件格式的支持。
支持
对于问题:
- 检查调试日志:
gdrive_mcp_debug.log - 验证Google Drive API配额
- 确保文件夹权限正确
- 测试用
test_server.py第一
许可证
本项目按原样提供,用于教育和发展目的。