Cannot create Chatflow as MCP Tool with Docker + localhost #24207
Replies: 1 comment
-
|
Hi @naisy! I'm Dosu and I’m helping the dify team. This is a known Docker networking issue: inside a container, Your workaround—using Best practice is to avoid Currently, Dify does not automatically generate Docker-aware MCP URLs, and documentation does not clearly cover this scenario. It would help if the docs explained this networking behavior and recommended correct MCP URL formats for Docker deployments. Your suggestion to update the docs or improve URL generation logic is spot on. To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Self Checks
Dify version
1.7.1
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
Title
Cannot create Chatflow as MCP Tool with Docker + localhost
Version
docker compose -f docker-compose.yaml -p dify up -d)Description
My environment
localhostThe problem is: what does
localhostrefer to in this context?When I enable the MCP server for a Chatflow, Dify generates a URL like:
When I try to add this in:
Tools → MCP → Add MCP Server (HTTP)
I get the following error:
Cause
localhostrefers to the container itself, so it tries to connect to port 80 of the API container.https://github.com/langgenius/dify/blob/1.7.1/docker/nginx/conf.d/default.conf.template#L42-L45
Solution
Use this URL instead of the generated one:
Also add the following to the API service’s environment variables in
docker-compose.yaml:After these changes, I was able to connect successfully and call the Chatflow as an MCP tool:
Notes
This appears to be a Docker + localhost specific behavior.
✔️ Expected Behavior
When running in Docker on localhost, Dify should generate an MCP server URL with the correct host/port
(e.g.,
http://localhost:5001/mcp/server/<serverid>/mcp), or document that this change is required.❌ Actual Behavior
When enabling the MCP server for a Chatflow in Docker on localhost,
Dify generates a URL like
http://localhost/mcp/server/<serverid>/mcp.When this URL is used in Tools → MCP → Add MCP Server (HTTP),
the connection fails with:
Beta Was this translation helpful? Give feedback.
All reactions