MCPR: A Practical Framework for Stateful Human-AI Collaboration in R 
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:
# 1. Install MCPR
remotes::install_github("phisanti/MCPR")
# 2. Start an R session and make it discoverable
library(MCPR)
mcpr_session_start()
# 3. In your AI agent (Claude, etc.), connect to the session
# The agent will use: manage_r_sessions("list") then manage_r_sessions("join", session_id)
# 4. Now your AI agent can run R code in your live session!
# Example: execute_r_code("summary(mtcars)")





