MCP Client
as Agent Strategy Plugin.
[!IMPORTANT] Dify is not
MCP Server
butMCP Host
.
Each MCP client
(ReAct Agent) node can connect MCP servers
.
Tool
, Resource
, Prompt
lists are converted into Dify Tools.name
, description
, argument type
[!NOTE] Most of the code in this repository contains the following files.
Dify Official Plugins / Agent Strategies
https://github.com/langgenius/dify-official-plugins/tree/main/agent-strategies/cot_agent
ReAct.py
and renamed file as mcpReAct.py
config_json
GUI input field by editing mcpReAct.yaml
and class mcpReActParams()
__init__()
for initializing AsyncExitStack
and event loop
_handle_invoke_action()
for MCP_invoke()
[!IMPORTANT] ReAct while loop is as they are
[!CAUTION] This plugin does not implement a human-in-the-loop mechanism by default, so connect reliable mcp server only.
To avoid it, decreasemax itereations
(default:3
) to1
, and use this Agent node repeatedly in Chatflow.
However, agent memory is reset by the end of Workflow.
UseConversaton Variable
to save history and pass it to QUERY.
Don't forget to add a phrase such as "ask for user's permission when calling tools" in INSTRUCTION.
https://github.com/3dify-project/dify-mcp-client/
.difypkg
Issue: If you encounter the error message: plugin verification has been enabled, and the plugin you want to install has a bad signature
, how to handle the issue?
Solution: Open /docker/.env
and change from true
to false
:
FORCE_VERIFYING_SIGNATURE=false
Run the following commands to restart the Dify service:
cd docker
docker compose down
docker compose up -d
Once this field is added, the Dify platform will allow the installation of all plugins that are not listed (and thus not verified) in the Dify Marketplace.
[!TIP] Marketplace need Approval. If stars⭐ reach 100, I'll consider to make PR for them.
MCP Agent Plugin node require config_json like this to command or URL to connect MCP servers
{
"mcpServers":{
"name_of_server1":{
"url": "http://host.docker.internal:8080/sse"
},
"name_of_server2":{
"url": "http://host.docker.internal:8008/sse"
}
}
}
[!WARNING]
- Each server's port number should be different, like 8080, 8008, ...
- If you want to use stdio mcp server, there are 3 ways.
- Convert it to SSE mcp server https://github.com/3dify-project/dify-mcp-client/edit/main/README.md#how-to-convert-stdio-mcp-server-into-sse-mcp-server
- Deploy with source code (NOT by .difypkg or GitHub reposity name install) https://github.com/3dify-project/dify-mcp-client/edit/main/README.md#-how-to-develop-and-deploy-plugin
- Pre-install Node.js inside dify-plugin docker (issue:https://github.com/3dify-project/dify-mcp-client/issues/10) guide: https://github.com/tangyoha/tangyoha-bili/tree/master/dify/mcp/map_mcp
[!WARNING]
- The Tools field should not be left blank. so select Dify tools like "current time".
.yml
for testing this plugin.https://github.com/3dify-project/dify-mcp-client/tree/main/test/chatflow
https://github.com/modelcontextprotocol/servers/tree/main/src/everything
stdio
MCP server into SSE MCP serverIf fastMCP server, change like this
if __name__ == "__main__":
- mcp.run(transport="stdio")
+ mcp.run(transport="sse")
\mcp-proxy>uv venv -p 3.12
.venv\Scripts\activate
uv tool install mcp-proxy
(Mac/Linux)
which npx
(Windows)
where npx
result
C:\Program Files\nodejs\npx
C:\Program Files\nodejs\npx.cmd
C:\Users\USER_NAME\AppData\Roaming\npm\npx
C:\Users\USER_NAME\AppData\Roaming\npm\npx.cmd
If claude_desktop_config.json is following schema,
{
"mcpServers": {
"SERVER_NAME": {
"command": CMD_NAME_OR_PATH
"args": {VALUE1, VALUE2}
}
}
}
mcp-proxy --sse-port=8080 --pass-environment -- CMD_NAME_OR_PATH --arg1 VALUE1 --arg2 VALUE2 ...
If your OS is Windows, use npx.cmd instead of npx. Following is example command to convert stdio "everything MCP server" to SSE via mcp-proxy.
mcp-proxy --sse-port=8080 --pass-environment -- C:\Program Files\nodejs\npx.cmd --arg1 -y --arg2 @modelcontextprotocol/server-everything
Similarly, on another command line (If you use sample Chatflow for v0.0.3)
pip install mcp-simple-arxiv
mcp-proxy --sse-port=8008 --pass-environment -- C:\Users\USER_NAME\AppData\Local\Programs\Python\Python310\python.exe -m -mcp_simple_arxiv
Following is a mcp-proxy setup log.
(mcp_proxy) C:\User\USER_NAME\mcp-proxy>mcp-proxy --sse-port=8080 --pass-environment -- C:\Program Files\nodejs\npx.cmd --arg1 -y --arg2 @modelcontextprotocol/server-everything
DEBUG:root:Starting stdio client and SSE server
DEBUG:asyncio:Using proactor: IocpProactor
DEBUG:mcp.server.lowlevel.server:Initializing server 'example-servers/everything'
DEBUG:mcp.server.sse:SseServerTransport initialized with endpoint: /messages/
INFO: Started server process [53104]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8080 (Press CTRL+C to quit)
https://github.com/3dify-project/dify-mcp-client/blob/main/GUIDE.md
If your OS is Windows and CPU is Intel or AMD, you need to download dify-plugin-windows-amd64.exe
(v0.0.7)
Choose your OS-compatible verson here:
https://github.com/langgenius/dify-plugin-daemon/releases
dify.exe
to under dify-mcp-client/[!TIP] Following guide is helpful. https://docs.dify.ai/plugins/quick-start/develop-plugins/initialize-development-tools
https://docs.dify.ai/plugins/quick-start/develop-plugins/initialize-development-tools
[!NOTE] You can skip this stage if you pull or download codes of this repo
dify plugin init
Initial settings are as follow
cd dify-mcp-client
Python3.12+ is compatible. The venv
and uv
are not necessary, but recommended.
uv venv -p 3.12
.venv\Scripts\activate
Install python modules for plugin development
uv pip install -r requirements.txt
env.example
and rename one to .env
I changed REMOTE_INSTALL_HOST
from debug.dify.ai
to localhost
(Docker Compose environment)
click 🪲bug icon button to see these information
python -m main
(ctrl+C to stop)
[!TIP] REMOTE_INSTALL_KEY of .env often changes. If you encounter error messages like
handshake failed, invalid key
, renew it.
./dify-mcp-client
is my default root name
dify plugin package ./ROOT_OF_YOUR_PROJECT
https://github.com/langgenius/dify-plugin-sdks
https://github.com/modelcontextprotocol/python-sdk
[!TIP] MCP client example
https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/clients/simple-chatbot/mcp_simple_chatbot/main.py
[!NOTE] Dify plugin has
requirements.txt
which automatically installs python modules.
I include latestmcp
in it, so you don't need to download the MCP SDK separately.
Seamless access to top MCP servers powering the future of AI integration.