mcpr
Model Context Protocol server and client for R
claude mcp add --transport stdio devopifex-mcpr Rscript path/to/server.R \ --env R_LIBS_USER="Path to user library (optional)"
How to use
mcpr provides an MCP server implementation in R, enabling R applications to expose capabilities (tools, resources, and prompts) to AI models via a standard JSON-RPC 2.0 interface. It also includes client utilities to connect to and interact with MCP servers. With mcpr, you can define tools using a concise API, set up input schemas, and implement handlers that return one or more responses (text, images, audio, video, files, or resources). The package offers built-in support for HTTP transport as well as roxygen2-based automation to generate MCP servers from existing R functions via the mcpr roclet. You can also mix and match tooling styles, including ellmer tools, and integrate with clients such as Claude Code, Cursor, or VS Code Agent mode through documented integrations.
How to install
Prerequisites:
- R (>= 4.0)
- An R package manager (recommended: pak)
- Optional: internet access to install packages from CRAN/GitHub
Installation steps:
- Install the pak package (if not already installed):
install.packages("pak")
- Install mcpr directly from GitHub:
pak::pkg_install("devOpifex/mcpr")
- Verify installation by loading the package and listing available functions:
library(mcpr)
ls("package:mcpr")
- Start a basic MCP server example (after defining tools as shown in the README) and serve via HTTP if needed:
library(mcpr)
# Define a simple tool and server as shown in the README...
# Then start serving, for example:
# serve_http(mcp, port = 3000)
- Follow the Get Started guide in the mcpr docs for more advanced features and client integration.
Additional notes
Tips and notes:
- mcpr focuses on exposing R functions as MCP tools with clearly defined input schemas. Use new_tool to define a tool, including a descriptive name, input_schema, and a handler that returns one or more response objects.
- You can return multiple responses per call by returning a list of response objects (e.g., response_text, response_image, response_audio, etc.).
- The roxygen2 ROCLET allows auto-generating MCP servers from R functions annotated with @mcp and @type tags; this can speed up exposing existing functions.
- For HTTP transport, mcpr provides serve_http to expose the MCP server over a port. Ensure the port is available and not blocked by firewalls.
- Ellmer integration is supported, letting you mix mcpr tools with ellmer tools for flexible tool definitions.
- If you plan to deploy in a container or orchestration system, ensure the server script path is correctly mounted and the environment has the necessary R libraries installed.
- Environment variables like R_LIBS_USER or custom variables can be used to control library paths or configuration; document them in env for clarity.
Related MCP Servers
mcptools
Model Context Protocol For R
ClaudeR
Connect RStudio to Claude, Codex, Gemini, and other AI assistants via MCP. Multi-agent orchestration, async execution, and zero-config setup with uvx.
MCPR
MCPR enables AI agents to participate in interactive R sessions for professional analysis workflows.
rstudiomcp
MCP (Model Context Protocol) server for RStudio - Bridge your RStudio session with Claude Code