谷歌工作区MCP服务
生产就绪的Google Workspace MCP服务,为全面的Google Workspace自动化提供84个专用工具。旨在作为与Rube MCP集成的持久后台服务运行,以实现集中式OAuth身份验证。
🚀 特性
- 84定制工具:完整的Google Workspace API覆盖范围(83个工具+1个通过Composio的授权)
- MCP服务:具有PM2进程管理的持久后台服务
- 集中式身份验证:OAuth由Composio/Rube处理(桌面上没有客户端机密)
- TypeScript:具有现代ES2022功能的全型安全
- ES模块:全程支持本地ES模块
- 自动启动:可配置的启动时间服务激活
- 健康监测:用于服务监控的内置健康端点
- 符合PKCE标准:解决远程工作人员的安全合规问题
📋 先决条件
🛠️ 快速开始
1.安装
# Clone or download the project
git clone
cd composio-google-workspace
# Install dependencies
npm install2.环境设置
# Copy environment template
cp .env.example .env
# Edit .env with your API keys
COMPOSIO_API_KEY=your_composio_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here3.发展
# Run in development mode
npm run dev
# Or build and run
npm run build
npm start🏗️ 项目结构
src/
├── agents/ # AI agent implementations
│ └── google-workspace-agent.ts
├── tools/ # Custom tool definitions
│ └── custom-tools.ts
├── composio-client.ts # Composio SDK initialization
└── index.ts # Main application entry🤖 谷歌工作区代理
这 GoogleWorkspaceAgent 类为常见的工作区任务提供了高级方法:
import { GoogleWorkspaceAgent } from './src/agents/google-workspace-agent.js'
const agent = new GoogleWorkspaceAgent('user-123')
await agent.initialize(['gmail', 'googlecalendar'])
// Send emails
await agent.sendEmail('colleague@company.com', 'Project Update', 'Here is the status...')
// Create calendar events
await agent.createCalendarEvent({
title: 'Team Standup',
start: '2024-01-15T09:00:00Z',
end: '2024-01-15T09:30:00Z',
attendees: ['team@company.com']
})
// Complex workflows
await agent.scheduleMeetingWithInvites({
title: 'Q1 Planning',
start: '2024-01-20T14:00:00Z',
end: '2024-01-20T15:00:00Z',
attendees: ['stakeholder1@company.com', 'stakeholder2@company.com'],
agenda: 'Q1 objectives and resource allocation'
})🔧 自定义工具
为您的工作空间需求创建专用工具:
import { initializeCustomTools } from './src/tools/custom-tools.js'
// Initialize all custom tools
const tools = await initializeCustomTools()
// Available custom tools:
// - EMAIL_ANALYTICS: Analyze email patterns
// - MEETING_OPTIMIZER: Find optimal meeting times
// - DOCUMENT_INTELLIGENCE: Extract insights from documents
// - WORKSPACE_WORKFLOW: Automate cross-app workflows🔐 身份验证流程
选项1:交互式设置
import { setupAuthentication, waitForAuthentication } from './src/composio-client.js'
// Setup Gmail authentication
const connectionRequest = await setupAuthentication('user-123', 'gmail')
console.log('Visit this URL:', connectionRequest.redirectUrl)
// Wait for user to complete OAuth flow
const connectedAccount = await waitForAuthentication(connectionRequest.id)
console.log('Gmail connected:', connectedAccount.id)选项2:预配置连接
通过配置连接 Composio仪表板 并通过ID引用它们。
📚 可用脚本
# Development
npm run dev # Start development server
npm run build # Build for production
npm run preview # Preview production build
npm start # Run built application
# Code Quality
npm run typecheck # TypeScript type checking
npm run lint # ESLint code linting
npm run lint:fix # Fix ESLint issues automatically
npm run format # Format code with Prettier
npm run format:check # Check code formatting🔗 集成示例
Gmail集成
// Fetch recent emails
const emails = await agent.getRecentEmails(10, 'is:unread')
// Send email with attachments
await agent.sendEmail('client@company.com', 'Proposal', 'Please find attached...', {
attachments: ['path/to/proposal.pdf']
})日历集成
// Get upcoming events
const events = await agent.getUpcomingEvents(5)
// Create recurring meeting
await agent.createCalendarEvent({
title: 'Weekly Sync',
start: '2024-01-15T10:00:00Z',
end: '2024-01-15T10:30:00Z',
recurrence: ['RRULE:FREQ=WEEKLY;BYDAY=MO']
})Google Drive集成
// Upload documents
await agent.uploadToDrive('report.md', reportContent)
// Search files
const files = await agent.searchDriveFiles('type:document modified:2024')🚀 高级工作流
每日摘要生成
// Generate comprehensive daily summary
const summary = await agent.generateDailySummary('2024-01-15')
console.log(summary)
// Includes email activity, calendar events, and insights会议编排
// Complete meeting workflow: schedule + invites + follow-up
await agent.scheduleMeetingWithInvites({
title: 'Product Review',
start: '2024-01-20T15:00:00Z',
end: '2024-01-20T16:00:00Z',
attendees: ['product@company.com', 'engineering@company.com'],
agenda: 'Q1 product roadmap review and prioritization',
location: 'Conference Room A'
})🛡️ 错误处理
该项目包括全面的错误处理:
try {
await agent.sendEmail('invalid-email', 'Test', 'Body')
} catch (error) {
console.error('Email failed:', error.message)
// Handle specific error cases
}📖 api参考
Composio客户端
initializeComposio()-初始化SDK连接getAvailableTools(toolkits, userId)-列出可用工具setupAuthentication(userId, toolkit)-启动OAuth流waitForAuthentication(requestId)-等待身份验证完成executeTool(toolSlug, userId, arguments)-执行任何工具
谷歌工作区代理
initialize(services)-安装具有所需服务的代理sendEmail()-发送带有附件的电子邮件getRecentEmails()-获取和过滤电子邮件createCalendarEvent()-创建日历事件getUpcomingEvents()-列出即将举行的活动uploadToDrive()-将文件上传到驱动器searchDriveFiles()-搜索驱动器内容generateDailySummary()-生成每日活动摘要
🔧 配置
TypeScript配置
该项目使用现代TypeScript设置 tsconfig.json:
- 目标:ES2022
- 模块:ESNext
- 严格模式已启用
- 支持路径别名(
@/→src/)
快速配置
针对Node.js开发进行了优化:
- ES模块输出
- 源映射已启用
- 正确的外部处理
- 路径别名解析
代码质量
- ESLint:支持TypeScript的linting和推荐规则
- 更漂亮:一致的代码格式
- 预提交挂钩:自动格式化和linting
🤝 贡献
- 分叉存储库
- 创建要素分支:
git checkout -b feature/amazing-feature - 进行更改并添加测试
- 运行质量检查:
npm run lint && npm run typecheck - 提交您的更改:
git commit -m 'Add amazing feature' - 推到分支:
git push origin feature/amazing-feature - 打开拉取请求
📄 许可证
该项目根据ISC许可证获得许可。有关详细信息,请参阅LICENSE文件。
🆘 故障排除
常见问题
身份验证错误
# Verify API keys are set
npm run dev
# Check console for authentication statusTypeScript错误
# Run type checking
npm run typecheck
# Check for missing dependencies
npm install构建问题
# Clear cache and rebuild
rm -rf dist node_modules
npm install
npm run build获取帮助
🔮 接下来是什么?
- 添加Anthropic-Claude集成,用于人工智能电子邮件回复
- 实施工作流调度和自动化
- 添加对Google表格数据处理的支持
- 创建用于监视代理活动的仪表板
- 添加单元测试和CI/CD管道
______________________________________________________________________
内置于❤️ 使用 公司开发 -AI代理在现实世界中采取行动的平台。
