MCPR:用于 R 中有状态人机协作的实用框架 标志

MCPR:用于 R 中有状态人机协作的实用框架

社区
phisanti

MCPR enables AI agents to participate in interactive R sessions for professional analysis workflows.

发布者phisanti
代码仓库MCPR
语言HTML
复刻数
6
星标数
26
可用工具
0
传输类型stdio
分类
许可协议CC-BY-SA-4.0
链接
  • 将工具接入 AI 工作流

    MCPR:用于 R 中有状态人机协作的实用框架 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 26 个 Star 和 6 个 Fork。

MCPR: A Practical Framework for Stateful Human-AI Collaboration in R

Lifecycle:
experimental R-CMD-check Codecov test
coverage GitHub release (latest by
date)

The MCPR (Model Context Protocol Tools for R) package addresses a fundamental limitation in the current paradigm of AI-assisted R programming. Existing AI agents operate in a stateless execution model, invoking Rscript for each command, which is antithetical to the iterative, state-dependent nature of serious data analysis. An analytical workflow is a cumulative process of exploration, modelling, and validation that can span hours or days. Moreover, intermediate steps can involve heavy computation, and small changes in downstream code such as plot aesthetics require running the entire script again. MCPR aims to tackle this issue by enabling AI agents to establish persistent, interactive sessions within a live R environment, thereby preserving workspace state and enabling complex, multi-step analytical workflows.

Quick Start

Get up and running with MCPR in under 2 minutes:

r
# 1. Install MCPR
remotes::install_github("phisanti/MCPR")

# 2. Configure your AI agent to launch the MCPR server
library(MCPR)
install_mcpr(agent = "claude")

# 3. In your AI agent (Claude, etc.), start using MCPR tools
# MCPR::mcpr_server() is the agent's private R session by default

# 4. Optionally attach to a live R session with manage_r_sessions()
# Example: execute_r_code("summary(mtcars)")

That’s it! Your AI agent can execute R code, create plots, and inspect a persistent private workspace. If you want the agent to work inside an existing interactive R session, run mcpr_session_start() there and attach with manage_r_sessions().

Core capabilities

MCPR’s design is guided by principles of modularity, robustness, and practicality.

  • Communication Protocol: MCPR uses JSON-RPC 2.0 over nanonext sockets, providing a lightweight, asynchronous, and reliable messaging layer. This choice ensures cross-platform compatibility and non-blocking communication suitable for an interactive environment.
  • Tool-Based Design: Functionality is exposed to the AI agent as a discrete set of tools (show_plot, execute_r_code, etc.). This modular approach simplifies the agent’s interaction logic and provides clear, well-defined endpoints for R operations.
  • Session Management: The MCP server process is a private R session by default. The optional manage_r_sessions tool can list attachable sessions, join a human session started with mcpr_session_start(), start a secondary session, detach back to private/local execution, or close MCPR-owned secondary sessions.
  • Graphics Subsystem: Plot generation leverages httpgd when available for high-performance, off-screen rendering. A fallback to standard R graphics devices (grDevices) ensures broad compatibility. The system includes intelligent token management to prevent oversized image payloads.

Installation

The first requirement is to have R installed and then install the MCPR package from GitHub:

r
if (!require("remotes")) install.packages("remotes")

remotes::install_github("phisanti/MCPR")

Next, you should install the MCP server to give the agent access to the tools included in the package. System integration is designed to be straightforward, with both automated and manual pathways.

Automated Setup

A convenience function, install_mcpr(), is provided to handle package installation and agent-specific MCP configuration. Supported agents include Claude, Gemini, Copilot, and Codex.

r
library(MCPR)
install_mcpr(agent = "claude") # Supported agents: 'claude', 'gemini', 'copilot', 'codex'

Manual MCP Configuration

For Claude Desktop, configure claude_desktop_config.json. You can likely find it in one of these locations depending on your OS:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json Linux: ~/.config/claude/claude_desktop_config.json

Then, add the following MCP server configuration:

json
{
  "mcpServers": {
    "mcpr": {
      "command": "R",
      "args": ["--quiet", "--slave", "-e", "MCPR::mcpr_server()"]
    }
  }
}

Supported agents

Currently, MCPR supports configuration for the following AI agents with the given configuration paths (note that these are approximate and might vary based on OS and installation):

  • Claude: Claude Desktop config at ~/Library/Application Support/Claude/claude_desktop_config.json (macOS), %APPDATA%/Claude/claude_desktop_config.json (Windows), or ~/.config/Claude/claude_desktop_config.json (Linux).
  • Gemini: Global settings at ~/.gemini/settings.json (use ./.gemini/settings.json for a project-local setup).
  • Copilot: Workspace configuration at .vscode/mcp.json (user-level fallback at ~/.config/Code/User/mcp.json or %APPDATA%/Code/User/mcp.json).
  • Codex: Global TOML configuration at ~/.codex/config.toml.

Usage Pattern

The intended workflow is simple and user-centric.

  1. The MCP client launches MCPR::mcpr_server().
  2. Ordinary tools run in that server process, which is the agent’s private R session.
  3. If the user wants collaboration inside an existing R console, they run mcpr_session_start() in that console.
  4. The agent uses manage_r_sessions('list') and manage_r_sessions('join', session=ID) to attach. Ordinary tools still omit session; the runtime sends them to the active session until manage_r_sessions('detach') returns execution to private/local.

Agent tools

The philosophy in the development of the MCPR package is to provide the agent with few, well-defined tools that can be composed to perform complex tasks. The goal was to give the agent a persistent private R workspace by default, optional attachment controls (manage_r_sessions), code execution (execute_r_code), graphical data (show_plot), and session inspection (view). Ordinary tools do not take a session argument; attachment is controlled separately. See the details below.

execute_r_code(code)

Purpose: Execute arbitrary R code in the active session Input: Character string containing R expressions Output: Structured response with results, output, warnings, and errors

r
execute_r_code("
  library(dplyr)
  data <- mtcars %>%
    filter(mpg > 20) %>%
    select(mpg, cyl, wt)
  nrow(data)
")

show_plot(expr, target, width, height, format)

Purpose: Create and display R plots with target-based output selection Input: R plotting expression, target (‘user’ or ‘agent’), dimensions and format (agent only) Output: For target=‘user’ (default): displays the plot to the user via the active graphics device. For target=‘agent’: returns a base64-encoded image with metadata and token usage information.

r
# Show a plot to the user (default)
show_plot("
  library(ggplot2)
  ggplot(mtcars, aes(wt, mpg)) +
    geom_point() +
    geom_smooth(method = 'lm')
")

# Render a plot for agent analysis
show_plot("
  ggplot(mtcars, aes(wt, mpg)) + geom_point()
", target = "agent", width = 600, height = 450)

manage_r_sessions(action, session)

Purpose: Optional session attachment and management Actions:

  • "list": Show the private session, active session, and attachable sessions
  • "join": Attach to a specific human session by ID
  • "start": Launch and attach an MCPR-owned secondary R session
  • "detach": Return ordinary tools to the private/local session
  • "close": Close an MCPR-owned secondary session
r
manage_r_sessions("list")        # Show available sessions
manage_r_sessions("join", 2)     # Attach to human session 2
manage_r_sessions("start")       # Create and attach a secondary session
manage_r_sessions("detach")      # Return to the private session

view(what, max_lines)

Purpose: Environment introspection and debugging what:

  • 'session': Object summaries with statistical metadata
  • 'terminal': Command history for workflow reproducibility
  • 'workspace': File system context
  • 'installed_packages': Available libraries

Common errors

  • Attachment Failed: If you want to attach to a live R console, ensure mcpr_session_start() is running there. Set the MCPTOOLS_LOG_FILE environment variable to a valid path and inspect logs for detailed error messages.
  • Tools Not Found: Confirm the path in user_mcp.json is correct and that the agent has been restarted. Manually install the MCP server to verify the setup.
  • Plotting Errors: Ensure the plotting expression is valid and that all necessary libraries are loaded, and install httpgd.

If these issues persist, please open an issue on the GitHub repository with relevant logs and context.

Acknowledgments

We thank Simon P. Couch (mcptools) for the inspiration to use nanonext and Aleksander Dietrichson (mcpr) for the idea of using roxygen2 for parsing tools.


This project is licensed under the Creative Commons Attribution 4.0 International License.

安装

TypingMind
{
  "mcpServers": {
    "mcpr": {
      "command": "Rscript",
      "args": [
        "-e",
        "MCPR::mcp_server()"
      ]
    }
  }
}

将 MCPR:用于 R 中有状态人机协作的实用框架 MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 MCPR:用于 R 中有状态人机协作的实用框架 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请保持终端窗口及其中的进程运行。
3

将 MCPR:用于 R 中有状态人机协作的实用框架 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 MCPR:用于 R 中有状态人机协作的实用框架 MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "mcpr": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 MCPR:用于 R 中有状态人机协作的实用框架 MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 MCPR:用于 R 中有状态人机协作的实用框架 MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 MCPR:用于 R 中有状态人机协作的实用框架 帮我完成这项任务吗?
MCPR:用于 R 中有状态人机协作的实用框架
当然。我已阅读。
以下是我使用 MCPR:用于 R 中有状态人机协作的实用框架 得到的结果。

常见问题

MCPR:用于 R 中有状态人机协作的实用框架 MCP 服务器有什么用途?

MCPR:用于 R 中有状态人机协作的实用框架 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 MCPR:用于 R 中有状态人机协作的实用框架 MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您可以让 Claude、ChatGPT、Gemini 等不同 AI 模型,或您在 TypingMind 中配置的其他模型使用 MCPR:用于 R 中有状态人机协作的实用框架,而无需为每个模型单独配置 MCP 服务器。

为什么在 TypingMind 中使用 MCPR:用于 R 中有状态人机协作的实用框架 MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是优秀的大语言模型聊天前端之一。连接 MCPR:用于 R 中有状态人机协作的实用框架 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 MCPR:用于 R 中有状态人机协作的实用框架 MCP 连接到 TypingMind?

MCPR:用于 R 中有状态人机协作的实用框架 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

MCPR:用于 R 中有状态人机协作的实用框架 MCP 在 TypingMind 中提供哪些工具?

MCPR:用于 R 中有状态人机协作的实用框架 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 MCPR:用于 R 中有状态人机协作的实用框架 MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行掌控模型提供商、API 密钥、提示词和 MCP 配置。如果 MCPR:用于 R 中有状态人机协作的实用框架 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇