Appearance
🔌 MCP Server
Mã nguồn:
mcp-server/· SDK:@modelcontextprotocol/sdk· Transport: stdio · Tools: 7
Xem thêm: Agent API · Cài đặt Agent · OpenFang/OpenClaw
Kiến trúc
Agent gọi tool (VD: crm_search) → MCP Server chuyển thành HTTP request → CRM API xử lý → trả kết quả cho Agent.
Cấu trúc
mcp-server/
├── index.js # Server — khởi tạo, listen stdio
├── tools.js # 7 tool definitions (inputSchema)
├── crm-client.js # HTTP wrapper → Agent API
├── full-test.js # Test script (19 cases)
└── package.json # @modelcontextprotocol/sdkBiến môi trường
| Biến | Bắt buộc | Mô tả |
|---|---|---|
CRM_AGENT_TOKEN | ✅ | API Key từ Admin (sk_live_xxx) |
CRM_BASE_URL | ❌ | URL API (mặc định: https://salehay.com) |
7 Tools
| Tool | Mô tả | Params chính |
|---|---|---|
crm_create_lead | Tạo lead mới | phone ✅, name, email, source, priority |
crm_search | Tìm kiếm leads | query, status, limit |
crm_update_lead | Cập nhật lead | lead_id ✅, status, priority, note |
crm_log_call | Ghi cuộc gọi | lead_id, outcome ✅, duration, note |
crm_get_bookings | Bookings hôm nay | — |
crm_send_message | Log tin nhắn | lead_id, channel ✅, message_text |
crm_get_analytics | Analytics | — |
Chi tiết params: Agent API Reference
Quick Start
bash
# 1. Install
cd mcp-server && npm install
# 2. Run
CRM_BASE_URL=https://salehay.com \
CRM_AGENT_TOKEN=sk_live_xxx \
node index.js
# → "SaleHay CRM MCP Server running on stdio"
# 3. Test (19 test cases)
node full-test.js
# → 19/19 PASS — 100%Kết nối Agent Platform
OpenFang — MCP Config
Trong OpenFang Dashboard → Settings → MCP Servers → thêm:
toml
[mcp.salehay-crm]
command = "node"
args = ["/absolute/path/to/mcp-server/index.js"]
[mcp.salehay-crm.env]
CRM_BASE_URL = "https://salehay.com"
CRM_AGENT_TOKEN = "sk_live_xxx"OpenClaw — JSON Config
File openclaw.json tại root project:
json
{
"mcpServers": {
"salehay-crm": {
"command": "node",
"args": ["/absolute/path/to/mcp-server/index.js"],
"env": {
"CRM_BASE_URL": "https://salehay.com",
"CRM_AGENT_TOKEN": "sk_live_xxx"
}
}
}
}Troubleshooting
| Lỗi | Nguyên nhân | Cách sửa |
|---|---|---|
Agent token required | Token sai hoặc key bị xóa | Kiểm tra key trong Admin → API Keys |
Missing scope | Key chưa có đủ quyền | Liên hệ admin update scopes → * |
Rate limit exceeded | Quá 100 req/phút | Giảm tần suất hoặc tăng rate_limit |
fetch failed | Sai URL hoặc mất mạng | Kiểm tra CRM_BASE_URL = https://salehay.com |