mcpField
D
dify-mcp

dify-mcp

Local
github.com/salted-butter-joshuaMemory & Knowledge0Updated 17w ago

About dify-mcp

dify-mcp exposes Dify knowledge-base retrieval to Cursor and other MCP clients. It connects to self-hosted or remote Dify instances and can restrict access with a dataset allowlist.

Key features

  1. 01Discover and inspect datasets
  2. 02Retrieve relevant chunks semantically
  3. 03Browse documents and text segments
  4. 04Restrict access with a dataset allowlist
  5. 05Use stdio transport

Use cases

  1. 01Search a Dify knowledge base from Cursor
  2. 02Check which datasets are accessible
  3. 03Inspect documents and segments in a dataset

MCP support

As an MCP server, it provides tools for dataset discovery, semantic retrieval, and browsing documents and segments. It calls the Dify Knowledge API over HTTP and communicates with local clients over stdio.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

mcp.json · Universal config
{
"mcpServers": {
"salted-butter-joshua-dify": {
"command": "uvx",
"args": [
"dify-mcp"
],
"env": {
"DIFY_API_BASE": "<DIFY_API_BASE>",
"DIFY_API_KEY": "<DIFY_API_KEY>",
"DIFY_ALLOWED_DATASETS": "<DIFY_ALLOWED_DATASETS>",
"DIFY_TIMEOUT": "<DIFY_TIMEOUT>",
"DIFY_VERIFY_SSL": "<DIFY_VERIFY_SSL>"
}
}
}
}
Run commanduvx dify-mcp
Environment variables to set
DIFY_API_BASEDify Knowledge API base URL, e.g. http://192.168.1.100/v1
DIFY_API_KEYSecretDify Knowledge Base API key
DIFY_ALLOWED_DATASETSComma-separated dataset UUIDs to expose
DIFY_TIMEOUTHTTP timeout in seconds (default: 30)
DIFY_VERIFY_SSLVerify TLS certificates (default: false)

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
pypidify-mcp0.1.0

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project 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
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:

# 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:

cp .env.example .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:

# 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:

{
  "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:

{
  "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

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.