> For the complete documentation index, see [llms.txt](https://docs.clickai.vn/clickai-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clickai.vn/clickai-docs/tinh-nang/bang-so-lieu/tich-hop-voi-ai.md).

# Tích hợp với AI

## Mục lục

·       \[Tổng quan tích hợp]\(#tổng-quan-tích-hợp)

·       \[Tables + Workflow]\(#tables--workflow)

·       \[Tables + AI Agent]\(#tables--ai-agent)

·       \[Tables + Webhooks]\(#tables--webhooks)

·       \[REST API]\(#rest-api)

·       \[MCP Server — Kết nối AI qua giao thức MCP]\(#mcp-server--kết-nối-ai-qua-giao-thức-mcp)

·       \[Use-cases tích hợp AI]\(#use-cases-tích-hợp-ai)

·       \[Best Practices]\(#best-practices)

&#x20;

## Tổng quan tích hợp

ClickAI Tables không chỉ là nơi lưu trữ dữ liệu — nó là trung tâm kết nối toàn bộ hệ sinh thái AI của ClickAI. Bạn có thể:

graph LR\
&#x20;   A\[📊 Tables] --> B\[🤖 AI Agent]\
&#x20;   A --> C\[⚙️ Workflow]\
&#x20;   A --> D\[🔔 Webhooks]\
&#x20;   A --> E\[📡 REST API]\
&#x20;   A --> F\[🔌 MCP Server]\
&#x20;   C --> A\
&#x20;   B --> A\
&#x20;   F --> B

·       Đọc dữ liệu từ Tables trong Workflow/Agent

·       Ghi dữ liệu vào Tables từ kết quả AI xử lý

·       Trigger tự động khi dữ liệu thay đổi qua Webhooks

·       Truy cập programmatic qua REST API

·       Kết nối LLM trực tiếp qua MCP Server (Model Context Protocol)

&#x20;

## Tables + Workflow

### Đọc dữ liệu từ Tables trong Workflow

Sử dụng node HTTP Request trong Workflow để truy vấn dữ liệu từ Tables API:

1\.     Thêm node HTTP Request vào Workflow

2\.     Cấu hình:

·       Method: GET

·       URL: <https://tables.clickai.vn/api/v2/tables/{table\\_id}/records>

·       Headers: xc-auth: {API\_TOKEN}

3\.     Xử lý response data trong các node tiếp theo

### Ghi dữ liệu vào Tables từ Workflow

4\.     Thêm node HTTP Request vào Workflow

5\.     Cấu hình:

·       Method: POST

·       URL: <https://tables.clickai.vn/api/v2/tables/{table\\_id}/records>

·       Headers: xc-auth: {API\_TOKEN}

·       Body: JSON chứa dữ liệu record mới

{\
&#x20; "Title": "{{workflow\.output.title}}",\
&#x20; "Status": "Processed",\
&#x20; "AI\_Summary": "{{workflow\.output.summary}}",\
&#x20; "Score": {{workflow\.output.score}}\
}

### Ví dụ Workflow: Xử lý Lead tự động

graph TD\
&#x20;   A\[🔔 Webhook: New Lead] --> B\[📊 Đọc Lead từ Tables]\
&#x20;   B --> C\[🧠 LLM: Phân tích Lead]\
&#x20;   C --> D{Score > 80?}\
&#x20;   D -->|Có| E\[📊 Update Status = Hot]\
&#x20;   D -->|Không| F\[📊 Update Status = Cold]\
&#x20;   E --> G\[📧 Gửi email thông báo Sales]\
&#x20;   F --> H\[📧 Gửi email nurturing]

&#x20;

## Tables + AI Agent

### Kết nối Tables như Tool cho Agent

AI Agent có thể sử dụng Tables API như một tool để tra cứu và cập nhật dữ liệu:

6\.     Trong Agent configuration, thêm Custom Tool

7\.     Cấu hình API endpoint của Tables

8\.     Agent sẽ tự động gọi API khi cần tra cứu thông tin

Ví dụ: Agent CSKH có thể:

·       Tra cứu thông tin khách hàng từ table "Customers"

·       Kiểm tra trạng thái đơn hàng từ table "Orders"

·       Tạo ticket mới trong table "Support Tickets"

·       Cập nhật trạng thái xử lý

### Kết nối Tables qua App Integration

Sử dụng module App Integration (Composio) để kết nối Tables:

9\.     Vào Workspace → App Integration

10\.  Tìm và kết nối NocoDB/ClickAI Tables

11\.  Cấu hình authentication

12\.  Sử dụng các actions có sẵn trong Agent/Workflow

&#x20;

## Tables + Webhooks

Webhooks cho phép gửi thông báo tự động khi dữ liệu trong Tables thay đổi:

### Cấu hình Webhook

13\.  Mở table → Table Details → Tab Webhooks

14\.  Nhấn Create Webhook

15\.  Cấu hình:

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Cấu hình</td><td valign="top">Mô tả</td></tr><tr><td valign="top">Event</td><td valign="top">After Insert / After Update / After Delete</td></tr><tr><td valign="top">URL</td><td valign="top">Endpoint nhận webhook (VD: ClickAI Workflow trigger)</td></tr><tr><td valign="top">Method</td><td valign="top">POST</td></tr><tr><td valign="top">Headers</td><td valign="top">Custom headers nếu cần</td></tr><tr><td valign="top">Condition</td><td valign="top">Chỉ trigger khi thỏa điều kiện cụ thể</td></tr></tbody></table>

&#x20;

### Webhook Payload

{\
&#x20; "type": "records.after.insert",\
&#x20; "data": {\
&#x20;   "table\_id": "tbl\_xxxxx",\
&#x20;   "rows": \[\
&#x20;     {\
&#x20;       "Id": 1,\
&#x20;       "Title": "New Customer Lead",\
&#x20;       "Email": "<customer@example.com>",\
&#x20;       "Status": "New"\
&#x20;     }\
&#x20;   ]\
&#x20; },\
&#x20; "timestamp": "2024-01-15T10:30:00Z"\
}

### Kết nối Webhook → ClickAI Workflow

16\.  Tạo Workflow mới trong ClickAI Studio

17\.  Sử dụng Start Node với trigger type Webhook

18\.  Copy Webhook URL từ Workflow

19\.  Dán URL vào cấu hình Webhook của table

20\.  Mỗi khi dữ liệu thay đổi → Webhook trigger → Workflow chạy tự động

&#x20;

## REST API

ClickAI Tables cung cấp REST API đầy đủ cho mọi thao tác dữ liệu:

### Authentication

\# Sử dụng API Token\
curl -H "xc-auth: YOUR\_API\_TOKEN" \\\
&#x20; <https://tables.clickai.vn/api/v2/tables/{table\\_id}/records>

### Các API Endpoints chính

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Method</td><td valign="top">Endpoint</td><td valign="top">Mô tả</td></tr><tr><td valign="top">GET</td><td valign="top">/api/v2/tables/{id}/records</td><td valign="top">Liệt kê records</td></tr><tr><td valign="top">GET</td><td valign="top">/api/v2/tables/{id}/records/{row_id}</td><td valign="top">Lấy record cụ thể</td></tr><tr><td valign="top">POST</td><td valign="top">/api/v2/tables/{id}/records</td><td valign="top">Tạo record(s) mới</td></tr><tr><td valign="top">PATCH</td><td valign="top">/api/v2/tables/{id}/records</td><td valign="top">Cập nhật record(s)</td></tr><tr><td valign="top">DELETE</td><td valign="top">/api/v2/tables/{id}/records</td><td valign="top">Xóa record(s)</td></tr></tbody></table>

&#x20;

### Query Parameters

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Parameter</td><td valign="top">Mô tả</td><td valign="top">Ví dụ</td></tr><tr><td valign="top">where</td><td valign="top">Filter records</td><td valign="top">(Status,eq,Active)</td></tr><tr><td valign="top">sort</td><td valign="top">Sort records</td><td valign="top">-CreatedAt (desc)</td></tr><tr><td valign="top">fields</td><td valign="top">Chọn fields trả về</td><td valign="top">Title,Email,Status</td></tr><tr><td valign="top">limit</td><td valign="top">Giới hạn số records</td><td valign="top">25</td></tr><tr><td valign="top">offset</td><td valign="top">Phân trang</td><td valign="top">50</td></tr></tbody></table>

&#x20;

### Ví dụ: Lấy danh sách khách hàng Active

curl -X GET \\\
&#x20; "<https://tables.clickai.vn/api/v2/tables/tbl\\_xxx/records?where=(Status,eq,Active)\\&sort=-CreatedAt\\&limit=10>" \\\
&#x20; -H "xc-auth: YOUR\_API\_TOKEN"

### Ví dụ: Tạo record mới

curl -X POST \\\
&#x20; "<https://tables.clickai.vn/api/v2/tables/tbl\\_xxx/records>" \\\
&#x20; -H "xc-auth: YOUR\_API\_TOKEN" \\\
&#x20; -H "Content-Type: application/json" \\\
&#x20; -d '{\
&#x20;   "Title": "Nguyễn Văn A",\
&#x20;   "Email": "<nguyenvana@example.com>",\
&#x20;   "Phone": "0901234567",\
&#x20;   "Status": "New"\
&#x20; }'

💡 TIP: Bạn có thể tìm API Token trong \*\*Table Details\*\* → tab \*\*API Snippet\*\* hoặc trong \*\*Workspace Settings\*\* → \*\*API Tokens\*\*.

&#x20;

## MCP Server — Kết nối AI qua giao thức MCP

MCP (Model Context Protocol) là giao thức chuẩn cho phép các ứng dụng AI (LLM) tương tác trực tiếp với dữ liệu trong Tables bằng ngôn ngữ tự nhiên — không cần viết code API.

Với MCP, bạn có thể yêu cầu AI trực tiếp:

·       \*"Hiển thị tất cả khách hàng ở Hà Nội"\*

·       \*"Thêm task mới: Review tài liệu, priority High"\*

·       \*"Cập nhật đơn hàng #123 sang trạng thái Đã giao"\*

·       \*"Xóa tất cả leads có status = Lost"\*

### MCP hoạt động như thế nào?

graph LR\
&#x20;   A\[👤 Người dùng] -->|Ngôn ngữ tự nhiên| B\[🤖 AI Client]\
&#x20;   B -->|MCP Protocol| C\[🔌 MCP Server]\
&#x20;   C -->|REST API| D\[📊 ClickAI Tables]\
&#x20;   D -->|Dữ liệu| C\
&#x20;   C -->|Kết quả| B\
&#x20;   B -->|Phản hồi| A

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Thành phần</td><td valign="top">Vai trò</td></tr><tr><td valign="top">AI Client</td><td valign="top">Ứng dụng AI (Claude Desktop, Cursor, Windsurf...)</td></tr><tr><td valign="top">MCP Server</td><td valign="top">Cầu nối giữa AI và Tables — dịch lệnh AI thành API calls</td></tr><tr><td valign="top">ClickAI Tables</td><td valign="top">Database nhận và xử lý yêu cầu dữ liệu</td></tr></tbody></table>

&#x20;

### Các khả năng của MCP Server

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Nhóm chức năng</td><td valign="top">Khả năng</td></tr><tr><td valign="top">Record CRUD</td><td valign="top">Tạo, đọc, cập nhật, xóa records bằng ngôn ngữ tự nhiên</td></tr><tr><td valign="top">Table Management</td><td valign="top">Liệt kê, tạo mới, xóa tables</td></tr><tr><td valign="top">Field Management</td><td valign="top">Thêm, xóa, quản lý fields/columns</td></tr><tr><td valign="top">View Management</td><td valign="top">Liệt kê, tạo, xóa views (Grid, Gallery, Kanban...)</td></tr><tr><td valign="top">Data Operations</td><td valign="top">Lọc, sắp xếp, tìm kiếm, tổng hợp dữ liệu</td></tr></tbody></table>

&#x20;

### Cấu hình MCP trên ClickAI Tables

#### Cách 1: Tạo MCP Endpoint từ giao diện (Recommended)

21\.  Mở base trong ClickAI Tables

22\.  Nhấn nút Overview trên sidebar trái

23\.  Chọn tab Settings

24\.  Chọn Model Context Protocol từ menu settings

25\.  Nhấn New MCP Endpoint

26\.  Đặt tên cho endpoint và nhấn Create

27\.  Copy MCP Config JSON được tạo tự động

#### Cách 2: Cấu hình thủ công (Self-hosted)

Nếu bạn sử dụng ClickAI Tables self-hosted, cấu hình thủ công với API Token:

Bước 1: Lấy thông tin cấu hình

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Thông tin</td><td valign="top">Cách lấy</td></tr><tr><td valign="top">NOCODB_BASE_URL</td><td valign="top">URL instance Tables (VD: https://tables.clickai.vn)</td></tr><tr><td valign="top">NOCODB_API_TOKEN</td><td valign="top">Account Settings → API Tokens → Create Token</td></tr><tr><td valign="top">NOCODB_BASE_ID</td><td valign="top">Trong URL khi mở base: .../#/nc/base/BASE_ID_HERE/...</td></tr></tbody></table>

&#x20;

Bước 2: Tạo MCP Config JSON

{\
&#x20; "mcpServers": {\
&#x20;   "clickai-tables": {\
&#x20;     "command": "npx",\
&#x20;     "args": \["-y", "nocodb-mcp-server"],\
&#x20;     "env": {\
&#x20;       "NOCODB\_BASE\_URL": "<https://tables.clickai.vn",\\>
&#x20;       "NOCODB\_API\_TOKEN": "your\_api\_token\_here",\
&#x20;       "NOCODB\_BASE\_ID": "your\_base\_id\_here"\
&#x20;     }\
&#x20;   }\
&#x20; }\
}

### Kết nối với Claude Desktop

28\.  Mở Claude Desktop → Preferences (⌘+, trên Mac / Ctrl+, trên Windows)

29\.  Vào Develop → Edit Config

30\.  Dán MCP Config JSON vào file claude\_desktop\_config.json

31\.  Lưu file và khởi động lại Claude Desktop

32\.  Kiểm tra: mở Claude, bạn sẽ thấy icon 🔌 MCP Tools trong input area

// \~/Library/Application Support/Claude/claude\_desktop\_config.json (macOS)\
// %APPDATA%\Claude\claude\_desktop\_config.json (Windows)\
{\
&#x20; "mcpServers": {\
&#x20;   "clickai-tables": {\
&#x20;     "command": "npx",\
&#x20;     "args": \["-y", "nocodb-mcp-server"],\
&#x20;     "env": {\
&#x20;       "NOCODB\_BASE\_URL": "<https://tables.clickai.vn",\\>
&#x20;       "NOCODB\_API\_TOKEN": "xc-auth-xxxxxxxxxxxxx",\
&#x20;       "NOCODB\_BASE\_ID": "p\_xxxxxxxxxxxxxxxx"\
&#x20;     }\
&#x20;   }\
&#x20; }\
}

### Kết nối với Cursor

33\.  Mở Cursor → Settings (⇧+⌘+J / Ctrl+Shift+J)

34\.  Chuyển đến tab MCP

35\.  Nhấn Add Custom MCP

36\.  Dán MCP Config JSON và lưu

37\.  Khi kết nối thành công, bạn sẽ thấy danh sách NocoDB tools

### Ví dụ sử dụng MCP với Claude

Sau khi kết nối, bạn có thể giao tiếp bằng ngôn ngữ tự nhiên:

👤 "Cho tôi xem 10 khách hàng mới nhất trong bảng Customers"\
🤖 Claude tự động gọi MCP → list\_records(table: Customers, sort: -CreatedAt, limit: 10)\
&#x20;  → Trả về bảng 10 khách hàng mới nhất\
\
👤 "Thêm khách hàng mới: Nguyễn Văn A, email: <a@example.com>, phone: 090xxx"\
🤖 Claude tự động gọi MCP → create\_record(table: Customers, data: {...})\
&#x20;  → ✅ Đã tạo record thành công\
\
👤 "Tạo bảng mới tên 'Feedback' với 3 cột: Customer Name, Rating, Comment"\
🤖 Claude tự động gọi MCP → create\_table(...) + create\_fields(...)\
&#x20;  → ✅ Đã tạo bảng Feedback với 3 fields

### Quản lý quyền MCP

<table data-header-hidden><thead><tr><th valign="top"></th><th valign="top"></th><th valign="top"></th></tr></thead><tbody><tr><td valign="top">Chế độ</td><td valign="top">Mô tả</td><td valign="top">Phù hợp cho</td></tr><tr><td valign="top">Always Ask Permission</td><td valign="top">AI hỏi xác nhận trước mỗi thao tác</td><td valign="top">Dữ liệu production, quan trọng</td></tr><tr><td valign="top">Allow Unsupervised</td><td valign="top">AI tự thực hiện không cần xác nhận</td><td valign="top">Dữ liệu test, dev environment</td></tr></tbody></table>

&#x20;

🚨 WARNING: \*\*Bảo mật khi sử dụng MCP:\*\* - Sử dụng API Token với quyền hạn tối thiểu (read-only nếu chỉ cần query) - Không sử dụng Admin token cho MCP integration - Bật chế độ "Always Ask Permission" cho dữ liệu production - Kiểm tra kỹ MCP Config JSON trước khi chia sẻ — đảm bảo không lộ token

💡 TIP: MCP đặc biệt hữu ích cho các developer muốn nhanh chóng prototype, query dữ liệu, hoặc thao tác database mà không cần mở giao diện Tables. Kết hợp MCP với Claude Desktop giúp biến Tables thành trợ lý dữ liệu cá nhân.

&#x20;

## Use-cases tích hợp AI

### 1. CRM thông minh với AI Agent

Khách hàng chat → AI Agent tra cứu CRM trong Tables →\
Trả lời dựa trên lịch sử mua hàng → Ghi nhận tương tác vào Tables

### 2. Phân nhóm khách hàng tự động

Webhook: New Order → Workflow → LLM phân tích hành vi →\
Cập nhật Segment field trong Tables → Trigger chăm sóc tự động

### 3. Content Calendar AI-powered

Form View thu thập ý tưởng → Workflow → LLM viết draft →\
Lưu draft vào table → Kanban View quản lý tiến độ

### 4. Helpdesk tự động

Form View nhận ticket → Webhook → AI phân loại →\
Cập nhật Priority & Category → Assign cho nhân viên phù hợp

### 5. Báo cáo thông minh

Scheduled Workflow → Query Tables API → LLM phân tích dữ liệu →\
Tạo báo cáo → Gửi email cho management

&#x20;

## Best Practices

💡 TIP: \*\*Thiết kế Table hiệu quả:\*\* - Mỗi table nên tập trung vào một đối tượng (Customers, Orders, Products) - Sử dụng Links để tạo quan hệ thay vì duplicate dữ liệu - Đặt tên fields rõ ràng, dễ hiểu - Sử dụng Single Select cho các trạng thái để tận dụng Kanban View

🚨 WARNING: \*\*Lưu ý khi tích hợp API:\*\* - Bảo mật API Token — không hardcode trong client-side code - Sử dụng rate limiting để tránh gọi API quá nhiều - Validate dữ liệu trước khi ghi vào Tables - Thiết lập error handling trong Workflow cho các trường hợp API fail

⚠️ IMPORTANT: \*\*Tối ưu performance:\*\* - Sử dụng \`fields\` parameter để chỉ lấy dữ liệu cần thiết - Phân trang (pagination) cho table có nhiều records - Sử dụng \`where\` filter ở API level thay vì lọc phía client - Cache kết quả API khi dữ liệu không thay đổi thường xuyên


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.clickai.vn/clickai-docs/tinh-nang/bang-so-lieu/tich-hop-voi-ai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
