Connect Dify API with MCP server for chat and knowledge base queries seamlessly
Dify Connect MCP Server is designed to facilitate seamless integration between AI applications, such as Claude Desktop, Continue, and Cursor, with specific data sources and tools through the Model Context Protocol (MCP). This server acts as a middleware, enabling these advanced applications to leverage Dify’s robust API for complex queries and responses.
The primary capabilities of Dify Connect MCP Server include:
These features are implemented using a standardized protocol that ensures compatibility across various AI tools and platforms.
Dify Connect MCP Server leverages the Model Context Protocol (MCP) to establish communication between AI applications and Dify’s data sources. The architecture is designed with the following layers:
graph TD
A[AI Application] -->|MCP Client| B[MCP Protocol]
B --> C[MCP Server]
C --> D[Dify Chat API/KB]
style A fill:#e1f5fe
style B fill:#f3e5f5
style C fill:#f0f8ff
style D fill:#fddfd6
This diagram illustrates the flow of communication from an AI application, through the MCP client and server layer, to the underlying Dify API.
Before setting up Dify Connect MCP Server, you will need:
Install Dependencies:
npm install
Compile TypeScript Code:
./build.sh
Set Environment Variables: These include DIFY_BASE_URL
, DIFY_SECRET_KEY
, NODE_ENV
, and LOG_LEVEL
. These can be set in a .env
file as follows:
Copy the example .env file:
cp .env.example .env
Edit the .env
file to include your Dify API key:
# Dify API Settings
DIFY_BASE_URL=https://api.dify.ai/v1
DIFY_SECRET_KEY=your_actual_dify_secret_key_here
# Server Settings
NODE_ENV=production
LOG_LEVEL=info
To start serving requests, use the following command:
./start-mcp.sh
Below are two realistic scenarios where Dify Connect MCP Server can be leveraged within an AI workflow:
{
"mcpServers": {
"dify-connect-mcp": {
"command": "/bin/bash",
"args": ["<repo-path>/run-mcp.sh"],
"disabled": false,
"autoApprove": []
}
}
}
The above sample MCP server configuration demonstrates how the integration can be realized within a larger architecture.
Dify Connect MCP Server is compatible with popular MCP clients such as Claude Desktop and Continue. The provided client compatibility matrix below illustrates the support:
graph LR
A[Claude Desktop] --> B[MCP Client]
C[Continue] --> B
D[Cursor] --> B
table "MCP Client", "", "Resources", "Tools", "Prompts"
| | Resources | Tools | Prompts |
|------------|-----------|--------|---------|
| Clausde Desktop | ✅ | ✅ | ✅ |
| Continue | ✅ | ✅ | ✅ |
| Cursor | ❌ | ✅ | ❌ |
The diagram and table show that both Claude Desktop and Continue support resources, tools, and prompts fully; while Cursor supports only tools.
This server ensures reliable communication for various AI applications by adhering to the MCP protocol accurately. It serves a diverse set of clients, providing a robust solution for integrating with Dify’s APIs efficiently.
Configure environmental variables like DIFY_BASE_URL
, DIFY_SECRET_KEY
, and NODE_ENV
within the .env.example
file according to your requirements. For live deployments, ensure proper security measures are in place by setting appropriate logging levels (LOG_LEVEL
) and securing API keys.
{
"mcpServers": {
"dify-connect-mcp": {
"command": "/bin/bash",
"args": ["<repo-path>/run-mcp.sh"],
"disabled": false,
"autoApprove": []
}
}
}
Implementing the above configuration ensures seamless operations across different environments.
To contribute to this project or seek developer support, follow these guidelines:
For further exploration of Model Context Protocol (MCP), visit the official documentation at ModelContextProtocol.com for detailed protocol specifications, and join the community forums to interact with other developers.
This comprehensive guide positions Dify Connect MCP Server as a crucial component in modern AI workflow integrations, emphasizing its robust integration capabilities and seamless operation within various development environments.
RuinedFooocus is a local AI image generator and chatbot image server for seamless creative control
Learn to set up MCP Airflow Database server for efficient database interactions and querying airflow data
Simplify MySQL queries with Java-based MysqlMcpServer for easy standard input-output communication
Build stunning one-page websites track engagement create QR codes monetize content easily with Acalytica
Access NASA APIs for space data, images, asteroids, weather, and exoplanets via MCP integration
Explore CoRT MCP server for advanced self-arguing AI with multi-LLM inference and enhanced evaluation methods