Skip to content
Back to search

mcptools

Model Context Protocol For R

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/posit-dev--mcptools/badge.svg)](/listings/posit-dev--mcptools)

HTML

<a href="/listings/posit-dev--mcptools"><img src="/api/listings/posit-dev--mcptools/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

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](https://github.com/github/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?")

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 163 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. <!-- README.md is generated from README.Rmd. Please edit that file -->
  2. # mcptools <a href="https://posit-dev.github.io/mcptools/"><img src="man/figures/logo.png" align="right" height="240" alt="A hexagonal logo showing a bridge connecting two portions of a forested meadow." /></a>
  3. <!-- badges: start -->
  4. [![Lifecycle:
  5. experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
  6. [![CRAN
  7. status](https://www.r-pkg.org/badges/version/mcptools)](https://CRAN.R-project.org/package=mcptools)
  8. [![R-CMD-check](https://github.com/posit-dev/mcptools/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/posit-dev/mcptools/actions/workflows/R-CMD-check.yaml)
  9. <!-- badges: end -->
  10. mcptools implements the [Model Context
  11. Protocol](https://modelcontextprotocol.io/) in R. There are two sides to
  12. mcptools:
  13. **R as an MCP server**:
  14. <img src="man/figures/r_as_a_server.png" alt="A system architecture diagram showing three main components: Client (left), Server (center), and Session (right). The Client box lists AI coding assistants including Claude Desktop, Claude Code, Copilot Chat in VS Code, and Positron Assistant. The Server is initiated with `mcp_server()` and contains tools for R functions like reading package documentation, running R code, and inspecting global environment objects. Sessions can be configured with `mcp_session()` and can optionally connect to interactive R sessions, with two example projects shown: 'Some R Project' and 'Other R Project'." width="100%" />
  15. When configured with mcptools, MCP-enabled tools like Claude Desktop,
  16. Claude Code, and VS Code GitHub Copilot can run R code *in the sessions
  17. you have running* to answer your questions. While the package supports
  18. configuring arbitrary R functions, you may be interested in the
  19. [btw](https://posit-dev.github.io/btw/) package’s integrated support for
  20. mcptools, which provides a default set of tools to to peruse the
  21. documentation of packages you have installed, check out the objects in
  22. your global environment, and retrieve metadata about your session and
  23. platform.
  24. **R as an MCP client**:
  25. <img src="man/figures/r_as_a_client.png" alt="An architecture diagram showing the Client (left) with R code using the ellmer library to create a chat object and then setting tools from mcp with `mcp_tools()`, and the Server (right) containing third-party tools including GitHub (for reading PRs/Issues), Confluence (for searching), and Google Drive (for searching). Bidirectional arrows indicate communication between the client and server components." width="100%" />
  26. Register third-party MCP servers with
  27. [ellmer](https://ellmer.tidyverse.org/) chats to integrate additional
  28. context into e.g. [shinychat](https://github.com/posit-dev/shinychat)
  29. and [querychat](https://posit-dev.github.io/querychat/) apps.
  30. ## Installation
  31. Install mcptools from CRAN with:
  32. ``` r
  33. install.packages("mcptools")
  34. ```
  35. You can install the development version of mcptools like so:
  36. ``` r
  37. pak::pak("posit-dev/mcptools")
  38. ```
  39. ### R as an MCP server
  40. mcptools can be hooked up to any application that supports MCP. For
  41. example, to use with Claude Desktop, you might paste the following in
  42. your Claude Desktop configuration (on macOS, at
  43. `~/Library/Application Support/Claude/claude_desktop_config.json`):
  44. ``` json
  45. {
  46. "mcpServers": {
  47. "r-mcptools": {
  48. "command": "Rscript",
  49. "args": ["-e", "mcptools::mcp_server()"]
  50. }
  51. }
  52. }
  53. ```
  54. Or, to use with Claude Code, you might type in a terminal:
  55. ``` bash
  56. claude mcp add -s "user" r-mcptools -- Rscript -e "mcptools::mcp_server()"
  57. ```
  58. Then, if you’d like models to access variables in specific R sessions,
  59. call `mcptools::mcp_session()` in those sessions. (You might include a
  60. call to this function in your .Rprofile, perhaps using
  61. `usethis::edit_r_profile()`, to automatically register every session you
  62. start up.)
  63. To deploy an HTTP MCP server to Posit Connect, add a `_server.yml` file
  64. with `engine: mcptools` and a `tools` file:
  65. ``` yaml
  66. engine: mcptools
  67. tools: tools.R
  68. ```
  69. Deploy the directory as an R API and mark it as MCP content:
  70. ``` r
  71. rsconnect::deployAPI(".", contentCategory = "mcp")
  72. ```
  73. If the content URL is `https://connect.example.com/content/abc123/`, use
  74. `https://connect.example.com/content/abc123/mcp` as the MCP endpoint.
  75. If you cannot set `contentCategory = "mcp"` during deployment, set the
  76. MCP category in Connect after deploying and set minimum processes to at
  77. least 1.
  78. ### R as an MCP client
  79. mcptools uses the Claude Desktop configuration file format to register
  80. third-party MCP servers, as most MCP servers provide setup instructions
  81. for Claude Desktop in their documentation. For example, here’s what the
  82. [official GitHub MCP
  83. server](https://github.com/github/github-mcp-server) configuration would
  84. look like:
  85. ``` json
  86. {
  87. "mcpServers": {
  88. "github": {
  89. "command": "docker",
  90. "args": [
  91. "run",
  92. "-i",
  93. "--rm",
  94. "-e",
  95. "GITHUB_PERSONAL_ACCESS_TOKEN",
  96. "ghcr.io/github/github-mcp-server"
  97. ],
  98. "env": {
  99. "GITHUB_PERSONAL_ACCESS_TOKEN": "<YOUR_TOKEN>"
  100. }
  101. }
  102. }
  103. }
  104. ```
  105. Once the configuration file has been created (by default, mcptools will
  106. look to `file.path("~", ".config", "mcptools", "config.json")`),
  107. `mcp_tools()` will return a list of ellmer tools which you can pass
  108. directly to the `$set_tools()` method from ellmer:
  109. ch <- ellmer::chat_anthropic()
  110. ch$set_tools(mcp_tools())
  111. ch$chat("What issues are open on posit-dev/mcptools?")
  112. ## Example
  113. In Claude Desktop, I’ll write the following:
  114. > “From what year is the earliest recorded sample in the `forested` data
  115. > in my Positron session?”
  116. Without mcptools, Claude couldn’t get far here; by default, it can’t run
  117. R code and doesn’t have any way to “speak to” my interactive R sessions.
  118. <img src="https://github.com/user-attachments/assets/064df664-2669-498e-a644-fb191a30235f" alt="A screencast of a chat with Claude. After the question is asked, a tool called 'describe data frame' is called with the `data_frame` argument set to `forested`. The results are returned from mcptools as json, which the model then integrates into its response: 'Based on the data structure, I can see there's a `year` column with values ranfing from 1995 to 2024. The earliest recorded sample in the `forested` data is from 1995.'" width="100%" />
  119. Using the package, the model asks to describe the data frame using a
  120. structure that will show summary statistics from the data. mcptools will
  121. appropriately route the request to the open Positron session, forwarding
  122. the results back to the model for it to situate in a response.

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.