Bỏ qua để đến nội dung

MCP Server (Model Context Protocol)

Thông tin nhanh

  • Vị trí mã nguồn: mcp-server/
  • SDK: @modelcontextprotocol/sdk v1.x
  • Transport: stdio (stdin/stdout)
  • Tools: 7 CRM tools
  • Dùng với: OpenFang, OpenClaw, hoặc bất kỳ MCP-compatible agent

Xem thêm: Agent API · OpenFang/OpenClaw

graph LR
style AGENT fill:#2d333b,stroke:#d2a8ff,color:#e6edf3
style MCP fill:#2d333b,stroke:#f0883e,color:#e6edf3
style CLIENT fill:#2d333b,stroke:#6d5dfc,color:#e6edf3
style API fill:#2d333b,stroke:#3fb950,color:#e6edf3
AGENT["🤖 AI Agent<br/>(OpenFang/OpenClaw)"]
MCP["🔌 MCP Server<br/>(index.js)"]
CLIENT["📡 CRM Client<br/>(crm-client.js)"]
API["⚙️ CRM API<br/>(api.salehay.com)"]
AGENT -->|"stdio (JSON-RPC)"| MCP
MCP -->|"Tool call → method"| CLIENT
CLIENT -->|"HTTP + X-Agent-Token"| API

Mô tả: Agent giao tiếp với MCP Server qua stdio. Khi agent gọi tool (ví dụ crm_search), MCP Server chuyển thành HTTP request qua CRM Client tới Agent API.

mcp-server/
├── index.js # Server entry point — khởi tạo Server, connect stdio transport
├── tools.js # Tool definitions (inputSchema cho mỗi tool)
├── crm-client.js # HTTP wrapper — gọi Agent API endpoints
└── package.json # Dependencies: @modelcontextprotocol/sdk
BiếnBắt buộcMô tảDefault
CRM_AGENT_TOKENAgent token (tạo trong Admin)
CRM_BASE_URLURL API backendhttps://api.salehay.com

Tạo lead mới. Auto-create customer nếu phone chưa tồn tại.

ParamTypeRequiredMô tả
phonestringSĐT Việt Nam (0xxx, 9-11 số)
namestringTên khách hàng
emailstringEmail
sourcestringNguồn (default: agent)
service_intereststringDịch vụ quan tâm
notestringGhi chú
prioritystringlow / normal / high

Tìm kiếm leads theo phone, name, hoặc status.

ParamTypeRequiredMô tả
querystringSĐT hoặc tên
statusstringFilter status
limitnumberMax results (default 20, max 50)

Cập nhật status, priority, hoặc note.

ParamTypeRequiredMô tả
lead_idstringLead UUID
statusstringTrạng thái mới
prioritystringPriority mới
notestringGhi chú mới

Ghi nhận cuộc gọi tới lead hoặc booking.

ParamTypeRequiredMô tả
lead_idstring❌*Lead UUID
booking_idstring❌*Booking UUID
outcomestringanswered / no_answer / busy / voicemail / rejected
duration_secondsnumberThời lượng (giây)
notestringGhi chú
reject_reasonstringLý do từ chối

Lấy danh sách bookings hôm nay + status summary. Không cần params.

Log tin nhắn gửi qua Zalo, WhatsApp, SMS, Telegram.

ParamTypeRequiredMô tả
lead_idstring❌*Lead UUID
customer_idstring❌*Customer UUID
channelstringzalo / whatsapp / sms / telegram
message_textstringNội dung tin nhắn
template_namestringTemplate name

Analytics tổng hợp: pipeline, today’s metrics, hot leads, 30-day conversion. Không cần params.

HTTP wrapper đơn giản, gọi Agent API:

const crm = new CrmClient('https://api.salehay.com', 'agent_xxx');
// Các method:
crm.createLead({ phone: '0901234567', name: 'Test' });
crm.searchLeads('0901', { status: 'new', limit: 10 });
crm.updateLead('lead-uuid', { status: 'contacted' });
crm.logCall({ lead_id: 'uuid', outcome: 'answered' });
crm.getBookingsToday();
crm.sendMessage({ lead_id: 'uuid', channel: 'zalo', message_text: '...' });
crm.getAnalytics();

Mỗi request tự gắn header X-Agent-TokenContent-Type: application/json.

Terminal window
# 1. Install
cd mcp-server && npm install
# 2. Run
CRM_BASE_URL=https://api.salehay.com \
CRM_AGENT_TOKEN=agent_abc123... \
node index.js

Server sẽ log SaleHay CRM MCP Server running on stdio nếu thành công.

Xem hướng dẫn kết nối OpenFang/OpenClaw tại: Integration Guide