Skip to main content
Glama
kiotviet-mcp

kiotviet-mcp

by vansyson1308

kiotviet-mcp

A voice-first Model Context Protocol server for shops that run on KiotViet, the POS used by a very large number of Vietnamese grocery and convenience stores.

It lets any MCP client (Alexa+, Claude, IDE agents, your own Bedrock agent) answer a shop owner's questions in one spoken sentence:

  • "What's running low?"

  • "How many cartons of milk do we have?"

  • "How were sales yesterday?"

  • "What sold best this week?"

  • "What should I reorder?" → "Draft it." → "Yes, send it."

Every tool returns two things:

  • content[0].text: a sentence written to be spoken, at most 35 words, with rounded numbers and units, and never more than 3 list items read aloud.

  • structuredContent: data that matches the tool's declared outputSchema.

Tools carry MCP annotations (readOnlyHint, destructiveHint, idempotentHint).

It was extracted from ShopVoice, the Alexa+ MCP project in vansyson1308/groceryclaw, built for the Build, Ship, Shape Amazon Developer Hackathon. This package has no GroceryClaw dependencies: it talks to the KiotViet Public API directly.

Tools

Tool

Type

What it does

get_low_stock

read

Products at or below KiotViet minQuantity, most urgent first (days of cover = on hand / 14-day average daily sales)

get_stock_level

read

On hand plus days of cover for a product name, product code or barcode; asks which one when several match

get_sales_summary

read

Today, yesterday, the last 7 days or the last 28 days, against the previous equal period (same weekday last week for single days)

get_top_movers

read

Top or bottom sellers by units

suggest_reorder

read

(lead time + cover days) × forecast − on hand

create_purchase_order_draft

write, not destructive

Drafts a purchase order and returns a confirmation_token valid for 5 minutes. Nothing is sent yet.

confirm_purchase_order

write, destructive, idempotent

Sends the draft to KiotViet (POST /purchaseorders), only with the token

It also exposes a resource, shop://profile. Start with --read-only to hide the two purchase-order tools entirely.

Related MCP server: jumia-vendor-center

Quick start

npm install
npm run build

# Try it without KiotViet credentials (built-in demo shop), over stdio:
node dist/cli.js --demo

# Real shop:
export KIOTVIET_CLIENT_ID=... KIOTVIET_CLIENT_SECRET=... KIOTVIET_RETAILER=your-retailer
export KIOTVIET_BRANCH_ID=12345   # optional, used for purchase orders
node dist/cli.js                  # stdio
KIOTVIET_MCP_TOKEN=$(openssl rand -hex 24) node dist/cli.js --http 8787   # Streamable HTTP on 127.0.0.1:8787/mcp

Claude Desktop / any stdio client

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

Inspect it

npx @modelcontextprotocol/inspector@2.8.0 --cli node dist/cli.js -e KIOTVIET_MCP_DEMO=1 --method tools/list

How it uses the KiotViet Public API

  • Auth: POST https://id.kiotviet.vn/connect/token (client credentials, scope PublicApi.Access). The token is cached until shortly before it expires, and every call sends Authorization: Bearer … plus the Retailer header.

  • Products: GET /products?includeInventory=true (paged by 100). On hand is summed across branches (onHand − reserved), and the minimum stock comes from minQuantity.

  • Sales: GET /invoices?fromPurchaseDate=…&toPurchaseDate=… for the last 28 days, aggregated from invoiceDetails by product code. Cancelled invoices are skipped.

  • Purchase orders: POST /purchaseorders, and only from confirm_purchase_order.

Responses are read defensively, so missing fields fall back to safe defaults. A snapshot is cached for 60 seconds to stay within API rate limits.

Safety

  • Two-step writes. The draft token is random (96 bits), stored only as a SHA-256 hash, expires after 5 minutes, and confirming twice sends nothing new.

  • The HTTP mode binds to 127.0.0.1, requires a bearer token (compared in constant time), and rejects non-loopback browser Origins, which protects against DNS rebinding.

  • KiotViet credentials are read from the environment only and never logged.

Development

npm test   # builds, then runs node:test against a fake KiotViet API and the demo shop

Pinned: @modelcontextprotocol/sdk 1.30.1 (MCP protocol 2025-11-25), zod 4.6.5, Node ≥ 20.

License

MIT, see LICENSE.

Available Tools

7 tools
confirm_purchase_orderSend the purchase order (step 2 of 2)A
DestructiveIdempotent

Sends the drafted purchase order to KiotViet (POST /purchaseorders). Requires the confirmation_token from create_purchase_order_draft; expires after 5 minutes. Call only after the user explicitly confirms.

Inputs: confirmation_token (required). Returns: status, kiotviet_code

create_purchase_order_draftDraft a purchase order (step 1 of 2)A

Drafts a KiotViet purchase order from the current suggestions (or the given product codes) and returns a confirmation_token valid for 5 minutes. Nothing is sent to KiotViet until confirm_purchase_order is called after the user says yes.

Inputs: items. Returns: lines, est_total, confirmation_token, expires_in_seconds

get_low_stockWhat is running lowA
Read-onlyIdempotent

Products at or below their KiotViet minimum stock (minQuantity), most urgent first by days of cover.

Inputs: no named parameters. Returns: items, total_low

get_sales_summarySales summaryA
Read-onlyIdempotent

Revenue and units for today, yesterday, the last 7 days or the last 28 days, compared with the previous equal period (same weekday last week for single days).

Inputs: period. Returns: to, from, units, period, +3 more

get_stock_levelStock level for one productA
Read-onlyIdempotent

On-hand quantity and days of cover for a product by name, product code or barcode. Asks which one if several match.

Inputs: product (required). Returns: status, matches

get_top_moversBest and slowest sellersB
Read-onlyIdempotent

Top or bottom products by units sold over the last N days.

Inputs: days, limit, direction. Returns: items

suggest_reorderSuggest a reorderA
Read-onlyIdempotent

What to reorder now: items at/below minimum. Quantity = (lead time 2 + 7 days) x 14-day average daily sales - on hand. Read-only.

Inputs: no named parameters. Returns: lines, est_total

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 7 tools

    Disambiguation4/5

    Most tools are clearly distinct, but get_low_stock and suggest_reorder both surface items at or below minimum stock, which could cause some confusion. The descriptions clarify that one is a status report while the other provides specific reorder quantities, so the boundary is workable.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern: get_*, suggest_reorder, create_purchase_order_draft, confirm_purchase_order. The naming clearly communicates the action and object, with no mixed conventions or vague verbs.

    Tool Count5/5

    Seven tools is well-scoped for a KiotViet inventory and purchasing assistant. Each tool covers a meaningful step in the workflow from stock and sales visibility to reorder suggestions and purchase order confirmation.

    Completeness4/5

    The tool set covers the core inventory, sales, and purchase-order workflow end to end, including the important two-phase draft/confirm purchase order flow. Minor gaps exist, such as no ability to list or cancel existing purchase orders or adjust stock, but these do not break the primary use case.

    Maintenance

    ActivitySlowing
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      A
      quality
      C
      maintenance
      Enables MCP clients to manage Jumia Vendor Center catalogs and orders through natural language, including product creation/updates, inventory sync, order fulfillment, shipping labels, and payout monitoring.
      27
      -
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables hands-busy small online sellers to use voice-driven MCP tools for deterministic margin and listing checks and to draft ad headlines, 30-second shorts scripts, and detail page outlines.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables small shopkeepers to record credit and payment entries, check balances, list dues, and get ranked collection plans with drafted reminders through natural voice commands, including code-mixed Tamil/Hindi/English speech. It returns short spoken-style responses over a self-hosted Streamable HTTP MCP server backed by Amazon Bedrock, with a regex fallback when Bedrock is unavailable.
      MIT