Dify Mcp

io.github.salted-butter-joshua由 GitHub 账号 salted-butter-joshua 发布v0.1.0更新于 Oct 24, 2026

MCP server exposing Dify knowledge base retrieval to Cursor and other MCP clients

概览

AI 生成的概览

让助手通过 Dify 知识库 API 检索和浏览 Dify 知识库。

可以做什么
通过 HTTP 将 MCP 客户端连接到自建或远程 Dify 实例,并开放其知识库检索能力。工具可列出允许的数据集、获取单个数据集的元数据、执行语义分块检索,以及列出文档及其文本分段。数据集白名单用于限制可访问的 dataset UUID。
适用场景
当团队把文档或内部知识放在 Dify 中,并希望助手从该知识库检索相关分块、浏览文档时使用。适合 Dify 已在运行且本机可访问的环境。
运行要求
本机需 Python 3.11+ 运行环境并安装 dify-mcp 包,同时需要一个已启用知识库 API 的 Dify 实例。必需的环境变量为 DIFY_API_BASE、DIFY_API_KEY 和 DIFY_ALLOWED_DATASETS;可选 DIFY_TIMEOUT 与 DIFY_VERIFY_SSL。本机需能通过网络访问 Dify API 端点。
安装前请注意
DIFY_API_KEY 是密钥,应只保存在本地配置中,切勿提交到版本控制。单个知识库密钥可访问该账号下所有可见数据集,因此 DIFY_ALLOWED_DATASETS 白名单是限制暴露范围的主要手段。DIFY_VERIFY_SSL 默认值为 false,会关闭 TLS 证书校验;除非依赖自签名证书,否则应启用。查询内容与检索结果会发送到你的 Dify 实例。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Dify Mcp,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

dify-mcp

Expose Dify knowledge base retrieval capabilities via MCP (Model Context Protocol), for use in Cursor and other MCP-compatible clients.

Connect to a self-hosted or remote Dify instance over HTTP, with optional dataset allowlisting for access control.

Features

  • Knowledge base discovery — list and inspect allowed datasets
  • Semantic retrieval — search chunks via Dify POST /datasets/{dataset_id}/retrieve
  • Document browsing — list documents and segments within a dataset
  • Dataset allowlist — restrict access to specific dataset_id values
  • stdio transport — no manual server startup; the MCP client launches the process

Requirements

  • Python 3.11+
  • A running Dify instance with Knowledge Base API enabled
  • Network access from the machine running the MCP server to your Dify API endpoint
  • A Dify Knowledge Base API Key (Dify → Knowledge → Service API → API Key)

Quick Start

1. Clone and install

bash
git clone https://github.com/salted-butter-joshua/dify-mcp.git
cd dify-mcp

python3.11 -m venv .venv

# Windows
.venv\Scripts\python.exe -m pip install -e .

# macOS / Linux
.venv/bin/python -m pip install -e .

Verify import:

bash
# Windows
.venv\Scripts\python.exe -c "import dify_mcp; print('OK')"

# macOS / Linux
.venv/bin/python -c "import dify_mcp; print('OK')"

2. Configure environment

Copy the example env file and edit it:

bash
cp .env.example .env
env
DIFY_API_BASE=http://your-dify-host/v1
DIFY_API_KEY=dataset-your-api-key
DIFY_ALLOWED_DATASETS=dataset-uuid-1,dataset-uuid-2
DIFY_TIMEOUT=30
DIFY_VERIFY_SSL=false
VariableDescription
DIFY_API_BASEDify Knowledge API base URL, e.g. http://192.168.1.100/v1
DIFY_API_KEYKnowledge Base API key
DIFY_ALLOWED_DATASETSComma-separated dataset UUIDs to expose (required)
DIFY_TIMEOUTHTTP timeout in seconds (default: 30)
DIFY_VERIFY_SSLVerify TLS certificates (default: false for self-signed certs)

Run the health check:

bash
# Windows
.venv\Scripts\python.exe scripts/health_check.py

# macOS / Linux
.venv/bin/python scripts/health_check.py

3. Add to Cursor

You do not need to start the MCP server manually. Cursor launches it automatically via stdio.

  1. Open Cursor Settings → MCP → Edit config
  2. Add the following to mcpServers in your MCP config file:
    • Windows: %USERPROFILE%\.cursor\mcp.json
    • macOS / Linux: ~/.cursor/mcp.json
  3. Replace paths and env values with your own
  4. Restart Cursor

See mcp.json.example for a full example.

Windows example:

json
{
  "mcpServers": {
    "dify-knowledge": {
      "command": "/absolute/path/to/dify-mcp/.venv/Scripts/python.exe",
      "args": ["-m", "dify_mcp.server"],
      "cwd": "/absolute/path/to/dify-mcp",
      "env": {
        "DIFY_API_BASE": "http://your-dify-host/v1",
        "DIFY_API_KEY": "dataset-your-api-key",
        "DIFY_ALLOWED_DATASETS": "dataset-uuid-1,dataset-uuid-2",
        "DIFY_TIMEOUT": "30",
        "DIFY_VERIFY_SSL": "false"
      }
    }
  }
}

macOS / Linux example:

json
{
  "mcpServers": {
    "dify-knowledge": {
      "command": "/absolute/path/to/dify-mcp/.venv/bin/python",
      "args": ["-m", "dify_mcp.server"],
      "cwd": "/absolute/path/to/dify-mcp",
      "env": {
        "DIFY_API_BASE": "http://your-dify-host/v1",
        "DIFY_API_KEY": "dataset-your-api-key",
        "DIFY_ALLOWED_DATASETS": "dataset-uuid-1,dataset-uuid-2"
      }
    }
  }
}

4. Verify in Cursor

  1. Cursor Settings → MCP → confirm dify-knowledge shows as enabled
  2. In chat, try:
    • List available Dify knowledge bases
    • Search the knowledge base for "your query"

MCP Tools

ToolDescription
list_datasetsList knowledge bases within the allowlist
get_datasetGet metadata for one dataset
search_knowledgeRetrieve relevant chunks (primary retrieval tool)
list_documentsList documents in a dataset
list_document_segmentsList text segments for a document

Architecture

Cursor (MCP client)
    │ stdio
    ▼
dify-mcp (local process)
    │ HTTPS / HTTP
    ▼
Dify Knowledge API (/v1/datasets/...)

The MCP server runs locally on your machine and calls the Dify API over the network. Dify does not need to reach your machine.

Troubleshooting

IssueCauseFix
No matching distribution found for mcpPython < 3.11Use Python 3.11+ in .venv
MCP shows error (red)Wrong Python path, invalid key, or network issueCheck mcp.json paths and env vars
401 UnauthorizedInvalid API keyRegenerate key in Dify Service API panel
Dataset not in allowed listUUID not in DIFY_ALLOWED_DATASETSAdd the dataset UUID to the allowlist
Health check missing env vars.env not foundEnsure .env exists in the project root
Connection timeoutDify unreachableCheck network / VPN / firewall

Project Structure

dify-mcp/
├── src/dify_mcp/
│   ├── server.py        # MCP entry point
│   ├── config.py        # Settings and allowlist
│   ├── dify_client.py   # Dify Knowledge API client
│   └── formatters.py    # Response formatting
├── scripts/
│   └── health_check.py  # Connectivity test
├── mcp.json.example     # Cursor MCP config template
├── .env.example         # Environment variable template
└── Dify-API.md          # Local API path reference

API Reference

Security Notes

  • Never commit .env or API keys to version control
  • A single Knowledge Base API key can access all visible datasets under the account — use DIFY_ALLOWED_DATASETS to limit exposure
  • Prefer running MCP locally; keep API keys in mcp.json env or .env on your machine only

来源:README.md,提交 3a0957b

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.1.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分