@outsidedata/dolex 5.0.0 → 6.1.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.
- package/dist/src/mcp/index.d.ts +1 -1
- package/dist/src/mcp/index.js +6 -9
- package/dist/src/mcp/index.js.map +1 -1
- package/dist/src/mcp/tools/drop-columns.d.ts.map +1 -1
- package/dist/src/mcp/tools/drop-columns.js +8 -21
- package/dist/src/mcp/tools/drop-columns.js.map +1 -1
- package/dist/src/mcp/tools/export-html.d.ts.map +1 -1
- package/dist/src/mcp/tools/export-html.js +10 -28
- package/dist/src/mcp/tools/export-html.js.map +1 -1
- package/dist/src/mcp/tools/list-transforms.d.ts.map +1 -1
- package/dist/src/mcp/tools/list-transforms.js +14 -29
- package/dist/src/mcp/tools/list-transforms.js.map +1 -1
- package/dist/src/mcp/tools/promote-columns.d.ts.map +1 -1
- package/dist/src/mcp/tools/promote-columns.js +8 -25
- package/dist/src/mcp/tools/promote-columns.js.map +1 -1
- package/dist/src/mcp/tools/refine-cli.d.ts.map +1 -1
- package/dist/src/mcp/tools/refine-cli.js +8 -39
- package/dist/src/mcp/tools/refine-cli.js.map +1 -1
- package/dist/src/mcp/tools/refine.d.ts.map +1 -1
- package/dist/src/mcp/tools/refine.js +1 -12
- package/dist/src/mcp/tools/refine.js.map +1 -1
- package/dist/src/mcp/tools/screenshot.d.ts.map +1 -1
- package/dist/src/mcp/tools/screenshot.js +4 -14
- package/dist/src/mcp/tools/screenshot.js.map +1 -1
- package/dist/src/mcp/tools/shared.d.ts +55 -1
- package/dist/src/mcp/tools/shared.d.ts.map +1 -1
- package/dist/src/mcp/tools/shared.js +89 -0
- package/dist/src/mcp/tools/shared.js.map +1 -1
- package/dist/src/mcp/tools/sources.d.ts +0 -3
- package/dist/src/mcp/tools/sources.d.ts.map +1 -1
- package/dist/src/mcp/tools/sources.js +59 -8
- package/dist/src/mcp/tools/sources.js.map +1 -1
- package/dist/src/mcp/tools/transform-data.d.ts.map +1 -1
- package/dist/src/mcp/tools/transform-data.js +11 -31
- package/dist/src/mcp/tools/transform-data.js.map +1 -1
- package/dist/src/mcp/tools/visualize-cli.d.ts.map +1 -1
- package/dist/src/mcp/tools/visualize-cli.js +23 -113
- package/dist/src/mcp/tools/visualize-cli.js.map +1 -1
- package/dist/src/mcp/tools/visualize.d.ts.map +1 -1
- package/dist/src/mcp/tools/visualize.js +13 -49
- package/dist/src/mcp/tools/visualize.js.map +1 -1
- package/package.json +1 -1
- package/src/mcp/index.ts +6 -11
- package/src/mcp/tools/drop-columns.ts +8 -21
- package/src/mcp/tools/export-html.ts +9 -26
- package/src/mcp/tools/list-transforms.ts +14 -31
- package/src/mcp/tools/promote-columns.ts +7 -28
- package/src/mcp/tools/refine-cli.ts +7 -41
- package/src/mcp/tools/refine.ts +1 -14
- package/src/mcp/tools/screenshot.ts +4 -13
- package/src/mcp/tools/shared.ts +127 -0
- package/src/mcp/tools/sources.ts +56 -12
- package/src/mcp/tools/transform-data.ts +24 -47
- package/src/mcp/tools/visualize-cli.ts +27 -123
- package/src/mcp/tools/visualize.ts +16 -54
- package/src/mcp/prompts.ts +0 -35
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visualize-cli.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/visualize-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"visualize-cli.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/visualize-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAQtE,eAAO,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwBlC,CAAC;AAEH,wBAAgB,kBAAkB,CAChC,cAAc,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,eAAe,EAC1D,IAAI,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,GAAG,CAAA;CAAE,IAIhB,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,gDA8B5D"}
|
|
@@ -9,17 +9,10 @@
|
|
|
9
9
|
* - Returns only specId and metadata
|
|
10
10
|
*/
|
|
11
11
|
import { z } from 'zod';
|
|
12
|
-
import { writeFileSync, mkdirSync } from 'fs';
|
|
13
|
-
import { dirname } from 'path';
|
|
14
|
-
import { isCompoundSpec } from '../../types.js';
|
|
15
12
|
import { ALL_PALETTE_NAMES } from './sql-schemas.js';
|
|
16
|
-
import { buildChartHtml, isHtmlPatternSupported } from '../../renderers/html/index.js';
|
|
17
|
-
import { shouldCompound, buildCompoundSpec } from '../../renderers/html/compound.js';
|
|
18
|
-
import { buildCompoundHtml } from '../../renderers/html/builders/compound.js';
|
|
19
|
-
import { specStore } from '../spec-store.js';
|
|
20
13
|
import { getResult } from './result-cache.js';
|
|
21
|
-
import { errorResponse,
|
|
22
|
-
import { columnsSchema, dataShapeHintsSchema } from './visualize.js';
|
|
14
|
+
import { errorResponse, resolveData, isErrorResponse, writeHtmlToDisk, } from './shared.js';
|
|
15
|
+
import { columnsSchema, dataShapeHintsSchema, handleVisualizeCore } from './visualize.js';
|
|
23
16
|
export const visualizeCliInputSchema = z.object({
|
|
24
17
|
data: z.array(z.record(z.any())).optional().describe('Array of data rows to visualize. Optional if resultId or sourceId+sql is provided.'),
|
|
25
18
|
resultId: z.string().optional().describe('Result ID from a previous query_data call'),
|
|
@@ -46,117 +39,34 @@ export const visualizeCliInputSchema = z.object({
|
|
|
46
39
|
writeTo: z.string().describe('REQUIRED. File path to write the HTML chart to. The HTML is written to disk and NOT returned in the response.'),
|
|
47
40
|
});
|
|
48
41
|
export function handleVisualizeCli(selectPatterns, deps) {
|
|
42
|
+
const core = handleVisualizeCore(selectPatterns, 'visualize_cli_only');
|
|
49
43
|
return async (args) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!cached) {
|
|
68
|
-
return errorResponse(`Result "${args.resultId}" not found or expired. Re-run query_data to get a new resultId.`);
|
|
69
|
-
}
|
|
70
|
-
data = cached.rows;
|
|
71
|
-
}
|
|
72
|
-
if (!data || data.length === 0) {
|
|
73
|
-
return errorResponse('No data provided. Pass data array, resultId from query_data, or sourceId + sql.');
|
|
74
|
-
}
|
|
75
|
-
const notes = [];
|
|
76
|
-
const columns = args.columns || inferColumns(data);
|
|
77
|
-
const maxAlternativeChartTypes = args.maxAlternativeChartTypes ?? 2;
|
|
78
|
-
const input = {
|
|
79
|
-
data,
|
|
80
|
-
intent: args.intent,
|
|
81
|
-
columns,
|
|
82
|
-
dataShapeHints: args.dataShapeHints,
|
|
83
|
-
forcePattern: args.pattern,
|
|
84
|
-
geoLevel: args.geoLevel,
|
|
85
|
-
geoRegion: args.geoRegion,
|
|
86
|
-
};
|
|
87
|
-
const result = selectPatterns(input);
|
|
88
|
-
const alternatives = result.alternatives.slice(0, maxAlternativeChartTypes);
|
|
89
|
-
const colorPrefs = (args.palette || args.highlight || args.colorField)
|
|
90
|
-
? { palette: args.palette, highlight: args.highlight, colorField: args.colorField }
|
|
91
|
-
: undefined;
|
|
92
|
-
if (colorPrefs) {
|
|
93
|
-
const colorResult = applyColorPreferences(result.recommended.spec, colorPrefs, data);
|
|
94
|
-
notes.push(...colorResult.notes);
|
|
95
|
-
}
|
|
96
|
-
const spec = result.recommended.spec;
|
|
97
|
-
if (args.title)
|
|
98
|
-
spec.title = args.title;
|
|
99
|
-
if (args.subtitle)
|
|
100
|
-
spec.config = { ...spec.config, subtitle: args.subtitle };
|
|
101
|
-
const hasHtmlBuilder = spec && isHtmlPatternSupported(spec.pattern);
|
|
102
|
-
let outputHtml;
|
|
103
|
-
let finalSpec = spec;
|
|
104
|
-
if (hasHtmlBuilder && shouldCompound(spec, { compound: args.includeDataTable })) {
|
|
105
|
-
const compoundSpec = buildCompoundSpec(spec, columns);
|
|
106
|
-
outputHtml = buildCompoundHtml(compoundSpec);
|
|
107
|
-
finalSpec = compoundSpec;
|
|
108
|
-
}
|
|
109
|
-
else if (hasHtmlBuilder) {
|
|
110
|
-
outputHtml = buildChartHtml(spec);
|
|
111
|
-
}
|
|
112
|
-
const alternativesMap = new Map();
|
|
113
|
-
for (const alt of alternatives) {
|
|
114
|
-
alternativesMap.set(alt.pattern, alt.spec);
|
|
115
|
-
}
|
|
116
|
-
const specId = specStore.save(finalSpec, columns, alternativesMap, data);
|
|
117
|
-
// Write HTML to disk
|
|
118
|
-
let writeResult;
|
|
119
|
-
if (outputHtml) {
|
|
120
|
-
try {
|
|
121
|
-
mkdirSync(dirname(args.writeTo), { recursive: true });
|
|
122
|
-
writeFileSync(args.writeTo, outputHtml, 'utf-8');
|
|
123
|
-
writeResult = `Wrote ${outputHtml.length} bytes to ${args.writeTo}`;
|
|
124
|
-
}
|
|
125
|
-
catch (err) {
|
|
126
|
-
return errorResponse(`Failed to write to ${args.writeTo}: ${err instanceof Error ? err.message : String(err)}`);
|
|
127
|
-
}
|
|
44
|
+
const resolved = await resolveData(args, { sourceManager: deps?.sourceManager, getResult });
|
|
45
|
+
if (isErrorResponse(resolved))
|
|
46
|
+
return resolved;
|
|
47
|
+
const coreResult = core(resolved.data, args, resolved.queryMeta, resolved.extraMeta);
|
|
48
|
+
// Extract the text response body and add write info
|
|
49
|
+
const textContent = coreResult.content.find((c) => c.type === 'text');
|
|
50
|
+
if (!textContent)
|
|
51
|
+
return errorResponse('Unexpected error: no text content from core');
|
|
52
|
+
const body = JSON.parse(textContent.text);
|
|
53
|
+
// Write HTML to disk from structuredContent (if present)
|
|
54
|
+
const html = coreResult.structuredContent?.html;
|
|
55
|
+
if (html) {
|
|
56
|
+
const writeResult = writeHtmlToDisk(html, args.writeTo);
|
|
57
|
+
if (!writeResult.ok)
|
|
58
|
+
return errorResponse(writeResult.error);
|
|
59
|
+
body.writeTo = args.writeTo;
|
|
60
|
+
body.writeResult = writeResult.message;
|
|
128
61
|
}
|
|
129
62
|
else {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const compactResponse = {
|
|
133
|
-
specId,
|
|
134
|
-
writeTo: args.writeTo,
|
|
135
|
-
writeResult,
|
|
136
|
-
...(notes.length > 0 ? { notes } : {}),
|
|
137
|
-
recommended: {
|
|
138
|
-
pattern: result.recommended.pattern,
|
|
139
|
-
title: spec.title,
|
|
140
|
-
reasoning: result.recommended.reasoning,
|
|
141
|
-
},
|
|
142
|
-
alternatives: alternatives.map(a => ({
|
|
143
|
-
pattern: a.pattern,
|
|
144
|
-
reasoning: a.reasoning,
|
|
145
|
-
})),
|
|
146
|
-
dataShape: {
|
|
147
|
-
rowCount: data.length,
|
|
148
|
-
columnCount: columns.length,
|
|
149
|
-
...(queryMeta?.truncated ? { truncated: true, totalSourceRows: queryMeta.totalSourceRows } : {}),
|
|
150
|
-
},
|
|
151
|
-
};
|
|
152
|
-
if (isCompoundSpec(finalSpec)) {
|
|
153
|
-
compactResponse.compound = true;
|
|
63
|
+
body.writeTo = args.writeTo;
|
|
64
|
+
body.writeResult = `No HTML builder for pattern "${body.recommended?.pattern}"`;
|
|
154
65
|
}
|
|
155
|
-
// CLI tools NEVER return structuredContent - just text
|
|
156
66
|
return {
|
|
157
67
|
content: [{
|
|
158
68
|
type: 'text',
|
|
159
|
-
text: JSON.stringify(
|
|
69
|
+
text: JSON.stringify(body, null, 2),
|
|
160
70
|
}],
|
|
161
71
|
};
|
|
162
72
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visualize-cli.js","sourceRoot":"","sources":["../../../../src/mcp/tools/visualize-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"visualize-cli.js","sourceRoot":"","sources":["../../../../src/mcp/tools/visualize-cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EACL,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,eAAe,GAC7D,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1F,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9C,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,oFAAoF,CAAC;IAC1I,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,2CAA2C,CAAC;IACrF,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,iCAAiC,CAAC;IAC3E,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kEAAkE,CAAC;IACvG,MAAM,EAAE,CAAC,CAAC,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UAAkB,CAAC,iBAAiB,EAAE,IAAI,CAAC;QACzD,IAAI,IAAI,EAAE,CAAC;YACT,MAAM,WAAW,GAAG,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACxD,IAAI,CAAC,WAAW,CAAC,EAAE;gBAAE,OAAO,aAAa,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC7D,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;YAC5B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,OAAO,CAAC;QACzC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC;YAC5B,IAAI,CAAC,WAAW,GAAG,gCAAgC,IAAI,CAAC,WAAW,EAAE,OAAO,GAAG,CAAC;QAClF,CAAC;QAED,OAAO;YACL,OAAO,EAAE,CAAC;oBACR,IAAI,EAAE,MAAe;oBACrB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;iBACpC,CAAC;SACH,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visualize.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/visualize.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAiC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"visualize.d.ts","sourceRoot":"","sources":["../../../../src/mcp/tools/visualize.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAiC,MAAM,gBAAgB,CAAC;AAYrG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,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,SAAS,GAAG,aAAa,CAAC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,EAAE,YAAY;IAAE,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,YAAY,OAAO,CAAC,aAAa,CAAC;;;;;;;;;EA4GrG;AAED,wBAAgB,eAAe,CAC7B,cAAc,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,eAAe,EAC1D,IAAI,CAAC,EAAE;IAAE,aAAa,CAAC,EAAE,GAAG,CAAA;CAAE,IAIhB,MAAM,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC;;;;;;;;;GAiBzD"}
|
|
@@ -9,12 +9,11 @@
|
|
|
9
9
|
import { z } from 'zod';
|
|
10
10
|
import { isCompoundSpec } from '../../types.js';
|
|
11
11
|
import { ALL_PALETTE_NAMES } from './sql-schemas.js';
|
|
12
|
-
import {
|
|
12
|
+
import { isHtmlPatternSupported } from '../../renderers/html/index.js';
|
|
13
13
|
import { shouldCompound, buildCompoundSpec } from '../../renderers/html/compound.js';
|
|
14
|
-
import { buildCompoundHtml } from '../../renderers/html/builders/compound.js';
|
|
15
14
|
import { specStore } from '../spec-store.js';
|
|
16
15
|
import { getResult } from './result-cache.js';
|
|
17
|
-
import {
|
|
16
|
+
import { inferColumns, applyColorPreferences, buildOutputHtml, resolveData, isErrorResponse, } from './shared.js';
|
|
18
17
|
import { logOperation } from './operation-log.js';
|
|
19
18
|
export const columnsSchema = z.array(z.object({
|
|
20
19
|
name: z.string(),
|
|
@@ -95,17 +94,11 @@ export function handleVisualizeCore(selectPatterns, toolName = 'visualize') {
|
|
|
95
94
|
spec.title = args.title;
|
|
96
95
|
if (args.subtitle)
|
|
97
96
|
spec.config = { ...spec.config, subtitle: args.subtitle };
|
|
98
|
-
const hasHtmlBuilder = spec && isHtmlPatternSupported(spec.pattern);
|
|
99
|
-
let outputHtml;
|
|
100
97
|
let finalSpec = spec;
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
outputHtml = buildCompoundHtml(compoundSpec);
|
|
104
|
-
finalSpec = compoundSpec;
|
|
105
|
-
}
|
|
106
|
-
else if (hasHtmlBuilder) {
|
|
107
|
-
outputHtml = buildChartHtml(spec);
|
|
98
|
+
if (isHtmlPatternSupported(spec.pattern) && shouldCompound(spec, { compound: args.includeDataTable })) {
|
|
99
|
+
finalSpec = buildCompoundSpec(spec, columns);
|
|
108
100
|
}
|
|
101
|
+
const outputHtml = buildOutputHtml(finalSpec);
|
|
109
102
|
const alternativesMap = new Map();
|
|
110
103
|
for (const alt of alternatives) {
|
|
111
104
|
alternativesMap.set(alt.pattern, alt.spec);
|
|
@@ -175,49 +168,20 @@ export function handleVisualizeCore(selectPatterns, toolName = 'visualize') {
|
|
|
175
168
|
export function handleVisualize(selectPatterns, deps) {
|
|
176
169
|
const core = handleVisualizeCore(selectPatterns);
|
|
177
170
|
return async (args) => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// Path 1: sourceId + sql → server-side query
|
|
182
|
-
if (args.sourceId && args.sql) {
|
|
183
|
-
if (!deps?.sourceManager) {
|
|
184
|
-
return errorResponse('Source manager not available.');
|
|
185
|
-
}
|
|
186
|
-
const start = Date.now();
|
|
187
|
-
const source = deps.sourceManager.get?.(args.sourceId);
|
|
188
|
-
const sourceType = source?.type;
|
|
189
|
-
const result = await deps.sourceManager.querySql(args.sourceId, args.sql);
|
|
190
|
-
if (!result.ok) {
|
|
171
|
+
const resolved = await resolveData(args, { sourceManager: deps?.sourceManager, getResult });
|
|
172
|
+
if (isErrorResponse(resolved)) {
|
|
173
|
+
if (args.sourceId && args.sql) {
|
|
191
174
|
logOperation({
|
|
192
175
|
toolName: 'visualize',
|
|
193
|
-
timestamp:
|
|
194
|
-
durationMs:
|
|
176
|
+
timestamp: Date.now(),
|
|
177
|
+
durationMs: 0,
|
|
195
178
|
success: false,
|
|
196
|
-
meta: {
|
|
197
|
-
sqlPreview: args.sql.slice(0, 200),
|
|
198
|
-
sourceType,
|
|
199
|
-
error: result.error,
|
|
200
|
-
},
|
|
179
|
+
meta: { sqlPreview: args.sql.slice(0, 200), error: 'Data resolution failed' },
|
|
201
180
|
});
|
|
202
|
-
return errorResponse(result.error);
|
|
203
181
|
}
|
|
204
|
-
|
|
205
|
-
queryMeta = { truncated: result.truncated, totalSourceRows: result.totalRows };
|
|
206
|
-
extraMeta = { sqlPreview: args.sql.slice(0, 200), sourceType };
|
|
207
|
-
}
|
|
208
|
-
// Path 2: resultId → cached query result
|
|
209
|
-
if (!data && args.resultId) {
|
|
210
|
-
const cached = getResult(args.resultId);
|
|
211
|
-
if (!cached) {
|
|
212
|
-
return errorResponse(`Result "${args.resultId}" not found or expired. Re-run query_data to get a new resultId.`);
|
|
213
|
-
}
|
|
214
|
-
data = cached.rows;
|
|
215
|
-
}
|
|
216
|
-
// Path 3: inline data (already in args.data)
|
|
217
|
-
if (!data || data.length === 0) {
|
|
218
|
-
return errorResponse('No data provided. Pass data array, resultId from query_data, or sourceId + sql.');
|
|
182
|
+
return resolved;
|
|
219
183
|
}
|
|
220
|
-
return core(data, args, queryMeta, extraMeta);
|
|
184
|
+
return core(resolved.data, args, resolved.queryMeta, resolved.extraMeta);
|
|
221
185
|
};
|
|
222
186
|
}
|
|
223
187
|
//# sourceMappingURL=visualize.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visualize.js","sourceRoot":"","sources":["../../../../src/mcp/tools/visualize.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"visualize.js","sourceRoot":"","sources":["../../../../src/mcp/tools/visualize.ts"],"names":[],"mappings":"AAA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ACJ,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,eAAe,CAC7B,cAA0D,EAC1D,IAA8B;IAE9B,MAAM,IAAI,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAEjD,OAAO,KAAK,EAAE,IAA0C,EAAE,EAAE;QAC1D,MAAM,QAAQ,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,CAAC;QAC5F,IAAI,eAAe,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9B,IAAI,IAAI,CAAC,QAAQ,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;gBAC9B,YAAY,CAAC;oBACX,QAAQ,EAAE,WAAW;oBACrB,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;oBACrB,UAAU,EAAE,CAAC;oBACb,OAAO,EAAE,KAAK;oBACd,IAAI,EAAE,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,KAAK,EAAE,wBAAwB,EAAE;iBAC9E,CAAC,CAAC;YACL,CAAC;YACD,OAAO,QAAQ,CAAC;QAClB,CAAC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,SAAS,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC;IAC3E,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@outsidedata/dolex",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "AI data analyst — 43 handcrafted visualization patterns, SQL query engine with custom aggregates, and auto-analysis planning via MCP",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
package/src/mcp/index.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* An MCP server that provides visualization intelligence from a handcrafted
|
|
6
6
|
* pattern library that goes far beyond bar/line/pie.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* Tools:
|
|
9
9
|
* visualize — Data (inline, cached, or CSV+SQL) + intent → ranked visualization recommendations
|
|
10
10
|
* list_patterns — Browse all available visualization patterns
|
|
11
11
|
* refine_visualization — Tweak a visualization spec
|
|
@@ -70,7 +70,6 @@ import { handlePromoteColumns } from './tools/promote-columns.js';
|
|
|
70
70
|
import { handleListTransforms } from './tools/list-transforms.js';
|
|
71
71
|
import { handleDropColumns } from './tools/drop-columns.js';
|
|
72
72
|
import { specStore } from './spec-store.js';
|
|
73
|
-
import { registerPrompts } from './prompts.js';
|
|
74
73
|
|
|
75
74
|
import { mkdirSync, readFileSync } from 'fs';
|
|
76
75
|
import { join } from 'path';
|
|
@@ -114,7 +113,7 @@ const server = new McpServer(
|
|
|
114
113
|
'Dolex — CSV data analysis with 43 chart types.',
|
|
115
114
|
'',
|
|
116
115
|
'WORKFLOW:',
|
|
117
|
-
'• Got a CSV file? → load_csv(name, path)
|
|
116
|
+
'• Got a CSV file? → load_csv(name, path) — returns smart summary (column names, types, ranges, categorical values)',
|
|
118
117
|
'• Got inline data? → visualize(data, intent) directly',
|
|
119
118
|
'• Need to explore? → load_csv → analyze_data → visualize(sourceId, sql, intent) per step',
|
|
120
119
|
'',
|
|
@@ -127,8 +126,8 @@ const server = new McpServer(
|
|
|
127
126
|
'• specId expired? → re-run the original visualize call, then continue refining from the new specId',
|
|
128
127
|
'',
|
|
129
128
|
'TOOL GUIDE:',
|
|
130
|
-
'• load_csv: Load
|
|
131
|
-
'• describe_data:
|
|
129
|
+
'• load_csv: Load CSV. Returns sourceId + smart summary (columns, types, ranges, categorical values) — enough to write SQL.',
|
|
130
|
+
'• describe_data: Full column stats, top values, sample rows. Call only when you need deep exploration.',
|
|
132
131
|
'• analyze_data: Auto-generate analysis plan with ready SQL queries. Execute each step with visualize; present results one at a time.',
|
|
133
132
|
'• query_data: Run SQL query, get rows. Returns resultId for visualize().',
|
|
134
133
|
'• visualize: Chart data. Pass inline data array, resultId from query_data, or sourceId + sql for server-side query. Auto-selects best pattern. Set title/subtitle here to avoid a refine round-trip.',
|
|
@@ -225,7 +224,7 @@ server.registerTool(
|
|
|
225
224
|
'load_csv',
|
|
226
225
|
{
|
|
227
226
|
title: 'Load CSV Data',
|
|
228
|
-
description: 'Load a CSV file or directory. Datasets persist across restarts
|
|
227
|
+
description: 'Load a CSV file or directory. Datasets persist across restarts.\nReturns sourceId + smart summary: column names, types, numeric ranges, categorical values.\nThis gives you enough to write SQL. Call describe_data only if you need full stats.',
|
|
229
228
|
inputSchema: addSourceInputSchema,
|
|
230
229
|
},
|
|
231
230
|
handleAddSource({ sourceManager }),
|
|
@@ -254,7 +253,7 @@ server.registerTool(
|
|
|
254
253
|
'describe_data',
|
|
255
254
|
{
|
|
256
255
|
title: 'Describe Data',
|
|
257
|
-
description: '
|
|
256
|
+
description: 'Full column profiles: stats (min/max/mean/median), top values with counts, sample rows.\nUse only when you need deep exploration — load_csv already gives you enough to write SQL.',
|
|
258
257
|
inputSchema: describeSourceInputSchema,
|
|
259
258
|
},
|
|
260
259
|
handleDescribeSource({ sourceManager }),
|
|
@@ -419,10 +418,6 @@ registerAppResource(
|
|
|
419
418
|
}),
|
|
420
419
|
);
|
|
421
420
|
|
|
422
|
-
// ─── REGISTER PROMPTS ──────────────────────────────────────────────────────
|
|
423
|
-
|
|
424
|
-
registerPrompts(server);
|
|
425
|
-
|
|
426
421
|
// ─── START ──────────────────────────────────────────────────────────────────
|
|
427
422
|
|
|
428
423
|
async function main() {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* shadow restoration, and manifest updates.
|
|
6
6
|
*/
|
|
7
7
|
import type { z } from 'zod';
|
|
8
|
-
import { jsonResponse, errorResponse } from './shared.js';
|
|
8
|
+
import { jsonResponse, errorResponse, connectAndValidateTable, isTransformError } from './shared.js';
|
|
9
9
|
import type { dropColumnsSchema } from './transform-schemas.js';
|
|
10
10
|
import { TransformMetadata } from '../../transforms/metadata.js';
|
|
11
11
|
import { ColumnManager } from '../../transforms/column-manager.js';
|
|
@@ -16,31 +16,18 @@ import type { CsvSourceConfig } from '../../types.js';
|
|
|
16
16
|
|
|
17
17
|
export function handleDropColumns(deps: { sourceManager: any }) {
|
|
18
18
|
return async (args: z.infer<typeof dropColumnsSchema>) => {
|
|
19
|
-
const
|
|
20
|
-
if (
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const source = connResult.source!;
|
|
24
|
-
const db = source.getDatabase?.();
|
|
25
|
-
if (!db) {
|
|
26
|
-
return errorResponse('Source does not support transforms (no database handle)');
|
|
27
|
-
}
|
|
28
|
-
const schema = await source.getSchema();
|
|
29
|
-
const table = schema.tables.find((t: any) => t.name === args.table);
|
|
30
|
-
if (!table) {
|
|
31
|
-
const available = schema.tables.map((t: any) => t.name);
|
|
32
|
-
return errorResponse(`Table '${args.table}' not found. Available: [${available.join(', ')}]`);
|
|
33
|
-
}
|
|
34
|
-
const metadata = new TransformMetadata(db);
|
|
19
|
+
const ctx = await connectAndValidateTable(deps, args.sourceId, args.table);
|
|
20
|
+
if (isTransformError(ctx)) return ctx;
|
|
21
|
+
|
|
22
|
+
const metadata = new TransformMetadata(ctx.db);
|
|
35
23
|
metadata.init();
|
|
36
|
-
const mgr = new ColumnManager(db);
|
|
24
|
+
const mgr = new ColumnManager(ctx.db);
|
|
37
25
|
|
|
38
26
|
const columnsToDrop = resolveWildcard(args.columns, args.layer, metadata, args.table);
|
|
39
27
|
if (typeof columnsToDrop === 'string') {
|
|
40
28
|
return errorResponse(columnsToDrop);
|
|
41
29
|
}
|
|
42
30
|
|
|
43
|
-
// Pre-validate all columns (atomic: all-or-nothing)
|
|
44
31
|
const allCols = mgr.getColumnNames(args.table);
|
|
45
32
|
for (const col of columnsToDrop) {
|
|
46
33
|
const record = metadata.get(args.table, col);
|
|
@@ -105,14 +92,14 @@ export function handleDropColumns(deps: { sourceManager: any }) {
|
|
|
105
92
|
if (manifestUpdated) {
|
|
106
93
|
const entry = deps.sourceManager.get(args.sourceId);
|
|
107
94
|
if (entry?.config) {
|
|
108
|
-
const schema = await source.getSchema();
|
|
95
|
+
const schema = await ctx.source.getSchema();
|
|
109
96
|
const manifestPath = resolveManifestPath(entry.config as CsvSourceConfig);
|
|
110
97
|
const tableNames = schema.tables.map((t: any) => t.name);
|
|
111
98
|
writeManifest(metadata, tableNames, manifestPath);
|
|
112
99
|
}
|
|
113
100
|
}
|
|
114
101
|
|
|
115
|
-
source.invalidateSchema?.();
|
|
102
|
+
ctx.source.invalidateSchema?.();
|
|
116
103
|
|
|
117
104
|
return jsonResponse({
|
|
118
105
|
dropped,
|
|
@@ -10,13 +10,8 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { z } from 'zod';
|
|
13
|
-
import { writeFileSync, mkdirSync } from 'fs';
|
|
14
|
-
import { dirname } from 'path';
|
|
15
|
-
import { isCompoundSpec } from '../../types.js';
|
|
16
|
-
import { buildChartHtml, isHtmlPatternSupported } from '../../renderers/html/index.js';
|
|
17
|
-
import { buildCompoundHtml } from '../../renderers/html/builders/compound.js';
|
|
18
13
|
import { specStore } from '../spec-store.js';
|
|
19
|
-
import { errorResponse } from './shared.js';
|
|
14
|
+
import { errorResponse, buildOutputHtml, writeHtmlToDisk } from './shared.js';
|
|
20
15
|
|
|
21
16
|
export const exportHtmlInputSchema = z.object({
|
|
22
17
|
specId: z.string().describe('Spec ID from a previous visualize or refine call'),
|
|
@@ -30,31 +25,19 @@ export function handleExportHtml() {
|
|
|
30
25
|
return errorResponse(`Spec "${args.specId}" not found or expired. Create a new visualization first.`);
|
|
31
26
|
}
|
|
32
27
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (isCompoundSpec(spec)) {
|
|
37
|
-
html = buildCompoundHtml(spec);
|
|
38
|
-
} else if (isHtmlPatternSupported(spec.pattern)) {
|
|
39
|
-
html = buildChartHtml(spec);
|
|
40
|
-
} else {
|
|
41
|
-
return errorResponse(`Pattern "${spec.pattern}" does not have an HTML builder.`);
|
|
28
|
+
const html = buildOutputHtml(stored.spec);
|
|
29
|
+
if (!html) {
|
|
30
|
+
return errorResponse(`Spec "${args.specId}" does not have an HTML builder.`);
|
|
42
31
|
}
|
|
43
32
|
|
|
44
|
-
// Write to disk if path provided
|
|
45
33
|
if (args.writeTo) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
};
|
|
52
|
-
} catch (err) {
|
|
53
|
-
return errorResponse(`Failed to write to ${args.writeTo}: ${err instanceof Error ? err.message : String(err)}`);
|
|
54
|
-
}
|
|
34
|
+
const writeResult = writeHtmlToDisk(html, args.writeTo);
|
|
35
|
+
if (!writeResult.ok) return errorResponse(writeResult.error);
|
|
36
|
+
return {
|
|
37
|
+
content: [{ type: 'text' as const, text: writeResult.message }],
|
|
38
|
+
};
|
|
55
39
|
}
|
|
56
40
|
|
|
57
|
-
// Return HTML in response (original behavior)
|
|
58
41
|
return {
|
|
59
42
|
content: [{ type: 'text' as const, text: html }],
|
|
60
43
|
};
|
|
@@ -4,38 +4,22 @@
|
|
|
4
4
|
* Lists all columns for a table with their layer status and expressions.
|
|
5
5
|
*/
|
|
6
6
|
import type { z } from 'zod';
|
|
7
|
-
import {
|
|
7
|
+
import { jsonResponse, connectAndValidateTable, isTransformError } from './shared.js';
|
|
8
8
|
import type { listTransformsSchema } from './transform-schemas.js';
|
|
9
9
|
import { TransformMetadata } from '../../transforms/metadata.js';
|
|
10
10
|
import { ColumnManager } from '../../transforms/column-manager.js';
|
|
11
11
|
|
|
12
12
|
export function handleListTransforms(deps: { sourceManager: any }) {
|
|
13
13
|
return async (args: z.infer<typeof listTransformsSchema>) => {
|
|
14
|
-
const
|
|
15
|
-
if (
|
|
16
|
-
return errorResponse(`Source not found: ${args.sourceId}`);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const source = connResult.source!;
|
|
20
|
-
const db = source.getDatabase?.();
|
|
21
|
-
if (!db) {
|
|
22
|
-
return errorResponse('Source does not support transforms (no database handle)');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const schema = await source.getSchema();
|
|
26
|
-
const table = schema.tables.find((t: any) => t.name === args.table);
|
|
27
|
-
if (!table) {
|
|
28
|
-
const available = schema.tables.map((t: any) => t.name);
|
|
29
|
-
return errorResponse(`Table '${args.table}' not found. Available: [${available.join(', ')}]`);
|
|
30
|
-
}
|
|
14
|
+
const ctx = await connectAndValidateTable(deps, args.sourceId, args.table);
|
|
15
|
+
if (isTransformError(ctx)) return ctx;
|
|
31
16
|
|
|
32
|
-
const metadata = new TransformMetadata(db);
|
|
17
|
+
const metadata = new TransformMetadata(ctx.db);
|
|
33
18
|
metadata.init();
|
|
34
19
|
|
|
35
|
-
const mgr = new ColumnManager(db);
|
|
20
|
+
const mgr = new ColumnManager(ctx.db);
|
|
36
21
|
const allColumns = mgr.getColumnNames(args.table);
|
|
37
22
|
|
|
38
|
-
// Classify columns
|
|
39
23
|
const derivedRecords = metadata.list(args.table, 'derived');
|
|
40
24
|
const workingRecords = metadata.list(args.table, 'working');
|
|
41
25
|
const derivedNames = new Set(derivedRecords.map(r => r.column));
|
|
@@ -43,20 +27,19 @@ export function handleListTransforms(deps: { sourceManager: any }) {
|
|
|
43
27
|
|
|
44
28
|
const sourceColumns = allColumns.filter(c => !derivedNames.has(c) && !workingNames.has(c));
|
|
45
29
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
derived_columns: derivedRecords.map(r => ({
|
|
30
|
+
function formatRecord(r: { column: string; expr: string; type: string; partitionBy?: string }) {
|
|
31
|
+
return {
|
|
49
32
|
column: r.column,
|
|
50
33
|
expr: r.expr,
|
|
51
34
|
type: r.type,
|
|
52
35
|
...(r.partitionBy ? { partitionBy: r.partitionBy } : {}),
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return jsonResponse({
|
|
40
|
+
source_columns: sourceColumns,
|
|
41
|
+
derived_columns: derivedRecords.map(formatRecord),
|
|
42
|
+
working_columns: workingRecords.map(formatRecord),
|
|
60
43
|
total_columns: allColumns.length,
|
|
61
44
|
});
|
|
62
45
|
};
|