📦

acquaint

by posit-dev/acquaint

0 views

Model Context Protocol Server For Your R Sessions

integrationCode Generation

acquaint A hexagonal logo showing a sparse, forested path opening up into a well-trodden meadow path.

Lifecycle:
experimental CRAN
status R-CMD-check

acquaint implements the [Model Context Protocol] in R. There are two sides to acquaint:

  • R as an MCP server: When configured with acquaint, 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, acquaint provides a default set of tools from btw 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.

IMPORTANT: This package is highly experimental and its interface may change rapidly!

Installation

You can install the development version of acquaint like so:

pak::pak("posit-dev/acquaint")

R as an MCP server

acquaint 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-acquaint": {
      "command": "Rscript",
      "args": ["-e", "acquaint::mcp_server()"]
    }
  }
}

Or, to use with Claude Code, you might type in a terminal:

claude mcp add -s "user" r-acquaint -- Rscript -e "acquaint::mcp_server()"

Then, if you’d like models to access variables in specific R sessions, call acquaint::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.)

R as an MCP client

acquaint 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, acquaint will look to file.path("~", ".config", "acquaint", "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/acquaint?")

Example

In Claude Desktop, I’ll write the following:

Using the R packages I have installed, write code to download data on flights in/out of Chicago airports in 2024.

In a typical chat interface, I’d be wary of two failure points here:

  1. The model doesn’t know which packages I have installed.
  2. If the model correctly guesses which packages I have installed, there may not be enough information about how to use the packages baked into its weights to write correct code.
A screencast of a chat with Claude. I ask 'Using the R packages I have installed, write code to download data on flights in/out of Chicago airports in 2024.' and, after searching through the documentation of my currently installed R packages, Claude writes R code to do so.

Through first searching through my installed packages, Claude can locate the anyflights package, which seems like a reasonable solution. The model then discovers the package’s anyflights() function and reads its documentation, and can pattern-match from there to write the correct code.

Install

{
  "mcpServers": {
    "acquaint": {
      "command": "Rscript",
      "args": [
        "-e",
        "acquaint::mcp_server()"
      ]
    }
  }
}
For more configuration details, refer to the content on the left

Related

Related projects feature coming soon

Will recommend related projects based on sub-categories