langflow icon indicating copy to clipboard operation
langflow copied to clipboard

MCP Agent via Docker keeps spawning new containers on each use

Open ifanzalukhu97 opened this issue 8 months ago • 7 comments

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:

  1. 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
  1. Use the mcp/fetch image as the MCP server. The command used to run it is: docker run -i --rm mcp/fetch

  2. Run the playground and start a chat session that triggers the agent to call mcp/fetch.

  3. 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

Image Image

Flow File

MCP Introduction.json

ifanzalukhu97 avatar Apr 17 '25 15:04 ifanzalukhu97

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.

lovelyscientist avatar May 15 '25 11:05 lovelyscientist

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

ifanzalukhu97 avatar May 15 '25 12:05 ifanzalukhu97

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.

Image

lovelyscientist avatar May 15 '25 13:05 lovelyscientist

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.

ifanzalukhu97 avatar May 15 '25 13:05 ifanzalukhu97

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.

lovelyscientist avatar May 15 '25 13:05 lovelyscientist

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

lovelyscientist avatar May 22 '25 11:05 lovelyscientist

Hi @lovelyscientist, Awesome, thanks a lot for the update and for sharing!

ifanzalukhu97 avatar May 22 '25 16:05 ifanzalukhu97

Hi @ifanzalukhu97

Could you check if this error occurs in the latest version of Langflow?

thank you so much

andifilhohub avatar Dec 09 '25 19:12 andifilhohub

I'm closing this issue because I haven't gotten a response. If the problem continues, please feel free to reopen it.

andifilhohub avatar Dec 16 '25 20:12 andifilhohub