@outsidedata/dolex 0.1.13 → 1.0.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 (215) hide show
  1. package/README.md +8 -8
  2. package/dist/src/analysis/rules.d.ts.map +1 -1
  3. package/dist/src/analysis/rules.js +8 -2
  4. package/dist/src/analysis/rules.js.map +1 -1
  5. package/dist/src/connectors/csv.d.ts.map +1 -1
  6. package/dist/src/connectors/csv.js +31 -1
  7. package/dist/src/connectors/csv.js.map +1 -1
  8. package/dist/src/connectors/dsl-compiler.d.ts +7 -6
  9. package/dist/src/connectors/dsl-compiler.d.ts.map +1 -1
  10. package/dist/src/connectors/dsl-compiler.js +72 -79
  11. package/dist/src/connectors/dsl-compiler.js.map +1 -1
  12. package/dist/src/connectors/dsl-validator.js +6 -1
  13. package/dist/src/connectors/dsl-validator.js.map +1 -1
  14. package/dist/src/connectors/index.d.ts +0 -3
  15. package/dist/src/connectors/index.d.ts.map +1 -1
  16. package/dist/src/connectors/index.js +0 -3
  17. package/dist/src/connectors/index.js.map +1 -1
  18. package/dist/src/connectors/js-aggregation.d.ts +4 -4
  19. package/dist/src/connectors/js-aggregation.d.ts.map +1 -1
  20. package/dist/src/connectors/js-aggregation.js +22 -16
  21. package/dist/src/connectors/js-aggregation.js.map +1 -1
  22. package/dist/src/connectors/manager.d.ts.map +1 -1
  23. package/dist/src/connectors/manager.js +4 -21
  24. package/dist/src/connectors/manager.js.map +1 -1
  25. package/dist/src/mcp/app-shell.js +1 -1
  26. package/dist/src/mcp/index.d.ts +8 -8
  27. package/dist/src/mcp/index.js +87 -53
  28. package/dist/src/mcp/index.js.map +1 -1
  29. package/dist/src/mcp/prompts.js +4 -4
  30. package/dist/src/mcp/prompts.js.map +1 -1
  31. package/dist/src/mcp/spec-store.d.ts +2 -1
  32. package/dist/src/mcp/spec-store.d.ts.map +1 -1
  33. package/dist/src/mcp/spec-store.js +4 -2
  34. package/dist/src/mcp/spec-store.js.map +1 -1
  35. package/dist/src/mcp/tools/analyze.d.ts +1 -1
  36. package/dist/src/mcp/tools/analyze.js +2 -2
  37. package/dist/src/mcp/tools/analyze.js.map +1 -1
  38. package/dist/src/mcp/tools/bug-report.d.ts.map +1 -1
  39. package/dist/src/mcp/tools/bug-report.js +2 -10
  40. package/dist/src/mcp/tools/bug-report.js.map +1 -1
  41. package/dist/src/mcp/tools/dashboard.js +1 -1
  42. package/dist/src/mcp/tools/dashboard.js.map +1 -1
  43. package/dist/src/mcp/tools/dsl-schemas.d.ts +53 -52
  44. package/dist/src/mcp/tools/dsl-schemas.d.ts.map +1 -1
  45. package/dist/src/mcp/tools/dsl-schemas.js +3 -3
  46. package/dist/src/mcp/tools/dsl-schemas.js.map +1 -1
  47. package/dist/src/mcp/tools/export-html.d.ts +1 -1
  48. package/dist/src/mcp/tools/export-html.js +2 -2
  49. package/dist/src/mcp/tools/export-html.js.map +1 -1
  50. package/dist/src/mcp/tools/list-patterns.js +2 -2
  51. package/dist/src/mcp/tools/list-patterns.js.map +1 -1
  52. package/dist/src/mcp/tools/query-source.d.ts +17 -17
  53. package/dist/src/mcp/tools/query-source.js +4 -4
  54. package/dist/src/mcp/tools/query-source.js.map +1 -1
  55. package/dist/src/mcp/tools/refine.d.ts +124 -15
  56. package/dist/src/mcp/tools/refine.d.ts.map +1 -1
  57. package/dist/src/mcp/tools/refine.js +335 -253
  58. package/dist/src/mcp/tools/refine.js.map +1 -1
  59. package/dist/src/mcp/tools/result-cache.d.ts +1 -1
  60. package/dist/src/mcp/tools/result-cache.js +1 -1
  61. package/dist/src/mcp/tools/screenshot.js +1 -1
  62. package/dist/src/mcp/tools/screenshot.js.map +1 -1
  63. package/dist/src/mcp/tools/server-privacy.d.ts.map +1 -1
  64. package/dist/src/mcp/tools/server-privacy.js +6 -7
  65. package/dist/src/mcp/tools/server-privacy.js.map +1 -1
  66. package/dist/src/mcp/tools/shared.d.ts +15 -2
  67. package/dist/src/mcp/tools/shared.d.ts.map +1 -1
  68. package/dist/src/mcp/tools/shared.js +64 -6
  69. package/dist/src/mcp/tools/shared.js.map +1 -1
  70. package/dist/src/mcp/tools/sources.d.ts +5 -113
  71. package/dist/src/mcp/tools/sources.d.ts.map +1 -1
  72. package/dist/src/mcp/tools/sources.js +15 -44
  73. package/dist/src/mcp/tools/sources.js.map +1 -1
  74. package/dist/src/mcp/tools/visualize-from-source.d.ts +53 -77
  75. package/dist/src/mcp/tools/visualize-from-source.d.ts.map +1 -1
  76. package/dist/src/mcp/tools/visualize-from-source.js +24 -9
  77. package/dist/src/mcp/tools/visualize-from-source.js.map +1 -1
  78. package/dist/src/mcp/tools/visualize.d.ts +47 -102
  79. package/dist/src/mcp/tools/visualize.d.ts.map +1 -1
  80. package/dist/src/mcp/tools/visualize.js +24 -24
  81. package/dist/src/mcp/tools/visualize.js.map +1 -1
  82. package/dist/src/patterns/definitions/comparison/grouped-bar.js +5 -5
  83. package/dist/src/patterns/definitions/comparison/grouped-bar.js.map +1 -1
  84. package/dist/src/patterns/definitions/composition/waffle.d.ts.map +1 -1
  85. package/dist/src/patterns/definitions/composition/waffle.js +17 -3
  86. package/dist/src/patterns/definitions/composition/waffle.js.map +1 -1
  87. package/dist/src/patterns/definitions/distribution/strip-plot.d.ts.map +1 -1
  88. package/dist/src/patterns/definitions/distribution/strip-plot.js +12 -3
  89. package/dist/src/patterns/definitions/distribution/strip-plot.js.map +1 -1
  90. package/dist/src/patterns/definitions/time/sparkline-grid.js +2 -2
  91. package/dist/src/patterns/definitions/time/sparkline-grid.js.map +1 -1
  92. package/dist/src/patterns/selector.d.ts.map +1 -1
  93. package/dist/src/patterns/selector.js +46 -1
  94. package/dist/src/patterns/selector.js.map +1 -1
  95. package/dist/src/renderers/d3/comparison/bar.d.ts.map +1 -1
  96. package/dist/src/renderers/d3/comparison/bar.js +24 -1
  97. package/dist/src/renderers/d3/comparison/bar.js.map +1 -1
  98. package/dist/src/renderers/d3/comparison/grouped-bar.d.ts.map +1 -1
  99. package/dist/src/renderers/d3/comparison/grouped-bar.js +9 -4
  100. package/dist/src/renderers/d3/comparison/grouped-bar.js.map +1 -1
  101. package/dist/src/renderers/d3/composition/donut.d.ts.map +1 -1
  102. package/dist/src/renderers/d3/composition/donut.js +12 -0
  103. package/dist/src/renderers/d3/composition/donut.js.map +1 -1
  104. package/dist/src/renderers/d3/composition/stacked-bar.d.ts.map +1 -1
  105. package/dist/src/renderers/d3/composition/stacked-bar.js +4 -0
  106. package/dist/src/renderers/d3/composition/stacked-bar.js.map +1 -1
  107. package/dist/src/renderers/d3/composition/treemap.js +2 -1
  108. package/dist/src/renderers/d3/composition/treemap.js.map +1 -1
  109. package/dist/src/renderers/d3/distribution/beeswarm.d.ts.map +1 -1
  110. package/dist/src/renderers/d3/distribution/beeswarm.js +8 -0
  111. package/dist/src/renderers/d3/distribution/beeswarm.js.map +1 -1
  112. package/dist/src/renderers/d3/distribution/histogram.js +36 -2
  113. package/dist/src/renderers/d3/distribution/histogram.js.map +1 -1
  114. package/dist/src/renderers/d3/flow/funnel.d.ts.map +1 -1
  115. package/dist/src/renderers/d3/flow/funnel.js +4 -0
  116. package/dist/src/renderers/d3/flow/funnel.js.map +1 -1
  117. package/dist/src/renderers/d3/flow/sankey-layout.js +20 -3
  118. package/dist/src/renderers/d3/flow/sankey-layout.js.map +1 -1
  119. package/dist/src/renderers/d3/heatmap.d.ts.map +1 -1
  120. package/dist/src/renderers/d3/heatmap.js +18 -3
  121. package/dist/src/renderers/d3/heatmap.js.map +1 -1
  122. package/dist/src/renderers/d3/radar.d.ts.map +1 -1
  123. package/dist/src/renderers/d3/radar.js +3 -1
  124. package/dist/src/renderers/d3/radar.js.map +1 -1
  125. package/dist/src/renderers/d3/relationship.d.ts.map +1 -1
  126. package/dist/src/renderers/d3/relationship.js +29 -7
  127. package/dist/src/renderers/d3/relationship.js.map +1 -1
  128. package/dist/src/renderers/d3/shared.js +7 -7
  129. package/dist/src/renderers/d3/shared.js.map +1 -1
  130. package/dist/src/renderers/d3/time/area.js +21 -7
  131. package/dist/src/renderers/d3/time/area.js.map +1 -1
  132. package/dist/src/renderers/d3/time/calendar-heatmap.js +6 -0
  133. package/dist/src/renderers/d3/time/calendar-heatmap.js.map +1 -1
  134. package/dist/src/renderers/d3/time/horizon-chart.d.ts.map +1 -1
  135. package/dist/src/renderers/d3/time/horizon-chart.js +10 -0
  136. package/dist/src/renderers/d3/time/horizon-chart.js.map +1 -1
  137. package/dist/src/renderers/d3/time/line.d.ts.map +1 -1
  138. package/dist/src/renderers/d3/time/line.js +27 -7
  139. package/dist/src/renderers/d3/time/line.js.map +1 -1
  140. package/dist/src/renderers/d3/time/small-multiples.js +8 -0
  141. package/dist/src/renderers/d3/time/small-multiples.js.map +1 -1
  142. package/dist/src/renderers/d3/time/sparkline-grid.d.ts.map +1 -1
  143. package/dist/src/renderers/d3/time/sparkline-grid.js +5 -2
  144. package/dist/src/renderers/d3/time/sparkline-grid.js.map +1 -1
  145. package/dist/src/renderers/d3/time/stream-graph.js +6 -0
  146. package/dist/src/renderers/d3/time/stream-graph.js.map +1 -1
  147. package/dist/src/renderers/html/_generated/bundles.d.ts +39 -39
  148. package/dist/src/renderers/html/_generated/bundles.d.ts.map +1 -1
  149. package/dist/src/renderers/html/_generated/bundles.js +39 -39
  150. package/dist/src/renderers/html/_generated/bundles.js.map +1 -1
  151. package/dist/src/renderers/html/builders/dashboard.js +2 -2
  152. package/dist/src/renderers/html/template.js +2 -2
  153. package/dist/src/renderers/html/template.js.map +1 -1
  154. package/dist/src/types.d.ts +33 -26
  155. package/dist/src/types.d.ts.map +1 -1
  156. package/dist/src/types.js.map +1 -1
  157. package/package.json +2 -4
  158. package/src/analysis/rules.ts +10 -2
  159. package/src/connectors/csv.ts +31 -1
  160. package/src/connectors/dsl-compiler.ts +76 -82
  161. package/src/connectors/dsl-validator.ts +6 -1
  162. package/src/connectors/index.ts +0 -3
  163. package/src/connectors/js-aggregation.ts +20 -15
  164. package/src/connectors/manager.ts +4 -24
  165. package/src/mcp/app-shell.ts +1 -1
  166. package/src/mcp/index.ts +87 -53
  167. package/src/mcp/prompts.ts +4 -4
  168. package/src/mcp/spec-store.ts +5 -1
  169. package/src/mcp/tools/analyze.ts +2 -2
  170. package/src/mcp/tools/bug-report.ts +2 -10
  171. package/src/mcp/tools/dashboard.ts +1 -1
  172. package/src/mcp/tools/dsl-schemas.ts +3 -3
  173. package/src/mcp/tools/export-html.ts +2 -2
  174. package/src/mcp/tools/list-patterns.ts +2 -2
  175. package/src/mcp/tools/query-source.ts +4 -4
  176. package/src/mcp/tools/refine.ts +333 -258
  177. package/src/mcp/tools/result-cache.ts +1 -1
  178. package/src/mcp/tools/screenshot.ts +1 -1
  179. package/src/mcp/tools/server-privacy.ts +6 -7
  180. package/src/mcp/tools/shared.ts +70 -7
  181. package/src/mcp/tools/sources.ts +18 -46
  182. package/src/mcp/tools/visualize-from-source.ts +24 -9
  183. package/src/mcp/tools/visualize.ts +27 -27
  184. package/src/patterns/definitions/comparison/grouped-bar.ts +5 -5
  185. package/src/patterns/definitions/composition/waffle.ts +17 -3
  186. package/src/patterns/definitions/distribution/strip-plot.ts +12 -3
  187. package/src/patterns/definitions/time/sparkline-grid.ts +2 -2
  188. package/src/patterns/selector.ts +47 -1
  189. package/src/renderers/d3/comparison/bar.ts +24 -1
  190. package/src/renderers/d3/comparison/grouped-bar.ts +9 -4
  191. package/src/renderers/d3/composition/donut.ts +14 -0
  192. package/src/renderers/d3/composition/stacked-bar.ts +5 -0
  193. package/src/renderers/d3/composition/treemap.ts +2 -1
  194. package/src/renderers/d3/distribution/beeswarm.ts +12 -0
  195. package/src/renderers/d3/distribution/histogram.ts +44 -2
  196. package/src/renderers/d3/flow/funnel.ts +8 -0
  197. package/src/renderers/d3/flow/sankey-layout.ts +23 -3
  198. package/src/renderers/d3/heatmap.ts +20 -2
  199. package/src/renderers/d3/radar.ts +4 -1
  200. package/src/renderers/d3/relationship.ts +31 -6
  201. package/src/renderers/d3/shared.ts +7 -7
  202. package/src/renderers/d3/time/area.ts +22 -7
  203. package/src/renderers/d3/time/calendar-heatmap.ts +5 -0
  204. package/src/renderers/d3/time/horizon-chart.ts +11 -0
  205. package/src/renderers/d3/time/line.ts +24 -9
  206. package/src/renderers/d3/time/small-multiples.ts +6 -0
  207. package/src/renderers/d3/time/sparkline-grid.ts +5 -2
  208. package/src/renderers/d3/time/stream-graph.ts +5 -0
  209. package/src/renderers/html/_generated/bundles.ts +39 -39
  210. package/src/renderers/html/builders/dashboard.ts +2 -2
  211. package/src/renderers/html/template.ts +2 -2
  212. package/src/types.ts +21 -33
  213. package/src/connectors/mysql.ts +0 -378
  214. package/src/connectors/postgres.ts +0 -367
  215. package/src/connectors/sqlite.ts +0 -364
@@ -1,15 +1,15 @@
1
1
  /**
2
2
  * JS-based aggregation and window function helpers.
3
3
  *
4
- * Used when the SQL dialect doesn't support certain aggregates natively
5
- * (e.g., median, stddev, percentile on SQLite/MySQL) or window functions.
4
+ * Used when SQLite doesn't support certain aggregates natively
5
+ * (e.g., median, stddev, percentile) or window functions.
6
6
  * All functions are pure — no side effects or class dependencies.
7
7
  */
8
8
 
9
9
  import type { DslQuery, DslOrderBy, DslWindowField } from '../types.js';
10
10
  import { isDslAggregateField, isDslWindowField } from '../types.js';
11
11
  import type { ConnectedSource } from './types.js';
12
- import { compileDsl } from './dsl-compiler.js';
12
+ import { compileDsl, fieldAlias } from './dsl-compiler.js';
13
13
 
14
14
  const MAX_RESULT_LIMIT = 10000;
15
15
 
@@ -102,9 +102,7 @@ function pad2(n: number): string {
102
102
  return String(n).padStart(2, '0');
103
103
  }
104
104
 
105
- function bucketDate(dateStr: string, bucket: string): string {
106
- const d = new Date(dateStr);
107
- if (isNaN(d.getTime())) return dateStr;
105
+ function bucketDateFromParsed(d: Date, bucket: string): string {
108
106
  const year = d.getUTCFullYear();
109
107
  const month = d.getUTCMonth() + 1;
110
108
 
@@ -125,12 +123,19 @@ function bucketDate(dateStr: string, bucket: string): string {
125
123
  case 'year':
126
124
  return String(year);
127
125
  default:
128
- return dateStr;
126
+ return String(d);
129
127
  }
130
128
  }
131
129
 
132
- function stripTablePrefix(field: string): string {
133
- return field.includes('.') ? field.split('.', 2)[1] : field;
130
+ function bucketDate(dateStr: string, bucket: string): string {
131
+ const numVal = Number(dateStr);
132
+ if (!isNaN(numVal) && numVal > 1800 && numVal < 2200 && Math.floor(numVal) === numVal) {
133
+ if (bucket === 'year') return String(numVal);
134
+ return bucketDateFromParsed(new Date(Date.UTC(numVal, 0, 1)), bucket);
135
+ }
136
+ const d = new Date(dateStr);
137
+ if (isNaN(d.getTime())) return dateStr;
138
+ return bucketDateFromParsed(d, bucket);
134
139
  }
135
140
 
136
141
  // ─── Window Functions ────────────────────────────────────────────────────────
@@ -296,7 +301,7 @@ export async function executeJsAggregation(
296
301
  source: ConnectedSource,
297
302
  table: string,
298
303
  query: DslQuery,
299
- dialect: 'sqlite' | 'postgres' | 'mysql'
304
+ dialect: 'sqlite' = 'sqlite'
300
305
  ): Promise<DslQueryResult> {
301
306
  const fieldsNeeded = new Set<string>();
302
307
  for (const s of query.select) {
@@ -321,10 +326,10 @@ export async function executeJsAggregation(
321
326
 
322
327
  const groupKeys = groupBySpecs.map(g => {
323
328
  if (typeof g === 'string') {
324
- const col = stripTablePrefix(g);
329
+ const col = fieldAlias(g);
325
330
  return { name: col, extract: (row: Record<string, any>) => String(row[col] ?? '') };
326
331
  }
327
- const col = stripTablePrefix(g.field);
332
+ const col = fieldAlias(g.field);
328
333
  const alias = `${g.field.replace('.', '_')}_${g.bucket}`;
329
334
  return { name: alias, extract: (row: Record<string, any>) => bucketDate(String(row[col] ?? ''), g.bucket) };
330
335
  });
@@ -353,12 +358,12 @@ export async function executeJsAggregation(
353
358
 
354
359
  for (const s of query.select) {
355
360
  if (typeof s === 'string') {
356
- const col = stripTablePrefix(s);
361
+ const col = fieldAlias(s);
357
362
  if (!(col in row)) {
358
363
  row[col] = groupRows[0]?.[col];
359
364
  }
360
365
  } else if (isDslAggregateField(s)) {
361
- const col = stripTablePrefix(s.field);
366
+ const col = fieldAlias(s.field);
362
367
  row[s.as] = jsAggregate(groupRows.map(r => r[col]), s.aggregate, s.percentile);
363
368
  }
364
369
  }
@@ -379,7 +384,7 @@ export async function executeJsAggregationWithWindows(
379
384
  source: ConnectedSource,
380
385
  table: string,
381
386
  query: DslQuery,
382
- dialect: 'sqlite' | 'postgres' | 'mysql'
387
+ dialect: 'sqlite' = 'sqlite'
383
388
  ): Promise<DslQueryResult> {
384
389
  const windowFields = query.select.filter(isDslWindowField);
385
390
  const baseFields = query.select.filter(f => !isDslWindowField(f));
@@ -20,9 +20,6 @@ import type {
20
20
  import { compileDsl, hasJsAggregates, hasWindowFunctions } from './dsl-compiler.js';
21
21
  import { validateDsl, validateDslWithJoins } from './dsl-validator.js';
22
22
  import { csvConnector } from './csv.js';
23
- import { sqliteConnector } from './sqlite.js';
24
- import { postgresConnector } from './postgres.js';
25
- import { mysqlConnector } from './mysql.js';
26
23
  import type { DslQueryResult } from './js-aggregation.js';
27
24
  import { executeJsAggregation, executeJsAggregationWithWindows } from './js-aggregation.js';
28
25
 
@@ -37,26 +34,12 @@ function generateSourceId(name: string): string {
37
34
 
38
35
  const CONNECTOR_MAP: Record<string, typeof csvConnector> = {
39
36
  csv: csvConnector,
40
- sqlite: sqliteConnector,
41
- postgres: postgresConnector,
42
- mysql: mysqlConnector,
43
37
  };
44
38
 
45
39
  function getConnectorForType(type: DataSourceType): typeof csvConnector | undefined {
46
40
  return CONNECTOR_MAP[type];
47
41
  }
48
42
 
49
- const DIALECT_MAP: Record<string, 'sqlite' | 'postgres' | 'mysql'> = {
50
- csv: 'sqlite',
51
- sqlite: 'sqlite',
52
- postgres: 'postgres',
53
- mysql: 'mysql',
54
- };
55
-
56
- function dialectForType(type: DataSourceType): 'sqlite' | 'postgres' | 'mysql' {
57
- return DIALECT_MAP[type] ?? 'sqlite';
58
- }
59
-
60
43
  /**
61
44
  * Check if a query result contains an error encoded in the rows.
62
45
  * Some connectors return errors this way instead of throwing.
@@ -297,21 +280,18 @@ export class SourceManager {
297
280
  const validationError = await this.validateDslQuery(idOrName, table, dslQuery);
298
281
  if (validationError) return { ok: false, error: validationError };
299
282
 
300
- const entry = this.findEntry(idOrName)!;
301
- const dialect = dialectForType(entry.type);
302
-
303
- const needsJsAgg = dialect !== 'postgres' && hasJsAggregates(dslQuery);
283
+ const needsJsAgg = hasJsAggregates(dslQuery);
304
284
  const needsWindows = hasWindowFunctions(dslQuery);
305
285
 
306
286
  if (needsJsAgg && needsWindows) {
307
- return executeJsAggregationWithWindows(resolved.source, table, dslQuery, dialect);
287
+ return executeJsAggregationWithWindows(resolved.source, table, dslQuery, 'sqlite');
308
288
  }
309
289
  if (needsJsAgg) {
310
- return executeJsAggregation(resolved.source, table, dslQuery, dialect);
290
+ return executeJsAggregation(resolved.source, table, dslQuery, 'sqlite');
311
291
  }
312
292
 
313
293
  // Pure SQL path — compileDsl handles CTE wrapping for window functions
314
- const sql = compileDsl(table, dslQuery, dialect);
294
+ const sql = compileDsl(table, dslQuery, 'sqlite');
315
295
  const result = await resolved.source.executeQuery(sql);
316
296
  const errorMsg = hasErrorRow(result);
317
297
  if (errorMsg) return { ok: false, error: errorMsg };
@@ -51,7 +51,7 @@ html, body {
51
51
  .error-text { color: #ef4444; }
52
52
  .spinner {
53
53
  width: 24px; height: 24px; margin: 0 auto 12px;
54
- border: 2px solid #374151; border-top-color: #6366f1;
54
+ border: 2px solid #374151; border-top-color: #3366AA;
55
55
  border-radius: 50%; animation: spin 0.8s linear infinite;
56
56
  }
57
57
  @keyframes spin { to { transform: rotate(360deg); } }
package/src/mcp/index.ts CHANGED
@@ -7,17 +7,17 @@
7
7
  *
8
8
  * 17 tools:
9
9
  * visualize — Inline data + intent → ranked visualization recommendations
10
- * visualize_from_source — Source data (DSL query) + intent → ranked visualization recommendations
10
+ * visualize_data — CSV data (DSL query) + intent → ranked visualization recommendations
11
11
  * list_patterns — Browse all available visualization patterns
12
12
  * refine_visualization — Tweak a visualization spec
13
- * create_dashboard — Multi-view dashboard from a data source
13
+ * create_dashboard — Multi-view dashboard from a CSV dataset
14
14
  * refine_dashboard — Iterate on a dashboard (add/remove views, layout, filters, theme)
15
- * add_source — Connect a data source (CSV, SQLite, Postgres, MySQL)
16
- * list_sources — List connected data sources
17
- * remove_source — Disconnect a data source
18
- * describe_source — Re-examine column profiles and sample rows for a source
19
- * analyze_source — Generate a structured analysis plan with DSL queries
20
- * query_source — Run a declarative DSL query and see tabular results
15
+ * load_csv — Load a CSV file or directory
16
+ * list_data — List loaded datasets
17
+ * remove_data — Remove a loaded dataset
18
+ * describe_data — Re-examine column profiles and sample rows for a dataset
19
+ * analyze_data — Generate a structured analysis plan with DSL queries
20
+ * query_data — Run a declarative DSL query and see tabular results
21
21
  * server_status — Inspect cached data in server memory
22
22
  * clear_cache — Clear cached specs, results, and sessions
23
23
  * export_html — Get the full rendered HTML for a visualization by specId
@@ -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.13',
98
+ version: '1.0.0',
99
+ ...(serverIcons && { icons: serverIcons }),
90
100
  },
91
101
  {
92
102
  instructions: [
93
- 'STOP. Read this before doing anything else.',
103
+ 'Dolex — CSV data analysis with 43 chart types.',
104
+ '',
105
+ 'WORKFLOW:',
106
+ '• Got a CSV file? → load_csv(name, 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? → load_csv → analyze_data → visualize_data per step',
109
+ '• Need a dashboard? → load_csv → create_dashboard with views array',
110
+ '',
111
+ 'CONTINUATION (dataset already loaded):',
112
+ '• Chart from data → visualize_data(sourceId, table, query, intent)',
113
+ '• Want to SEE rows (answer a question, validate data, show a table)? → query_data',
114
+ '• Want to CHART rows you already queried? → visualize(resultId=...) to reuse cached data',
115
+ '• Want a table view? → query_data 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_data call, then continue refining from the new specId',
94
119
  '',
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.',
120
+ 'TOOL GUIDE:',
121
+ '• load_csv: Load a CSV file or directory. Returns sourceId.',
122
+ '• describe_data: See schema, stats, samples. Use detail="compact" for large schemas.',
123
+ '• analyze_data: Auto-generate analysis plan with ready DSL queries. Execute each step with visualize_data; present results one at a time.',
124
+ '• query_data: Run DSL query, get rows. Returns resultId for visualize().',
125
+ '• visualize: Chart from inline data OR resultId from query_data. Auto-selects best pattern. Set title/subtitle here to avoid a refine round-trip.',
126
+ '• visualize_data: Chart from loaded CSV + 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 loaded data 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.',
98
131
  '',
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).',
132
+ 'Utility tools: list_data, remove_data, server_status (inspect cached data), clear_cache, report_bug (generate GitHub issue), export_html (get chart HTML by specId), screenshot (render to PNG).',
101
133
  '',
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.',
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.',
104
136
  '',
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.',
137
+ 'ERRORS: If a DSL query fails with field name suggestions, retry with the corrected name. If specId is expired, re-run visualize.',
138
+ '',
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_data.\n\nWhen to use: You have data in the conversation (pasted, generated, or from query_data resultId). Use visualize_data instead when data lives in a loaded CSV — 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: {
@@ -152,13 +186,13 @@ registerAppTool(
152
186
  handleVisualize(selectPatternCallback),
153
187
  );
154
188
 
155
- // Source-based visualization tool
189
+ // CSV data visualization tool
156
190
  registerAppTool(
157
191
  server,
158
- 'visualize_from_source',
192
+ 'visualize_data',
159
193
  {
160
- 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.',
194
+ title: 'Visualize Data',
195
+ description: 'Chart data from a loaded CSV. Queries server-side — no data in the context window.\n\nWhen to use: CSV already loaded via load_csv. Prefer this over query_data + 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: {
@@ -200,61 +234,61 @@ registerAppTool(
200
234
  handleRefine(),
201
235
  );
202
236
 
203
- // Data source management tools
237
+ // CSV data management tools
204
238
  server.registerTool(
205
- 'add_source',
239
+ 'load_csv',
206
240
  {
207
- 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.',
241
+ title: 'Load CSV Data',
242
+ description: 'Load a CSV file or directory of CSV files. Call this immediately with any user-provided path — this server runs locally on the user\'s machine.\n\nDatasets 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 data operations).',
209
243
  inputSchema: addSourceInputSchema,
210
244
  },
211
245
  handleAddSource({ sourceManager }),
212
246
  );
213
247
 
214
248
  server.registerTool(
215
- 'list_sources',
249
+ 'list_data',
216
250
  {
217
- title: 'List Data Sources',
218
- description: 'List all connected data sources with their IDs, types, and table counts.',
251
+ title: 'List Loaded Data',
252
+ description: 'List all loaded datasets with IDs and table counts.',
219
253
  },
220
254
  handleListSources({ sourceManager }),
221
255
  );
222
256
 
223
257
  server.registerTool(
224
- 'remove_source',
258
+ 'remove_data',
225
259
  {
226
- title: 'Remove Data Source',
227
- description: 'Disconnect and remove a data source by its ID.',
260
+ title: 'Remove Data',
261
+ description: 'Remove a loaded dataset by ID.',
228
262
  inputSchema: removeSourceInputSchema,
229
263
  },
230
264
  handleRemoveSource({ sourceManager }),
231
265
  );
232
266
 
233
267
  server.registerTool(
234
- 'describe_source',
268
+ 'describe_data',
235
269
  {
236
- 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.',
270
+ title: 'Describe Data',
271
+ description: 'Examine column profiles for a loaded dataset. 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 }),
241
275
  );
242
276
 
243
277
  server.registerTool(
244
- 'analyze_source',
278
+ 'analyze_data',
245
279
  {
246
- 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.',
280
+ title: 'Analyze Data',
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 load_csv, to get an automatic data exploration plan. Execute each step with visualize_data and present results one at a time.',
248
282
  inputSchema: analyzeSourceInputSchema.shape,
249
283
  },
250
284
  handleAnalyzeSource({ sourceManager }),
251
285
  );
252
286
 
253
287
  server.registerTool(
254
- 'query_source',
288
+ 'query_data',
255
289
  {
256
- 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.',
290
+ title: 'Query Data',
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_data 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 loaded CSV dataset. 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(),
@@ -8,7 +8,7 @@ export function registerPrompts(server: McpServer) {
8
8
  title: 'Explore a Dataset',
9
9
  description: 'Drop a data file and get automatic analysis — like having a data analyst at your desk',
10
10
  argsSchema: {
11
- path: z.string().describe('File path (CSV, SQLite) or connection string (Postgres, MySQL)'),
11
+ path: z.string().describe('Path to a CSV file or directory of CSV files'),
12
12
  },
13
13
  },
14
14
  async ({ path }) => ({
@@ -20,9 +20,9 @@ export function registerPrompts(server: McpServer) {
20
20
  `I want to explore a dataset. The file path is: ${path}`,
21
21
  '',
22
22
  'Please:',
23
- '1. Connect it as a data source using add_source',
24
- '2. Call analyze_source to get an automatic analysis plan',
25
- '3. For each step in the plan, call visualize_from_source with the provided query and use one of the suggested patterns',
23
+ '1. Load it using load_csv',
24
+ '2. Call analyze_data to get an automatic analysis plan',
25
+ '3. For each step in the plan, call visualize_data with the provided query and use one of the suggested patterns',
26
26
  '4. After each chart, write a 2-3 sentence finding explaining what the data reveals — be specific about numbers, trends, and outliers',
27
27
  '5. End with a "Key Takeaways" summary',
28
28
  '',
@@ -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 {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * MCP Tool: analyze_source
2
+ * MCP Tool: analyze_data
3
3
  * Examines a data source and generates a structured analysis plan with DSL queries.
4
4
  */
5
5
 
@@ -8,7 +8,7 @@ import { buildAnalysisPlan } from '../../analysis/planner.js';
8
8
  import { errorResponse, jsonResponse } from './shared.js';
9
9
 
10
10
  export const analyzeSourceInputSchema = z.object({
11
- sourceId: z.string().describe('Source ID from add_source'),
11
+ sourceId: z.string().describe('Dataset ID returned by load_csv'),
12
12
  table: z.string().optional().describe('Table to analyze (defaults to first table)'),
13
13
  maxSteps: z.number().min(1).max(10).optional().describe('Maximum analysis steps (default: 6)'),
14
14
  });
@@ -56,7 +56,6 @@ export function sanitizeSpecConfig(config: Record<string, unknown>): Record<stri
56
56
 
57
57
  export function sanitizeError(error: string): string {
58
58
  return error
59
- .replace(/(?:postgres|mysql|sqlite):\/\/[^\s]+/g, '<connection-string>')
60
59
  .replace(/\/[\w/.~-]+/g, '<path>')
61
60
  .replace(/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z]{2,}\b/gi, '<email>');
62
61
  }
@@ -158,14 +157,7 @@ export function handleReportBug(deps: ReportDeps) {
158
157
 
159
158
  const specStats = specStore.stats();
160
159
  const resultStats = resultCacheStats();
161
- const sources = deps.sourceManager.list();
162
- const sourceTypes: Record<string, number> = {};
163
- for (const s of sources) {
164
- sourceTypes[s.type] = (sourceTypes[s.type] || 0) + 1;
165
- }
166
- const sourceTypeSummary = Object.entries(sourceTypes)
167
- .map(([t, c]) => `${t}: ${c}`)
168
- .join(', ') || 'none';
160
+ const datasets = deps.sourceManager.list();
169
161
 
170
162
  sections.push([
171
163
  '## Server State',
@@ -173,7 +165,7 @@ export function handleReportBug(deps: ReportDeps) {
173
165
  `- **Uptime**: ${formatUptime(Date.now() - deps.serverStartTime)}`,
174
166
  `- **Cached specs**: ${specStats.entries}`,
175
167
  `- **Cached results**: ${resultStats.entries}`,
176
- `- **Sources**: ${sources.length} (${sourceTypeSummary})`,
168
+ `- **Datasets**: ${datasets.length}`,
177
169
  ].join('\n'));
178
170
 
179
171
  const report = sections.join('\n\n');
@@ -24,7 +24,7 @@ export function handleCreateDashboard(deps: { sourceManager: any }) {
24
24
  return async (args: z.infer<typeof createDashboardInputSchema>) => {
25
25
  const sourceInfo = deps.sourceManager.get(args.sourceId);
26
26
  if (!sourceInfo) {
27
- return errorResponse(`Source not found: ${args.sourceId}. Use add_source first.`);
27
+ return errorResponse(`Dataset not found: ${args.sourceId}. Use load_csv first.`);
28
28
  }
29
29
 
30
30
  const result = await executeDashboardViews(