Dify Cloud MCP Server

Dify Cloud MCP Server

Exposes a SQLite database as MCP tools for Dify Cloud, ensuring LLM responses are based on real database records rather than generated data.

Category
Visit Server

README

MCP Server for Dify Cloud

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

场景

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

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 里已经有 users、products、orders 三张表。按需求修改表结构,然后在 mcp_server.py 里增减对应的 @mcp.tool() 即可。

环境变量

变量 默认值 说明
MCP_HOST 0.0.0.0 监听地址
MCP_PORT 8000 监听端口
DB_PATH ./data/data.db 数据库路径

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured