MesaYA MCP
MesaYA餐厅预订平台的MCP(模型上下文协议)服务器。
快速开始
# Run MCP server (stdio transport - for local tools)
uv run app
# Run MCP Gateway (HTTP/SSE transport - for web clients)
uv run gateway
# Or with explicit flags
uv run app --sse # SSE mode
uv run app --stdio # stdio mode (default)
# Inspect with MCP inspector
npx @modelcontextprotocol/inspector uv --directory . run app --port 3333运输方式
stdio(默认)
用于本地工具集成的标准输入/输出传输。
uv run appSSE(MCP网关)
用于web应用程序和远程访问的HTTP/SSE传输。
uv run gateway
# Or with environment variables
MCP_GATEWAY_HOST=0.0.0.0 MCP_GATEWAY_PORT=8000 uv run gateway网关端点:
GET /sse-MCP通信的SSE端点POST /messages-MCP命令的消息端点GET /health-健康检查
项目结构
mesaYA_mcp/
├── src/
│ └── mesaYA_mcp/
│ ├── __init__.py # Package initialization
│ ├── __main__.py # MCP server entry point
│ ├── server.py # FastMCP instance
│ ├── gateway.py # MCP Gateway entry point
│ ├── tools/ # Tool modules (LangChain pattern)
│ │ ├── __init__.py # Tool registration
│ │ ├── _formatters.py # Shared formatting helpers
│ │ ├── restaurants.py # 7 restaurant tools
│ │ ├── reservations.py # 10 reservation tools
│ │ ├── menus.py # 5 menu tools
│ │ └── users.py # 3 user tools
│ └── shared/ # Shared modules
│ ├── application/ # Application layer (ports)
│ ├── core/ # Core configuration
│ └── infrastructure/ # Infrastructure layer (adapters)
├── .env.template
├── pyproject.toml
└── README.md建筑
该项目遵循 六边形体系结构 (端口和适配器):
- 港口:抽象接口
shared/application/ports/ - 适配器:具体实施
shared/infrastructure/adapters/ - 工具:遵循LangChain推荐模式的扁平结构
LangChain MCP模式
工具按照LangChain的建议组织成扁平模块:
# server.py - Single MCP instance
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("mesaYA_mcp")
# tools/restaurants.py - Import and decorate
from mesaYA_mcp.server import mcp
@mcp.tool()
async def search_restaurants(...):
...
# __main__.py - Import tools, run server
import mesaYA_mcp.tools # Registers all tools
mcp.run()安装
# Using uv (recommended)
uv sync
# Or using pip
pip install -e .配置
复制环境模板并配置:
cp .env.template .env编辑 .env 使用您的设置:
APP_NAME=mesaYA_mcp
ENVIRONMENT=development
LOG_LEVEL=INFO
BACKEND_API_URL=http://localhost:3000运行服务器
# Using the script entry point
uv run app
# Or directly with Python
python -m mesaYA_mcp可用工具
餐厅工具
mcp_search_restaurants-按餐厅名称、菜肴或位置搜索餐厅mcp_get_restaurant_info-获取详细的餐厅信息
预订工具
mcp_create_reservation-创建新预订mcp_check_availability-检查桌子的可用性mcp_get_reservation_status-获取预订状态
日志记录
所有工具都通过 LoggerAdapter:
from mesaYA_mcp.shared.core.container import Container
logger = Container.resolve("logger")
logger.info("Message", context="tool_name", key="value")发展
添加新功能
- 在中创建新文件夹
features/:
features/your_feature/
├── __init__.py
└── tools.py- 实施工具
tools.py使用记录器:
from mesaYA_mcp.shared.core.container import Container
async def your_tool(param: str) -> str:
logger = Container.resolve("logger")
logger.info("Executing tool", context="your_tool", param=param)
# ... implementation- 在中注册工具
__main__.py
添加新端口/适配器
- 在中创建端口
shared/application/ports/your_port.py - 在中创建适配器
shared/infrastructure/adapters/your_adapter.py - 通过以下方式在容器中注册
_configure_dependencies()
