writing-skills
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
containerize-mcp-serverContainerize an R-based MCP (Model Context Protocol) server using Docker. Covers mcptools integration, port exposure, stdio vs HTTP transport, and connecting Claude Code to the containerized server. Use when deploying an R MCP server without requiring a local R installation, creating a reproducible MCP server environment, running MCP servers alongside other…
Independent GitHub snapshot · Automated classification · Original documentation governs
Package R MCP server into Docker container for portable deployment.
FROM rocker/r-ver:4.5.0
# Install system dependencies
RUN apt-get update && apt-get install -y \
libcurl4-openssl-dev \
libssl-dev \
libxml2-dev \
libgit2-dev \
libssh2-1-dev \
git \
curl \
&& rm -rf /var/lib/apt/lists/*
# Install R packages
RUN R -e "install.packages(c( \
'remotes', \
'ellmer' \
), repos='https://cloud.r-project.org/')"
# Install mcptools
RUN R -e "remotes::install_github('posit-dev/mcptools')"
# Set working directory
WORKDIR /workspace
# Expose MCP server ports
EXPOSE 3000 3001 3002
# Environment variables
ENV R_LIBS_USER=/workspace/renv/library
ENV RENV_PATHS_CACHE=/workspace/renv/cache
# Default: start MCP server
CMD ["R", "-e", "mcptools::mcp_server()"]
Got: Dockerfile exists in project root with rocker/r-ver base image, system dependencies, mcptools installation, MCP server as default command.
If fail: Verify base image tag matches your R version. remotes::install_github fails? Check git and libgit2-dev are in system dependencies layer.
version: '3.8'
services:
mcp-server:
build:
context: .
dockerfile: Dockerfile
container_name: r-mcp-server
image: r-mcp-server:latest
volumes:
- /path/to/projects:/workspace
- renv-cache:/workspace/renv/cache
stdin_open: true
tty: true
network_mode: "host"
environment:
- TERM=xterm-256color
- R_LIBS_USER=/workspace/renv/library
restart: unless-stopped
volumes:
renv-cache:
driver: local
Using network_mode: "host" ensures MCP server ports accessible on localhost.
Got: docker-compose.yml in project root with MCP server service, volume mounts for project files and renv cache, stdin_open/tty enabled for stdio transport.
If fail: Volume paths invalid? Adjust /path/to/projects to actual project directory. On Windows/WSL, use /mnt/c/... or /mnt/d/... paths.
docker compose build
docker compose up -d
Got: Container starts with MCP server running.
If fail: Check logs with docker compose logs mcp-server. Common issues:
For stdio transport (container must stay running with stdin):
claude mcp add r-mcp-docker stdio "docker" "exec" "-i" "r-mcp-server" "R" "-e" "mcptools::mcp_server()"
For HTTP transport (if MCP server supports it):
{
"mcpServers": {
"r-mcp-docker": {
"type": "http",
"url": "http://localhost:3000/mcp"
}
}
}
Got: Claude Code MCP configuration includes r-mcp-docker server entry. claude mcp list shows new server.
If fail: Stdio transport? Ensure container name matches (r-mcp-server) and container running with docker ps. HTTP transport? Verify port exposed, reachable with curl http://localhost:3000/mcp.
# Check container is running
docker ps | grep mcp-server
# Test R session inside container
docker exec -it r-mcp-server R -e "sessionInfo()"
# Verify mcptools is available
docker exec -it r-mcp-server R -e "library(mcptools)"
Got: docker ps shows r-mcp-server container running. sessionInfo() returns expected R version. library(mcptools) loads without error.
If fail: Container not running? Check docker compose logs mcp-server for startup errors. mcptools fails to load? Rebuild image to ensure package installed correctly.
To add project-specific MCP tools, mount R scripts:
volumes:
- ./mcp-tools:/mcp-tools
Load them in CMD:
CMD ["R", "-e", "source('/mcp-tools/custom_tools.R'); mcptools::mcp_server()"]
Got: Custom R scripts accessible inside container at /mcp-tools/. MCP server loads them on startup alongside default tools.
If fail: Verify volume mount path correct with docker exec -it r-mcp-server ls /mcp-tools/. Scripts fail to source? Check missing package dependencies in custom tools.
stdin_open: true and tty: truenetwork_mode: "host" or expose specific ports.create-r-dockerfile - base Dockerfile patterns for Rsetup-docker-compose - compose configuration detailsconfigure-mcp-server - MCP server configuration without Dockertroubleshoot-mcp-connection - debugging MCP connectivity issues