# peterbloomingdale/pmxagent architecture

> Architecture diagram of the GitHub repository peterbloomingdale/pmxagent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/peterbloomingdale/pmxagent
- Repository: https://github.com/peterbloomingdale/pmxagent

## Overview

PMxAgent turns pharmacometrics workflows into agent-callable tools: an MCP client invokes the Python server, which discovers and proxies the R Plumber API; its endpoints produce analysis, simulation, and standardized-data results. The graph preserves the five documented endpoint branches and their major domain engines. Endpoint implementations are represented by their exact tree paths, but their internals were not sampled; links to domain engines and the DATA-to-NCA handoff rely on README documentation.

Main entry points: [`apis/rapi.R`](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/rapi.R) (Plumber API), [`apis/endpoints/pk.R`](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/pk.R) (PK endpoint), [`server.py`](https://github.com/peterbloomingdale/pmxagent/blob/main/server.py) (MCP server), [`apis/endpoints/data.R`](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/data.R) (Data formatting)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_access["Agent access"]
  node_mcp["MCP server<br/>[server.py]"]
  node_oauth["OAuth tokens<br/>[server.py]"]
end

subgraph group_api["R API"]
  node_plumber["Plumber API<br/>[rapi.R]"]
end

subgraph group_analysis["Analysis workflows"]
  node_nca["NCA endpoint<br/>[nca.R]"]
  node_er["Exposure-response<br/>[er.R]"]
  node_pk["PK endpoint<br/>[pk.R]"]
  node_data["Data formatting<br/>[data.R]"]
  node_library["Model library<br/>[library.R]"]
  node_data_utils["Data processing<br/>[data_processing.R]"]
end

subgraph group_models["Model engines"]
  node_one_cm["One-compartment model<br/>[1CM.cpp]"]
  node_two_cm["Two-compartment model<br/>[2CM.cpp]"]
  node_er_models["ER model fitting<br/>[er_models.R]"]
  node_library_models["Literature PK models<br/>[nlmixr2lib_sim.R]"]
  node_mrgsolve["mrgsolve simulation<br/>[mrgsolve_pk.R]"]
end

node_agent(("AI agent"))

node_agent -->|"invokes tools"| node_mcp
node_mcp -->|"authenticates clients"| node_oauth
node_mcp -->|"discovers and proxies"| node_plumber
node_plumber -->|"routes requests"| node_nca
node_plumber -->|"routes requests"| node_er
node_plumber -->|"routes requests"| node_pk
node_plumber -->|"routes requests"| node_data
node_plumber -->|"routes requests"| node_library
node_data -.->|"standardizes data"| node_data_utils
node_data -->|"feeds formatted data"| node_nca
node_pk -.->|"simulates"| node_one_cm
node_pk -.->|"simulates"| node_two_cm
node_pk -.->|"uses simulation"| node_mrgsolve
node_er -.->|"fits models"| node_er_models
node_library -.->|"simulates library models"| node_library_models

click node_mcp "https://github.com/peterbloomingdale/pmxagent/blob/main/server.py"
click node_oauth "https://github.com/peterbloomingdale/pmxagent/blob/main/server.py"
click node_plumber "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/rapi.R"
click node_nca "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/nca.R"
click node_er "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/er.R"
click node_pk "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/pk.R"
click node_data "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/data.R"
click node_library "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/library.R"
click node_data_utils "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/utils/data_processing.R"
click node_one_cm "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/models/1CM.cpp"
click node_two_cm "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/models/2CM.cpp"
click node_er_models "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/models/er_models.R"
click node_library_models "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/models/nlmixr2lib_sim.R"
click node_mrgsolve "https://github.com/peterbloomingdale/pmxagent/blob/main/apis/models/mrgsolve_pk.R"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mcp,node_oauth toneBlue
class node_plumber toneAmber
class node_nca,node_er,node_pk,node_data,node_library,node_data_utils toneMint
class node_one_cm,node_two_cm,node_er_models,node_library_models,node_mrgsolve toneRose
class node_agent toneIndigo
```

## Components

### Agent access

- [MCP server](https://github.com/peterbloomingdale/pmxagent/blob/main/server.py): `server.py`
- [OAuth tokens](https://github.com/peterbloomingdale/pmxagent/blob/main/server.py): `server.py`

### R API

- [Plumber API](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/rapi.R): `apis/rapi.R`

### Analysis workflows

- [NCA endpoint](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/nca.R): `apis/endpoints/nca.R`
- [Exposure-response](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/er.R): `apis/endpoints/er.R`
- [PK endpoint](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/pk.R): `apis/endpoints/pk.R`
- [Data formatting](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/data.R): `apis/endpoints/data.R`
- [Model library](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/endpoints/library.R): `apis/endpoints/library.R`
- [Data processing](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/utils/data_processing.R): `apis/utils/data_processing.R`

### Model engines

- [One-compartment model](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/models/1CM.cpp): `apis/models/1CM.cpp`
- [Two-compartment model](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/models/2CM.cpp): `apis/models/2CM.cpp`
- [ER model fitting](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/models/er_models.R): `apis/models/er_models.R`
- [Literature PK models](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/models/nlmixr2lib_sim.R): `apis/models/nlmixr2lib_sim.R`
- [mrgsolve simulation](https://github.com/peterbloomingdale/pmxagent/blob/main/apis/models/mrgsolve_pk.R): `apis/models/mrgsolve_pk.R`

### Other components

- **AI agent**

## Connections

- AI agent → MCP server: invokes tools (evidence: `README.md`)
- MCP server → OAuth tokens: authenticates clients (evidence: `server.py`)
- MCP server → Plumber API: discovers and proxies (evidence: `server.py`)
- Plumber API → NCA endpoint: routes requests (evidence: `README.md`)
- Plumber API → Exposure-response: routes requests (evidence: `README.md`)
- Plumber API → PK endpoint: routes requests (evidence: `README.md`)
- Plumber API → Data formatting: routes requests (evidence: `README.md`)
- Plumber API → Model library: routes requests (evidence: `README.md`)
- Data formatting → Data processing: standardizes data
- Data formatting → NCA endpoint: feeds formatted data (evidence: `README.md`)
- PK endpoint → One-compartment model: simulates
- PK endpoint → Two-compartment model: simulates
- PK endpoint → mrgsolve simulation: uses simulation
- Exposure-response → ER model fitting: fits models
- Model library → Literature PK models: simulates library models
