Skip to main content
Glama
zalo-mcp
by nhminhhh
README.md
# zalo-mcp

[![CI](https://github.com/nhminhhh/zalo-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/nhminhhh/zalo-mcp/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
[![Node.js >= 20](https://img.shields.io/badge/node-%3E%3D20.0.0-brightgreen.svg)](https://nodejs.org/)
[![MCP](https://img.shields.io/badge/Protocol-MCP-purple.svg)](https://modelcontextprotocol.io/)

A production-ready **Model Context Protocol (MCP)** server for **Zalo Official Account (OA)** and **Zalo Notification Service (ZNS)**. Built in TypeScript with strict Zod validation, automatic OAuth v4 token refresh, retry resilience, MCP resources, and prompt templates.

---

## Features

- **28 MCP Tools** covering the full Zalo OA v2/v3 & ZNS lifecycle:
  - **OA & Auth**: Get OA profile, refresh OAuth v4 access tokens (plus automatic single-flight refresh on `-216` expiry)
  - **Messaging (v3.0)**: Send text, image, file, interactive list/button templates, transaction notifications, and promotion messages
  - **Followers & CRM Tags**: List followers, inspect follower profiles, update follower CRM info, create/list/assign/remove tags
  - **Conversations**: List recent chats and read message history with any user
  - **Media Upload**: Upload local images, documents/files, and GIFs via `multipart/form-data`
  - **Articles**: List, inspect, create, and delete OA articles
  - **ZNS (Business API)**: Send template notifications, list templates, inspect template schemas, and check delivery status
- **3 Live MCP Resources**: `zalo://oa/profile`, `zalo://oa/tags`, `zalo://zns/templates`
- **2 Built-in Prompts**: `zalo_draft_customer_reply`, `zalo_zns_campaign_check`
- **Resilient HTTP Client**: Automatic OAuth v4 token refresh with single-flight locking, 5xx retry with backoff, and configurable request timeouts

---

## Quick Start

### 1. Prerequisites

- **Node.js >= 20**
- A **Zalo Official Account (OA)** access token (and optionally OAuth v4 refresh credentials from the [Zalo Developers Console](https://developers.zalo.me/))

### 2. Install & Build

```bash
git clone https://github.com/nhminhhh/zalo-mcp.git
cd zalo-mcp
npm install
npm run build
```

### 3. Configure Your MCP Client

#### Claude Desktop / Cursor / Antigravity (`mcp_config.json`)

```json
{
  "mcpServers": {
    "zalo": {
      "command": "node",
      "args": ["/absolute/path/to/zalo-mcp/dist/index.js"],
      "env": {
        "ZALO_OA_ACCESS_TOKEN": "your_oa_access_token",
        "ZALO_OA_REFRESH_TOKEN": "your_oa_refresh_token",
        "ZALO_APP_ID": "your_zalo_app_id",
        "ZALO_APP_SECRET": "your_zalo_app_secret"
      }
    }
  }
}
```

> **Tip:** If you provide `ZALO_OA_REFRESH_TOKEN`, `ZALO_APP_ID`, and `ZALO_APP_SECRET`, `zalo-mcp` will automatically refresh expired access tokens (`error: -216`) without manual intervention.

---

## Environment Variables

| Variable | Required | Default | Description |
| --- | --- | --- | --- |
| `ZALO_OA_ACCESS_TOKEN` | Yes* | — | Zalo OA v2/v3 & ZNS access token |
| `ZALO_OA_REFRESH_TOKEN` | Optional | — | OAuth v4 refresh token for auto-renewal |
| `ZALO_APP_ID` | Optional | — | Zalo App ID (required for OAuth v4 refresh) |
| `ZALO_APP_SECRET` | Optional | — | Zalo App Secret (required for OAuth v4 refresh) |
| `ZALO_API_BASE_URL` | Optional | `https://openapi.zalo.me` | OA API base URL |
| `ZALO_BUSINESS_API_BASE_URL` | Optional | `https://business.openapi.zalo.me` | ZNS Business API base URL |
| `ZALO_OAUTH_BASE_URL` | Optional | `https://oauth.zaloapp.com` | OAuth v4 base URL |
| `ZALO_REQUEST_TIMEOUT_MS` | Optional | `15000` | HTTP request timeout in milliseconds |

*\*`ZALO_OA_ACCESS_TOKEN` can be omitted if all three OAuth v4 refresh variables are provided.*

---

## Complete Tool Reference

### OA & Authentication
| Tool | Description |
| --- | --- |
| `zalo_get_oa_info` | Get Official Account profile metadata |
| `zalo_refresh_token` | Manually refresh OAuth v4 access token |

### Messaging (OA v3.0)
| Tool | Description |
| --- | --- |
| `zalo_send_text_message` | Send a CS text message (supports `quote_message_id`) |
| `zalo_send_image_message` | Send an image via `attachment_id` or public `image_url` |
| `zalo_send_file_message` | Send a file attachment using `file_token` |
| `zalo_send_template_message` | Send interactive `list` or `button` template messages |
| `zalo_send_transaction_message` | Send transaction notification (order, billing, booking, etc.) |
| `zalo_send_promotion_message` | Send promotional message to followers |

### Followers & Tags
| Tool | Description |
| --- | --- |
| `zalo_get_followers` | List followers with pagination and optional `tag_name` filter |
| `zalo_get_follower_profile` | Get detailed follower profile by `user_id` |
| `zalo_update_follower_info` | Update follower CRM info (name, phone, address, city/district) |
| `zalo_list_tags` | List all tags configured on the OA |
| `zalo_tag_follower` | Assign a tag to a follower |
| `zalo_untag_follower` | Remove a tag from a follower |
| `zalo_remove_tag` | Delete a tag from the OA |

### Conversations
| Tool | Description |
| --- | --- |
| `zalo_list_recent_chats` | List recent OA conversations |
| `zalo_get_conversation` | Get message history with a specific `user_id` |

### Media Upload
| Tool | Description |
| --- | --- |
| `zalo_upload_image` | Upload a local image (JPG/PNG) to get `attachment_id` |
| `zalo_upload_file` | Upload a local file (PDF/DOC/DOCX) to get `token` |
| `zalo_upload_gif` | Upload a local GIF to get `attachment_id` |

### Articles
| Tool | Description |
| --- | --- |
| `zalo_get_articles` | List normal or video articles |
| `zalo_get_article_detail` | Get full article details by `id` |
| `zalo_create_article` | Create a new OA article |
| `zalo_remove_article` | Delete an article by `id` |

### Zalo Notification Service (ZNS)
| Tool | Description |
| --- | --- |
| `zalo_zns_send_message` | Send ZNS template message to `84xxxxxxxxx` (supports `development` mode) |
| `zalo_zns_list_templates` | List ZNS templates with status filtering |
| `zalo_zns_get_template_info` | Inspect ZNS template parameters and pricing |
| `zalo_zns_get_message_status` | Check ZNS message delivery status |

---

## Development & Testing

```bash
# Typecheck
npm run typecheck

# Run unit & MCP InMemoryTransport integration tests
npm test

# Build dist/
npm run build

# CLI help & version
node dist/index.js --help
node dist/index.js --version
```

---

## License

[MIT](LICENSE) © 2026 [nhminhhh](https://github.com/nhminhhh)

TDQS

B3.1/5.0

Scored across 28 tools

Disambiguation4/5

Most tools map to a distinct resource and action, such as articles, followers, tags, chats, uploads, and OA info. The main ambiguity is among the six send_* OA message tools and ZNS vs OA template messaging, where an agent must read descriptions to choose correctly.

Naming Consistency4/5

All names are snake_case with a zalo_ prefix and generally follow verb_noun order. Minor deviations include collection retrieval using both get_* (get_followers, get_articles) and list_* (list_tags, list_recent_chats), plus the zalo_zns_ sub-prefix.

Tool Count2/5

28 tools is above the comfortable range and creates noticeable selection overhead for an agent. The set is logically grouped by OA subdomain, so most tools earn their place, but the raw count is still heavy.

Completeness4/5

The surface covers article creation/listing/detail/deletion, ZNS messaging, CS messaging, follower management, tags, chats, uploads, and token refresh. Minor gaps remain: no article update/edit operation and no tag creation endpoint, though agents can work around these.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues