---
title: "Using MVPapp with AI"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Using MVPapp with AI}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(collapse = TRUE, comment = "#>", eval = FALSE)
```

_Last updated: 2026-12-03_

## Motivation  

You can ask an AI assistant such as Claude to run MVP for you, in plain language:

> Use MVP to simulate 100 mg once daily for a week in 50 adults with a one-compartment oral
> model, and show me the concentrations over time.

The assistant picks the model, sets up the dosing and the virtual patients, runs the
simulation with MVPapp, and shows you the plot and the key numbers, together with the
assumptions it made. You do not need to know R or install anything on your computer.

Everything the app does is available this way: simulations with a built-in model or your own
(from a paper, a NONMEM run or model code), virtual populations, comparing doses, the
percentage of patients above a target, parameter sensitivity, and exploring your own data.
The results come from MVPapp itself, so they are the same as in the app.

## Setup

Pick the line that best describes your situation (you only do this once).

| What you have | What to set up | Time |
|---|---|---|
| An AI chat app that supports skills and can run code (e.g. Claude), no R | The MVPapp skill | 2 minutes |
| R and MVPapp on your computer, and Claude desktop or Claude Code | The MVPapp plugin | 5 minutes |
| R and MVPapp on your computer, and another assistant that supports MCP (e.g. Codex, Gemini CLI, Cursor) | MVPapp's MCP server (see "Technical details" at the end) | 10 minutes |

### No R: an AI chat app with skills

MVPapp's skill is a folder in the open [Agent Skills](https://agentskills.io) format, so it is
not tied to one assistant. The assistant installs MVPapp in its own workspace in the cloud and
runs it there. You need an app that supports skills and can run code with internet access
(MVPapp is installed from GitHub and the Ubuntu package archives). It has been tested with
Claude.

1. In the app's settings, turn on code execution (in Claude: **Settings > Capabilities**,
   "Create and edit files").
2. Download
   [`mvpapp-skill.zip`](https://github.com/stevechoy/MVPapp/raw/master/claude-plugin/mvpapp-skill.zip).
3. Add it as a skill (in Claude: **Customize > Skills**, click **+**, then **Create skill >
   Upload a skill**, and choose the file). Upload the ZIP as it is, not just the `SKILL.md`
   inside it: it also holds the installer and the reference files the skill needs.

That's it. The first request in each new conversation takes about 2 minutes while the assistant
sets up MVPapp; after that, answers come in seconds. Everything runs in the assistant's
workspace except opening results in the MVPapp app, which needs R on your own computer.

**If your organisation manages the app**, an administrator may need to turn on code execution,
skills and network access, or can add the skill for everyone. In Claude (Team or Enterprise
plans), an owner controls these settings:

* **Organization settings > Plugins & skills > Policy**: "Cloud code execution and file
  creation" and "Skills" must be on. Users can upload their own skills only if "User-created
  skills" is on; otherwise, or to save everyone steps 2 and 3, an owner can upload
  `mvpapp-skill.zip` once for the whole organisation (**Add > Upload a skill** on the same
  page).
* **Organization settings > Capabilities**, network access: the default ("package managers
  only") is enough, as it includes GitHub and the Ubuntu package archives, which the installer
  uses. MVPapp cannot be installed if network access is turned off. To start from a link or
  DOI of a paper, also allow `www.ebi.ac.uk` (Europe PMC); attaching the paper works without it.

**No install usage (prompt-only)**: in an AI chat app that can run code with internet access,
you can also start a conversation by pasting this paragraph before your request:

```text
Use MVP (the MVPapp R package) for this. First set it up: run "git clone --depth 1 https://github.com/stevechoy/MVPapp",
then "bash MVPapp/claude-plugin/skills/mvpapp/scripts/install_mvpapp.sh", and read
MVPapp/claude-plugin/skills/mvpapp/SKILL.md and the reference files it points to, and follow them.
```

Without the skill or this paragraph, the assistant does not know how to install MVPapp in its
workspace and will tell you it cannot run it.

### R and MVPapp on your computer

MVPapp then runs on your own computer: your files stay there, and the assistant can open
results in the MVPapp app for you. The assistant connects to MVPapp's tools through the Model
Context Protocol (MCP). For Claude, the MVPapp plugin sets this up:

* **Claude desktop app**: go to **Customize > Plugins > Add > Add marketplace**, enter
  `stevechoy/MVPapp`, then install **mvpapp**. When asked for `Rscript`, give the full path
  that `MVPapp::mvp_mcp_config()` prints in R (on Windows, e.g.
  `C:/Program Files/R/R-4.5.1/bin/Rscript.exe`). Alternatively, run
  `MVPapp::mvp_mcp_config(install = TRUE)` in R and restart the Claude desktop app.
* **Claude Code**: run `claude plugin marketplace add stevechoy/MVPapp`, then
  `claude plugin install mvpapp@mvpapp`.

For other assistants that support MCP (e.g. OpenAI Codex, Gemini CLI, Cursor), see "Technical
details" at the end. The MVPapp tools need the optional packages mcptools and ellmer:
`install.packages(c("mcptools", "ellmer"))`.

## Example requests

Start your request with "Use MVP" (or "Use MVPapp": the assistant knows both names) so it
knows which tool to use, and say what you know: the dose and schedule, the units, and who the patients are. Anything you leave out
is filled in with the model's default values, which the assistant lists for you.

### Simulate a dosing regimen

> Use MVP to simulate 100 mg once daily for a week in 50 adults with a one-compartment
> oral model, and show me the concentrations over time.

> Use MVP to simulate a two-compartment model with CL = 3 L/h and Vc = 10 L: a 500 mg
> 1-hour infusion, then 250 mg every 12 hours for 3 days, in a typical 70 kg adult.

> Use MVP to simulate a loading dose of 100 mg, then 50 mg once weekly for 12 weeks, with
> a two-compartment model. Show the concentrations in weeks on a log scale.

You get a plot of the concentrations (the median and the 95% range for a population), the
peak, trough and AUC, and the list of doses and parameter values used.

### Choose the patients

> Use MVP to simulate 10 mg/kg once daily for 5 days in 100 children aged 6 to 12, using
> the CDC growth data. How do concentrations differ between the lightest and heaviest
> children?

> Use MVP to simulate 200 adults aged 40 to 75 from NHANES, with creatinine clearance
> normally distributed (mean 60, SD 20 mL/min) and 30% Japanese patients. Show me a summary
> of the simulated patients.

Virtual patients are drawn from the NHANES (US adults and children), CDC or WHO (children)
growth data, with extra characteristics you describe.

### Compare doses and check targets

> With MVP, compare 200 mg once daily and 100 mg twice daily over 2 weeks in 200 adults.
> What percentage of patients stay above 0.5 mg/L at the trough?

> Use MVP to find which dose keeps 90% of patients above 2 mg/L at the trough at steady
> state: 50, 100 or 200 mg once daily.

> Use MVP to compare Model 1 (CL = 3 L/h) and Model 2 (CL = 6 L/h) for 100 mg once daily,
> as box plots of the trough concentration on the last day.

You get the profiles side by side, box plots or a table of exposures, and the percentage of
patients above (or below) the target.

### Start from a published model

Give the link or DOI of the paper. The assistant downloads the paper and its supplementary files
(the model code is often there), loads the final model, and uses the study's dosing, patients
and sampling times unless you say otherwise.

> Use MVP to simulate the model from this paper with the dosing they studied: _(paste its DOI
> or link)_

> Use MVP to simulate the final model in PMC7654321 in 200 children aged 2 to 11, at the
> doses the study used. Show the concentrations at the study's sampling times.

> Use MVP to simulate the model in this paper's supplementary NONMEM code for 12 weeks of
> the recommended dose, and compare the steady-state exposure with what the paper reports.

You get the model it used (the file or table), each default it took from the study (with the
section or table), the simulation, and a comparison with the exposures the paper reports.
Open-access papers work best. For a paywalled paper, it works only if your computer has access
to it; otherwise the assistant asks you to attach the PDF and the supplementary files. When
MVPapp runs in the assistant's workspace (no R), allow `www.ebi.ac.uk` (Europe PMC) in the
app's network settings first.

### Start from a model you already have

> _(attach the paper as a PDF)_ Use MVP to simulate the final model in this paper: 300 mg
> every 3 weeks for 6 cycles in 100 patients aged 40 to 75. List every parameter value you
> used and the table it came from.

> _(attach the NONMEM control stream, e.g. run7.mod, and its run7.ext)_ Use MVP to
> simulate this NONMEM model with 10 mg/kg every 2 weeks in 100 adults, and plot the
> concentrations.

> Use MVP to simulate this model: one compartment with first-order absorption,
> ka = 1.2 /h, CL = 4 L/h, V = 35 L, 30% variability on CL and V. Dose 50 mg twice daily
> for 10 days.

The assistant translates the model into MVPapp's format using the same instructions as the
app's AI translation, checks that it works, and tells you which values it took from where.
Attach the NONMEM `.ext` file too, so it uses the final estimates rather than the initial
ones.

### Get the model as code

You can also ask only for the translation, e.g. to check the model or to use it in the app later.

> _(attach the paper as a PDF)_ Use MVP to translate the final model in this paper into
> mrgsolve code and give me the .cpp file. List each parameter value and the table it came from.

> _(attach run7.mod and run7.ext)_ Use MVP to translate this NONMEM model to mrgsolve and
> give me the .cpp file.

> _(attach the paper as a PDF)_ Use MVP to translate the final model in this paper into rxode2
> code.

> _(attach the paper as a PDF)_ Use MVP to write this model as a NONMEM control stream.

For mrgsolve, you get a `.cpp` file that has compiled in MVPapp, the parameter values with
where each came from, and what was checked. Open it in the app with "Upload External .cpp
File", or in mrgsolve. For NONMEM or rxode2, you get a `.ctl` or `.R` file written with the
app's NONMEM or rxode2 instructions: MVPapp checks that a control stream has the blocks it
needs, and rxode2 code is checked by rxode2 where it is installed, but MVPapp cannot run
either, so check them in NONMEM or rxode2. This needs no API key: the assistant translates
the model itself, with the same instructions as the app's AI translation.

### Work with your own data

> _(attach a de-identified CSV)_ Use MVP to summarise this dataset, plot concentration
> over time coloured by dose, and run a non-compartmental analysis (NCA) on the first dose.

> Use MVP to overlay my observed data on the simulation, only the plasma concentrations
> (CMT 2), with the median of the data.

> Use MVP to show the correlations between weight, age and creatinine clearance in my
> dataset, and histograms of each.

If MVPapp runs on your computer, give the file's location instead of attaching it, e.g.
`C:/data/study1.csv`.

### Understand what drives exposure

> Use MVP to show which parameters affect the AUC the most for this model, as a tornado
> plot.

> Use MVP to show what happens to the trough concentration if clearance is halved or
> doubled.

### Keep and share the results

> Give me a file that a pharmacometrician can use to reproduce this simulation.

> Give me one file that reproduces this comparison.

> Save the simulated concentrations as a CSV file.

> Open both regimens in the MVP app so I can keep exploring. _(R on your computer only.)_

### Follow-up requests

Once you have a result, keep the conversation going:

> Now double the dose.

> Use 500 patients instead.

> Zoom in on the last day, on a log scale.

> Only show me the trough concentrations, as a table.

## Checking the answers

Treat the assistant like a capable colleague whose work you review:

* **Check the dosing and the parameter values** it reports against what you asked for, and,
  for a model from a paper, against the paper's tables.
* **Read the assumptions**: the route (oral or IV), the units, the dosing compartment, any
  effect of body weight in the model, and values left at their defaults.
* **Ask why** if a number surprises you ("why is the trough so low?"), or ask for the plot on a
  log scale.
* For a decision that matters, ask for the reproducible file (above) and have it checked by a
  pharmacometrician.

## Privacy and limits

* **Data**: when MVPapp runs in the assistant's workspace (no R), files you attach and the
  results are processed on the provider's servers. Use de-identified data only. With MVPapp on your computer, your files
  stay there.
* **Publications**: papers are downloaded from Europe PMC (open access) or the publisher, under
  your access. Check that the model and the study design were read correctly.
* **Assistants**: the skill and the MCP tools follow open standards (Agent Skills, MCP) and
  are not tied to one assistant, but they have been tested with Claude. The skill needs an app
  that supports skills and can run code with internet access; the MCP tools need an assistant
  that can start a local MCP server (e.g. Claude desktop, Claude Code, OpenAI Codex, Gemini CLI,
  Cursor). Chat apps that only connect to remote MCP servers cannot use the tools on your
  computer, but may still use the skill.
* **The app**: opening results in the MVPapp app needs MVPapp on your computer.

## Technical details

This section is for people who set up the connection by hand or support other users.

**How it works.** MVPapp's analyses are R functions (see `vignette("scripting")`). An
assistant reaches them in one of two ways: it runs R code itself, guided by MVPapp's skill
file (in a chat app, in the app's own workspace), or it calls MVPapp's tools through the
[Model Context Protocol](https://modelcontextprotocol.io) (MCP), served by R on your computer
with `mvp_mcp_server()`. The tools (`mvp_load_model`, `mvp_simulate`, `mvp_compare`,
`mvp_target`, `mvp_plot`, `mvp_open_in_app`, ...) wrap the same functions; plots are returned
to the assistant as images, and files are written to `output_dir`. No API key is needed for
translating models: the assistant translates them itself with the app's prompts (or your own,
with `mvp_mcp_server(prompts_path = ...)`). The `mvp_guide` tool gives the assistant the
skill's advice.

**Settings for your computer.** `mvp_mcp_config()` prints them, with the full path to
`Rscript`:

```{r}
MVPapp::mvp_mcp_config(output_dir = "~/MVP-outputs")                 # prints the settings
MVPapp::mvp_mcp_config(output_dir = "~/MVP-outputs", install = TRUE) # adds them to Claude Desktop
```

For Claude Desktop the settings look like this (`claude_desktop_config.json`):

```json
{
  "mcpServers": {
    "mvpapp": {
      "command": "Rscript",
      "args": ["-e", "MVPapp::mvp_mcp_server(output_dir = '~/MVP-outputs')"]
    }
  }
}
```

and for Claude Code:

```bash
claude mcp add mvpapp -- Rscript -e "MVPapp::mvp_mcp_server(output_dir = '~/MVP-outputs')"
```

**Other assistants.** Any assistant that can start a local MCP server takes the same command
and arguments, e.g. OpenAI Codex
(`codex mcp add mvpapp -- Rscript -e "MVPapp::mvp_mcp_server(output_dir = '~/MVP-outputs')"`)
or Gemini CLI (`gemini mcp add mvpapp Rscript -e "..."`). On Windows, use the full path to
`Rscript.exe`. Ask the assistant to read `mvp_guide` first.

**The skill files.** Assistants that run R code themselves can use the skill shipped with the
package (the plugin and `mvpapp-skill.zip` include it):

```{r}
# SKILL.md and its references/ folder; e.g. for Claude Code, as a personal skill:
src  <- system.file("ai", package = "MVPapp")
dest <- "~/.claude/skills/mvpapp"
for (f in list.files(src, recursive = TRUE)) {
  dir.create(dirname(file.path(dest, f)), recursive = TRUE, showWarnings = FALSE)
  file.copy(file.path(src, f), file.path(dest, f), overwrite = TRUE)
}
```

In a workspace without R, the skill's installer
(`claude-plugin/skills/mvpapp/scripts/install_mvpapp.sh` on GitHub) sets up R and MVPapp,
also where CRAN cannot be reached.
