Skip to content

🔌 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/sdk

Biến môi trường

BiếnBắt buộcMô tả
CRM_AGENT_TOKENAPI Key từ Admin (sk_live_xxx)
CRM_BASE_URLURL API (mặc định: https://salehay.com)

7 Tools

ToolMô tảParams chính
crm_create_leadTạo lead mớiphone ✅, name, email, source, priority
crm_searchTìm kiếm leadsquery, status, limit
crm_update_leadCập nhật leadlead_id ✅, status, priority, note
crm_log_callGhi cuộc gọilead_id, outcome ✅, duration, note
crm_get_bookingsBookings hôm nay
crm_send_messageLog tin nhắnlead_id, channel ✅, message_text
crm_get_analyticsAnalytics

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ỗiNguyên nhânCách sửa
Agent token requiredToken sai hoặc key bị xóaKiểm tra key trong Admin → API Keys
Missing scopeKey chưa có đủ quyềnLiên hệ admin update scopes → *
Rate limit exceededQuá 100 req/phútGiảm tần suất hoặc tăng rate_limit
fetch failedSai URL hoặc mất mạngKiểm tra CRM_BASE_URL = https://salehay.com

🔒 Internal Documentation — Dev Team Only