Skip to main content
Glama
QUARES-1

Dify Cloud MCP Server

by QUARES-1

MCP Server for Dify Cloud

把 SQLite 数据库暴露为 MCP Tool,接入 Dify Cloud Chatflow/Agent,杜绝 LLM 编造数据——所有回答来自数据库真实记录。

场景

用户提问 → Dify API → Chatflow/Agent → MCP Tool → SQLite → 只返回真实数据

Related MCP server: MCP SQLite Server

Windows 部署

1. 环境准备

# 安装 Python 3.10+(https://python.org 下载,记得勾选 "Add to PATH")
python --version

# 安装依赖
pip install -r requirements.txt

2. 初始化数据库

python init_db.py

3. 启动 MCP Server

python mcp_server.py
# 看到 "Uvicorn running on http://0.0.0.0:8000" 就是跑起来了

4. 暴露公网(任选一种)

你的 PC 在内网,Dify Cloud 访问不到 127.0.0.1,需要打洞。

推荐:bore(零注册,一行命令)

https://github.com/ekzhang/bore/releases 下载 bore.exe,放到 PATH 里:

bore local 8000 --to bore.pub
# 输出 bore.pub:xxxxx

备选:serveo(Windows 10/11 自带 SSH)

ssh -R 80:localhost:8000 serveo.net
# 输出 https://xxxxxxxx.serveousercontent.com

5. 让 MCP Server 不掉线

关了终端就没了,用以下任一方式常驻后台:

NSSM(注册为 Windows 服务)

nssm install MCP_Server "python" "D:\mcp_dify_server\mcp_server.py"
nssm set MCP_Server AppDirectory "D:\mcp_dify_server"
nssm start MCP_Server

或者简单写个 bat 放启动目录

@echo off
cd /d D:\mcp_dify_server
start /min python mcp_server.py
start /min bore local 8000 --to bore.pub

接入 Dify Cloud

1. 添加 MCP Server

Dify 工作空间 → 工具 → MCP → 添加 MCP Server (HTTP)

URL 填入 bore 或 serveo 给的地址 + /mcp

  • http://bore.pub:xxxxx/mcp

  • https://xxxxxxxx.serveousercontent.com/mcp

Dify 会自动发现 9 个 Tool。

2. 创建 Chatflow

新建 Chatflow 应用,拖入:开始 → Agent → 回答

Agent 节点里勾选所有 MCP Tool。

3. System Prompt(关键)

你是一个帮助查询公司内部数据库的助手。
你只能通过调用数据库工具获取数据,数据库里有 users(用户)、products(产品)、orders(订单)三张表。

规则:
1. 任何用户提问,必须先调用对应的数据库工具查询,不得直接回答
2. 如果工具返回"未找到匹配记录",如实告知用户未找到
3. 回答时只引用工具返回的真实数据,不得编造任何信息
4. 如果用户问题不够明确,调用工具尝试查询,而不是解释你为什么不知道

4. 发布

右上角发布 → 拿到 API Key → 前端调 /v1/chat-messages

验证示例

问 Dify:"技术部有哪些人?"

返回:

张三 | zhangsan@example.com | 13800001001 | 技术部
赵六 | zhaoliu@example.com | 13800001004 | 技术部  
吴九 | wujiu@example.com | 13800001007 | 技术部

都是数据库里的真实记录,不是 LLM 编的。

自定义数据库

database.py 里已经有 usersproductsorders 三张表。按需求修改表结构,然后在 mcp_server.py 里增减对应的 @mcp.tool() 即可。

环境变量

变量

默认值

说明

MCP_HOST

0.0.0.0

监听地址

MCP_PORT

8000

监听端口

DB_PATH

./data/data.db

数据库路径

F
license - not found
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/QUARES-1/dify-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server