使用说明
模型上下文协议(MCP)服务器:带奖金休假管理服务器的顺序思维。
该项目实施了两个 模型上下文协议(MCP) 服务器使用 FastMCP 框架:
- 顺序思维:结构化解决问题的工具,非常适合供应链管理规划等任务。
- 休假经理:人力资源部管理员工休假任务的人工智能工具,与模拟休假数据库交互。
服务器使用 main.py 脚本,可以通过以下方式查询 克劳德桌面与MCP服务器集成,用于使用模型上下文协议发送API请求。
项目结构
directory/
├── main.py # Launches both MCP servers
├── leave_manager.py # Leave Manager MCP server
├── sequential.py # Sequential Thinking MCP server
特性
顺序思维MCP服务器
- 目的:使用模型上下文协议促进结构化、分步解决问题,非常适合规划供应链管理等复杂任务。
- 工具:
sequential_thinking- 将问题分解为连续的思考。
- 支持修改想法、为替代策略分支以及动态调整步骤数。
- 通过某种方式维护上下文
sessionId.
- 用例:规划供应链、项目或任何需要迭代推理的任务。
- 端口:继续运行
http://localhost:8001.
离开管理器MCP服务器
- 目的:使用模型上下文协议协助人力资源部进行员工休假管理。
- 工具:
get_leave_balance:检查员工的剩余休假天数。apply_leave:在特定日期申请休假。get_leave_history:查看员工的休假历史记录。
- 资源:
greeting://{name}个性化问候。 - 端口:继续运行
http://localhost:8000.
主启动器
- main.py:用途
multiprocessing在各自的端口上同时运行两个服务器。
先决条件
- python:3.8或更高版本。
- 克劳德桌面:用于向服务器发送MCP查询。
- 紫外线:用于安装依赖项的包管理器。
- 操作系统:在Linux(例如Ubuntu)上测试。
设置步骤
按照以下步骤设置项目:
-
安装克劳德桌面:
- 从官方来源下载并安装Claude Desktop。
- 确保其配置为发送API查询(例如,通过查询输入字段)。
-
安装uv:
pip install uv -
创建项目目录:
uv init my-first-mcp-server cd my-first-mcp-server -
添加MCP CLI:
uv add "mcp[cli]" -
添加服务器代码:
- 将以下文件放入
my-first-mcp-server/:main.py:两台服务器的启动器。leave_manager.py:保留Manager服务器代码。sequential.py:顺序思维服务器代码。
- 确保代码与提供的实现相匹配(请参阅项目存储库或文档)。
- 将以下文件放入
-
运行服务器:
- 而非
uv run mcp install main.py(可能由于多个服务器而失败),运行:uv run python main.py
- 而非
-
重新启动克劳德桌面 (如果需要):
- 通过任务管理器(Windows)或
killall(Linux)。 - 重新启动Claude Desktop以确保它识别正在运行的服务器。
- 通过任务管理器(Windows)或
用法
运行服务器
使用以下命令启动两台服务器:
cd ~/my-first-mcp-server
uv run python main.py
这将启动:
- 让经理打开
http://localhost:8000. - 顺序思维
http://localhost:8001.
备注:保持终端打开,以保持服务器正常运行。
通过Claude Desktop进行交互
使用Claude Desktop的查询输入字段通过模型上下文协议向服务器发送JSON查询。以下是两台服务器的示例,重点是 供应链管理 使用顺序思维服务器。
顺序思维MCP服务器
- 端点:
http://localhost:8001/tool/sequential_thinking - 目的:通过将供应链分解为步骤、修改计划或使用MCP探索替代方案来规划供应链。
- 输入:将JSON查询粘贴到Claude Desktop的查询字段中并提交。
示例:为智能手表规划供应链
-
界定目标:
{ "thought": "Define objective: Plan a cost-efficient supply chain for a new smartwatch, ensuring global delivery within 5 months.", "nextThoughtNeeded": true, "thoughtNumber": 1, "totalThoughts": 8 }- 在Claude Desktop中提交(例如,粘贴到查询字段中并单击“发送”)。
- 复制
sessionId(例如。,123e4567-...)从回应中。
-
选择供应商:
{ "sessionId": "<sessionId>", "thought": "Select suppliers: Source microchips from Supplier X (Taiwan), displays from Supplier Y (South Korea), batteries from Supplier Z (China).", "nextThoughtNeeded": true, "thoughtNumber": 2, "totalThoughts": 8 }- 替换
<sessionId>使用步骤1中的ID。
- 替换
-
计划制造:
{ "sessionId": "<sessionId>", "thought": "Plan manufacturing: Assemble smartwatches in Factory A (Vietnam) for low labor costs and supplier proximity.", "nextThoughtNeeded": true, "thoughtNumber": 3, "totalThoughts": 8 } -
修改供应商:
{ "sessionId": "<sessionId>", "thought": "Revised: Switch battery supplier to Supplier W (Japan) for better quality, despite 10% higher cost.", "nextThoughtNeeded": true, "thoughtNumber": 2, "totalThoughts": 8, "isRevision": true, "revisesThought": 2 } -
探索替代物流(分支机构):
{ "sessionId": "<sessionId>", "thought": "Alternative: Use air freight for distribution to Europe to ensure 7-day delivery.", "nextThoughtNeeded": true, "thoughtNumber": 4, "totalThoughts": 8, "branchFromThought": 3, "branchId": "air_freight" } -
计划库存:
{ "sessionId": "<sessionId>", "thought": "Plan inventory: Maintain 20,000 units in regional warehouses (USA, Europe, Asia) with just-in-time delivery.", "nextThoughtNeeded": true, "thoughtNumber": 5, "totalThoughts": 8 } -
缓解风险:
{ "sessionId": "<sessionId>", "thought": "Mitigate risks: Dual-source microchips and maintain 15% buffer inventory for supply disruptions.", "nextThoughtNeeded": true, "thoughtNumber": 6, "totalThoughts": 10, "needsMoreThoughts": true } -
设置时间线:
{ "sessionId": "<sessionId>", "thought": "Set timeline: Supplier contracts by Month 1, manufacturing by Month 3, distribution by Month 4.", "nextThoughtNeeded": false, "thoughtNumber": 7, "totalThoughts": 10 }
提示:
- 会话ID:保存
sessionId在第一个查询之后,用于后续查询。 - 克劳德桌面格式:如果需要,请在JSON前面加上:例子:
POST http://localhost:8001/tool/sequential_thinkingPOST http://localhost:8001/tool/sequential_thinking { "thought": "Define objective: Plan a cost-efficient supply chain for a new smartwatch, ensuring global delivery within 5 months.", "nextThoughtNeeded": true, "thoughtNumber": 1, "totalThoughts": 8 } - 定制:修改
thought其他供应链(如食品、药品)的内容。食品示例:{ "thought": "Define objective: Plan a cold-chain supply chain for fresh produce, ensuring delivery within 48 hours.", "nextThoughtNeeded": true, "thoughtNumber": 1, "totalThoughts": 8 }
离开管理器MCP服务器
- 端点:
http://localhost:8000 - 目的:通过模拟数据库管理员工休假(
employee_leaves.json)使用MCP。 - 查询示例:
- 检查假期余额:发送到
{ "employee_id": "E001" }http://localhost:8000/tool/get_leave_balance. - 请假申请:发送到
{ "employee_id": "E001", "leave_dates": ["2025-06-01", "2025-06-02"] }http://localhost:8000/tool/apply_leave. - 获取休假历史记录:发送到
{ "employee_id": "E001" }http://localhost:8000/tool/get_leave_history.
- 检查假期余额:
扩展项目
- 坚持顺序思维:添加JSON或数据库存储以保存供应链计划,类似于
employee_leaves.json. - 克劳德桌面自动化:创建要管理的脚本
sessionId并简化查询输入。 - 可视化:根据顺序思维数据生成供应链流程图或时间线。
- 指标:增强
sequential_thinking根据想法计算成本或交付周期。