餐厅预订MCP服务器
A完整 模型上下文协议(MCP) 用于餐厅发现和预订的服务器,与 谷歌人工智能工作室(Gemini API) 和 Google Places API该项目演示了如何构建一个基于人工智能的餐厅预订系统,该系统可以搜索餐厅、模拟预订和生成日历邀请。
🚀 特性
- 🔍 餐厅搜索:使用Google Places API查找带有美食、位置、评级和价格过滤器的餐厅
- 🤖 人工智能集成:使用Google AI Studio(Gemini)理解自然语言查询
- 📅 预订系统:带可用性检查的模拟预订系统
- 📧 日历邀请:生成
.ics预订日历文件 - 🛠️ MCP协议:完全符合模型上下文协议标准
- 💰 免费API:仅使用免费的谷歌服务
📋 先决条件
- Python 3.10+
- 谷歌云帐户(免费版)
- 谷歌AI工作室帐户(免费)
🔧 安装说明
1.克隆和安装依赖项
# Clone or download the project files
# Install required packages
pip install -r requirements.txt2.获取API密钥
Google Places API密钥
- 首选 谷歌云控制台
- 创建新项目或选择现有项目
- 启用 地点API 和 地理编码API
- 转到“API和服务”>“凭据”
- 单击“创建凭据”>“API密钥”
- 复制API密钥
谷歌人工智能工作室(Gemini)API密钥
- 首选 谷歌人工智能工作室
- 使用您的Google帐户登录
- 点击左上角的“获取API键”
- 点击“创建API密钥”
- 复制API密钥
3.配置环境变量
# Edit .env and add your API keys
GOOGLE_PLACES_API_KEY=your_actual_places_api_key
GEMINI_API_KEY=your_actual_gemini_api_key4.运行MCP服务器
# Start the MCP server
python server.py5.使用示例客户端进行测试
# Run the example client (in a new terminal)
python client.py🛠️ 可用的MCP工具
服务器提供了可供任何MCP客户端使用的这些工具:
search_restaurants
使用过滤器搜索餐厅
{
"location": "New York, NY",
"cuisine_type": "italian",
"radius": 5000,
"min_rating": 4.0,
"max_results": 10
}get_available_slots
获取可用的预订时段(模拟数据)
{
"restaurant_name": "Bella Italia",
"date": "2025-08-20",
"party_size": 4
}make_reservation
创建餐厅预订
{
"restaurant_name": "Bella Italia",
"restaurant_address": "123 Main St, New York, NY",
"date": "2025-08-20",
"time": "19:00",
"party_size": 4,
"customer_name": "John Doe",
"customer_email": "john@example.com",
"special_requests": "Window seat preferred"
}generate_calendar_invite
为预订生成.ics日历文件
{
"reservation_id": "RES12345",
"duration_minutes": 90
}list_reservations
列出所有预订(可选择通过电子邮件过滤)
{
"customer_email": "john@example.com"
}💻 使用示例
使用自然语言
# The client can understand natural language:
user_input = "Find me a good Italian restaurant in Manhattan for tonight, party of 4"
# AI extracts: location="Manhattan, NY", cuisine_type="italian", party_size=4
# Then calls: search_restaurants(location="Manhattan, NY", cuisine_type="italian")直接MCP工具调用
# Direct tool usage:
result = mcp_server.call_tool("search_restaurants", {
"location": "Los Angeles, CA",
"cuisine_type": "sushi",
"min_rating": 4.5,
"max_results": 5
})🏗️ 项目结构
restaurant-mcp/
├── server.py # Main MCP server implementation
├── client_example.py # Example client with AI integration
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .env # Your actual API keys (create this)
└── README.md # This file🔌 与您自己的客户整合
要在您自己的应用程序中使用此MCP服务器:
- 启动服务器:
python server.py - 连接您的MCP客户端 到服务器端点
- 使用可用的工具 上面列出的
Claude Desktop示例
添加到您的Claude Desktop MCP配置中:
{
"mcpServers": {
"restaurant-server": {
"command": "python",
"args": ["path/to/your/server.py"],
"env": {
"GOOGLE_PLACES_API_KEY": "your_key_here",
"GEMINI_API_KEY": "your_key_here"
}
}
}
}⚠️ 重要提示
局限性
- 模拟预订:模拟预订系统。真正的集成需要餐厅预订API(如OpenTable)
- 速率限制:Google Places API在免费层上有使用配额
- 仅限开发:这是一个演示项目,尚未准备好投入生产
安全
- 永远不要将API密钥提交到版本控制
- 对所有机密使用环境变量
- 考虑将Google Cloud IAM用于生产部署
🎯 后续步骤和增强功能
想扩展这个项目吗?以下是一些想法:
- 真实预订API:与OpenTable、Resy或餐厅特定的预订系统集成
- 支付处理:为预订押金添加Stripe集成
- 短信通知:使用Twilio发送确认文本
- 多语言支持:使用Gemini的多语言功能
- 餐厅评论:删除并分析评论,以提出更好的建议
- 可用性缓存:缓存实时可用性数据
- 用户认证:添加用户帐户和预订历史记录
🐛 故障排除
常见问题
“未配置Google Places API密钥”
- 确保您已设置
GOOGLE_PLACES_API_KEY在你的.env文件 - 验证在Google云控制台中启用了Places API
“未找到餐厅”
- 检查您的位置字符串是否有效(例如,“New York,NY”)
- 尝试增加搜索半径
- 降低最小额定值过滤器
日历邀请未打开
- 确保您安装了日历应用程序
- 尝试打开
.ics从文件系统手动创建文件
用餐愉快! 🍽️
