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

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

Cộng đồng
phisanti

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

Nhà phát hànhphisanti
Kho mãMCPR
Ngôn ngữHTML
Bản fork
6
Sao
26
Công cụ có sẵn
0
Phương thức truyền tảistdio
Danh mục
Giấy phépCC-BY-SA-4.0
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    MCPR:用于 R 中有状态人机协作的实用框架 cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    26 sao và 6 bản fork từ kho mã được liên kết.

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.

Cài đặt

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

Dùng MCP MCPR:用于 R 中有状态人机协作的实用框架 với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối MCPR:用于 R 中有状态人机协作的实用框架, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm MCPR:用于 R 中有状态人机协作的实用框架 làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của MCPR:用于 R 中有状态人机协作的实用框架.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "mcpr": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của MCPR:用于 R 中有状态人机协作的实用框架, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của MCPR:用于 R 中有状态人机协作的实用框架.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng MCPR:用于 R 中有状态人机协作的实用框架 giúp tôi làm việc này không?
MCPR:用于 R 中有状态人机协作的实用框架
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng MCPR:用于 R 中有状态人机协作的实用框架.

Câu hỏi thường gặp

Máy chủ MCP MCPR:用于 R 中有状态人机协作的实用框架 dùng để làm gì?

MCPR:用于 R 中有状态人机协作的实用框架 là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP MCPR:用于 R 中有状态人机协作的实用框架 với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng MCPR:用于 R 中有状态人机协作的实用框架 với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP MCPR:用于 R 中有状态人机协作的实用框架 với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối MCPR:用于 R 中有状态人机协作的实用框架, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP MCPR:用于 R 中有状态人机协作的实用框架 với TypingMind?

MCPR:用于 R 中有状态人机协作的实用框架 hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP MCPR:用于 R 中有状态人机协作的实用框架 cung cấp những công cụ nào trong TypingMind?

MCPR:用于 R 中有状态人机协作的实用框架 cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP MCPR:用于 R 中有状态人机协作的实用框架 không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu MCPR:用于 R 中有状态人机协作的实用框架 yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇