README
🚀 MCP 集成服务器
本仓库提供了基于 Model Control Protocol (MCP) 的服务器,可将各类服务与 Claude Desktop 集成,为用户带来便捷的服务交互体验。
🚀 快速开始
MCP 集成服务器包含 Gmail 和 Google Calendar MCP 服务器、后端 API MCP 服务器。下面将为你介绍它们的使用方法。
✨ 主要特性
Gmail 和 Google Calendar MCP 服务器
- Gmail 操作:
- 可获取收件箱中的最新邮件。
- 支持使用 Gmail 查询语法搜索邮件。
- 能够查看电子邮件内容。
- 支持带 CC 和 BCC 的邮件发送。
- 日历操作:
- 可搜索日历事件。
- 能创建新的日历事件。
- 可查看即将进行的事件。
后端 API MCP 服务器
- 支持用户管理操作。
- 提供标准化 API 响应。
- 具备错误处理和日志记录功能。
- 使用 Pydantic 模型进行数据验证。
📦 安装指南
Gmail 和 Google Calendar MCP 服务器
- 先决条件:
- 安装 Python 3.x。
- 安装 MCP 包。
- 在 Google Cloud Console 项目中启用 Gmail 和 Calendar API。
- OAuth 凭证:
- 访问 Google Cloud Console。
- 创建新项目或选择现有项目。
- 启用 Gmail API 和 Google Calendar API。
- 创建 OAuth 2.0 凭证。
- 下载凭证并保存为
credentials.json在项目目录中。
- 安装:
# 安装所需包 pip install google-auth-oauthlib google-auth-httplib2 google-api-python-client # 在 Claude Desktop 中安装服务器 mcp install server.py - 首次运行:
- 运行服务器:
mcp run server.py。 - 首次运行会提示进行 OAuth 认证。
- 跟随浏览器链接授权应用程序。
- 令牌将保存以备下次使用。
- 运行服务器:
后端 API MCP 服务器
- 先决条件:
- 安装 Python 3.x。
- 安装 MCP 包。
- 安装:
# 安装所需包 pip install pydantic # 在 Claude Desktop 中安装服务器 mcp install backend_server.py - 配置:
- 根据需要在
backend_server.py中配置 API 端点和其他设置。
- 根据需要在
💻 使用示例
Gmail 和 Google Calendar MCP 服务器
Gmail 工具
# 获取收件箱中的最新邮件
from server import get_latest_emails
latest_emails = get_latest_emails(max_results=10)
# 使用 Gmail 查询搜索邮件
from server import search_emails
search_results = search_emails(query='subject:important', max_results=10)
# 查看特定电子邮件的内容
from server import get_email_content
email_content = get_email_content(email_id='123456')
# 发送电子邮件
from server import send_email
send_email(to='example@example.com', subject='Test', body='This is a test email', cc=None, bcc=None)
Calendar 工具
# 搜索日历事件
from server import search_events
events = search_events(query='meeting', max_results=10, time_min='2024-01-01T00:00:00Z')
# 创建新的日历事件
from server import create_calendar_event
create_calendar_event(summary='Meeting', start_time='2024-01-01T09:00:00Z', end_time='2024-01-01T10:00:00Z', description='Important meeting', location='Office')
后端 API MCP 服务器
# 假设 backend_server.py 中有一个与后端 API 交互的函数
from backend_server import interact_with_backend
result = interact_with_backend()
📚 详细文档
可用工具
Gmail 工具
get_latest_emails(max_results: int = 10):获取收件箱中的最新邮件。search_emails(query: str, max_results: int = 10):使用 Gmail 查询搜索邮件。get_email_content(email_id: str):查看特定电子邮件的内容。send_email(to: str, subject: str, body: str, cc: Optional[str], bcc: Optional[str]):发送电子邮件。
Calendar 工具
search_events(query: str, max_results: int = 10, time_min: Optional[str]):搜索日历事件。create_calendar_event(summary: str, start_time: str, end_time: str, description: Optional[str], location: Optional[str]):创建新的日历事件。
后端 API MCP 服务器
- 包含与后端 API 进行交互的各种函数和方法。
开发说明
- 可修改代码以满足特定需求。
- 可扩展功能或添加新的 API 支持。
- 使用 MCP 协议进行通信。
常见问题
- 如何处理错误? 请参考文档中的错误处理部分。
- 是否支持其他 API? 是的,可以扩展以支持更多服务。
- 如何优化性能? 建议使用缓存机制和高效的代码设计。
🔧 技术细节
本项目使用 Python 开发,借助 Google API 实现 Gmail 和 Google Calendar 的集成,使用 Pydantic 模型进行数据验证。通过 MCP 协议,实现与 Claude Desktop 的通信。
📄 许可证
文档未提及相关许可证信息。
⚠️ 重要提示
- 确保凭证和其他敏感信息的安全。
- 避免在公共仓库中存储机密数据。
- 定期更新和管理访问权限。
结束语
感谢使用 MCP 集成服务器。如需更多信息,请查阅完整文档或联系支持团队。
Scan to join WeChat group