> For the complete documentation index, see [llms.txt](https://docs.rhinofcp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.rhinofcp.com/using-the-rhino-mcp-server/mcp-worked-example.md).

# MCP Worked Example

Example workflow for querying via the MCP including sample responses you would get from the agent.

This **example project** uses a synthetic OMOP CDM dataset at two sites (1,000 patients each): the standard clinical tables and curated tables for patient\_analytics (one row per patient: demographics, labs, cost, outcome flags) and survival\_analysis (followup\_days, event, covariates).&#x20;

***

## Step 0: Prerequisites

1. Confirm your MCP connection:

   | <p><strong>Example Prompt</strong></p><p>Confirm who I am, whether Rhino is reachable, and which projects and sites I can use.</p> |
   | ---------------------------------------------------------------------------------------------------------------------------------- |
2. Build a semantic layer using your data dictionary, then have a subject-matter expert review it:

   | <p><strong>Example Prompt</strong></p><p>Using the attached data dictionary, enrich the data schemas in my OMOP project. Set each column's type (Integer for IDs and flags, String for categories and ISO dates, Float for measures) and describe: what it is; valid values and units; the metric parameter it maps to; join key; key concept IDs. Show me the proposed schemas before creating new versions.</p> |
   | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

***

## Step 1: Get an overview of the data

Loading dataset information into the LLM's context offers an effective initial step for enabling your agent to explore available project data.

| <p><strong>Example Prompt</strong></p><p>Give me an overview of my OMOP project so I can plan a COPD analysis: which tables each site holds and their row counts, and which code objects have run and what datasets they produced.</p> |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

**Example Output**

Your OMOP project has 30 datasets —15 matching tables at each site—with no code objects, runs, or lineage.

| Table Name                       | Site 1 Row Count | Site 2 Row Count |
| -------------------------------- | ---------------- | ---------------- |
| person                           | 1,000            | 1,000            |
| observation\_period              | 1,000            | 1,000            |
| visit\_occurrence                | 5,122            | 4,844            |
| condition\_occurrence            | 2,133            | 1,798            |
| drug\_exposure                   | 3,691            | 3,399            |
| procedure\_occurrence            | 1,752            | 1,619            |
| measurement                      | 7,000            | 7,000            |
| observation                      | 1,000            | 1,000            |
| death                            | 28               | 15               |
| concept                          | 39               | 39               |
| concept\_ancestor                | 4                | 4                |
| patient\_analytics               | 1,000            | 1,000            |
| survival\_analysis               | 1,000            | 1,000            |
| multiclass\_ranking\_predictions | 1,000            | 1,000            |
| lesion\_detection\_predictions   | 1,397            | 1,332            |

***

## Step 2: Profile the dataset

| <p><strong>Example Prompt</strong></p><p>Profile Site 1 patient\_analytics as a Table 1: return the mean (SD) and median \[IQR] for age, FEV1 % predicted and eosinophil count; n (%) for sex, treatment arm, COPD flag (detected) and outcome.</p> |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

**Example Output**

| Variable (Site 1, n = 1,000) | Summary                                  |
| ---------------------------- | ---------------------------------------- |
| Age, years                   | mean 66.3 (SD 9.9) · median 66 \[60–73]  |
| FEV1 % predicted             | mean 77.9 · median 79.3 \[67.2–89.4]     |
| Eosinophils, cells/µL        | mean 230.7 · median 197.3 \[115.9–308.7] |
| COPD (detected) / outcome    | 311 (31.1%) / 223 (22.3%)                |

***

## Step 3: Explore across sites

| <p><strong>Example Prompt</strong></p><p>Compare Site 1 and Site 2 patient\_analytics for age, COPD flag, outcome and FEV1 % predicted, then give me the pooled mean age.</p> |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

**Example Output**

| Variable                        | Site 1             | Site 2             |
| ------------------------------- | ------------------ | ------------------ |
| Age, mean (SD)                  | 66.3(9.9)          | 60.3(9.6)          |
| Age, median \[IQR]              | 66 \[60, 73]       | 60 \[54, 67]       |
| COPD flag (detected), n (%)     | 311 (31.1)         | 201 (20.1)         |
| Outcome, n (%)                  | 223 (22.3)         | 141 (14.1)         |
| FEV1 % predicted, mean (SD)     | 77.9 (15.1)        | 81.2 (13.8)        |
| FEV1 % predicted, median \[IQR] | 79.3 \[67.2, 89.4] | 82.4 \[71.9, 90.9] |

Pooled mean age is 63.3, computed from each site's aggregates. Site 1 is older and sicker, you should take that into account when building the cohort.

***

## Step 4: Build the cohort

This is where specificity matters most. Compare a one-line request with a protocol-level one:

| <p><strong>Example Prompt (vague)</strong></p><p>Find older COPD patients on inhalers with exacerbations.</p> |
| ------------------------------------------------------------------------------------------------------------- |

**Example Output (vague)**

"Older", "COPD", "inhalers" and "exacerbations" each hide a decision: ≥ 65 or > 65? Parent concept only or descendants too? Which drugs? How many events, and in what window? The assistant will choose for you, and the choices won't be visible. For agentic cohort building, a good prompt includes details such as:

* Execution scope: State the project, sites, and if a code object is needed.
* Inputs: Specify datasets, input order, join keys, and base population table.
* Population & join rules: Detail retention rules, unmatched record handling, and output row structure.
* Eligibility criteria: Define explicit thresholds, concept sets, date windows, and exclusions.
* Criterion sources: Name the exact table and column for each eligibility rule.
* Funnel logic: Separate individual eligibility flags from sequential filtering and exclusion logging.
* Output specifications: List each required dataset, its columns, and carried-through variables.
* Pre-execution validation: Instruct Rhino MCP to verify schemas, flag ambiguities, and show a code preview.
* Verifiable results: Require execution status, dataset references, final cohort size, and step counts.

| <p><strong>Example Prompt (better!)</strong></p><p>Build a Site 1 cohort with a Python code object (run at Site 1 only).</p><p></p><p>Inputs, in slot order (all "Site 1 - ..."):</p><p>  0 patient\_analytics</p><p>  1 condition\_occurrence</p><p>  2 drug\_exposure</p><p>  3 survival\_analysis</p><p></p><p>Join on person\_id. Base population: every person\_id in patient\_analytics, one</p><p>output row per person, including people with no condition or drug records.</p><p>Left-join survival\_analysis on person\_id so nobody is dropped if there is no</p><p>match; unmatched people keep missing survival columns.</p><p></p><p>Criteria, evaluated in this order (flag = 1 if met, else 0):</p><p>1. flag\_age: age >= 65 (age column in patient\_analytics)</p><p>2. flag\_copd: condition\_concept\_id in {2000001000, 2000001001, 2000001002,</p><p>   2000001003} in condition\_occurrence (explicit list, no concept\_ancestor)</p><p>3. flag\_therapy: drug\_concept\_id in {2000002001, 2000002006} in drug\_exposure</p><p>   (tiotropium or triple therapy; use drug records, not treatment\_arm)</p><p>4. flag\_exacerbation: condition\_concept\_id = 2000001070 in</p><p>   condition\_occurrence, at least one record, any time (no date window)</p><p></p><p>Compute all four flags independently for every person. Apply the criterion</p><p>order only when calculating funnel\_step and dropped\_at.<br></p><p>Derived columns:</p><p>- funnel\_step: number of consecutive criteria passed starting from criterion 1,</p><p>  stopping at the first failure (0-4)</p><p>- dropped\_at: first failed criterion, one of age / copd / therapy /</p><p>  exacerbation / none</p><p>- in\_cohort: 1 if all four flags = 1, else 0</p><p>- male: 1 if sex = "Male", 0 if "Female", missing if sex is missing</p><p></p><p>Carry these columns through into both outputs:</p><p>- from patient\_analytics: age, sex, treatment\_arm, fev1\_percent\_predicted,</p><p>  eosinophil\_count, outcome</p><p>- from survival\_analysis: followup\_days, event, current\_smoker,</p><p>  comorbidity\_score</p><p>  (use age from patient\_analytics only; do not carry survival\_analysis age</p><p>  or its male/copd columns)</p><p></p><p>Outputs:</p><p>- output 0, named "Site 1 - COPD candidates": all persons.</p><p>  Columns: person\_id, flag\_age, flag\_copd, flag\_therapy, flag\_exacerbation,</p><p>  funnel\_step, dropped\_at, in\_cohort, age, sex, male, treatment\_arm,</p><p>  fev1\_percent\_predicted, eosinophil\_count, outcome, followup\_days, event,</p><p>  current\_smoker, comorbidity\_score</p><p>- output 1, named "Site 1 - COPD cohort": only in\_cohort = 1</p><p>  rows, same columns</p><p></p><p>Before running: check that the column names and concept IDs above exist in the</p><p>Site 1 tables, then show me the code object preview and wait for my OK.</p><p></p><p>After the run: confirm completion; give the final cohort size (rows in</p><p>output 1) and the persons remaining after each funnel step. </p> |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

Because every person keeps their flags, you can iterate with quick filtered counts instead of rebuilding:

| <p><strong>Example Prompt</strong></p><p>Using the dataset "Site 1 - COPD candidates", filter to in\_cohort = 1 and count how many patients have eosinophil\_count of at least 300, at least 200, and at least 150?</p> |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

That returned 16, 34 and 43. Re-running with eosinophils ≥ 150 cells/µL as a final criterion gives a 43-patient cohort (23 male, 20 female).

***

## Step 5: Show the attrition funnel

Request the attrition funnel in a separate prompt after cohort creation. This lets you visualize the filtering steps directly from the newly created datasets.

| <p><strong>Example Prompt</strong></p><p>Count patients by funnel\_step on the Site 1 - COPD candidates dataset and plot the attrition funnel with number and percent remaining. Include eosinophil\_count of at least 150 as a criteria. </p> |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

**Example Output**

<img src="https://2949362692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FydySyCBmy6F7NnGn4bPa%2Fuploads%2FYahBmVCTfeDgSVza0YVF%2Funknown.png?alt=media&amp;token=d37d630a-107b-45ed-a051-3191e835e55c" alt="" height="175" width="326">

***

## Step 6: Kaplan–Meier survival analysis

| <p><strong>Example Prompt</strong></p><p>Using "Site 1 - COPD cohort", run a Kaplan-Meier by sex with</p><p>time = followup\_days and event = event. Plot the curves with a number-at-risk</p><p>table. Show counts under 5 as "<5".</p> |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

**Example Output**

<img src="https://2949362692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FydySyCBmy6F7NnGn4bPa%2Fuploads%2FgcqRROEURCpkdy5KJxOH%2Funknown.png?alt=media&amp;token=ff2836d0-168d-4007-a2e7-44c7a16c14ff" alt="" height="157" width="322">

<br>

***

## Step 7: Cox regression

The cox metric expects a time column, an event column and a list of covariates, and returns one β and standard error per covariate in the order given (HR = e^β):

| <p><strong>Example Prompt</strong></p><p>Fit a Cox model on the Site 1 - COPD cohort dataset with time\_variable followup\_days, event\_variable event and covariates age, male, current\_smoker, and comorbidity\_score. Report HR, 95% CI and p per covariate, and draw a waterfall plot of the sorted log hazard ratios.</p> |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

**Example Output**

<img src="https://2949362692-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FydySyCBmy6F7NnGn4bPa%2Fuploads%2FPKjJ9FCThMZIKiyLnmTJ%2Funknown.png?alt=media&amp;token=e6d26704-8dd2-4318-aadd-6f58831c2f0b" alt="" height="166" width="384">

| Covariate                     | HR   | 95% CI    | p     |
| ----------------------------- | ---- | --------- | ----- |
| Age (per year)                | 1.02 | 0.98–1.08 | 0.25  |
| Male                          | 0.91 | 0.63–2.60 | 0.70  |
| Current smoker                | 1.49 | 0.46–1.91 | 0.16  |
| Comorbidity score (per point) | 1.70 | 1.07–2.46 | <0.05 |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.rhinofcp.com/using-the-rhino-mcp-server/mcp-worked-example.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
