Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 | 53x 53x 53x 53x 53x 5x | /**
* MCP Prompts for AI Agents
*
* These prompts provide guidance for AI agents using the Drizzle Cube MCP server.
* They help prevent common query mistakes and ensure correct query construction.
*/
export interface MCPPrompt {
name: string
description: string
messages: Array<{
role: 'user' | 'assistant'
content: {
type: 'text'
text: string
}
}>
}
/**
* Main workflow guide for using drizzle-cube MCP tools
*/
export const MCP_GUIDE_PROMPT: MCPPrompt = {
name: 'drizzle-cube-mcp-guide',
description: 'How to use drizzle-cube MCP tools to generate and run queries',
messages: [
{
role: 'user' as const,
content: {
type: 'text' as const,
text: [
'You are an analyst agent using drizzle-cube MCP.',
'',
'Workflow:',
'1) tools/call name=discover {topic|intent} - Find cubes and understand schema',
'2) Construct your query using the schema from discover (see cross-cube joins below)',
'3) tools/call name=validate {query} - Optional: fix schema issues',
'4) tools/call name=load {query} - Execute and get results',
'',
'CRITICAL - CROSS-CUBE JOINS:',
'The "joins" property in discover results shows relationships between cubes.',
'You can include dimensions from ANY related cube in your query!',
'Example: If Productivity joins to Employees, query:',
'{ "measures": ["Productivity.totalPullRequests"], "dimensions": ["Employees.name"] }',
'The system automatically joins the cubes for you.',
'',
'Query shapes:',
'- Regular: { measures, dimensions, filters[], timeDimensions[], order, limit, offset }',
'- Funnel: { funnel: { bindingKey, timeDimension, steps[], includeTimeMetrics? } }',
'- Flow: { flow: { bindingKey, eventDimension, steps?, window? } }',
'- Retention: { retention: { bindingKey, timeDimension, periods, granularity, retentionType, breakdownDimensions } }',
'',
'Time handling:',
'- For AGGREGATED TOTALS (e.g., "last 3 months"): use filters with inDateRange, NOT timeDimensions',
'- For TIME SERIES (e.g., "by month"): use timeDimensions with granularity',
'- You can combine both when needed',
'',
'Filters: flat arrays of { member, operator, values }. Do not nest arrays.',
'Do NOT hallucinate cube/field names—always use discover first.'
].join('\n')
}
}
]
}
/**
* Quick reference rules for query generation
*/
export const QUERY_RULES_PROMPT: MCPPrompt = {
name: 'drizzle-cube-query-rules',
description: 'Key generation rules aligned with Gemini single-step prompt',
messages: [
{
role: 'user' as const,
content: {
type: 'text' as const,
text: [
'Rules (keep JSON only):',
'- Use only measures/dimensions/timeDimensions from schema.',
'- timeDimensions: include granularity when grouping; use inDateRange filter for relative windows; combine when both requested.',
'- Funnel detection keywords: funnel, conversion, journey, drop off, step by step; use funnel format only if eventStream metadata exists.',
'- Funnel rules: bindingKey/timeDimension from cube metadata; include time filter on step 0 (default last 6 months) using inDateRange; steps ordered; flat filters.',
'- Chart selection: line/area for time trends; bar for categories; scatter for 2-measure correlations; bubble for 3-measure correlations; funnel for funnels.',
'- Correlation keywords (correlation/relationship/vs/compare) -> scatter/bubble, never line.',
'- Prefer .name fields over .id; avoid Id dimensions unless requested.',
'- Filters: flat array of {member, operator, values}; operators equals, notEquals, contains, notContains, gt, gte, lt, lte, inDateRange, set, notSet.'
].join('\n')
}
}
]
}
/**
* Comprehensive guide for building valid queries of all types
*/
export const QUERY_BUILDING_PROMPT: MCPPrompt = {
name: 'drizzle-cube-query-building',
description: 'CRITICAL: Complete guide for building valid queries of all types with examples',
messages: [
{
role: 'user' as const,
content: {
type: 'text' as const,
text: [
'# Drizzle Cube Query Building Guide',
'',
'## CRITICAL: Cross-Cube Joins',
'',
'You can combine measures from one cube with dimensions from RELATED cubes!',
'Check the "joins" property in discover results to see relationships.',
'',
'Example: "Top 5 employees by pull requests last 3 months"',
'- Productivity cube has: measures (totalPullRequests), dimensions (date)',
'- Productivity joins to Employees (via employeeId)',
'- Employees cube has: dimensions (name, department)',
'',
'Query combining BOTH cubes:',
'```json',
'{',
' "measures": ["Productivity.totalPullRequests"],',
' "dimensions": ["Employees.name"],',
' "filters": [',
' { "member": "Productivity.date", "operator": "inDateRange", "values": ["last 3 months"] }',
' ],',
' "order": { "Productivity.totalPullRequests": "desc" },',
' "limit": 5',
'}',
'```',
'The system AUTOMATICALLY joins Productivity to Employees for you!',
'',
'---',
'',
'## Date Filtering vs Time Grouping',
'',
'### For AGGREGATED TOTALS (no time breakdown)',
'Use `filters` with `inDateRange` operator. Do NOT use timeDimensions.',
'',
'```json',
'{',
' "measures": ["Productivity.totalPullRequests"],',
' "dimensions": ["Employees.name"],',
' "filters": [{ "member": "Productivity.date", "operator": "inDateRange", "values": ["last 3 months"] }],',
' "order": { "Productivity.totalPullRequests": "desc" },',
' "limit": 5',
'}',
'```',
'Result: 5 rows total, one per employee, with SUMMED pull requests.',
'',
'### For TIME SERIES (grouped by period)',
'Use `timeDimensions` WITH `granularity`.',
'',
'```json',
'{',
' "measures": ["Productivity.totalPullRequests"],',
' "timeDimensions": [{ "dimension": "Productivity.date", "dateRange": "last 3 months", "granularity": "month" }]',
'}',
'```',
'Result: 3 rows (one per month) with pull request totals.',
'',
'### WRONG: timeDimensions without granularity',
'```json',
'// DON\'T DO THIS - groups by DAY, returns ~90 rows!',
'{ "timeDimensions": [{ "dimension": "X.date", "dateRange": "last 3 months" }] }',
'```',
'',
'---',
'',
'## Regular Query Structure',
'',
'```json',
'{',
' "measures": ["Cube.measure1", "Cube.measure2"],',
' "dimensions": ["Cube.dimension1", "RelatedCube.dimension"],',
' "filters": [',
' { "member": "Cube.field", "operator": "equals", "values": ["value"] },',
' { "member": "Cube.date", "operator": "inDateRange", "values": ["last 30 days"] }',
' ],',
' "timeDimensions": [],',
' "order": { "Cube.measure1": "desc" },',
' "limit": 100,',
' "offset": 0',
'}',
'```',
'',
'### Filter Operators',
'- String: equals, notEquals, contains, notContains, startsWith, endsWith',
'- Numeric: gt, gte, lt, lte',
'- Null: set, notSet',
'- Date: inDateRange, beforeDate, afterDate',
'',
'### Date Range Values',
'- Relative: "last 7 days", "last 3 months", "last year", "this week", "this month"',
'- Absolute: ["2024-01-01", "2024-03-31"]',
'',
'---',
'',
'## Funnel Query Structure',
'',
'Use when: conversion analysis, user journeys, step-by-step analysis',
'Requires: Cube with eventStream metadata',
'',
'```json',
'{',
' "funnel": {',
' "bindingKey": "Events.userId",',
' "timeDimension": "Events.timestamp",',
' "steps": [',
' {',
' "name": "Step 1",',
' "filter": [',
' { "member": "Events.eventType", "operator": "equals", "values": ["signup"] },',
' { "member": "Events.timestamp", "operator": "inDateRange", "values": ["last 6 months"] }',
' ]',
' },',
' {',
' "name": "Step 2",',
' "filter": [',
' { "member": "Events.eventType", "operator": "equals", "values": ["purchase"] }',
' ],',
' "timeToConvert": { "value": 7, "unit": "day" }',
' }',
' ],',
' "includeTimeMetrics": true',
' }',
'}',
'```',
'',
'IMPORTANT: Put time filter (inDateRange) ONLY on step 0!',
'',
'---',
'',
'## Flow Query Structure',
'',
'Use when: analyzing event sequences, path analysis',
'',
'```json',
'{',
' "flow": {',
' "bindingKey": "Events.sessionId",',
' "eventDimension": "Events.eventType",',
' "timeDimension": "Events.timestamp",',
' "stepsBefore": 2,',
' "stepsAfter": 2,',
' "startingStep": "checkout"',
' }',
'}',
'```',
'',
'---',
'',
'## Retention Query Structure',
'',
'Use when: cohort analysis, user retention tracking',
'',
'```json',
'{',
' "retention": {',
' "bindingKey": "Users.id",',
' "timeDimension": "Events.timestamp",',
' "periods": 8,',
' "granularity": "week",',
' "retentionType": "rolling",',
' "breakdownDimensions": ["Events.country"]',
' }',
'}',
'```',
'',
'---',
'',
'## Common Mistakes to Avoid',
'',
'1. Using timeDimensions when you want aggregated totals → Use filters with inDateRange instead',
'2. Omitting granularity in timeDimensions → Results in day-level grouping',
'3. Guessing field names → Always use discover first to get actual schema',
'4. Nested filter arrays → Filters must be flat: [{ member, operator, values }]',
'5. Missing date filter for "last N" queries → Always add inDateRange filter'
].join('\n')
}
}
]
}
/**
* Critical guide specifically for date filtering vs time grouping
*/
export const DATE_FILTERING_PROMPT: MCPPrompt = {
name: 'drizzle-cube-date-filtering',
description: 'CRITICAL: How to correctly filter by date vs group by time period - the #1 source of query mistakes',
messages: [
{
role: 'user' as const,
content: {
type: 'text' as const,
text: [
'# Date Filtering vs Time Grouping - CRITICAL GUIDE',
'',
'This is the most common mistake when building queries. These are TWO DIFFERENT operations.',
'',
'## Quick Decision Tree',
'',
'```',
'User wants data over a time period?',
'├── Wants AGGREGATED TOTALS (e.g., "total sales last month")',
'│ └── Use: filters with inDateRange operator',
'│',
'└── Wants TIME SERIES breakdown (e.g., "daily sales last month")',
' └── Use: timeDimensions with granularity',
'```',
'',
'## For Aggregated Totals (MOST COMMON)',
'',
'When user says: "last 3 months", "over the past year", "in Q1", "since January"',
'',
'```json',
'{',
' "measures": ["Sales.totalRevenue"],',
' "dimensions": ["Products.category"],',
' "filters": [',
' { "member": "Sales.date", "operator": "inDateRange", "values": ["last 3 months"] }',
' ]',
'}',
'```',
'',
'Result: One row per category with TOTAL revenue over the 3-month period.',
'',
'## For Time Series (Trend Analysis)',
'',
'When user says: "by month", "per week", "daily trend", "over time"',
'',
'```json',
'{',
' "measures": ["Sales.totalRevenue"],',
' "timeDimensions": [',
' { "dimension": "Sales.date", "dateRange": "last 3 months", "granularity": "month" }',
' ]',
'}',
'```',
'',
'Result: Multiple rows, one per month.',
'',
'## WRONG: timeDimensions Without Granularity',
'',
'```json',
'// This returns ~90 rows (daily) instead of aggregates!',
'{',
' "timeDimensions": [{ "dimension": "Sales.date", "dateRange": "last 3 months" }]',
'}',
'```',
'',
'## Both: Filter AND Group',
'',
'When user wants: "monthly breakdown for last quarter"',
'',
'```json',
'{',
' "measures": ["Sales.totalRevenue"],',
' "filters": [',
' { "member": "Sales.date", "operator": "inDateRange", "values": ["last quarter"] }',
' ],',
' "timeDimensions": [',
' { "dimension": "Sales.date", "granularity": "month" }',
' ]',
'}',
'```',
'',
'## Summary Table',
'',
'| User Request | Use | Example |',
'|-------------|-----|---------|',
'| "total for last 3 months" | filters + inDateRange | { filters: [{ operator: "inDateRange", values: ["last 3 months"] }] } |',
'| "top 5 last quarter" | filters + inDateRange | Same as above + order + limit |',
'| "monthly trend" | timeDimensions + granularity | { timeDimensions: [{ granularity: "month" }] } |',
'| "daily breakdown last week" | timeDimensions | { timeDimensions: [{ dateRange: "last week", granularity: "day" }] } |'
].join('\n')
}
}
]
}
/**
* All MCP prompts for the Drizzle Cube server
*/
export const MCP_PROMPTS: MCPPrompt[] = [
MCP_GUIDE_PROMPT,
QUERY_RULES_PROMPT,
QUERY_BUILDING_PROMPT,
DATE_FILTERING_PROMPT
]
/**
* Get all default MCP prompts
*/
export function getDefaultMCPPrompts(): MCPPrompt[] {
return MCP_PROMPTS
}
|