Skip to main content
Glama
cheng180

Customer-Try

by cheng180

Customer-Try — Dify 智能汽车销售客服 Demo

基于 Dify Chatflow/Workflow + MCP Server 的智能汽车销售客服系统。支持多轮对话、本地库存查询、知识库检索、实拍照片展示。

架构

┌─────────────────┐     HTTP/SSE      ┌──────────────────┐
│   Dify (Docker) │ ←───────────────→ │  MCP Server      │
│                 │                   │  (9020端口)       │
│  Chatflow/      │                   │  inventory 查询    │
│  Workflow       │                   │  stock 检查        │
│  + 知识库        │                   │  price 报价        │
│  + LLM          │                   └────────┬─────────┘
└────────┬────────┘                            │
         │                                     │ SQLite
         │ Chat API                            ▼
         │                           ┌──────────────────┐
         ▼                           │ company_inventory │
┌─────────────────┐                  │      .db          │
│  FastAPI        │                  │                   │
│  (7860端口)      │                  │  品牌/车型/配置     │
│  代理转发 +      │                  │  价格/库存/颜色     │
│  聊天UI          │                  │  实拍照片路径       │
│  + 图片服务       │                  └──────────────────┘
└────────┬────────┘
         │
         ▼
    用户浏览器
    http://127.0.0.1:7860

Related MCP server: MCP Carvana

快速开始

1. 环境要求

  • Python 3.11+

  • Conda 环境 customer

  • Docker Desktop(运行 Dify)

2. 安装依赖

conda activate customer
pip install fastapi uvicorn httpx mcp

3. 初始化数据库

python init_company_db.py

数据库 company_inventory.db 包含 8 条示例车辆数据,可按需修改。

4. 启动服务

需要两个终端窗口

终端 1 — FastAPI + 聊天 UI(7860 端口)

conda activate customer
python main.py
# → http://127.0.0.1:7860

终端 2 — MCP Server(9020 端口)

conda activate customer
python mcp_server.py
# → http://127.0.0.1:9020/sse

5. 配置 Dify

连接 MCP Server:

  1. Dify → 插件 → MCP SSE/StreamableHTTP → 设置

  2. 填入:{"car-tools":{"url":"http://host.docker.internal:9020/sse","headers":{},"timeout":50,"sse_read_timeout":50}}

  3. 授权

Workflow 中使用 MCP 工具:

在 Workflow 画布添加「调用 MCP 工具」节点:

字段

工具名称

search_inventory / check_stock / get_price

参数

{"query": "{{#sys.query#}}"}

MCP 工具

工具

参数

说明

search_inventory

query

关键词搜索公司库存(自动检测品牌/车型)

check_stock

brand, model

精确查询某款车库存和价格

get_price

brand, model

获取最优报价

返回值带前缀标记:

  • [STOCK:AVAILABLE] — 有库存

  • [STOCK:EMPTY] — 无库存

数据库结构

company_inventory.dbinventory 表:

字段

类型

说明

brand

TEXT

品牌

model

TEXT

车型

variant

TEXT

具体配置款

year

INTEGER

年款

price_guide

REAL

指导价(万元)

price_sale

REAL

实际售价(万元)

stock

INTEGER

库存数量

fuel_type

TEXT

能源类型(纯电/插混/增程)

color

TEXT

可选颜色

description

TEXT

车辆简介

photo_path

TEXT

实拍照片文件名(放入 photos/ 目录)

添加车辆照片

  1. 将照片放入 photos/ 目录

  2. 更新数据库 photo_path 字段为文件名

  3. 重启 MCP Server

图片通过 FastAPI 静态文件服务访问:http://127.0.0.1:7860/photos/xxx.jpg

知识库

项目包含以下知识库文档,可导入 Dify 知识库:

  • knowledge_base/购车引导话术.md — 销售引导流程

  • knowledge_base/模糊语义情绪处理话术.md — 模糊表达和情绪处理

  • knowledge_base/汽车百科知识库.md — 汽车信息百科

  • scrape/car_data.md — 网易汽车爬取的 2849 款车数据

  • scrape/car_data.json — 结构化车辆数据

项目文件

customer-try/
├── main.py              # FastAPI 后端 + 聊天 UI 代理
├── mcp_server.py         # MCP Server(库存查询工具)
├── init_company_db.py    # 数据库初始化脚本
├── company_inventory.db  # SQLite 数据库
├── templates/
│   └── index.html        # 聊天界面
├── photos/               # 车辆实拍照片
├── knowledge_base/       # 知识库文档
└── scrape/               # 车辆数据爬虫
    ├── scraper.py        # 爬虫脚本
    ├── car_data.json     # 2849 款车数据
    └── car_data.md       # Markdown 格式

License

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    An MCP server that integrates with the Carvana marketplace to enable vehicle searching, financing estimation, and trade-in value assessments. It allows AI assistants to retrieve detailed vehicle information, history reports, and market insights directly from Carvana's inventory.
    10
    16 npm
    1
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    MCP server for insurance claim pilot tools, providing policy search, claim lookup, and fraud score calculation.
    MIT