Install mcptools
mainYou can install the stable version of mcptools from CRAN or the development version using pak.
# Install from CRAN
install.packages("mcptools")
# Install development version
pak::pak("posit-dev/mcptools")repository·main·Indexed 41 days ago
https://github.com/posit-dev/mcptoolsmcptools implements the Model Context Protocol (MCP) in R, enabling bidirectional communication between AI coding assistants and R sessions. It allows R to function as an MCP server, enabling AI to run R code and inspect environments, or as an MCP client to integrate third-party tools into ellmer chats. It supports configuration for Claude Desktop, Claude Code, and deployment to Posit Connect.
You can install the stable version of mcptools from CRAN or the development version using pak.
# Install from CRAN
install.packages("mcptools")
# Install development version
pak::pak("posit-dev/mcptools")You can use mcptools to register third-party MCP servers (using the Claude Desktop configuration format) into ellmer chats.
By default, mcptools looks for a configuration file at file.path("~", ".config", "mcptools", "config.json"). Once configured, use mcp_tools() to retrieve the tools and pass them to an ellmer chat object via $set_tools().
# Example: Integrating GitHub MCP server into an ellmer chat
ch <- ellmer::chat_anthropic()
ch$set_tools(mcp_tools())
ch$chat("What issues are open on posit-dev/mcptools?")To deploy an MCP server to Posit Connect, follow these steps:
_server.yml file in your project directory:engine: mcptools
tools: tools.Rrsconnect:rsconnect::deployAPI(".", contentCategory = "mcp")https://connect.example.com/content/abc123/, your MCP endpoint will be https://connect.example.com/content/abc123/mcp.Note: If you cannot set contentCategory = "mcp" during deployment, set the MCP category in Connect manually after deployment and ensure minimum processes are set to at least 1.
engine: mcptools
tools: tools.Rrsconnect::deployAPI(".", contentCategory = "mcp")To use mcptools with Claude Code, run the following command in your terminal to add the server:
claude mcp add -s "user" r-mcptools -- Rscript -e "mcptools::mcp_server()"To allow Claude Desktop to run R code in your sessions, add the r-mcptools server to your Claude Desktop configuration file.
On macOS, this file is located at ~/Library/Application Support/Claude/claude_desktop_config.json.
{
"mcpServers": {
"r-mcptools": {
"command": "Rscript",
"args": ["-e", "mcptools::mcp_server()"]
}
}
}By default, the MCP server provides tools for R. To allow models to access variables and objects in specific R sessions, call mcptools::mcp_session() within those sessions.
Tip: You can add mcptools::mcp_session() to your .Rprofile (using usethis::edit_r_profile()) to automatically register every R session you start.
mcptools::mcp_session()