dify-knowledge
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@dify-knowledgesearch for 'neural networks' in knowledge base"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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}/retrieveDocument browsing — list documents and segments within a dataset
Dataset allowlist — restrict access to specific
dataset_idvaluesstdio transport — no manual server startup; the MCP client launches the process
Related MCP server: open-webui-knowledge-mcp-server
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 .envDIFY_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=falseVariable | Description |
| Dify Knowledge API base URL, e.g. |
| Knowledge Base API key |
| Comma-separated dataset UUIDs to expose (required) |
| HTTP timeout in seconds (default: |
| Verify TLS certificates (default: |
Run the health check:
# Windows
.venv\Scripts\python.exe scripts/health_check.py
# macOS / Linux
.venv/bin/python scripts/health_check.py3. Add to Cursor
You do not need to start the MCP server manually. Cursor launches it automatically via stdio.
Open Cursor Settings → MCP → Edit config
Add the following to
mcpServersin your MCP config file:Windows:
%USERPROFILE%\.cursor\mcp.jsonmacOS / Linux:
~/.cursor/mcp.json
Replace paths and env values with your own
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
Cursor Settings → MCP → confirm
dify-knowledgeshows as enabledIn chat, try:
List available Dify knowledge bases
Search the knowledge base for "your query"
MCP Tools
Tool | Description |
| List knowledge bases within the allowlist |
| Get metadata for one dataset |
| Retrieve relevant chunks (primary retrieval tool) |
| List documents in a dataset |
| List 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
Issue | Cause | Fix |
| Python < 3.11 | Use Python 3.11+ in |
MCP shows error (red) | Wrong Python path, invalid key, or network issue | Check |
| Invalid API key | Regenerate key in Dify Service API panel |
| UUID not in | Add the dataset UUID to the allowlist |
Health check missing env vars |
| Ensure |
Connection timeout | Dify unreachable | Check 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 referenceAPI Reference
Local path reference:
Dify-API.md
Security Notes
Never commit
.envor API keys to version controlA single Knowledge Base API key can access all visible datasets under the account — use
DIFY_ALLOWED_DATASETSto limit exposurePrefer running MCP locally; keep API keys in
mcp.jsonenv or.envon your machine only
This server cannot be deployed
Maintenance
Related MCP Connectors
Knowledge base MCP for AI agents on iknow.dev. Search, read, and maintain via OAuth.
Agentic search over your Dewey document collections from any MCP-compatible client.
Make your knowledge agent-ready. One MCP endpoint, 5 connectors, 3 search modes.
DocBase MCP server for AI agents
Related MCP Servers
- AlicenseBqualityDmaintenanceA Model Context Protocol server that enables AI assistants like Cursor to directly query and retrieve information from Dify knowledge bases through natural language.213 npm6MIT
- AlicenseNot gradedqualityCmaintenanceMCP server for Open WebUI Knowledge Bases – search and access your knowledge bases from Cursor, Claude Desktop, and other MCP clients.41 npm11MIT
- AlicenseNot gradedqualityDmaintenanceAn MCP server that integrates Dify knowledge bases, enabling AI assistants to retrieve and search content from Dify via tools like list datasets, get dataset details, and knowledge retrieval.8 npm4MIT
- FlicenseNot gradedqualityCmaintenanceMCP server exposing a RAG knowledge base as read-only tools (search_knowledge_base, ask_knowledge_base, kb_stats, kb_diagnostic) for AI clients like Claude Desktop and Cursor, enabling token-efficient document retrieval and Q&A.-