General Introduction
Dify Connect MCP is an open source project hosted on GitHub that aims to provide users of the Dify platform with a convenient tool to seamlessly connect with Dify workflows via the Model Context Protocol (MCP). Developed by the difybase team, the project focuses on improving the development efficiency of AI applications, and is particularly suitable for developers who need to integrate complex workflows. It efficiently interfaces external services with Dify's core functions (e.g., model invocation, knowledge base access, etc.) through standardized protocol support. Both individual developers and enterprise users can quickly implement custom functionality extensions and simplify the development process through this tool. Currently, the project is still in the development stage, the community is highly active, developers are welcome to participate in contributing code or make suggestions.
Function List
- Server setup with MCP protocol support: Provides a server framework for connecting Dify workflows based on the Model Context Protocol.
- Dify API Integration: Enables direct communication with the Dify platform by configuring Dify's API key and base URL.
- Multi-workflow support: Allows multiple Dify workflows to be managed and invoked with different keys.
- Standardized Context Delivery: Utilize the MCP protocol to ensure smooth data interaction between external services and Dify.
- Open Source Collaboration: The project code is completely open source , users are free to modify or extend the function to meet specific needs .
- Debugging Support: Provides compatibility with tools such as MCP Inspector for developers to debug and optimize.
Using Help
Installation process
Dify Connect MCP is an open source project based on GitHub, which requires some technical foundation to install and use. Here are the detailed installation steps:
- environmental preparation
- Make sure you have Node.js (recommended version 16 or higher) and Git installed on your computer.
- If you need to debug, it is recommended to install MCP Inspector, you can get the installation method through the official documentation.
- Prepare a Dify account and get the API key (Dify API Key) and the base URL (usually the
https://cloud.dify.ai/v1
(which may vary depending on your deployment).
- Cloning Project Code
Open a terminal and enter the following command to clone the project locally:
git clone https://github.com/difybase/dify-connect-mcp.git
Once the cloning is complete, go to the project directory:
cd dify-connect-mcp
- Installation of dependencies
The project is based on TypeScript development, so you need to install the relevant dependencies. Run the following command:
npm install
This will automatically download all the npm packages needed for the project.
- Configuring Environment Variables
In the project root directory, create aconfig.yaml
file, used to store Dify's configuration information. A sample configuration is shown below:
dify_base_url: "https://cloud.dify.ai/v1"
dify_app_sks.
- "app-sk1"
- "app-sk2"
dify_base_url
: API address for the Dify platform.dify_app_sks
: A list of keys for the Dify application, each corresponding to a workflow.
- Build and run
After completing the configuration, use the following command to build the project:npm run build
Once the build is complete, run the server:
npm start
If you see a log like "Server running", the server has started successfully.
How to use
Once installed, Dify Connect MCP runs as an MCP server and can communicate with clients via standard input and output (stdio). Below are the details of how to use it:
Configuring the Client
To create an application on the client side (e.g., the Claude Desktop or other MCP-enabled tools), you need to add MCP server information to the client configuration file. A sample configuration is shown below:
{
"mcpServers": {
"diy-connect-mcp": {
"command": "node",
"args": ["/build/index.js"],
"env": {
"DIFY_API_KEY": "your-api-key"
}
}
}
}
<你的项目路径>
: Replace withdify-connect-mcp
The actual path of theDIFY_API_KEY
: Replace it with the API key you got from the Dify platform.
After saving the configuration file, restart the client and the MCP server will automatically establish a connection with the Dify platform.
Invoking Dify Workflows
Assuming you have created a workflow in the Dify platform (e.g., a text analysis workflow called "text-analyzer"), you can invoke it by following these steps:
- assure
config.yaml
The key for the corresponding workflow has been added in the - In an MCP-enabled client, enter a command similar to the following:
Run the text-analyzer workflow and enter the text "This is a test message".
- The MCP server sends the request to Dify, executes the workflow and returns the results.
Debugging and Optimization
If you encounter problems, you can use the MCP Inspector for debugging:
- Start the MCP Inspector (refer to its documentation for details).
- Run the following command in the terminal to enable debug mode:
npm run start:debug
- The Inspector displays communication logs to help you locate problems.
Main function operation flow
1. Integration of the Dify API
- procedure:: Editorial
config.yaml
If you want to use Dify, fill in Dify's base URL and API key. - functional role: Enables connectivity to Dify cloud or self-hosted instances, supporting calls to models, knowledge bases, and other resources.
- caveat: Ensure that the key is valid and matches the target workflow, otherwise an authentication error is returned.
2. Multi-workflow management
- procedure: in
dify_app_sks
Multiple keys are added to the list, each corresponding to a workflow. - functional role: Allows multiple independent workflows to run simultaneously, such as text generation, data analysis, etc.
- usage example: Configure two keys to invoke "Translation Workflow" and "Summarization Workflow" respectively, and input the same text to get translation and summarization results at the same time.
3. Customized extensions
- procedure::
- Modify the project source code (e.g.
src/index.ts
), adding new features. - Rebuild and run:
npm run build && npm start
The
- Modify the project source code (e.g.
- functional role: Meet specific needs, such as adding logging or customizing data processing logic.
- caveatIt is recommended to fork the project first and test it locally to avoid modifying the master branch directly.
caveat
- safety: Do not give out your API key to others, it is recommended that the
config.yaml
become a member.gitignore
The - compatibility: Ensure that the client supports the MCP protocol, or it will not be able to communicate.
- Community Support: If you run into problems, submit feedback on the GitHub Issues page and the community developers will help.
With the above steps, you can quickly get started with Dify Connect MCP, integrate Dify workflows into your own projects, and enjoy an efficient AI development experience!