MCP Agent via Docker keeps spawning new containers on each use
Bug Description
Hi team,
I’m encountering an issue when using Langflow with a Docker-based MCP setup.
Every time an MCP tool or agent is executed (e.g., during a chat session), Langflow spawns a new Docker container, and this happens every single time the agent runs. Over time, this leads to a buildup of many containers being created and removed, which could potentially affect performance or monitoring/logging setups.
The command used by the MCP agent is as follows:
docker run -i --rm mcp/fetch
Please see the attached image for an example of the container spawning behavior.
Reproduction
Steps to Reproduce:
- Create a new project in Langflow with components similar to the one shown in the attached image. The project should include:
- Chat input
- Output
- Agent
- MCP server
-
Use the mcp/fetch image as the MCP server. The command used to run it is:
docker run -i --rm mcp/fetch -
Run the playground and start a chat session that triggers the agent to call mcp/fetch.
-
Observe Docker: every time a tool is executed, a new container is created. The old containers are not cleaned up as expected, resulting in many containers piling up (as shown in the screenshot).
Expected behavior
Ideally, the MCP Docker tool should reuse an existing container or have a more efficient lifecycle mechanism rather than spawning a new one every time it is used.
Who can help?
@italojohnny @ogabrielluiz
Operating System
MacOS Sequoia 15.4
Langflow Version
1.3.3
Python Version
3.12
Screenshot
Flow File
Hey! How did you manage to make Langflow run "docker run" command to start mcp? Did you add docker as a dependency to langflow container? I'm just trying to do it and it's not successful.
Hi @lovelyscientist ,
Langflow automatically runs the docker run command to start the MCP server.
For example, with the MCP Server Fetch: https://github.com/modelcontextprotocol/servers/tree/main/src/fetch
According to the documentation, the docker command looks like this:
"mcpServers": {
"fetch": {
"command": "docker",
"args": ["run", "-i", "--rm", "mcp/fetch"]
}
}
So in Langflow, you just need to set the MCP command to:
docker run -i --rm mcp/fetch
Thanks @ifanzalukhu97 but I have this error when I add "docker run -i --rm mcp/fetch" as MCP command. Maybe this is because I use the standard MCP Component and you have something custom.
Hi @lovelyscientist ,
By the way, are you also running Langflow inside Docker? As far as I know, if you run Langflow using Docker, MCP can’t run Docker commands from inside it — because the Docker CLI isn’t available inside a Docker container by default.
If you want to use the MCP Docker servers, Langflow needs to be run using the PIP or UV version (not in a Docker container).
Alternatively, if you’re running Langflow in Docker, you might want to use the MCP servers that run via Python or NPX instead of Docker.
Thank you @ifanzalukhu97, yes I am running it inside the docker. Will try to find a workaround with other commands to start the mcp server.
Hey, @ifanzalukhu97 just in case, I fixed my issue by switching to SSE MCP connection, my MCP server is a separate docker container open on specific port. This is the MCP SSE URL http://{container_name}:{port}/sse
Hi @lovelyscientist, Awesome, thanks a lot for the update and for sharing!
Hi @ifanzalukhu97
Could you check if this error occurs in the latest version of Langflow?
thank you so much
I'm closing this issue because I haven't gotten a response. If the problem continues, please feel free to reopen it.