MCP Client node in n8n workflow unable to establish connection with local FastAPI MCP server

I’m having trouble getting my n8n automation to work with a FastAPI MCP server that I built locally. The MCP Client node keeps throwing connection errors even though I know my server is running properly.

I already tested my MCP server using MCP-Inspector and it shows all the tools correctly. I also tried it with Cursor IDE and everything works fine there, so the server itself is definitely working.

The error I get in n8n says it cannot connect to the MCP server. I’m running n8n in Docker with this command:

docker run -it --rm --name automation-tool \
  -p 5678:5678 \
  -v workflow_data:/home/node/.n8n \
  -e N8N_SKIP_RESPONSE_COMPRESSION=true \
  docker.n8n.io/n8nio/n8n

I added the compression skip flag because I read that gzip might cause issues with SSE transport, but it didn’t help.

My n8n version info:

  • Version: 1.94.1
  • Platform: docker self-hosted
  • Node.js: 20.19.1
  • Database: sqlite
  • License: enterprise production

I tried looking at similar issues but none of the solutions worked for me. The MCP Client node configuration points to my local server endpoint but it just won’t connect.

Has anyone successfully connected n8n to a local MCP server? What could be causing this connection failure?

Update: Fixed

The issue was with the URL I was using. I had http://localhost:8000/mcp but since n8n runs in Docker, localhost refers to the container, not my host machine. Changing it to http://host.docker.internal:8000/mcp solved the problem!

Another Docker networking gotcha! If host.docker.internal doesn’t work, try running n8n with --network=host. Less isolated but skips all the container networking mess. Also check your FastAPI server logs for actual connection attempts - n8n’s error messages can be misleading and the real problem might be something else entirely.

Good catch on the Docker networking issue. This trips up tons of developers when containerizing apps. If you’re hitting similar problems, check that your FastAPI server binds to the right interface. Use 0.0.0.0:8000 instead of 127.0.0.1:8000 or localhost:8000 - otherwise Docker can’t reach it even with host.docker.internal. Hit this exact problem last month with another service and wasted hours debugging before I figured out it was the binding interface. Also check your firewall isn’t blocking port communication between container and host.

Had the same issue with MCP connections in Docker. Besides the networking fix, check your MCP server’s CORS setup if you haven’t. FastAPI gets weird about cross-origin requests from containerized clients. I added CORS middleware with allow_origins=["*"] for dev work and it fixed my connection drops. On Linux, you might need --add-host=host.docker.internal:host-gateway in your run command since host.docker.internal isn’t available by default like it is on Mac/Windows Docker Desktop.