TL;DR: `connection refused` from a containerized Redis MCP server usually means it is trying to reach Redis at `the loopback address`, which inside the container is itself. Set `REDIS_HOST` to the real address: `host.YOUR_HOST` for Redis on your laptop, or the container/service name on a shared Docker network.

```text
Error: connect ECONNREFUSED the loopback address:6379
```

## Fix it

1. Figure out where Redis actually lives relative to the MCP server:
   - Redis on your laptop, MCP server in Docker: host is `host.YOUR_HOST`.
   - Both in Docker Compose: host is the service name, e.g. `redis`.
   - Both on the host: `the loopback address` is correct, check Redis is running.

2. Set it explicitly. Do not rely on the default:

```bash
REDIS_HOST=host.YOUR_HOST
REDIS_PORT=6379
```

   In a client config `env` block, add `"REDIS_HOST": "host.YOUR_HOST"`.

3. Verify from inside the same network namespace if you can:

```bash
docker run --rm redis:7 redis-cli -h host.YOUR_HOST ping
```

   Expected: `PONG`.

4. Restart the MCP server.

   Expected: connection refused is gone.

## When to use this

- `redis-cli ping` works on your host but the MCP server gets ECONNREFUSED.
- The MCP server runs in Docker and Redis runs elsewhere.

## When NOT to use this

- Both run on the same host outside Docker and it still refuses. Then Redis is not running or not listening on 6379.
- The error is NOAUTH or WRONGPASS. The connection works; auth is the problem.

## Compatibility

- redis/mcp-redis in Docker / Docker Compose.
- Docker Desktop (macOS/Windows) supports `host.YOUR_HOST`. On Linux, add `--add-host=host.YOUR_HOST:host-gateway`.

## Why it happens

Every container has its own loopback interface. `the loopback address` inside the MCP container never leaves the container, so it can only reach a Redis running in that same container. The default `REDIS_HOST=the loopback address` is only correct when server and Redis share a network namespace.

## Edge cases

- `--network=host` on Linux makes container YOUR_HOST equal host YOUR_HOST, but it does not work on Docker Desktop for Mac/Windows.
- If Redis is bound to `the loopback address` in its own config, other containers cannot reach it even by service name. Bind Redis to `the all-interfaces address` (with a password) for container networking.
- Port mappings (`-p 6379:6379`) matter for host-to-container, not container-to-container. On a shared network, use the container port directly.