Running the MCP and nREPL servers in a container - bhauman/clojure-mcp GitHub Wiki
Why would I do that
The AI can be pretty unpredictable about what it does via the MCP tools, and that's why many AI assistants would ask for a user confirmation before using tools with potentially harmful side effects.
If you don't want to always review the commands or if you simply want a better safety by default, it is wise to limit those side effects more or less to only the intended cases, and that's why running the MCP server and the nREPL in an isolated environment makes sense.
The setup with Docker
To run the nREPL server in a container, have this Dockerfile
at the root of your Clojure project:
FROM clojure:temurin-21-tools-deps
WORKDIR /app
EXPOSE 7888
CMD ["clojure", "-M:nrepl"]
You want to mount your project folder to the container's filesystem. They will both point to the same files which can be edited both from inside and outside the container. Also, you want to be able to connect the nREPL from outside the container, so the nREPL port is exposed outside the container.
Have this docker-compose.yml
file also at the root:
services:
nrepl:
build: .
ports:
- "7888:7888"
volumes:
- .:/app
working_dir: /app
You can start/stop the nREPL server like:
docker-compose up # '-d' option for 'detached' will run in the background
docker-compose down
Then to run the MCP server inside the same container, your can run:
docker-compose exec nrepl clojure -X:mcp