这是一个功能强大的模型上下文协议(MCP)服务器,它能够与Google Drive实现无缝集成。借助该服务器,AI模型可以轻松地在Google Drive中进行文件搜索、列表查看以及内容读取操作。
创建Google Cloud项目
启用Google Drive API
设置OAuth 2.0客户端ID
urn:ietf:wg:oauth:2.0:oob)。gcp-oauth.json。安装依赖
npm install @google/drive --save
gdrive_search可在你的Google Drive中使用强大的全文搜索功能查找文件。
{
"query": "string (你的搜索查询)"
}
gdrive_read_file使用Google Drive文件ID直接读取文件内容。
{
"file_id": "string (Google Drive文件ID)"
}
服务器能够智能处理不同的Google Workspace文件类型:
克隆仓库并安装依赖:
git clone https://github.com/your-repository/mcp-gdrive.git
cd mcp-gdrive
npm install
按照以下步骤配置和运行认证:
config.json文件,添加你的Google Cloud项目ID和密钥路径:{
"projectId": "your-project-id",
"keyFile": "path/to/gcp-oauth.json"
}
npm run authenticate
这将引导你完成OAuth 2.0流程,获取必要的访问令牌。
// 搜索文件示例
const { searchFiles } = require('./src/drive');
async function main() {
const query = "quarterly report";
const result = await searchFiles(query);
console.log(result.files);
}
main().catch(console.error);
// 读取文件内容示例
const { readFile } = require('./src/drive');
async function main() {
const fileId = "your-file-id";
const contents = await readFile(fileId);
console.log(contents);
}
main().catch(console.error);
遇到问题时:
credentials目录中。本MCP服务器根据MIT License授权。查看LICENSE文件以获取详细信息。