配方助手——MCP演示
A完整 模型上下文协议 以食谱/烹饪为主题的演示。 服务器 公开8个工具、4个资源和3个提示。 两个客户 让您手动或通过LLM代理探索它们。
______________________________________________________________________
TL;DR——60秒后开始运行
# Terminal 1 — server (stdio, auto-used by clients)
cd server && uv sync && source .venv/bin/activate
python recipe_server.py
# Terminal 2 — manual REPL explorer
cd client && uv sync && source .venv/bin/activate
python recipe_repl.py
# Terminal 2 — OR: LLM agent (needs Ollama running)
ollama pull qwen3:8b
python llm_agent.py______________________________________________________________________
两种运输方式
| 模式 | 服务器命令 | 客户端标志 |
|---|---|---|
| 标准 (默认) | python recipe_server.py | _(none--客户端自动生成服务器)_ |
| 流式HTTP | python recipe_server.py --http | --http |
# HTTP mode example
python recipe_server.py --http # default: 127.0.0.1:8000
python recipe_server.py --http --port 9000 --host 0.0.0.0
python llm_agent.py --http # connects to http://127.0.0.1:8000/mcp
python llm_agent.py --http --url http://my-server:9000/mcp______________________________________________________________________
两个客户
recipe_repl.py --交互式菜单资源管理器
使用预先填写的示例手动浏览工具、资源和提示。
python recipe_repl.py # connect via stdio选择 选项4 进行全自动演示。
llm_agent.py --LLM驱动的自然语言代理
用简单的英语提问;代理会自动调用正确的工具。
python llm_agent.py # stdio, interactive chat
python llm_agent.py --demo # scripted multi-tool demo
python llm_agent.py --http # HTTP transport示例问题:
Find a chicken recipe and suggest a wine pairing
Convert 3 cups to ml and scale from 4 to 7 servings
How long to roast a 5-lb chicken at 350°F?通过编辑顶部来切换LLM后端 llm_agent.py (Ollama默认,OpenAI已发表评论)。
______________________________________________________________________
服务器暴露了什么
| 类型 | 项目 |
|---|---|
| 工具 | search_recipes, get_recipe_details, get_random_recipe, convert_measurement, scale_recipe, calculate_cooking_time, suggest_wine_pairing, calculate_calories_per_serving |
| 资源 | recipes://favorites, recipes://dietary-restrictions, recipes://recipe/{id}, recipes://conversion-table |
| 提示 | meal_plan_generator, recipe_formatter, substitution_suggester |
______________________________________________________________________
堆栈
- Python 3.10+·FastMCP·MCP Python SDK
- 朗链+
langchain-mcp-adapters·奥拉马qwen3:8b(或OpenAI) - 计量数据库API --免费,无需身份验证
______________________________________________________________________
添加到MCP主机(VS Code、Claude Desktop等)
VS Code
添加到您的 用户设置JSON (Cmd+Shift+P → _打开用户设置(JSON)_):
标准 --VS Code会自动生成服务器:
{
"mcp": {
"servers": {
"recipe-assistant": {
"type": "stdio",
"command": "python",
"args": ["/absolute/path/to/mcp-example/server/recipe_server.py"],
"env": {}
}
}
}
}流式HTTP --首先启动服务器,然后将VS Code指向它:
# start server (keep running)
cd server && python recipe_server.py --http{
"mcp": {
"servers": {
"recipe-assistant": {
"type": "http",
"url": "http://127.0.0.1:8000/mcp"
}
}
}
}克劳德桌面
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"recipe-assistant": {
"command": "python",
"args": ["/absolute/path/to/mcp-example/server/recipe_server.py"]
}
}
}重新启动Claude Desktop——配方工具将自动出现在工具面板中。
提示: 使用绝对路径python在venv内部进行独立设置:"/absolute/path/to/mcp-example/server/.venv/bin/python"
______________________________________________________________________
详细文档
server/README.md--服务器设置、标志、工具参考client/README.md--客户端使用情况、LLM代理、传输模式PROJECT_OVERVIEW.md--架构和学习目标
