Get the FREE Ultimate OpenClaw Setup Guide →

mcptools

Model Context Protocol For R

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio posit-dev-mcptools Rscript -e mcptools::mcp_server()

How to use

mcptools implements the Model Context Protocol (MCP) for R. It can act as an MCP server that exposes a set of R tools and sessions which clients (like Claude, Copilot, or other MCP-enabled frontends) can invoke to run R code, inspect the global environment, and read package documentation. When configured as a server, you start mcptools via Rscript mcptools::mcp_server() and then register the server in your MCP client configuration (e.g., Claude Desktop or Claude Code) so the model can request tool actions against your R environment. You can also configure mcptools as an MCP client to consume or integrate third-party MCP servers, using the mcp_tools() helper to enumerate available tools and set_tools() to wire them into an Ellmer chat session.

In practice, you typically expose a reusable set of R-accessible tools through mcp_server(), and you can further tailor which functions are available by configuring sessions with mcp_session() so models can access specific variables or interactive sessions. The README provides concrete examples for registering mcptools as an MCP server in Claude Desktop and Claude Code, including an example that uses Rscript -e "mcptools::mcp_server()". If you’re using Ellmer-based clients, you can fetch the available tools via mcp_tools() and pass them to set_tools(), enabling the model to query data, describe objects, or run R code within your running sessions.

When using mcptools as a client, you can register third-party MCP servers (e.g., GitHub, Confluence, Google Drive) to enrich the context available to the model, similar to how mcptools can be extended with btw for a default toolset. The package emphasizes seamless integration with existing MCP tooling paradigms and provides practical configuration examples for Claude Desktop and Claude Code.

How to install

Prerequisites:

  • R (latest supported version) installed on the host
  • Internet access to install R packages
  1. Install mcptools from CRAN:
R
install.packages("mcptools")
  1. (Optional) Install the development version from GitHub via pak for the latest changes:
# If you have pak installed
pak::pak("posit-dev/mcptools")
  1. Start the MCP server (in a background process or separate terminal):
Rscript -e "mcptools::mcp_server()"
  1. Create your MCP client configuration (e.g., Claude Desktop or Claude Code) and reference the server. A typical configuration for R as an MCP server looks like:
{
  "mcpServers": {
    "r-mcptools": {
      "command": "Rscript",
      "args": ["-e", "mcptools::mcp_server()"]
    }
  }
}
  1. If you want to use mcptools as a client to a third-party MCP server, follow the usage in the README to obtain and register tool sets via mcp_tools() and set_tools().

Additional notes

Notes and tips:

  • The default configuration path for mcptools is ~/.config/mcptools/config.json; when you start the server, mcptools will look there to discover registered tools and sessions. You can customize the path if needed.
  • You can register R sessions via mcp_session() so models can access predefined variables or active sessions. This is useful when you want the model to inspect or manipulate data in a controlled environment.
  • To integrate with Ellmer-based workflows, call mcp_tools() to obtain the available tools and then pass them to the client’s tool set using set_tools().
  • If you’re using third-party MCP servers (e.g., GitHub MCP server, Google Drive MCP server) you can register them in your client config to enrich the model’s context.
  • Common issues: ensure the R process running the MCP server has the necessary permissions to start a long-running R session, and verify that the MCP client configuration points to the correct server address/port if you’re running remotely.

Related MCP Servers

Sponsor this space

Reach thousands of developers