@outsidedata/dolex 0.1.12 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. package/dist/src/analysis/rules.d.ts.map +1 -1
  2. package/dist/src/analysis/rules.js +8 -2
  3. package/dist/src/analysis/rules.js.map +1 -1
  4. package/dist/src/connectors/csv.d.ts.map +1 -1
  5. package/dist/src/connectors/csv.js +31 -1
  6. package/dist/src/connectors/csv.js.map +1 -1
  7. package/dist/src/connectors/dsl-compiler.d.ts +4 -0
  8. package/dist/src/connectors/dsl-compiler.d.ts.map +1 -1
  9. package/dist/src/connectors/dsl-compiler.js +51 -18
  10. package/dist/src/connectors/dsl-compiler.js.map +1 -1
  11. package/dist/src/connectors/dsl-validator.js +6 -1
  12. package/dist/src/connectors/dsl-validator.js.map +1 -1
  13. package/dist/src/connectors/js-aggregation.d.ts.map +1 -1
  14. package/dist/src/connectors/js-aggregation.js +18 -12
  15. package/dist/src/connectors/js-aggregation.js.map +1 -1
  16. package/dist/src/mcp/index.js +63 -29
  17. package/dist/src/mcp/index.js.map +1 -1
  18. package/dist/src/mcp/spec-store.d.ts +2 -1
  19. package/dist/src/mcp/spec-store.d.ts.map +1 -1
  20. package/dist/src/mcp/spec-store.js +4 -2
  21. package/dist/src/mcp/spec-store.js.map +1 -1
  22. package/dist/src/mcp/tools/dsl-schemas.d.ts +52 -51
  23. package/dist/src/mcp/tools/dsl-schemas.d.ts.map +1 -1
  24. package/dist/src/mcp/tools/dsl-schemas.js +1 -1
  25. package/dist/src/mcp/tools/dsl-schemas.js.map +1 -1
  26. package/dist/src/mcp/tools/list-patterns.js +2 -2
  27. package/dist/src/mcp/tools/list-patterns.js.map +1 -1
  28. package/dist/src/mcp/tools/query-source.d.ts +16 -16
  29. package/dist/src/mcp/tools/refine.d.ts +124 -15
  30. package/dist/src/mcp/tools/refine.d.ts.map +1 -1
  31. package/dist/src/mcp/tools/refine.js +335 -253
  32. package/dist/src/mcp/tools/refine.js.map +1 -1
  33. package/dist/src/mcp/tools/shared.d.ts +15 -2
  34. package/dist/src/mcp/tools/shared.d.ts.map +1 -1
  35. package/dist/src/mcp/tools/shared.js +64 -6
  36. package/dist/src/mcp/tools/shared.js.map +1 -1
  37. package/dist/src/mcp/tools/visualize-from-source.d.ts +52 -76
  38. package/dist/src/mcp/tools/visualize-from-source.d.ts.map +1 -1
  39. package/dist/src/mcp/tools/visualize-from-source.js +20 -5
  40. package/dist/src/mcp/tools/visualize-from-source.js.map +1 -1
  41. package/dist/src/mcp/tools/visualize.d.ts +45 -100
  42. package/dist/src/mcp/tools/visualize.d.ts.map +1 -1
  43. package/dist/src/mcp/tools/visualize.js +19 -19
  44. package/dist/src/mcp/tools/visualize.js.map +1 -1
  45. package/dist/src/patterns/definitions/comparison/grouped-bar.js +5 -5
  46. package/dist/src/patterns/definitions/comparison/grouped-bar.js.map +1 -1
  47. package/dist/src/patterns/definitions/composition/waffle.d.ts.map +1 -1
  48. package/dist/src/patterns/definitions/composition/waffle.js +17 -3
  49. package/dist/src/patterns/definitions/composition/waffle.js.map +1 -1
  50. package/dist/src/patterns/definitions/distribution/strip-plot.d.ts.map +1 -1
  51. package/dist/src/patterns/definitions/distribution/strip-plot.js +12 -3
  52. package/dist/src/patterns/definitions/distribution/strip-plot.js.map +1 -1
  53. package/dist/src/patterns/definitions/time/sparkline-grid.js +2 -2
  54. package/dist/src/patterns/definitions/time/sparkline-grid.js.map +1 -1
  55. package/dist/src/patterns/selector.d.ts.map +1 -1
  56. package/dist/src/patterns/selector.js +46 -1
  57. package/dist/src/patterns/selector.js.map +1 -1
  58. package/dist/src/renderers/d3/comparison/bar.d.ts.map +1 -1
  59. package/dist/src/renderers/d3/comparison/bar.js +24 -1
  60. package/dist/src/renderers/d3/comparison/bar.js.map +1 -1
  61. package/dist/src/renderers/d3/comparison/grouped-bar.d.ts.map +1 -1
  62. package/dist/src/renderers/d3/comparison/grouped-bar.js +9 -4
  63. package/dist/src/renderers/d3/comparison/grouped-bar.js.map +1 -1
  64. package/dist/src/renderers/d3/composition/donut.d.ts.map +1 -1
  65. package/dist/src/renderers/d3/composition/donut.js +12 -0
  66. package/dist/src/renderers/d3/composition/donut.js.map +1 -1
  67. package/dist/src/renderers/d3/composition/stacked-bar.d.ts.map +1 -1
  68. package/dist/src/renderers/d3/composition/stacked-bar.js +4 -0
  69. package/dist/src/renderers/d3/composition/stacked-bar.js.map +1 -1
  70. package/dist/src/renderers/d3/composition/treemap.js +2 -1
  71. package/dist/src/renderers/d3/composition/treemap.js.map +1 -1
  72. package/dist/src/renderers/d3/distribution/beeswarm.d.ts.map +1 -1
  73. package/dist/src/renderers/d3/distribution/beeswarm.js +8 -0
  74. package/dist/src/renderers/d3/distribution/beeswarm.js.map +1 -1
  75. package/dist/src/renderers/d3/distribution/histogram.js +36 -2
  76. package/dist/src/renderers/d3/distribution/histogram.js.map +1 -1
  77. package/dist/src/renderers/d3/flow/funnel.d.ts.map +1 -1
  78. package/dist/src/renderers/d3/flow/funnel.js +4 -0
  79. package/dist/src/renderers/d3/flow/funnel.js.map +1 -1
  80. package/dist/src/renderers/d3/flow/sankey-layout.js +20 -3
  81. package/dist/src/renderers/d3/flow/sankey-layout.js.map +1 -1
  82. package/dist/src/renderers/d3/heatmap.d.ts.map +1 -1
  83. package/dist/src/renderers/d3/heatmap.js +18 -3
  84. package/dist/src/renderers/d3/heatmap.js.map +1 -1
  85. package/dist/src/renderers/d3/radar.d.ts.map +1 -1
  86. package/dist/src/renderers/d3/radar.js +3 -1
  87. package/dist/src/renderers/d3/radar.js.map +1 -1
  88. package/dist/src/renderers/d3/relationship.d.ts.map +1 -1
  89. package/dist/src/renderers/d3/relationship.js +29 -7
  90. package/dist/src/renderers/d3/relationship.js.map +1 -1
  91. package/dist/src/renderers/d3/shared.js +7 -7
  92. package/dist/src/renderers/d3/shared.js.map +1 -1
  93. package/dist/src/renderers/d3/time/area.js +21 -7
  94. package/dist/src/renderers/d3/time/area.js.map +1 -1
  95. package/dist/src/renderers/d3/time/calendar-heatmap.js +6 -0
  96. package/dist/src/renderers/d3/time/calendar-heatmap.js.map +1 -1
  97. package/dist/src/renderers/d3/time/horizon-chart.d.ts.map +1 -1
  98. package/dist/src/renderers/d3/time/horizon-chart.js +10 -0
  99. package/dist/src/renderers/d3/time/horizon-chart.js.map +1 -1
  100. package/dist/src/renderers/d3/time/line.d.ts.map +1 -1
  101. package/dist/src/renderers/d3/time/line.js +27 -7
  102. package/dist/src/renderers/d3/time/line.js.map +1 -1
  103. package/dist/src/renderers/d3/time/small-multiples.js +8 -0
  104. package/dist/src/renderers/d3/time/small-multiples.js.map +1 -1
  105. package/dist/src/renderers/d3/time/sparkline-grid.d.ts.map +1 -1
  106. package/dist/src/renderers/d3/time/sparkline-grid.js +5 -2
  107. package/dist/src/renderers/d3/time/sparkline-grid.js.map +1 -1
  108. package/dist/src/renderers/d3/time/stream-graph.js +6 -0
  109. package/dist/src/renderers/d3/time/stream-graph.js.map +1 -1
  110. package/dist/src/renderers/html/_generated/bundles.d.ts +39 -39
  111. package/dist/src/renderers/html/_generated/bundles.d.ts.map +1 -1
  112. package/dist/src/renderers/html/_generated/bundles.js +39 -39
  113. package/dist/src/renderers/html/_generated/bundles.js.map +1 -1
  114. package/dist/src/renderers/html/template.js +2 -2
  115. package/dist/src/renderers/html/template.js.map +1 -1
  116. package/dist/src/types.d.ts +30 -2
  117. package/dist/src/types.d.ts.map +1 -1
  118. package/dist/src/types.js.map +1 -1
  119. package/package.json +2 -1
  120. package/src/analysis/rules.ts +10 -2
  121. package/src/connectors/csv.ts +31 -1
  122. package/src/connectors/dsl-compiler.ts +56 -20
  123. package/src/connectors/dsl-validator.ts +6 -1
  124. package/src/connectors/js-aggregation.ts +16 -11
  125. package/src/mcp/index.ts +63 -29
  126. package/src/mcp/spec-store.ts +5 -1
  127. package/src/mcp/tools/dsl-schemas.ts +1 -1
  128. package/src/mcp/tools/list-patterns.ts +2 -2
  129. package/src/mcp/tools/refine.ts +333 -258
  130. package/src/mcp/tools/shared.ts +70 -7
  131. package/src/mcp/tools/visualize-from-source.ts +20 -5
  132. package/src/mcp/tools/visualize.ts +22 -22
  133. package/src/patterns/definitions/comparison/grouped-bar.ts +5 -5
  134. package/src/patterns/definitions/composition/waffle.ts +17 -3
  135. package/src/patterns/definitions/distribution/strip-plot.ts +12 -3
  136. package/src/patterns/definitions/time/sparkline-grid.ts +2 -2
  137. package/src/patterns/selector.ts +47 -1
  138. package/src/renderers/d3/comparison/bar.ts +24 -1
  139. package/src/renderers/d3/comparison/grouped-bar.ts +9 -4
  140. package/src/renderers/d3/composition/donut.ts +14 -0
  141. package/src/renderers/d3/composition/stacked-bar.ts +5 -0
  142. package/src/renderers/d3/composition/treemap.ts +2 -1
  143. package/src/renderers/d3/distribution/beeswarm.ts +12 -0
  144. package/src/renderers/d3/distribution/histogram.ts +44 -2
  145. package/src/renderers/d3/flow/funnel.ts +8 -0
  146. package/src/renderers/d3/flow/sankey-layout.ts +23 -3
  147. package/src/renderers/d3/heatmap.ts +20 -2
  148. package/src/renderers/d3/radar.ts +4 -1
  149. package/src/renderers/d3/relationship.ts +31 -6
  150. package/src/renderers/d3/shared.ts +7 -7
  151. package/src/renderers/d3/time/area.ts +22 -7
  152. package/src/renderers/d3/time/calendar-heatmap.ts +5 -0
  153. package/src/renderers/d3/time/horizon-chart.ts +11 -0
  154. package/src/renderers/d3/time/line.ts +24 -9
  155. package/src/renderers/d3/time/small-multiples.ts +6 -0
  156. package/src/renderers/d3/time/sparkline-grid.ts +5 -2
  157. package/src/renderers/d3/time/stream-graph.ts +5 -0
  158. package/src/renderers/html/_generated/bundles.ts +39 -39
  159. package/src/renderers/html/template.ts +2 -2
  160. package/src/types.ts +18 -2
  161. package/dist/src/mcp/tools/connect-data.d.ts +0 -14
  162. package/dist/src/mcp/tools/connect-data.d.ts.map +0 -1
  163. package/dist/src/mcp/tools/connect-data.js +0 -80
  164. package/dist/src/mcp/tools/connect-data.js.map +0 -1
  165. package/src/mcp/tools/connect-data.ts +0 -94
package/src/mcp/index.ts CHANGED
@@ -61,9 +61,10 @@ import { screenshotInputSchema, handleScreenshot, closeBrowser } from './tools/s
61
61
  import { specStore } from './spec-store.js';
62
62
  import { registerPrompts } from './prompts.js';
63
63
 
64
- import { mkdirSync } from 'fs';
64
+ import { mkdirSync, readFileSync } from 'fs';
65
65
  import { join } from 'path';
66
66
  import { homedir } from 'os';
67
+ import { fileURLToPath } from 'url';
67
68
 
68
69
  // Pattern library imports
69
70
  import { registry } from '../patterns/registry.js';
@@ -81,29 +82,62 @@ const sourceManager = new SourceManager(join(dolexDir, 'sources.json'));
81
82
 
82
83
  const serverStartTime = Date.now();
83
84
 
85
+ const __dirname = join(fileURLToPath(import.meta.url), '..');
86
+ const iconPath = join(__dirname, '..', '..', 'assets', 'icon.svg');
87
+ let serverIcons: Array<{ src: string; mimeType: string }> | undefined;
88
+ try {
89
+ const svgData = readFileSync(iconPath);
90
+ serverIcons = [{ src: `data:image/svg+xml;base64,${svgData.toString('base64')}`, mimeType: 'image/svg+xml' }];
91
+ } catch {}
92
+
84
93
  // ─── CREATE SERVER ──────────────────────────────────────────────────────────
85
94
 
86
95
  const server = new McpServer(
87
96
  {
88
97
  name: 'dolex',
89
- version: '0.1.12',
98
+ version: '0.1.13',
99
+ ...(serverIcons && { icons: serverIcons }),
90
100
  },
91
101
  {
92
102
  instructions: [
93
- 'STOP. Read this before doing anything else.',
103
+ 'Dolex — Data visualization with 43 chart types.',
104
+ '',
105
+ 'WORKFLOW:',
106
+ '• Got a file path? → add_source(path) immediately, don\'t verify — this server runs locally on the user\'s machine',
107
+ '• Got inline data? → visualize(data, intent) directly',
108
+ '• Need to explore? → add_source → analyze_source → visualize_from_source per step',
109
+ '• Need a dashboard? → add_source → create_dashboard with views array',
110
+ '',
111
+ 'CONTINUATION (source already connected):',
112
+ '• Chart from source → visualize_from_source(sourceId, table, query, intent)',
113
+ '• Want to SEE rows (answer a question, validate data, show a table)? → query_source',
114
+ '• Want to CHART rows you already queried? → visualize(resultId=...) to reuse cached data',
115
+ '• Want a table view? → query_source for raw data, or visualize with includeDataTable=true for a formatted table with chart',
116
+ '• Tweak a chart → refine_visualization(specId, ...) — always use the MOST RECENT specId',
117
+ '• Tweak a dashboard → refine_dashboard(currentSpec, refinement)',
118
+ '• specId expired? → re-run the original visualize/visualize_from_source call, then continue refining from the new specId',
119
+ '',
120
+ 'TOOL GUIDE:',
121
+ '• add_source: Connect CSV/SQLite/Postgres/MySQL. Returns sourceId.',
122
+ '• describe_source: See schema, stats, samples. Use detail="compact" for large schemas.',
123
+ '• analyze_source: Auto-generate analysis plan with ready DSL queries. Execute each step with visualize_from_source; present results one at a time.',
124
+ '• query_source: Run DSL query, get rows. Returns resultId for visualize().',
125
+ '• visualize: Chart from inline data OR resultId from query_source. Auto-selects best pattern. Set title/subtitle here to avoid a refine round-trip.',
126
+ '• visualize_from_source: Chart from source + DSL query. Same as visualize but queries server-side — saves tokens.',
127
+ '• refine_visualization: Tweak a chart — sort, limit, filter, palette, highlight, flip, title, format. Each call returns a new specId.',
128
+ '• create_dashboard: Multi-chart layout from source with per-view queries.',
129
+ '• refine_dashboard: Iterate dashboard — add/remove views, filters, layout, theme.',
130
+ '• list_patterns: Browse available chart types. Only needed when the user asks what charts are available or you need a pattern ID.',
94
131
  '',
95
- 'When a user gives ANY file path, call add_source with that path IMMEDIATELY.',
96
- 'Do not check /mnt/user-data/uploads. Do not use the view tool. Do not verify the path. Do not hesitate.',
97
- 'Just call add_source. This MCP server runs locally on the user\'s machine.',
132
+ 'Utility tools: list_sources, remove_source, server_status (inspect cached data), clear_cache, report_bug (generate GitHub issue), export_html (get chart HTML by specId), screenshot (render to PNG).',
98
133
  '',
99
- 'add_source can access: /Users/*, /home/*, ~/*, /var/*, /tmp/*, C:\\*, D:\\*, any absolute path.',
100
- 'add_source CANNOT access: /mnt/user-data/*, /home/claude/* (cloud sandbox only).',
134
+ 'COLOR: Set palette (categorical/blue/warm/blueRed/etc.) and/or highlight specific values. Use colorField to control which column drives color.',
135
+ 'PATTERNS: 43 types auto-selected by data shape + intent. When user names a specific chart type, pass pattern="<id>" to force it. Use list_patterns to browse.',
101
136
  '',
102
- 'If user says "analyze /Users/bill/data/sales.csv" → call add_source with path=/Users/bill/data/sales.csv. Done.',
103
- 'If add_source returns an error, THEN discuss it. Never pre-emptively refuse.',
137
+ 'ERRORS: If a DSL query fails with field name suggestions, retry with the corrected name. If specId is expired, re-run visualize.',
104
138
  '',
105
- 'Dolex is a data analysis and visualization server with 43 chart types.',
106
- 'Workflow: add_source → describe_source or analyze_source → visualize_from_source → refine_visualization.',
139
+ 'DON\'T use Dolex for: simple arithmetic, explanations of chart types, non-data questions, or file format conversions (CSV export, PowerPoint, etc.).',
140
+ 'DO use Dolex when the user asks "what chart should I use" — run visualize and let the pattern selector recommend.',
107
141
  ].join('\n'),
108
142
  },
109
143
  );
@@ -138,7 +172,7 @@ registerAppTool(
138
172
  'visualize',
139
173
  {
140
174
  title: 'Visualize Data',
141
- description: 'Takes inline data + intent and returns visualization recommendations from a handcrafted pattern library of 41 chart types (bump chart, beeswarm, waffle, slope chart, etc.). Use `pattern` to force a specific chart type by ID (use list_patterns to discover IDs).\n\nPass data as an array of row objects, OR pass `resultId` from a previous `query_source` call to reuse cached data (saves tokens). For source-based data (CSV, SQLite, Postgres), use `visualize_from_source` instead.\n\nSet `title` and `subtitle` upfront to avoid a refine round-trip.\n\n**Response**: Returns compact JSON with `specId` (for refine calls), recommended pattern + title + reasoning, alternative chart types, and data shape summary. Chart HTML is delivered via structuredContent.\n\nColor system: Request a palette or highlight specific values via colorPreferences. Palettes: categorical, blue, green, purple, warm, blueRed, greenPurple, tealOrange, redGreen, traffic-light, profit-loss, temperature. Highlight mode: specify values to emphasize — all others become muted gray.\n\nGeographic maps: For choropleth/proportional-symbol patterns, set `geoRegion` to a region code (US, CN, JP, AU, EU, world, etc.) and/or `geoLevel` ("country" or "subdivision"). If omitted, Dolex auto-detects the region from data values — US states, Chinese provinces, Japanese prefectures, European countries, and 18 other regions are recognized automatically.',
175
+ description: 'Chart inline data or cached query results. Pass data array + intent, OR resultId from query_source.\n\nWhen to use: You have data in the conversation (pasted, generated, or from query_source resultId). Use visualize_from_source instead when data lives in a connected source — saves tokens.\n\nKey params: pattern (force a specific chart type), palette, highlight, colorField, title, subtitle.\n\nResponse: specId (use in refine calls — always use the most recent one), recommended pattern + reasoning, alternatives, data shape summary. Chart HTML in structuredContent. If the response includes notes, present each note to the user — they explain decisions the system made automatically.',
142
176
  inputSchema: visualizeInputSchema.shape,
143
177
  _meta: {
144
178
  ui: {
@@ -158,7 +192,7 @@ registerAppTool(
158
192
  'visualize_from_source',
159
193
  {
160
194
  title: 'Visualize from Data Source',
161
- description: 'Takes a data source + DSL query + intent and returns visualization recommendations from a handcrafted pattern library of 41 chart types. Use this when data lives in a connected source (CSV, SQLite, Postgres, MySQL) — Dolex queries the data server-side. If the user mentions a file path and no source exists yet, call add_source first with the path they gave you.\n\nRequires a source from `add_source`. Pass `sourceId`, `table`, and a `query` (declarative DSL with select, groupBy, filter, join, orderBy, limit). Set `title` and `subtitle` upfront to avoid a refine round-trip.\n\n**DSL query example**:\n```json\n{\n "select": ["region", { "field": "revenue", "aggregate": "sum", "as": "total" }],\n "groupBy": ["region"],\n "filter": { "field": "year", "equals": 2024 },\n "orderBy": { "field": "total", "direction": "desc" },\n "limit": 10\n}\n```\n\n**Filter shorthand**: `{ "field": "x", "equals": "y" }` — also `gt`, `gte`, `lt`, `lte`, `not_equals`. Single filters can be bare objects (no array needed). Canonical form: `{ "field", "op": "=", "value": "y" }`.\n\n**Joins**: Use `join` to combine tables within the same source (inner/left). Use `table.field` dot notation for joined fields. Multi-hop: `{ "table": "orders", "on": { "left": "order_id", "right": "id" } }, { "table": "customers", "on": { "left": "orders.customer_id", "right": "id" } }`.\n\n**Response**: Same as `visualize` — compact JSON with specId, recommended pattern, alternatives, data shape. Chart HTML via structuredContent.\n\nGeographic maps: For choropleth/proportional-symbol patterns, set `geoRegion` to a region code (US, CN, JP, AU, EU, world, etc.) and/or `geoLevel` ("country" or "subdivision"). If omitted, Dolex auto-detects the region from data values.',
195
+ description: 'Chart data from a connected source. Queries server-side — no data in the context window.\n\nWhen to use: Source already connected via add_source. Prefer this over query_source + visualize for one-step charting.\n\nKey params: sourceId, table, query (DSL: { select, groupBy, filter, orderBy, limit }), intent, pattern, palette, highlight, colorField.\n\nResponse: Same as visualize — specId, pattern, alternatives, chart HTML.',
162
196
  inputSchema: visualizeFromSourceInputSchema.shape,
163
197
  _meta: {
164
198
  ui: {
@@ -176,7 +210,7 @@ server.registerTool(
176
210
  'list_patterns',
177
211
  {
178
212
  title: 'List Visualization Patterns',
179
- description: 'Browse all available visualization patterns with their descriptions, best-for hints, data requirements, and per-pattern capabilities (color encoding, config options). Also returns full color system documentation (palettes, highlight mode, usage).',
213
+ description: 'Browse all 43 chart types with data requirements, capabilities, and examples. Returns per-pattern color encoding support and config options.\n\nWhen to use: User asks what charts are available, or you need to look up a pattern ID for the pattern parameter.',
180
214
  },
181
215
  handleListPatterns(() => registry.getAll()),
182
216
  );
@@ -186,7 +220,7 @@ registerAppTool(
186
220
  'refine_visualization',
187
221
  {
188
222
  title: 'Refine Visualization',
189
- description: 'Tweak a visualization — sort, limit, flip axes, change colors, highlight values, update title. Pass `specId` from a previous visualize or refine call (no data round-trip needed).\n\nUse `selectAlternative` with a pattern ID to switch to an alternative from the original visualize call (e.g., "line", "area"). Returns a new `specId` for further refinements.\n\nColor refinements: "use warm palette", "highlight North and South", "highlight Q1 in #ff6b6b", "mute to 30% opacity", "color by target" (alluvial). Palettes: categorical, blue, green, purple, warm, blueRed, greenPurple, tealOrange, redGreen, traffic-light, profit-loss, temperature.',
223
+ description: 'Tweak a chart using structured parameters. Pass specId from a previous visualize or refine call.\n\nAlways use the most recent specId — each refine returns a new one that includes all previous changes. If the response includes notes, present each note to the user.\n\nParameters (all optional except specId):\n• sort: { direction: "asc"|"desc", field?: "column_name" } — if field omitted, sorts by primary measure axis\n• limit: number (top N rows)\n• filter: [{ field: "col", op: "in"|"not_in"|"gt"|"gte"|"lt"|"lte", values: [...] }] — pass [] to clear filters\n• flip: true (swap axes — Cartesian charts only)\n• title / subtitle / xLabel / yLabel: strings\n• palette: "categorical"|"blue"|"warm"|"blueRed"|"green"|"purple"|"greenPurple"|"tealOrange"|"redGreen"|"traffic-light"|"profit-loss"|"temperature"\n• highlight: { values: ["val1", "val2"], color?: "css-color", mutedOpacity?: 0.3 } — pass null to clear\n• colorField: "column_name" (which field drives color)\n• flowColorBy: "source"|"target" (alluvial charts only)\n• format: "percent"|"dollar"|"integer"|"decimal"|"compact"\n• switchPattern: "pattern-id" (switch chart type)\n\nCompound chart params: removeTable, layout ("rows"|"columns"), hideColumns (array of column names to hide from data table).\n\nReturns new specId + changes applied + available alternatives.',
190
224
  inputSchema: refineInputSchema.shape,
191
225
  _meta: {
192
226
  ui: {
@@ -205,7 +239,7 @@ server.registerTool(
205
239
  'add_source',
206
240
  {
207
241
  title: 'Add Data Source',
208
- description: 'STOP. Call this tool with the user\'s path. Do not check uploads. Do not verify. Just call it.\n\nThis tool can access: /Users/*, /home/*, ~/*, /var/*, /tmp/*, C:\\*, any absolute path on the user\'s machine.\nThis tool cannot access: /mnt/user-data/*, /home/claude/* (cloud sandbox).\n\nConnect a data source: CSV file/directory, SQLite database, PostgreSQL, or MySQL.\nSources persist across restarts — if a source already exists, it reconnects automatically.\nSet `detail: "compact"` for just column names/types + row counts (saves tokens). Default `"full"` includes stats, top values, and sample rows.',
242
+ description: 'Connect a data source. Call this immediately with any user-provided path — this server runs locally on the user\'s machine.\n\nSupports CSV files/directories, SQLite, PostgreSQL, MySQL. Sources persist across restarts.\n\nKey params: detail="compact" for just column names/types (saves tokens), detail="full" for stats + samples (default).\n\nReturns sourceId (use in all subsequent source operations).',
209
243
  inputSchema: addSourceInputSchema,
210
244
  },
211
245
  handleAddSource({ sourceManager }),
@@ -215,7 +249,7 @@ server.registerTool(
215
249
  'list_sources',
216
250
  {
217
251
  title: 'List Data Sources',
218
- description: 'List all connected data sources with their IDs, types, and table counts.',
252
+ description: 'List all connected data sources with IDs, types, and table counts.',
219
253
  },
220
254
  handleListSources({ sourceManager }),
221
255
  );
@@ -224,7 +258,7 @@ server.registerTool(
224
258
  'remove_source',
225
259
  {
226
260
  title: 'Remove Data Source',
227
- description: 'Disconnect and remove a data source by its ID.',
261
+ description: 'Disconnect and remove a data source by ID.',
228
262
  inputSchema: removeSourceInputSchema,
229
263
  },
230
264
  handleRemoveSource({ sourceManager }),
@@ -234,7 +268,7 @@ server.registerTool(
234
268
  'describe_source',
235
269
  {
236
270
  title: 'Describe Data Source',
237
- description: 'Returns column profiles for a previously-added data source. Use this to re-examine a source mid-conversation.\n\nSet `detail: "compact"` to get just column names/types + row counts (saves tokens). Default `"full"` includes stats, top values, and sample rows.',
271
+ description: 'Examine column profiles for a connected source. Use to re-inspect data mid-conversation.\n\nKey params: detail="compact" for column names/types only (saves tokens), detail="full" for stats + samples (default).',
238
272
  inputSchema: describeSourceInputSchema,
239
273
  },
240
274
  handleDescribeSource({ sourceManager }),
@@ -244,7 +278,7 @@ server.registerTool(
244
278
  'analyze_source',
245
279
  {
246
280
  title: 'Analyze Data Source',
247
- description: 'Examines a connected data source and generates a structured analysis plan with ready-to-execute DSL queries. Returns 4-6 analysis steps covering trends, comparisons, distributions, and relationships — each with a title, question, query, and suggested chart patterns.\n\nUse this after add_source to get an automatic analysis plan. If the user mentions a file and no source exists, call add_source first with their path. Then execute each step with visualize_from_source.',
281
+ description: 'Auto-generate a structured analysis plan with ready-to-execute DSL queries. Returns 4-6 analysis steps covering trends, comparisons, distributions, and relationships.\n\nWhen to use: After add_source, to get an automatic data exploration plan. Execute each step with visualize_from_source and present results one at a time.',
248
282
  inputSchema: analyzeSourceInputSchema.shape,
249
283
  },
250
284
  handleAnalyzeSource({ sourceManager }),
@@ -254,7 +288,7 @@ server.registerTool(
254
288
  'query_source',
255
289
  {
256
290
  title: 'Query Data Source',
257
- description: 'Run a declarative DSL query against a data source and see tabular results. Useful for exploration, validation, or answering data questions without visualizing.\n\nReturns a `resultId` — pass it to `visualize` with `resultId` to chart the same data without re-sending rows (saves tokens).\n\n**DSL query example**:\n```json\n{\n "select": ["category", { "field": "amount", "aggregate": "sum", "as": "total" }],\n "groupBy": ["category"],\n "filter": { "field": "status", "op": "=", "value": "completed" },\n "orderBy": { "field": "total", "direction": "desc" },\n "limit": 20\n}\n```\n\n**Filter shorthand**: `{ "field": "status", "equals": "active" }` — also `gt`, `gte`, `lt`, `lte`, `not_equals`. Single filters can be bare objects (no array wrapping needed).\n\n**Joins**: Use `join` to combine tables. Use `table.field` dot notation for joined fields in select/groupBy/filter.\n```json\n{\n "join": [\n { "table": "orders", "on": { "left": "order_id", "right": "id" } },\n { "table": "customers", "on": { "left": "orders.customer_id", "right": "id" } }\n ],\n "select": ["customers.name", { "field": "price", "aggregate": "sum", "as": "total" }],\n "groupBy": ["customers.name"]\n}\n```\nMulti-hop: chain joins and use `table.field` in later join ON clauses to reference columns from earlier joins.',
291
+ description: 'Run a DSL query and get tabular results. Returns resultId — pass to visualize(resultId=...) to chart the same data without re-sending rows.\n\nWhen to use: Need to see raw data, answer a data question, or validate before charting. For one-step charting, use visualize_from_source instead.\n\nKey params: sourceId, table, query (DSL: { select, groupBy, filter, join, orderBy, limit }).',
258
292
  inputSchema: querySourceInputSchema,
259
293
  },
260
294
  handleQuerySource({ sourceManager }),
@@ -266,7 +300,7 @@ registerAppTool(
266
300
  'create_dashboard',
267
301
  {
268
302
  title: 'Create Dashboard',
269
- description: 'Create a multi-view dashboard from a data source. Each view has its own DSL query and intent for pattern selection. Supports global filters (select, multi-select, range) and cross-view interactions (crossfilter, highlight).\n\nRequires an existing data source (from add_source). Each view specifies an intent and query — Dolex selects the best chart pattern for each.\n\nLayout: auto-calculated grid columns, or specify columns (1-4) and per-view colSpan/rowSpan.\n\nReturns the full DashboardSpec (pass to refine_dashboard for iterations).',
303
+ description: 'Create a multi-view dashboard from a data source. Each view has its own DSL query and intent.\n\nKey params: sourceId, table, views (array with id, title, intent, query per view), layout, filters.\n\nReturns DashboardSpec (pass to refine_dashboard for iterations) + rendered HTML.',
270
304
  inputSchema: createDashboardInputSchema.shape,
271
305
  _meta: {
272
306
  ui: {
@@ -285,7 +319,7 @@ registerAppTool(
285
319
  'refine_dashboard',
286
320
  {
287
321
  title: 'Refine Dashboard',
288
- description: 'Iterate on a dashboard — add/remove/modify views, change layout, add filters, switch themes, swap view positions, or override chart patterns.\n\nPass the currentSpec from a previous create_dashboard or refine_dashboard call, plus a natural language refinement.\n\nExamples:\n- "add a chart showing revenue by month"\n- "remove the bar chart"\n- "make it 3 columns"\n- "add a region filter"\n- "dark mode"\n- "swap view-1 and view-2"\n- "show the trend as a line chart"',
322
+ description: 'Iterate on a dashboard using natural language. Pass currentSpec from create_dashboard or previous refine.\n\nUnlike refine_visualization which uses structured parameters, this tool accepts natural language descriptions of changes.\n\nExamples: "add a chart showing revenue by month", "remove the bar chart", "3 columns", "add region filter", "dark mode".\n\nReturns updated DashboardSpec + rendered HTML.',
289
323
  inputSchema: refineDashboardInputSchema.shape,
290
324
  _meta: {
291
325
  ui: {
@@ -306,7 +340,7 @@ server.registerTool(
306
340
  'server_status',
307
341
  {
308
342
  title: 'Server Status',
309
- description: 'Shows what data Dolex currently holds in memory: cached visualization specs (with data row counts), query result cache, connected data sources, and server uptime. Use this to audit data retention before clearing.',
343
+ description: 'Inspect cached data in server memory: specs with row counts, query results, connected sources, uptime. Use before clear_cache.',
310
344
  },
311
345
  handleServerStatus(privacyDeps),
312
346
  );
@@ -315,7 +349,7 @@ server.registerTool(
315
349
  'clear_cache',
316
350
  {
317
351
  title: 'Clear Cache',
318
- description: 'Clears cached data from server memory. Scope options: "all" (specs + results), "specs" (visualization specs and their embedded data), "results" (query result cache). Use after working with sensitive data.',
352
+ description: 'Clear cached data from memory. Scope: "all" (specs + results), "specs" (visualization specs), "results" (query cache). Use after working with sensitive data.',
319
353
  inputSchema: clearCacheInputSchema,
320
354
  },
321
355
  handleClearCache(privacyDeps),
@@ -325,7 +359,7 @@ server.registerTool(
325
359
  'report_bug',
326
360
  {
327
361
  title: 'Report Bug',
328
- description: 'Generate a sanitized bug report for a GitHub issue. Includes environment info, recent operation history, and visualization context — but never includes data values, connection strings, or file paths. Field names are anonymized by default; set includeFieldNames to show real names. Copy the markdown output and paste into a GitHub issue.',
362
+ description: 'Generate a sanitized bug report for GitHub issues. Includes environment info and recent operations — never includes data values or file paths.',
329
363
  inputSchema: bugReportInputSchema.shape,
330
364
  },
331
365
  handleReportBug({ sourceManager, serverStartTime }),
@@ -335,7 +369,7 @@ server.registerTool(
335
369
  'export_html',
336
370
  {
337
371
  title: 'Export Chart HTML',
338
- description: 'Returns the full, self-contained HTML for a previously-created visualization. Pass a specId from visualize, visualize_from_source, or refine_visualization. The returned HTML is a complete document with embedded D3 and data — suitable for saving to a file, opening in a browser, or screenshotting programmatically.',
372
+ description: 'Get the full self-contained HTML for a visualization by specId. Suitable for saving to file or opening in a browser.',
339
373
  inputSchema: exportHtmlInputSchema.shape,
340
374
  },
341
375
  handleExportHtml(),
@@ -345,7 +379,7 @@ server.registerTool(
345
379
  'screenshot',
346
380
  {
347
381
  title: 'Screenshot Visualization',
348
- description: 'Render a visualization to a PNG image via headless Chromium. Returns a base64-encoded PNG that Claude can see directly. Pass a specId from visualize, visualize_from_source, or refine_visualization.\n\nRequires Playwright: npm install playwright && npx playwright install chromium',
382
+ description: 'Render a visualization to PNG via headless Chromium. Returns base64-encoded image. Requires Playwright: npm install playwright && npx playwright install chromium.',
349
383
  inputSchema: screenshotInputSchema.shape,
350
384
  },
351
385
  handleScreenshot(),
@@ -18,6 +18,7 @@ export interface StoredSpec {
18
18
  spec: VisualizationSpec | CompoundVisualizationSpec;
19
19
  columns: DataColumn[];
20
20
  alternatives: Map<string, VisualizationSpec>;
21
+ originalData?: Record<string, any>[];
21
22
  createdAt: number;
22
23
  }
23
24
 
@@ -47,6 +48,7 @@ export class SpecStore {
47
48
  spec: VisualizationSpec | CompoundVisualizationSpec,
48
49
  columns: DataColumn[],
49
50
  alternatives: Map<string, VisualizationSpec> = new Map(),
51
+ originalData?: Record<string, any>[],
50
52
  ): string {
51
53
  this.purgeExpired();
52
54
 
@@ -60,6 +62,7 @@ export class SpecStore {
60
62
  spec,
61
63
  columns,
62
64
  alternatives,
65
+ originalData,
63
66
  createdAt: Date.now(),
64
67
  });
65
68
  return id;
@@ -82,7 +85,8 @@ export class SpecStore {
82
85
  const existing = this.store.get(specId);
83
86
  const columns = existing?.columns ?? [];
84
87
  const alternatives = existing?.alternatives ?? new Map<string, VisualizationSpec>();
85
- return this.save(newSpec, columns, alternatives);
88
+ const originalData = existing?.originalData;
89
+ return this.save(newSpec, columns, alternatives, originalData);
86
90
  }
87
91
 
88
92
  getAlternative(specId: string, patternId: string): VisualizationSpec | null {
@@ -185,7 +185,7 @@ export const dslQuerySchema = z.preprocess(normalizeDslQueryInput, dslQueryInner
185
185
 
186
186
  // ─── DASHBOARD SCHEMAS ──────────────────────────────────────────────────────
187
187
 
188
- const ALL_PALETTE_NAMES = [
188
+ export const ALL_PALETTE_NAMES = [
189
189
  'categorical', 'blue', 'green', 'purple', 'warm',
190
190
  'blueRed', 'greenPurple', 'tealOrange', 'redGreen',
191
191
  'traffic-light', 'profit-loss', 'temperature',
@@ -272,8 +272,8 @@ const COLOR_SYSTEM_DOCS = {
272
272
  ],
273
273
  },
274
274
  howToApply: {
275
- visualize: 'Pass colorPreferences: { palette?, highlight?, colorField? } in the visualize tool input',
276
- refine: 'Pass a natural language refinement like "use warm palette", "highlight Engineering and Science", "mute to 30% opacity", "color by target"',
275
+ visualize: 'Pass palette, highlight, colorField as top-level params in the visualize tool input',
276
+ refine: 'Pass structured params: palette, highlight: { values: [...] }, colorField, etc.',
277
277
  },
278
278
  };
279
279