StockPilot
Provides inventory management capabilities for products, stock levels, transactions, and inbound/outbound operations, using PostgreSQL as the underlying data store.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@StockPilotCheck stock levels for SKU-1001 and alert if low"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
📦 StockPilot — AI-Powered Inventory Assistant with Model Context Protocol (MCP)
🌐 Live Demo & Trải nghiệm Trực tuyến
🚀 Giao diện Web Chat (Streamlit): https://tutran27-stockpilot-mcp.streamlit.app/
⚡ Backend API & Swagger Docs (Railway): https://stockpilot-mcp-production.up.railway.app/docs
🐘 Database: Managed PostgreSQL 17 trên Supabase Cloud (Transaction Pooler - PgBouncer).
Related MCP server: MCP Inventory Manager
🎯 Điểm nổi bật & Tính năng cốt lõi
🔌 Chuẩn MCP Toàn diện: Hỗ trợ đầy đủ Tools (tra cứu/nhập/xuất kho), Resources (báo cáo realtime), và Prompts (
/audit,/restock).🛡️ Human-in-the-loop (HITL): Tự động chặn và yêu cầu người dùng bấm nút duyệt (
CONFIRMED) trước khi thực hiện thao tác nhạy cảm.🧠 Bộ nhớ Ngữ cảnh Thông minh: Tự động nhớ thực thể (Working State: mã SKU, NCC, số HĐ) và quản lý đa phiên chat (Multi-Session).
🔒 Giao dịch An toàn (ACID & Idempotency): Khóa giao dịch và chống xuất/nhập kho trùng lặp dữ liệu.
🛠️ Công nghệ cốt lõi (Tech Stack)
Thành phần | Công nghệ nổi bật | Điểm nhấn kỹ thuật |
Giao thức MCP | Model Context Protocol ( | Chuẩn hóa kết nối giữa AI Agent và FastMCP Server (Tools, Resources, Prompts). |
AI Orchestration | ReAct Agent + Groq / OpenAI | Phân tích ngôn ngữ tự nhiên, tự động gọi Tool và duy trì bộ nhớ ngữ cảnh (Working State). |
Backend & API | FastAPI (Async Python 3.12) | Xử lý bất đồng bộ hiệu năng cao, tích hợp cổng kiểm soát an toàn (Human-in-the-loop). |
Database | PostgreSQL 17 (Supabase) | Quản lý kho chuẩn ACID, chống trùng lặp dữ liệu ( |
Frontend & Cloud | Streamlit + Railway | Giao diện Web tương tác thời gian thực, triển khai container hóa tự động từ GitHub. |
🏗️ Kiến trúc luồng xử lý hệ thống
flowchart TD
subgraph ClientLayer ["1. Lớp Giao diện & Người dùng"]
User([👤 Người dùng]) <-->|Web UI| Streamlit["💻 Streamlit Web App (tutran27-stockpilot-mcp)"]
end
subgraph HostLayer ["2. Lớp Điều phối (Chat Host / FastAPI)"]
Streamlit <-->|REST API / JSON| Host["🌐 FastAPI Host (Railway)"]
Host <--> Agent["🤖 ReAct Agent Loop"]
Agent <--> LLM["🧠 LLM (Groq / OpenAI)"]
Agent <--> Memory["🧠 Working State & Session Memory"]
Agent <--> HITL["🛡️ Human-in-the-loop Gate"]
Agent <--> MCPClient["🔌 MCP Client"]
end
subgraph ServerLayer ["3. Lớp Giao thức MCP (FastMCP Server)"]
MCPClient <==>|MCP Protocol| MCPServer["⚙️ FastMCP Server"]
MCPServer --> ReadTools["📖 Read Tools (find, get_stock, alert)"]
MCPServer --> WriteTools["✍️ Write Tools (receive, issue, add)"]
MCPServer --> Resources["📊 Resources (summary, policy)"]
MCPServer --> Prompts["📝 Prompts (audit, restock)"]
end
subgraph DBLayer ["4. Lớp Dữ liệu (Supabase Cloud Database)"]
ReadTools & WriteTools & Memory --> DBModule["💾 asyncpg Pool (statement_cache_size=0)"]
DBModule <==>|PgBouncer Pooler| Postgres[(🐘 Supabase PostgreSQL 17)]
end📁 Cấu trúc thư mục dự án
stockpilot/
├── 📄 compose.yaml # Cấu hình Docker Compose chuẩn Production
├── 📄 Dockerfile # Đóng gói Chat Host & MCP Server
├── 📄 requirements.txt # Danh mục thư viện phụ thuộc
├── 📄 .env.example # File mẫu biến môi trường
├── 📁 db/
│ └── 📄 init.sql # Khởi tạo Schema DB, Indexes và ràng buộc FK
├── 📁 scripts/
│ └── 📄 seed_products.py # Nạp dữ liệu sản phẩm mẫu
├── 📁 src/
│ ├── 📁 chat_host/ # Chat Host Orchestrator
│ │ ├── 📄 main.py # FastAPI Endpoints (/api/chat, /confirm, /cancel)
│ │ ├── 📄 agent.py # Vòng lặp Agent ReAct & MCP Tool Routing
│ │ ├── 📄 memory.py # Bộ nhớ Working State & Ánh xạ thực thể
│ │ ├── 📄 confirmation.py # Xử lý Human-in-the-loop (Pending Actions)
│ │ ├── 📄 llm.py # Kết nối AsyncOpenAI / Groq LLM
│ │ └── 📄 prompts.py # System Prompts & Working State Injection
│ ├── 📁 mcp_server/ # MCP Server Layer
│ │ ├── 📄 server.py # Định nghĩa FastMCP Server & Đăng ký Tool/Resource/Prompt
│ │ ├── 📄 db.py # Thao tác PostgreSQL (asyncpg connection pool)
│ │ ├── 📄 tools_read.py # MCP Read Tools
│ │ ├── 📄 tools_write.py # MCP Write Tools
│ │ ├── 📄 resources.py # MCP Resources
│ │ └── 📄 prompts.py # MCP Prompts Templates
│ └── 📁 ui/
│ └── 📄 app.py # Giao diện Web Chat Streamlit🚦 Hướng dẫn Khởi chạy Môi trường Local (Self-Hosted)
1. Kéo mã nguồn & Cài đặt môi trường
git clone https://github.com/tutran27/stockpilot-mcp.git
cd stockpilot-mcp
cp .env.example .env(Mở file .env và điền GROQ_API_KEY hoặc OPENAI_API_KEY, cùng chuỗi kết nối Database).
2. Khởi chạy trọn gói bằng Docker Compose
docker compose up -d --build3. Truy cập các cổng dịch vụ Local:
🌐 Giao diện Web Chat (Streamlit): http://localhost:8501
⚡ API Swagger Docs (FastAPI): http://localhost:8000/docs
🐘 pgAdmin Quản trị DB: http://localhost:5050 (Email:
admin@admin.com| Pass:admin)
🧪 Kịch bản Trải nghiệm Mẫu (Demo Flows)
Kịch bản 1: Ghi nhớ Ngữ cảnh Thông minh (Working State)
Người dùng: "Kiểm tra mặt hàng Dell XPS 13"
🤖 AI: Tra cứu và báo tồn kho hiện có 15 chiếc (ID:
bf9ddbda-...).
Người dùng: "Nhập thêm 10 cái từ NCC FPT, số HĐ: FPT-8899"
🤖 AI: Tự động nhận diện sản phẩm đang nói đến là Dell XPS 13, nạp mã hóa đơn
FPT-8899, nhà cung cấpFPTvà tạo yêu cầu xác nhậnreceive_stock.
Kịch bản 2: Duyệt hành động nhạy cảm (Human-in-the-loop)
Khi AI yêu cầu xác nhận, giao diện Web sẽ hiển thị thẻ chi tiết kèm 2 nút bấm:
🟢 Xác nhận thực hiện: Gọi
POST /api/chat/confirm, cập nhật tồn kho tức thì và khóa nút.🔴 Hủy bỏ: Hủy bỏ thao tác an toàn.
📄 License
Dự án được phân phối dưới giấy phép MIT License.
This server cannot be deployed
Maintenance
Related MCP Connectors
Hosted MCP for e-commerce: live product catalog, stock, and pricing for AI agents.
Let AI agents query data and act across all your business apps via MCP.
Pay-per-use tool marketplace for AI agents. Search, price-check, and call APIs via MCP.
Search & install 6,500+ AI agent skills from skills-hub.ai inside any MCP tool.
Related MCP Servers
FlicenseNot gradedqualityCmaintenanceEnables interaction with ScanPower's inventory and shipment management system through a secure MCP interface. Supports retrieving inventory data, creating shipment plans, and managing logistics operations through natural language.2-- FlicenseNot gradedqualityDmaintenanceAn AI-powered inventory management system with a natural language interface, enabling CRUD operations on items and suppliers, stock transfers, and supplier management via MCP tools.-
- AlicenseNot gradedqualityBmaintenanceUnifies inventory data from four sources (Jikeyun, Supor factory, WeChat Excel, RPA) with timestamps, and exposes MCP tools for AI agents to query stock levels.6 npmISC
- FlicenseNot gradedqualityCmaintenanceEnables AI agents to view SAP production orders, answer questions, and post goods receipts by integrating with SAP backend through MCP tools.-