Lets AI clients run R code in active sessions and registers third-party MCP servers as tools in R chats.
Also known as posit-dev/mcptools
- Stars
- 206
- Tools
- —
- Downloads, 30 days
- —
- Latest version
- —
- Last commit
- Oct 20, 2026
- License
- —
What is mcptools MCP?
mcptools lets AI clients run R code in active sessions and registers third-party MCP servers as tools in R chats.
Summary generated from the project's README
About mcptools MCP server
Running R code directly within your active AI coding sessions is what mcptools enables for data scientists and developers. By implementing the Model Context Protocol in R, this package allows AI assistants like Claude Desktop, Claude Code, and VS Code GitHub Copilot to interact with your live R environment. You can use the mcp_server function to expose R functions as tools, or use the mcp_session function to grant models access to specific variables and objects in your running sessions.
Beyond acting as a server, the package also functions as an MCP client. This allows you to register third-party MCP servers, such as those for GitHub, Confluence, or Google Drive, into your R-based chat applications. By using the mcp_tools function with the ellmer library, you can integrate these external tools into apps like shinychat or querychat, bringing diverse data sources into your R-driven conversational interfaces.
What you can do with it
- 1Querying live R session dataAsk an AI assistant to find specific values or summary statistics from a data frame currently loaded in your interactive R session.
Written from the project's README. Every use case is checked against a quote from it.
Configuration
GITHUB_PERSONAL_ACCESS_TOKEN
| Name | Description | |
|---|---|---|
| GITHUB_PERSONAL_ACCESS_TOKEN | — |
Automated checks
Ran Nov 13, 2026Full report →Not verified yet. A server needs a score of 80, no serious finding, and enough data for us to check. How checks work · What to fix for more points
- Source repository linked and reachableposit-dev/mcptools is public and reachablegithub.com/posit-dev/mcptools ↗Pass
- Package names this repository as its sourceNot checked
- Build provenance (Sigstore attestation)Not checked
- Open source license (OSI)No licenseFinding
- Commit or release in the last yearLast commit or release 2026-10-20github.com/posit-dev/mcptools ↗Pass
- OpenSSF ScorecardNot checked
- Package name not close to a popular packageNot checked
- No critical advisory in the package or its dependenciesNot checked
- No hidden instructions to the model0 tool descriptions and the README read; no override phrases, credential paths or hidden charactersPass
- Destructive tools are labelledNot checked
- Remote endpoint answers the MCP handshakeNot checked
README
View on GitHubmcptools
mcptools implements the Model Context Protocol in R. There are two sides to mcptools:
R as an MCP server:
When configured with mcptools, MCP-enabled tools like Claude Desktop, Claude Code, and VS Code GitHub Copilot can run R code in the sessions you have running to answer your questions. While the package supports configuring arbitrary R functions, you may be interested in the btw package’s integrated support for mcptools, which provides a default set of tools to to peruse the documentation of packages you have installed, check out the objects in your global environment, and retrieve metadata about your session and platform.
R as an MCP client:
Register third-party MCP servers with ellmer chats to integrate additional context into e.g. shinychat and querychat apps.
Installation
Install mcptools from CRAN with:
install.packages("mcptools")
You can install the development version of mcptools like so:
pak::pak("posit-dev/mcptools")
R as an MCP server
mcptools can be hooked up to any application that supports MCP. For
example, to use with Claude Desktop, you might paste the following in
your Claude Desktop configuration (on macOS, at
~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"r-mcptools": {
"command": "Rscript",
"args": ["-e", "mcptools::mcp_server()"]
}
}
}
Or, to use with Claude Code, you might type in a terminal:
claude mcp add -s "user" r-mcptools -- Rscript -e "mcptools::mcp_server()"
Then, if you’d like models to access variables in specific R sessions,
call mcptools::mcp_session() in those sessions. (You might include a
call to this function in your .Rprofile, perhaps using
usethis::edit_r_profile(), to automatically register every session you
start up.)
To deploy an HTTP MCP server to Posit Connect, add a _server.yml file
with engine: mcptools and a tools file:
engine: mcptools
tools: tools.R
Deploy the directory as an R API and mark it as MCP content:
rsconnect::deployAPI(".", contentCategory = "mcp")
If the content URL is https://connect.example.com/content/abc123/, use
https://connect.example.com/content/abc123/mcp as the MCP endpoint.
If you cannot set contentCategory = "mcp" during deployment, set the
MCP category in Connect after deploying and set minimum processes to at
least 1.
R as an MCP client
mcptools uses the Claude Desktop configuration file format to register third-party MCP servers, as most MCP servers provide setup instructions for Claude Desktop in their documentation. For example, here’s what the official GitHub MCP server configuration would look like:
{
"mcpServers": {
"github": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"GITHUB_PERSONAL_ACCESS_TOKEN",
"ghcr.io/github/github-mcp-server"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
}
}
}
}
Once the configuration file has been created (by default, mcptools will
look to file.path("~", ".config", "mcptools", "config.json")),
mcp_tools() will return a list of ellmer tools which you can pass
directly to the $set_tools() method from ellmer:
ch <- ellmer::chat_anthropic()
ch$set_tools(mcp_tools())
ch$chat("What issues are open on posit-dev/mcptools?")
Example
In Claude Desktop, I’ll write the following:
“From what year is the earliest recorded sample in the
foresteddata in my Positron session?”
Without mcptools, Claude couldn’t get far here; by default, it can’t run R code and doesn’t have any way to “speak to” my interactive R sessions.
Using the package, the model asks to describe the data frame using a structure that will show summary statistics from the data. mcptools will appropriately route the request to the open Positron session, forwarding the results back to the model for it to situate in a response.
mcptools MCP questions
Can Claude Desktop run R code from my session?
Yes. With mcptools configured as an MCP server, tools like Claude Desktop, Claude Code, and VS Code Copilot can run R code in the sessions you have running.
How do I install mcptools in R?
Install the released version from CRAN with install.packages("mcptools"), or the development version from GitHub with pak::pak("posit-dev/mcptools").
How do I connect mcptools to Claude Desktop?
Add an entry to your Claude Desktop configuration file that runs Rscript -e "mcptools::mcp_server()" as the server command.
Can R use third-party MCP servers as tools?
Yes. mcptools registers third-party MCP servers using the Claude Desktop config format, and mcp_tools() returns ellmer tools you can pass to a chat's $set_tools() method.
Can I deploy an mcptools MCP server to Posit Connect?
Yes. Add a _server.yml with engine: mcptools and a tools file, deploy the directory as an R API, and mark it as MCP content.