食谱助手

一个基于Model Context Protocol的食谱助手,提供食谱搜索、食谱详情、单位转换、食谱缩放、烹饪时间计算、葡萄酒搭配建议等功能。

  • by deepu-roy
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 deepu-roy/mcp-complete-example

使用说明

配方助手——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"


详细文档