This guide helps AI agents like Cline, Cursor, and other MCP clients install and configure M4 for clinical data analysis.
M4 is infrastructure for AI-assisted clinical research. It provides:
- MCP Server: Query clinical datasets (MIMIC-IV, eICU) via natural language
- Python API: Direct programmatic access returning pandas DataFrames
- Clinical Skills: A set of bundled skills for the Python API and validated clinical research patterns.
uvx m4-infrapip install m4-infra{
"mcpServers": {
"m4": {
"command": "uvx",
"args": ["m4-infra"]
}
}
}Features:
- Demo database (100 patients) downloads automatically
- No setup required
- Perfect for testing and development
First, switch the active backend:
m4 backend bigqueryThen use this MCP configuration:
{
"mcpServers": {
"m4": {
"command": "uvx",
"args": ["m4-infra"],
"env": {
"M4_PROJECT_ID": "user-project-id"
}
}
}
}Prerequisites:
- Google Cloud credentials configured (
gcloud auth application-default login) - PhysioNet credentialed access to MIMIC-IV or eICU
| Tool | Description |
|---|---|
list_datasets |
List available datasets and their status |
set_dataset |
Switch the active dataset |
| Tool | Description |
|---|---|
get_database_schema |
List all tables in the database |
get_table_info |
Get column details and sample data for a table |
execute_query |
Run SQL SELECT queries |
| Tool | Description |
|---|---|
search_notes |
Full-text search with snippets |
get_note |
Retrieve a single note by ID |
list_patient_notes |
List notes for a patient (metadata only) |
For AI agents with code execution capabilities (Claude Code, Cursor), M4 provides a Python API that returns native types instead of formatted strings:
from m4 import set_dataset, execute_query, get_schema
set_dataset("mimic-iv")
# Returns pandas DataFrame
df = execute_query("""
SELECT subject_id, gender, anchor_age
FROM mimiciv_hosp.patients
WHERE anchor_age > 65
""")
# Full pandas power: filter, aggregate, visualize
print(df.describe())
df.plot(kind='bar', x='gender', y='anchor_age')When to use the Python API:
- Multi-step analyses where each query informs the next
- Statistical computations and survival analysis
- Large result sets that shouldn't flood context
- Building reproducible analysis notebooks
M4 ships with a set of bundled skills for the Python API (m4-api) and clinical research patterns extracted from MIT-LCP validated code.
For the canonical list of bundled skills, see src/m4/skills/SKILLS_INDEX.md.
sofa-score- Sequential Organ Failure Assessmentapsiii-score- APACHE III with mortality predictionsapsii-score- SAPS-II scoreoasis-score- Oxford Acute Severity of Illness Scorelods-score- Logistic Organ Dysfunction Scoresirs-criteria- Systemic Inflammatory Response Syndrome
sepsis-3-cohort- Sepsis-3 identification (SOFA >= 2 + infection)suspicion-of-infection- Suspected infection events
kdigo-aki-staging- KDIGO AKI staging (creatinine + urine output)
vasopressor-equivalents- Norepinephrine-equivalent dose
baseline-creatinine- Baseline creatinine estimationgcs-calculation- Glasgow Coma Scale extraction
first-icu-stay- First ICU stay selection
mimic-table-relationships- Table relationships and join patternsmimic-eicu-mapping- Cross-database concept mappingclinical-research-pitfalls- Common methodological mistakes
Install skills for Claude Code:
m4 skills --tools claudeAfter configuration, test by asking:
- "What tables are available in the database?"
- "Show me patient demographics"
- "Search for notes mentioning diabetes"
DuckDB backend fails:
- The demo database downloads automatically on first query
- No manual
m4 initneeded when using uvx
BigQuery backend fails:
- Verify GCP authentication:
gcloud auth list - Confirm PhysioNet access to the dataset
- Check project ID is correct
Tools not appearing:
- Ensure the MCP client configuration is valid JSON
- Restart the MCP client after configuration changes
- GitHub: https://github.com/hannesill/m4
- Documentation: https://github.com/hannesill/m4/tree/main/docs
- Python API Guide: https://github.com/hannesill/m4/blob/main/docs/CODE_EXECUTION.md
- Skills Guide: https://github.com/hannesill/m4/blob/main/docs/SKILLS.md