InventorySystem MCP服务器
基于Python MCP(模型上下文协议)服务器 它连接到库存管理系统,并提供各种工具来处理对它的CRUD操作。
这是一个简单的副项目,我为了好玩而尝试将人工智能与我们大学的一个小型项目兼容。
此MCP服务器的功能
- 充当InventorySystem服务器和MCP客户端之间的接口(例如:Claude)
- 提供15个MCP工具,用于对库存管理系统数据库进行CRUD操作。
- 创建和读取注册用户。 - 创建、更新和读取库存项目。 - 创建、读取、更新和删除账单。
- 在传递给主服务器之前,使用Pydantic验证LLM给出的数据输入。
- 记录服务器日志以便于调试。
工具
以下是此MCP服务器提供的工具。
| S.否 | 工具 | 描述 |
|---|---|---|
| 1 | fetch_users | 读取系统中注册的所有用户 |
| 2 | add_user | 向系统添加新用户 |
| 3 | fetch_inventory_items | 读取库存中存储的所有物品 |
| 4 | add_inventory_item | 将新项目添加到库存 |
| 5 | update_inventory_item | 更新库存中项目的详细信息 |
| 6 | update_inventory_item_stock | 仅更新库存中项目的库存 |
| 7 | fetch_bill_records | 读取系统中创建的所有账单 |
| 8 | fetch_bill_records_by_cashier | 读取按创建账单的收银员筛选的账单 |
| 9 | open_bill | 读取账单中的项目条目 |
| 10 | create_bill | 根据产品Id和库存创建新账单 |
| 11 | issue_bill | 发出账单(账单已支付) |
| 12 | discard_bill | 放弃汇票草稿(未付款汇票) |
| 13 | add_item_to_bill | 在账单中添加新项目 |
| 14 | edit_bill_item_quantity | 更改账单中项目条目的数量 |
| 15 | delete_bill_item | 从账单中删除项目条目 |
如何设置此MCP服务器
先决条件
- Python 3.8或更高版本
- uv(MCP服务器的Python包管理器)
- XAMPP Apache服务器 库存系统 服务器设置正确。
- 支持MCP服务器的MCP客户端,例如:Claude Desktop、Cursor、WindSurf等。
- \[可选\]Node.js(用于检查MCP服务器)
设置InventorySystem主服务器
- 从以下位置安装XAMPP XAMPP官方网站
- 确保Apache和MySQL(MariaDB)服务正在运行
- 导航到htdocs文件夹(安装XAMPP的位置,例如:
C://xampp/htdocs) - 创建一个新目录invmgmt(或您选择的名称)
mkdir invmgmt
cd invmgmt- 克隆
mcp此文件夹上InventorySystem存储库的分支
git clone -b mcp --single-branch https://github.com/AllanSJoseph/InventorySystem.git设置MCP服务器
设置uv
对于Windows用户:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"对于Linux/Mac用户(注意:此服务器在Windows上运行和测试):
curl -LsSf https://astral.sh/uv/install.sh | sh安装项目依赖项
- 克隆此存储库
- 在终端中打开目录
- 使用uv安装所需的依赖项
uv sync- 打开MCP客户端(此处我使用的是Claude Desktop)。
- 转到克劳德设置
Ctrl + ,.
- 转到“开发人员”选项卡。
- 点击
Edit Config在本地MCP服务器下。
- 它突出了
claude_desktop_config.json文件,在您最喜欢的文本编辑器中打开它。
- 将以下代码添加到
mcp_servers保存并关闭JSON文件中的列表。
"mcpServers": {
"inventory_mgmt_mcp": {
"command": "uv",
"args": [
"--directory",
"your_project_directory_path",
"run",
"main.py"
]
}
}- 重新启动克劳德桌面
- 打开一个新的聊天室,点击聊天框上的工具按钮,你会看到 文档 工具可用。
- 尝试以下提示:
Could you list the users that are registered to Inventory Management System.- LLM将使用
fetch_users搜索答案并在聊天中返回的工具。如果它请求许可,请单击 *始终允许*.
请注意,Claude的免费版本对令牌或字符的数量有限制,因此它可能无法提供所需的结果,有时可能会给您超过令牌限制的错误。您可以尝试使用付费版本的Claude或使用其他MCP客户端,如Cursor、WindSurf等。
有关如何在客户端中设置MCP服务器的更多详细信息,请参阅Antropic的官方MCP文档 服务器开发人员-模型上下文协议
示例提示与Claude一起尝试
添加演示用户
Could you add a demo user with a name of your choice and details of your choice, user must be a Cashier.添加产品
Could you add the below product to the Inventory Server.
AMUL MILK with stock 200 and price 20. Add a description of your choice.创建法案并发布
Could you create a bill with the items 2 units of product id 1, 5 units of product id 21 and 3 units of product id 5, Issue the bill with payment method 'UPI'注: 这些产品应该已经在库存管理主服务器中。安装后,数据库将没有任何项目。
检查日志
在项目根目录中找到 serverlogs.log,其中将包含日志。它在git中被忽略,但会在服务器启动时创建。
检查此MCP服务器
要检查工具并检查工具是否正常工作,请在项目目录的终端中运行以下命令。
npx @modelcontextprotocol/inspector uv run main.py
