Mastering Dify’s MCP Integration: Build Powerful AI Agents and Workflows
This guide walks developers through Dify's native MCP integration—explaining the protocol, showing step‑by‑step configuration, demonstrating usage in agents and chatflows, and presenting real‑world cases like data analysis and travel planning—to accelerate AI application development.
1. Introduction
In AI application development, efficiently integrating external tools and services is essential for enhancing functionality and performance. Dify, a low‑code AI application platform, introduced native bidirectional integration of the Model Context Protocol (MCP) in version 1.6.0 and above. MCP, open‑sourced by Anthropic at the end of 2024, standardizes interfaces so large models can plug‑and‑play with external tools, solving fragmentation and compatibility issues.
2. Dify and MCP Overview
2.1 Dify Platform Overview
Dify enables developers to build AI applications—such as intelligent assistants and chatbots—without deep programming knowledge, offering a visual interface, support for multiple large language models, and flexible component orchestration.
2.2 MCP Protocol Explained
The MCP protocol standardizes how AI models connect to external data sources, acting as a universal interface. Before MCP, each AI app required custom adapters for each service, leading to cumbersome and error‑prone code. MCP defines a unified API that allows tools like databases or file systems to be integrated with a single configuration, enabling plug‑and‑play, bidirectional communication, and ecosystem growth.
2.3 Advantages of Dify’s Native MCP Integration
Native integration lets developers call any MCP service directly from Dify, expanding the pool of callable tools beyond built‑in plugins. It also allows Dify applications to be published as MCP services for external clients, improving integration efficiency, stability, and performance by eliminating intermediate layers.
3. Configuring MCP Service in Dify
3.1 Accessing the MCP Configuration Page
After logging into Dify, go to the application management page, click the “Tools” button, and select “MCP” from the dropdown to open the MCP configuration interface.
3.2 Adding an MCP Service
Click “Add MCP Service (HTTP)” and fill in the required fields:
Server URL : the HTTP endpoint of the MCP server, e.g., http://localhost:8080.
Name and Icon : a descriptive name and optional custom icon for easy identification.
Server Identifier : a unique ID using only lowercase letters, numbers, underscores or hyphens (max 24 characters), e.g., my_mcp_service_01.
3.3 Example: Configuring Gaode Map MCP Service
Service address: https://www.modelscope.cn/mcp/servers/@amap/amap-maps Obtain Gaode Map MCP service information by creating a web app on the Gaode Open Platform and retrieving the API key.
In Dify’s MCP add page, enter the service URL, set a name such as “Gaode Map MCP Service”, and define an identifier like gaode_mcp. Save the configuration.
Verify the configuration by opening the newly created service entry and confirming that tools such as route planning and place search are listed.
4. Different Ways to Use MCP in Dify
4.1 Using MCP in an Agent
Create a new Agent‑type application.
Add MCP tools to the Agent by selecting the configured Gaode Map service and choosing specific tools (e.g., route planning).
Write a prompt such as: “You are an intelligent travel assistant connected to the Gaode Map MCP service. When a user requests route planning, use the tool to generate the optimal route.”
Test the Agent by asking, for example, “Best route from Tiananmen to the Forbidden City.” The Agent will invoke the MCP tool and return the route.
4.2 Using MCP in a Workflow (Chatflow)
Create a new Chatflow application.
Install required plugins such as “MCP Agent Strategy” or “MCP SSE” if needed.
Add an Agent node, select the MCP Agent Strategy, choose an AI model, and add the desired MCP tools (e.g., Gaode Map place search).
Define instruction prompts like “You are a smart guide that can call the Gaode Map MCP place search tool to find tourist attractions.” Set the query variable (e.g., sys.query).
Test the workflow by asking “Find popular tourist spots in Beijing.” The workflow will call the MCP tool and return results.
4.3 Publishing a Dify Application as an MCP Service
Enable MCP service in the application settings, which generates a unique MCP server URL containing authentication credentials.
Test the generated MCP endpoint with external tools (e.g., CherryStudio, Cursor) or integrate it into Claude Desktop via the integration URL field.
5. Practical Cases Based on Dify and MCP
5.1 Intelligent Data Analysis Assistant
Background: Build an assistant that queries a database via a database MCP service, executes SQL, and visualizes results.
Deploy a PostgreSQL MCP service (e.g., using the postgre‑mcp‑server project).
Add the database MCP service in Dify with the appropriate URL and identifier.
Create a Chatflow that receives user analysis requests, calls the database MCP tool, and passes results to a chart‑generation tool.
5.2 Intelligent Travel Planning Assistant
Background: Provide end‑to‑end travel planning by invoking Gaode Map MCP services for route, traffic, and weather information.
Configure the Gaode Map MCP service as described earlier.
Create an Agent with prompts that gather user travel details, call route planning, traffic, and weather tools, and generate a natural‑language itinerary.
Test the Agent with queries like “Plan a trip from Beijing Tiananmen to the Forbidden City.”
6. Summary and Outlook
This article detailed how to configure and use MCP within the Dify platform—from service setup to agent and workflow integration, and finally publishing Dify apps as MCP services. The native integration simplifies tool orchestration, reduces latency, and opens possibilities for diverse domains such as healthcare, education, and beyond. As the MCP ecosystem matures and Dify continues to evolve, developers can expect richer, more innovative AI applications.
— End —
Data Thinking Notes
Sharing insights on data architecture, governance, and middle platforms, exploring AI in data, and linking data with business scenarios.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
