🧩 Step 1: Prepare Dify Platform Resources
Before integration, you need to prepare the resources you want to connect to on the Dify Platform, such as:- Knowledge Base: e.g., FAQ documents, product introductions, etc.;
- Workflow: e.g., an automated process for exception handling or approvals;
- Chatflow: Custom LLM-based dialogue processes.
✅ Required Information
Prepare the following information for use during tool configuration:- Dify API Key (it’s recommended to use a key with the appropriate resource permissions);
- The unique identifiers of the resources (such as Workflow ID, Chatflow ID);
- Other required access parameters (e.g., Base URL, Agent ID, etc.).
🛠️ Step 2: Install Dify Tool Template from MCP Marketplace
- Go to the MCP Tool Marketplace in the Xpert AI platform;
- Search for the keyword “Dify”, and you will find several official Dify integration templates:
- Dify Chatflow Invocation Template
- Dify Workflow Invocation Template
- Dify Knowledge Base Q&A Template
- Select the template that fits your needs and click “Install”;
- On the installation page, fill in:
- The API Key of the Dify platform
- The target resource ID (e.g., Chatflow ID, Workflow ID)
- Optional: default parameters, environment variable configurations, etc.
- After installation, the MCP tool will be automatically generated and appear in your tool list.
🧬 Step 3: Customize MCP Tool Code for Parameters and Logic
Go to the “Code” tab to fine-tune the tool’s logic. Here’s an example:main.py
💡 Tips
- The
inputparameter can be extended with more fields (e.g., user role, business type); - The function’s docstring is critical for guiding the model in tool invocation—describe purpose, input expectations, and typical use cases clearly;
- For structured outputs (e.g., JSON), add parsing logic to extract key fields;
- Use environment variables to manage sensitive data securely.
🧠 Step 4: Integrate MCP Tool into an Agent
- Open the agent orchestration page for the agent that needs to access Dify resources;
- Click “Add Toolkit”, and select the Dify MCP tool you just created;
- The configuration will auto-save;
- Now your agent can invoke Dify Chatflow, Workflows, or Knowledge Base content based on user input in conversations.
✅ Example Use Cases
- Customer Support Copilot: Automatically answer user questions by invoking Dify Chatflow;
- Process Collaboration Agent: Connect to Dify workflows for sales approvals, exception handling, etc.;
- Knowledge Search Assistant: Integrate Dify Knowledge Base for real-time business knowledge retrieval.
❓ Frequently Asked Questions (FAQ)
Here are some common issues and solutions when integrating and using Dify tools on the Xpert AI platform:1. 🧠 The model didn’t invoke the tool?
Possible reasons & solutions:- Check if the model supports tool calling;
- Ensure the MCP tool’s
Docstringis clear and descriptive; - Check if the agent’s prompt guides the model to recognize tool use;
- Make sure the tool is properly bound to the agent.
2. 🧾 Missing parameters when calling the MCP tool?
Check the following:- Are parameters set as optional instead of required?
- Is the parameter usage described clearly in the docstring?
- Use required parameters (no default value) to force input;
- Provide structured prompts to guide input correctly.
3. 🔐 “Unauthorized” or “401” error?
Possible reasons:- Incorrect or expired API Key;
- API Key not correctly passed via environment variables;
- Key lacks permission to access the target resource.
4. 🆔 “Resource Not Found” or “Invalid ID”?
Check:- If the Chatflow/Workflow ID is correct;
- Whether the resource is private and accessible to the API Key user;
- Avoid spaces or hidden characters when copying the ID.
5. 🌐 Dify call fails or has no response?
Tips:- Increase
timeout(e.g.,timeout=30) if request times out; - Ensure network can access
https://api.dify.ai; - Add error handling and logging in the MCP tool.
6. 🧪 Incomplete or malformed return from the tool?
Check:- Understand Dify’s response format (typically JSON);
- Log the full response to debug;
- If the response is in markdown or HTML, add cleanup logic.
7. 🤖 Agent hit rate limits or errors when calling tools?
Solutions:- Check Dify’s rate limit policy;
- Use higher-permission API Key or upgrade plan;
- Add cooldowns or retry logic in MCP tool.
8. 📦 MCP tool fails to connect?
Check:- Are required Python packages (e.g.,
requests,httpx) missing? - Add them to
requirements.txt; - Re-deploy after updating dependencies;
- Check logs for
ModuleNotFoundError.
9. 🛠️ How to debug if the tool was called successfully?
Try:- Print
response.status_codeandresponse.json()in the MCP tool; - Use Postman or curl to test Dify API manually;
- Use Xpert AI’s MCP tool test console to simulate input and inspect logs.
10. 🔄 How to update or upgrade Dify integration tools?
Steps:- Edit the code in the MCP tool backend;
- If a new version of the template is available, reinstall or merge changes;
- Save the toolkit after updating to apply changes.
If you have more questions, feel free to join our developer community or contact technical support for assistance.