sql_query
Run a custom read-only SQL query (one SELECT or WITH … SELECT) over the approved views when no other tool answers the question — e.g. comparing several markers, custom date filters or aggregates.
Instructions
Run a custom read-only SQL query (one SELECT or WITH … SELECT) over the
approved views when no other tool answers the question — e.g. comparing several markers, custom
date filters or aggregates. Runs as a view-only database role in a read-only transaction with a
5 s timeout; returns at most 200 rows (truncated tells you if there were more). Base tables,
pending values and writes are not accessible. Prefer the dedicated tools (query_observations,
get_trend, query_food…) when they fit.
Only READ-ONLY views are available (approved + not deleted): v_observations(id, user_id, type_code, name_uk, category, specimen, effective_at, value_numeric, comparator, value_text, unit, value_canonical, canonical_unit, ref_min, ref_max, status, result_status, context, panel_id) v_observations_pending(... , review_status, review_note, raw_name, unmapped) -- NOT fact, review only v_medications_current(id, medication_name, dose_amount, dose_unit, times_per_day, ...) v_diagnoses(id, diagnosed_at, diagnosis_name, icd10_code, clinical_status, verification_status) v_allergies(id, allergen, reaction, severity, verified) -- verified=false is ALSO an allergy v_habits(id, habit_type, status, frequency, cigarettes_per_day, smoking_years, drinks_per_week, start_date, end_date, notes) -- smoking/alcohol/cannabis… v_food_log(id, user_id, eaten_at, meal_type, description, portion, nutrient_source, glycemic_index, glycemic_load, symptoms, wellbeing, notes) v_food_nutrients(food_log_id, user_id, eaten_at, meal_type, nutrient_code, name_uk, category, unit, amount, rda, upper_limit) -- nutrients per meal v_meal_templates(id, user_id, name, meal_type, description, nutrients, glycemic_index) health_timeline(kind, user_id, id, at, title) Examples: SELECT type_code, effective_at, value_canonical FROM v_observations WHERE type_code='cholesterol_total' ORDER BY effective_at DESC; SELECT * FROM v_diagnoses WHERE verification_status='confirmed';
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"sql": "<sql>"
},
"name": "sql_query"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sql | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |