这是一个功能强大的模型上下文协议 (MCP) 服务器,它实现了与 Google Drive 的无缝集成,让 AI 模型能够在 Google Drive 中进行文件搜索、列表查看以及内容读取操作。
npm install gdrive-mcp-server
import { GDriveMCP } from 'gdrive-mcp-server';
async function main() {
const gdrive = new GDriveMCP({
credentialsPath: './credentials.json',
tokenPath: './token.json'
});
// 搜索文件
const files = await gdrive.search({ query: 'quarterly report' });
console.log('搜索结果:', files);
// 读取文件内容
const contents = await gdrive.read('your-file-id');
console.log('文件内容:', contents);
}
main().catch(console.error);
gdrive_search可在你的 Google Drive 中利用强大的全文搜索功能来搜索文件。
{
"query": "string (你的搜索查询)"
}
gdrive_read_file能使用 Google Drive 文件 ID 直接读取文件内容。
{
"file_id": "string (Google Drive 文件 ID)"
}
服务器可智能处理不同的 Google Workspace 文件类型:
需在 credentials.json 中添加你的 Google Drive 凭据:
{
"type": "service_account",
"project_id": "your-project-id",
"private_key_id": "your-private-key-id",
"private_key": "your-private-key",
"client_email": "your-client-email",
"token_uri": "https://oauth2.googleapis.com/token"
}
credentials.json)。运行你的应用以获取必要的 OAuth 令牌:
node src/auth.js
在 credentials.json 中添加你的 Google Drive 凭据,具体格式如下:
{
"type": "service_account",
"project_id": "your-project-id",
"private_key_id": "your-private-key-id",
"private_key": "your-private-key",
"client_email": "your-client-email",
"token_uri": "https://oauth2.googleapis.com/token"
}
credentials.json)。运行以下命令来获取必要的 OAuth 令牌:
node src/auth.js
credentials 目录中。欢迎大家贡献代码!你可以随意提交 Pull Request。
此 MCP 服务器遵循 MIT 许可证进行分发。你可以查看 LICENSE 文件以获取详细信息。
若你遇到问题,可按以下步骤排查:
credentials 目录中。