周计划MCP服务器
它做什么
连接后,Claude可以:
- 列出、添加和删除 成分 (名称+单位)
- 列出、添加和删除 食谱 (名称、配料数量和分步说明)
- 添加配方时自动创建缺少的成分
______________________________________________________________________
先决条件
- Node.js 18+ — 点击此处下载
- 跑步 周计划API 服务器(默认为
http://localhost:3000)
______________________________________________________________________
安装
选项1——克隆和构建(建议用于本地开发)
git clone weekplan-mcp-server
cd weekplan-mcp-server
npm install
npm run build编译后的服务器将位于 dist/index.js.
选项2——从npm全局安装(一旦发布)
npm install -g weekplan-mcp-server这使得 weekplan-mcp-server 命令在系统范围内可用。
______________________________________________________________________
配置
服务器通过单个环境变量配置:
| 变量 | 默认值 | 描述 |
|---|---|---|
WEEKPLAN_URL | http://localhost:3000 | WeekPlan REST API的基本URL |
______________________________________________________________________
添加到克劳德代码
运行以下命令,使用Claude Code注册服务器:
claude mcp add weekplan-mcp-server -e WEEKPLAN_URL=http://localhost:3000 -- node /absolute/path/to/weekplan-mcp-server/dist/index.js替换 /absolute/path/to/weekplan-mcp-server 使用克隆仓库的实际路径。
或编辑 ~/.claude.json 将其添加到特定项目中。
或编辑 claude_desktop_config.json 直接(请参阅下面的Claude Desktop部分——格式相同)。
______________________________________________________________________
添加到Claude桌面
编辑您的Claude Desktop配置文件:
- macOS:
~/Library/'Application Support'/Claude/claude_desktop_config.json - 窗户:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
在下面添加服务器 mcpServers:
{
"mcpServers": {
"weekplan": {
"command": "node",
"args": ["/absolute/path/to/weekplan-mcp-server/dist/index.js"],
"env": {
"WEEKPLAN_URL": "http://localhost:3000"
}
}
}
}保存文件后重新启动Claude Desktop。
______________________________________________________________________
添加到光标
打开光标设置并导航到 特性→ MCP服务器,然后添加:
{
"weekplan": {
"command": "node",
"args": ["/absolute/path/to/weekplan-mcp-server/dist/index.js"],
"env": {
"WEEKPLAN_URL": "http://localhost:3000"
}
}
}______________________________________________________________________
添加到VS代码(复制品/MCP扩展)
在你的 .vscode/mcp.json 或用户设置:
{
"servers": {
"weekplan": {
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/weekplan-mcp-server/dist/index.js"],
"env": {
"WEEKPLAN_URL": "http://localhost:3000"
}
}
}
}______________________________________________________________________
可用工具
配料
| 工具 | 说明 | 参数 |
|---|---|---|
weekplan_list_ingredients | 列出所有成分 | _(无)_ |
weekplan_add_ingredient | 添加或更新配料 | name (字符串), unit (字符串) |
weekplan_delete_ingredient | 删除配料 | id (字符串) |
食谱
| 工具 | 说明 | 参数 |
|---|---|---|
weekplan_list_recipes | 列出所有食谱 | _(无)_ |
weekplan_add_recipe | 添加或更新食谱 | name (字符串), ingredients (阵列), steps (字符串数组) |
weekplan_delete_recipe | 删除配方 | id (字符串) |
这 ingredients 数组in weekplan_add_recipe 接受以下对象:
ingredientName--配料名称(如果缺少,则自动创建)quantity--数字金额unit--计量单位(例如。"g","ml","tbsp")
ID由名称自动生成(例如。 "Olive Oil" → "olive-oil"),因此add操作是幂等的——运行两次不会创建重复项。
______________________________________________________________________
示例提示
服务器连接后,试着问克劳德:
Add a recipe for spaghetti bolognese with ingredients and steps.List all my ingredients.Add 500g of chicken breast as an ingredient.Delete the recipe for lasagne.______________________________________________________________________
发展
# Run directly from TypeScript (no build step needed)
npm run dev
# Build to dist/
npm run build
# Run the compiled server
npm start服务器通过以下方式进行通信 标准,因此它没有开放端口,可以安全地作为人工智能客户端管理的子流程运行。
______________________________________________________________________
项目结构
src/
├── index.ts # Entry point — connects stdio transport
├── server.ts # Registers all tools with the MCP server
├── api-client.ts # HTTP client for the WeekPlan REST API
├── slugify.ts # Converts names to stable IDs
└── tools/
├── ingredients.ts # Ingredient tool handlers
└── recipes.ts # Recipe tool handlers______________________________________________________________________
故障排除
“无法连接到WeekPlan API” 确保您的WeekPlan服务器正在运行 WEEKPLAN_URL 指向正确的地址。
“找不到命令:node” Node.js未安装或不在您的PATH中。从安装 .
工具未出现在Claude中
- 确认配置中指向的路径
dist/index.js(不是src/index.ts) - 确保你跑了
npm run build克隆后 - 更改配置后重新启动AI客户端
构建错误 跑 npm install 首先确保所有依赖项都存在,然后 npm run build.
