Back to Skills

containerize-mcp-server

pjt222
Updated 2 days ago
8 views
17
2
17
View on GitHub
Metaaimcpdesign

About

This skill containerizes R-based MCP servers using Docker, enabling deployment without local R installations. It handles mcptools integration, port exposure, and transport configuration (stdio/HTTP) for reproducible environments. Use it to run MCP servers alongside other containerized services or distribute them to other developers.

Quick Install

Claude Code

Recommended
Primary
npx skills add pjt222/agent-almanac -a claude-code
Plugin CommandAlternative
/plugin add https://github.com/pjt222/agent-almanac
Git CloneAlternative
git clone https://github.com/pjt222/agent-almanac.git ~/.claude/skills/containerize-mcp-server

Copy and paste this command in Claude Code to install this skill

Documentation

容 MCP 伺

以 Docker 包 R MCP 伺為可移部。

用時

  • 部 R MCP 伺而無本 R 裝
  • 建可復之 MCP 伺境
  • 與他容服並行 MCP 伺
  • 分 MCP 伺於他開者

  • :R MCP 伺之實(mcptools 基或自)
  • :Docker 已裝行
  • 可選:伺所需他 R 包
  • 可選:傳之模(stdio 或 HTTP)

第一步:建 Dockerfile 為 MCP 伺

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()"]

得: 項目根有 Dockerfilerocker/r-ver 基像、系依、mcptools 裝、MCP 伺為默令。

敗則: 驗基像合汝 R 版。若 remotes::install_github 敗,察 gitlibgit2-dev 於系依層。

第二步:建 docker-compose.yml

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

network_mode: "host" 保 MCP 伺埠於 localhost 可訪。

得: 項目根有 docker-compose.yml 附 MCP 伺服、項目檔與 renv 緩之卷掛、stdin_open/tty 啟為 stdio 傳。

敗則: 若卷徑誤,改 /path/to/projects 為實項徑。Windows/WSL 則用 /mnt/c/.../mnt/d/... 徑。

第三步:建而啟

docker compose build
docker compose up -d

得: 容啟附 MCP 伺行。

敗則:docker compose logs mcp-server 察誌。常問:

  • 缺 R 包:加於 Dockerfile RUN 裝步
  • 埠已用:改露埠或止衝服

第四步:連 Claude Code 於容

stdio 傳(容須附 stdin 續行):

claude mcp add r-mcp-docker stdio "docker" "exec" "-i" "r-mcp-server" "R" "-e" "mcptools::mcp_server()"

HTTP 傳(若 MCP 伺支):

{
  "mcpServers": {
    "r-mcp-docker": {
      "type": "http",
      "url": "http://localhost:3000/mcp"
    }
  }
}

得: Claude Code 之 MCP 設含 r-mcp-docker 條,claude mcp list 示新伺。

敗則: stdio 傳則確容名合(r-mcp-server)且以 docker ps 察容行。HTTP 傳則驗埠露且可達以 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)"

得: docker psr-mcp-server 容行,sessionInfo() 返期 R 版,library(mcptools) 載無誤。

敗則: 若容不行,察 docker compose logs mcp-server 啟誤。若 mcptools 載敗,重建像保包正裝。

第六步:加自定 MCP 具

加項特 MCP 具,掛 R 腳:

volumes:
  - ./mcp-tools:/mcp-tools

於 CMD 中載:

CMD ["R", "-e", "source('/mcp-tools/custom_tools.R'); mcptools::mcp_server()"]

得: 自 R 腳於容內 /mcp-tools/ 可訪,MCP 伺啟時載之與默具並。

敗則: 驗卷掛徑以 docker exec -it r-mcp-server ls /mcp-tools/。若腳 source 敗,察自具之缺依。

  • 容建無誤
  • 容內 MCP 伺啟
  • Claude Code 可連於容伺
  • MCP 具應請
  • 容清重啟
  • 卷掛許訪項檔

  • stdin/tty 之需:MCP stdio 傳需 stdin_open: truetty: true
  • 網隔:默 Docker 網或阻 localhost 訪。用 network_mode: "host" 或露特埠。
  • 包版:固 mcptools 於特提交為可復
  • 像大:mcptools 附依可大。產考多階建。
  • Windows Docker 徑:於 Windows 附 WSL 行 Docker Desktop 時徑映異

  • create-r-dockerfile - R 之基 Dockerfile 式
  • setup-docker-compose - compose 設詳
  • configure-mcp-server - 無 Docker 之 MCP 伺設
  • troubleshoot-mcp-connection - 察 MCP 連之問

GitHub Repository

pjt222/agent-almanac
Path: i18n/wenyan/skills/containerize-mcp-server
0
agentsagentskillsai-assisted-developmentclaude-codeskillsteams

Related Skills

content-collections

Meta

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

View skill

polymarket

Meta

This skill enables developers to build applications with the Polymarket prediction markets platform, including API integration for trading and market data. It also provides real-time data streaming via WebSocket to monitor live trades and market activity. Use it for implementing trading strategies or creating tools that process live market updates.

View skill

creating-opencode-plugins

Meta

This skill helps developers create OpenCode plugins that hook into 25+ event types like commands, files, and LSP operations. It provides the plugin structure, event API specifications, and implementation patterns for JavaScript/TypeScript modules. Use it when you need to intercept, monitor, or extend the OpenCode AI assistant's lifecycle with custom event-driven logic.

View skill

sglang

Meta

SGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.

View skill