1---2name: ktx-analytics3description: Use when answering a question that needs data from a KTX-connected database - investigating, analyzing, "how many", "show me", "what's the breakdown of", finding records by value, exploring tables, comparing periods, explaining metrics, or any data-analysis request. Triggers even when the user does not say "analytics"; if the answer requires querying a configured KTX connection, this skill applies.4---5
6# KTX Analytics Workflow
7
8You have access to KTX MCP tools for data discovery, semantic-layer analysis, raw read-only SQL, wiki context, and memory ingest. Follow this workflow.
9
10<workflow>
111. **Discover** - call `discover_data` first to see what exists across wiki pages, semantic-layer sources, metrics, dimensions, raw tables, and columns. Returns refs only.
122. **Inspect top hits in parallel** - for each promising ref:
13 - `kind: 'wiki'` -> `wiki_read`
14 - `kind: 'sl_source'`, `kind: 'sl_measure'`, or `kind: 'sl_dimension'` -> `sl_read_source`
15 - `kind: 'table'` or `kind: 'column'` -> `entity_details`
163. **Resolve business values** - if the user named a value such as "Acme Corp", "enterprise", or "status=shipped", call `dictionary_search` to find which column holds it.
174. **Plan the analysis** - identify the grain, metrics, dimensions, filters, time window, and expected row limits before querying.
185. **Query** -
19 - Prefer `sl_query` when the semantic layer covers the question.
20 - Use `sql_execution` only for questions the semantic layer does not cover.
216. **Validate and explain** - sanity-check totals, filters, null handling, and time zones. State the source tables or semantic-layer objects used.
227. **Capture durable learnings** - call `memory_ingest` whenever a turn produces something worth remembering (business rules, metric definitions, schema gotchas, recurring findings) **or** whenever the user asks you to remember something. Pass markdown in `content` including any source context the memory agent should weigh. Each call is a feedback loop; better notes today mean smarter `discover_data` and `wiki_search` results tomorrow.
23</workflow>
24
25<rules>
26- Always run `discover_data` before writing SQL. Do not guess table names.
27- Prefer the semantic layer over raw SQL when both can answer the question; measures are the source of truth.
28- Read entity details before writing SQL against an unfamiliar table. Do not assume column names.
29- Treat `sql_execution` as read-only. Writes are rejected by the server.
30- Validate value mentions with `dictionary_search` instead of guessing case or spelling. Treat a `dictionary_search` miss as non-authoritative. The index is built from profile-sampled values, so a missing value may simply have been outside the sample. Follow up with `sql_execution` against the most plausible columns before concluding the value is absent.
31- `connectionId` scoping when `connection_list` shows multiple connections:
32 - Always pass it: `entity_details`, `sl_read_source`, `sql_execution`.
33 - Pass it when intent pins a warehouse, otherwise omit for unscoped discovery: `sl_query`, `discover_data`, `dictionary_search`.
34 - `memory_ingest`: pass it for warehouse-specific knowledge (e.g. "in our warehouse"); without it the memory lands as wiki-only and cannot update the semantic layer.
35 - Never pass it: `connection_list`, `wiki_search`, `wiki_read`, `memory_ingest_status`.
36 - If scoping is required but intent is ambiguous, ask which warehouse before calling.
37- Show compact result tables for small outputs. For broad results, summarize the top findings and mention the applied limit.
38- Ask a concise clarification only when the metric, date range, entity, or grain is genuinely ambiguous and cannot be inferred from context.
39</rules>
40
41<examples>
42**Input:** "How many orders did Acme Corp place last month?"
43
44**Workflow:**
451. `dictionary_search({ values: ["Acme Corp"] })` finds `customers.name`.
462. `discover_data({ query: "orders customer monthly" })` finds an orders semantic-layer source.
473. `sl_read_source({ connectionId: "warehouse", sourceName: "orders_facts" })` confirms the source grain, measures, and dimensions.
484. `sl_query({ connectionId: "warehouse", measures: ["order_count"], filters: ["customer_name = 'Acme Corp'"] })` answers through the semantic layer.
495. `memory_ingest({ connectionId: "warehouse", content: "Acme Corp order analysis used orders_facts.order_count filtered by customers.name = 'Acme Corp'. Source: current analysis turn." })` captures the durable finding.
50
51---
52
53**Input:** "What columns does the events table have?"
54
55**Workflow:**
561. `discover_data({ query: "events table" })` returns a `table` ref.
572. `entity_details({ connectionId: "warehouse", entities: [{ table: "analytics.events" }] })` returns columns, types, and foreign keys.
583. Answer directly. No query is needed.
59
60---
61
62**Input:** "Heads up: ARR is always reported in cents in our warehouse."
63
64**Workflow:**
651. If multiple connections exist, call `connection_list` and identify the warehouse the user means. Ask if ambiguous.
662. `memory_ingest({ connectionId: "warehouse", content: "ARR is reported in cents (not dollars) in this warehouse. Multiply by 0.01 for dollar amounts. Source: user clarification." })` remembers the warehouse-specific rule without running an analysis turn.
67</examples>