KiotViet MCP Server

KiotViet MCP Server

Enables AI assistants to manage KiotViet retail and F\&B operations including products, orders, customers, invoices, and inventory through the Public API. Features 36 integrated tools with automatic token refresh, middleware chain support, and configurable presets for different access levels.

Category
Visit Server

README

KiotViet MCP Server

MCP (Model Context Protocol) Server cho KiotViet Public API — Kết nối AI assistant với hệ thống quản lý bán hàng KiotViet.

Tính năng

  • 36 tools bao phủ đầy đủ KiotViet Public API
  • Auto token refresh — Token 1 giờ được tự động làm mới trước khi hết hạn
  • Middleware chain — Error handler, validation, rate limit, pagination
  • 2 transport mode — stdio (Claude Desktop) và HTTP (multi-session, Streamable HTTP + SSE legacy)
  • 5 preset — Chọn nhóm tool phù hợp với nhu cầu
  • Docker ready — Build và deploy với Docker Compose

Yêu cầu

  • Node.js >= 18
  • Tài khoản KiotViet với quyền truy cập Public API
  • Client ID, Client Secret, Retailer name từ Thiết lập cửa hàng → Thiết lập kết nối API

Cài đặt

# Clone và cài dependencies
git clone <repo-url>
cd kiotviet-mcp
npm install
npm run build

Cấu hình

Tạo file .env từ template:

cp .env.example .env

Điền thông tin:

KIOTVIET_CLIENT_ID=your_client_id
KIOTVIET_CLIENT_SECRET=your_client_secret
KIOTVIET_RETAILER=your_retailer_name

Sử dụng

Claude Desktop (stdio)

Thêm vào claude_desktop_config.json:

{
  "mcpServers": {
    "kiotviet": {
      "command": "node",
      "args": ["/path/to/kiotviet-mcp/dist/cli.js", "mcp"],
      "env": {
        "KIOTVIET_CLIENT_ID": "your_client_id",
        "KIOTVIET_CLIENT_SECRET": "your_client_secret",
        "KIOTVIET_RETAILER": "your_retailer_name"
      }
    }
  }
}

Chạy thủ công

# stdio mode
node dist/cli.js mcp --client-id X --client-secret Y --retailer Z

# HTTP mode
node dist/cli.js mcp --client-id X --client-secret Y --retailer Z --mode http --port 3000

Docker

# Build image
docker build -t kiotviet-mcp .

# Chạy container
docker run -d -p 3000:3000 \
  -e KIOTVIET_CLIENT_ID=your_client_id \
  -e KIOTVIET_CLIENT_SECRET=your_client_secret \
  -e KIOTVIET_RETAILER=your_retailer_name \
  kiotviet-mcp

Endpoints:

  • Health check: http://localhost:3000/health
  • Streamable HTTP (khuyến nghị): http://localhost:3000/mcp
  • SSE legacy: http://localhost:3000/sse

Tools

Xem danh sách tools

# Tất cả tools
node dist/cli.js tools

# Theo project
node dist/cli.js tools --project products

# Xem presets
node dist/cli.js tools --presets

Danh sách tools theo nhóm

Nhóm Tools
categories kiotviet_categories_list
products list, get_by_id, get_by_code, create, update, delete
customers list, get_by_id, get_by_code, create, update
customers kiotviet_customer_groups_list
orders list, get, create, update, cancel
invoices list, get_by_id, get_by_code, create, update, cancel
purchase-orders list, get, create
branches kiotviet_branches_list
users kiotviet_users_list
suppliers kiotviet_suppliers_list
bank-accounts kiotviet_bank_accounts_list
cashbook kiotviet_cashbook_list
webhooks list, create, update, delete

Presets

Preset Mô tả Số tools
preset.default Tất cả tools 36
preset.readonly Chỉ GET — an toàn cho môi trường read-only 21
preset.products Hàng hóa + nhóm hàng 7
preset.sales Đơn hàng + hóa đơn + khách hàng 17
preset.inventory Hàng hóa + nhập kho + nhà cung cấp 11

Kích hoạt preset qua CLI:

node dist/cli.js mcp --tools "preset.readonly" ...

F&B Mode

Dùng cho nhà hàng, quán cà phê (API F&B):

KIOTVIET_BASE_URL=https://publicfnb.kiotapi.com

Xác thực

KiotViet dùng OAuth 2.0 Client Credentials. Token có hiệu lực 1 giờ và được tự động làm mới trước khi hết hạn (buffer 5 phút).

Token endpoint: https://id.kiotviet.vn/connect/token


Cấu trúc dự án

src/
├── auth/
│   └── token-manager.ts        # Client Credentials + auto-refresh
├── mcp-server/
│   ├── init.ts                 # Khởi tạo server, đăng ký tools
│   └── transport/
│       ├── stdio.ts            # stdio transport
│       └── sse.ts              # HTTP/SSE transport
├── mcp-tool/
│   ├── types.ts                # McpTool, MiddlewareContext...
│   ├── handler.ts              # KiotViet API handler
│   ├── registry.ts             # Đăng ký tất cả tools + presets
│   ├── presets.ts              # Resolver preset/filter
│   ├── middleware/
│   │   ├── chain.ts
│   │   ├── error-handler.ts
│   │   ├── rate-limiter.ts
│   │   ├── pagination.ts
│   │   └── validation.ts
│   └── tools/                  # 13 modules tool definitions
└── utils/
    ├── config.ts
    ├── http-client.ts
    └── logger.ts
Dockerfile
docker/
└── docker-compose.yml

Scripts

npm run build        # Build TypeScript → dist/
npm run dev          # Chạy trực tiếp với ts-node
npm run format       # Format code với Prettier
npm test             # Chạy tests
npm run test:coverage

Giới hạn API

Thông số Giá trị
pageSize tối đa 100 bản ghi/request
Token TTL 3600 giây (1 giờ)
Webhook timeout 5 giây
Base URL Retail https://public.kiotapi.com
Base URL F&B https://publicfnb.kiotapi.com

License

MIT

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured