Skip to main content
Glama
health-os

health-os

sql_query

Read-only

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

NameRequiredDescriptionDefault
sqlYes

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.2.0

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Adds substantial context beyond the readOnlyHint/openWorldHint annotations: view-only DB role, read-only transaction, 5 s timeout, 200-row cap with a `truncated` flag, and that base tables, pending values and writes are inaccessible. These are operational limits the annotations could never convey.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with purpose, constraints and alternatives before the reference material, and the view catalogue is genuinely necessary for writing a correct query. Minor redundancy: the 'approved/not deleted' and 'no base tables/pending/writes' ideas are restated in the view section.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

An open-ended SQL tool is the hardest case for description completeness, and this covers dialect limits, role/permissions, timeout, row cap, and the full readable schema. Return-value detail is unnecessary since an output schema exists, and the `truncated` note still flags the one return behavior an agent must act on.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0% and the single `sql` param has no description, so the description must carry the full burden — and it does: it constrains the statement form, enumerates every queryable view with column names and inline caveats (e.g. v_allergies verified=false is still an allergy; v_observations_pending is not fact), and supplies two worked examples.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource ('Run a custom read-only SQL query') and narrows the surface to 'one SELECT or WITH … SELECT' over approved views. It explicitly separates itself from the dedicated tools by naming the escape-hatch purpose (custom aggregates, cross-marker comparisons).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives an explicit when-to-use condition ('when no other tool answers the question'), concrete examples of that condition, and names the alternatives (query_observations, get_trend, query_food) with 'Prefer the dedicated tools … when they fit.' This is exactly the when/when-not/alternative triad.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.