@outsidedata/dolex 8.1.0 → 9.0.2
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/README.md +30 -7
- package/dist/src/analysis/planner.d.ts +2 -1
- package/dist/src/analysis/planner.js +2 -2
- package/dist/src/analysis/quality.js +96 -5
- package/dist/src/analysis/rules.d.ts +22 -2
- package/dist/src/analysis/rules.js +64 -23
- package/dist/src/cleaning/index.d.ts +2 -6
- package/dist/src/cleaning/index.js +8 -3
- package/dist/src/cleaning/replay.d.ts +34 -0
- package/dist/src/cleaning/replay.js +58 -0
- package/dist/src/cli/commands/analyze.js +13 -1
- package/dist/src/cli/commands/clean.js +15 -3
- package/dist/src/cli/commands/deps.d.ts +1 -0
- package/dist/src/cli/commands/deps.js +41 -0
- package/dist/src/cli/commands/help.js +2 -1
- package/dist/src/cli/commands/sources.d.ts +2 -2
- package/dist/src/cli/commands/sources.js +139 -12
- package/dist/src/cli/commands/transform.js +19 -4
- package/dist/src/cli/data-source.d.ts +0 -2
- package/dist/src/cli/data-source.js +0 -1
- package/dist/src/cli/index.js +3 -0
- package/dist/src/connectors/csv.js +29 -0
- package/dist/src/connectors/index.d.ts +2 -0
- package/dist/src/connectors/index.js +2 -0
- package/dist/src/connectors/manager.d.ts +39 -1
- package/dist/src/connectors/manager.js +191 -45
- package/dist/src/connectors/mongo/index.d.ts +21 -0
- package/dist/src/connectors/mongo/index.js +359 -0
- package/dist/src/connectors/pg/index.d.ts +2 -0
- package/dist/src/connectors/pg/index.js +316 -0
- package/dist/src/connectors/source-factory.d.ts +38 -0
- package/dist/src/connectors/source-factory.js +80 -0
- package/dist/src/connectors/sql-safety.d.ts +59 -17
- package/dist/src/connectors/sql-safety.js +275 -54
- package/dist/src/connectors/types.d.ts +59 -0
- package/dist/src/connectors/types.js +33 -1
- package/dist/src/mcp/index.d.ts +1 -1
- package/dist/src/mcp/index.js +43 -13
- package/dist/src/mcp/tools/analyze.js +12 -2
- package/dist/src/mcp/tools/capabilities.d.ts +1 -0
- package/dist/src/mcp/tools/capabilities.js +14 -0
- package/dist/src/mcp/tools/clean-column.js +2 -0
- package/dist/src/mcp/tools/clean-schemas.js +1 -1
- package/dist/src/mcp/tools/drop-columns.js +2 -0
- package/dist/src/mcp/tools/list-transforms.js +22 -0
- package/dist/src/mcp/tools/promote-columns.js +2 -0
- package/dist/src/mcp/tools/query-source.js +2 -2
- package/dist/src/mcp/tools/refine-cli.d.ts +4 -4
- package/dist/src/mcp/tools/refine.d.ts +4 -4
- package/dist/src/mcp/tools/shared.d.ts +5 -0
- package/dist/src/mcp/tools/shared.js +11 -4
- package/dist/src/mcp/tools/sources.d.ts +47 -4
- package/dist/src/mcp/tools/sources.js +51 -9
- package/dist/src/mcp/tools/transform-data.js +22 -0
- package/dist/src/mcp/tools/transform-schemas.js +4 -4
- package/dist/src/mcp/tools/visualize-cli.js +1 -1
- package/dist/src/mcp/tools/visualize.js +2 -2
- package/dist/src/patterns/index.d.ts +1 -1
- package/dist/src/patterns/index.js +1 -1
- package/dist/src/patterns/registry.d.ts +1 -12
- package/dist/src/patterns/registry.js +0 -13
- package/dist/src/patterns/utils.d.ts +0 -24
- package/dist/src/patterns/utils.js +0 -71
- package/dist/src/renderers/d3/shared.d.ts +0 -18
- package/dist/src/renderers/d3/shared.js +0 -62
- package/dist/src/types.d.ts +30 -3
- package/dist/src/utils/capabilities.d.ts +28 -0
- package/dist/src/utils/capabilities.js +58 -0
- package/dist/src/utils/optional-deps.d.ts +8 -0
- package/dist/src/utils/optional-deps.js +8 -0
- package/package.json +5 -2
- package/dist/src/analysis/clean-exec.d.ts +0 -23
- package/dist/src/analysis/clean-exec.js +0 -87
- package/dist/src/cleaning/author.d.ts +0 -30
- package/dist/src/cleaning/author.js +0 -7
- package/dist/src/cleaning/handlers.d.ts +0 -16
- package/dist/src/cleaning/handlers.js +0 -82
- package/dist/src/cleaning/manifest.d.ts +0 -35
- package/dist/src/cleaning/manifest.js +0 -95
|
@@ -2,6 +2,50 @@
|
|
|
2
2
|
* Connector-specific types for Dolex data source connectors.
|
|
3
3
|
*/
|
|
4
4
|
import type { DataSourceType, DataSourceConfig, DataSchema } from '../types.js';
|
|
5
|
+
/** Strip inline userinfo (`user:pass@`) from a connection string / URI. */
|
|
6
|
+
export declare function redactUri(uri: string): string;
|
|
7
|
+
/** Redact secrets from a source config so it can safely reach a model context, a terminal, or a
|
|
8
|
+
* log. `list_data` and `dolex sources list` MUST pass configs through this — the registry stores
|
|
9
|
+
* passwords/URIs in plaintext (owner-only file), but they must never be echoed back out. */
|
|
10
|
+
export declare function redactConfig(config: DataSourceConfig): DataSourceConfig;
|
|
11
|
+
/** Registry entry with its config secrets redacted (see redactConfig). */
|
|
12
|
+
export declare function redactEntry(entry: SourceRegistryEntry): SourceRegistryEntry;
|
|
13
|
+
/**
|
|
14
|
+
* Reflect a session-derived column in a connector's cached schema, so downstream consumers
|
|
15
|
+
* (schemaText, describe_data) see it. Shared by the live connectors' applyDerivation
|
|
16
|
+
* (Postgres shadow view / Mongo $set) — idempotent; a no-op if the column already exists.
|
|
17
|
+
*/
|
|
18
|
+
export declare function registerDerivedColumn(schema: DataSchema, table: string, column: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* How a source materializes a derived column, declared by the connector itself
|
|
21
|
+
* so the transform/clean surfaces stay source-agnostic (no getDatabase-truthiness gate).
|
|
22
|
+
*
|
|
23
|
+
* - `sqlite-alter` — CSV: ALTER TABLE + rowid-keyed UPDATE on the in-memory SQLite db.
|
|
24
|
+
* - `session-temp` — Postgres: a session-local TEMP TABLE keyed by `id`, exposed to
|
|
25
|
+
* arbitrary later queries via a same-named TEMP VIEW on ONE pinned client.
|
|
26
|
+
* - `computed-set` — Mongo: a `$set` aggregation expression prepended to every incoming pipeline,
|
|
27
|
+
* computing the derived field server-side on read. Base collection never written.
|
|
28
|
+
* - `sidecar` — Mongo alt: a throwaway sidecar collection keyed by `_id`, joined via $lookup
|
|
29
|
+
* (used when the derived value is precomputed rather than an expression).
|
|
30
|
+
* - `none` — the source cannot derive columns.
|
|
31
|
+
*/
|
|
32
|
+
export type DerivationMaterialization = 'sqlite-alter' | 'session-temp' | 'computed-set' | 'sidecar' | 'none';
|
|
33
|
+
/** The row key a derivation joins the derived value back on. */
|
|
34
|
+
export type DerivationRowKey = 'rowid' | 'id' | '_id' | null;
|
|
35
|
+
/**
|
|
36
|
+
* A connector's self-declared derivation contract. The transform/clean surfaces read this
|
|
37
|
+
* (via `ConnectedSource.derivationCapabilities()`) instead of probing for a raw db handle.
|
|
38
|
+
*/
|
|
39
|
+
export interface DerivationCapabilities {
|
|
40
|
+
/** Can this source materialize a derived column at all? */
|
|
41
|
+
canDerive: boolean;
|
|
42
|
+
/** How the derived column is materialized. */
|
|
43
|
+
materialization: DerivationMaterialization;
|
|
44
|
+
/** The key column the derived value is joined back on. */
|
|
45
|
+
rowKey: DerivationRowKey;
|
|
46
|
+
/** Is the derived column visible to arbitrary subsequent analyst queries (not just an explicit JOIN)? */
|
|
47
|
+
serverSideQueryable: boolean;
|
|
48
|
+
}
|
|
5
49
|
/**
|
|
6
50
|
* A data connector knows how to connect to a specific data source type,
|
|
7
51
|
* introspect its schema, and execute queries against it.
|
|
@@ -31,6 +75,21 @@ export interface ConnectedSource {
|
|
|
31
75
|
getSampleRows(tableName: string, count?: number): Promise<Record<string, any>[]>;
|
|
32
76
|
/** Get the underlying database handle (only available for SQL-backed connectors). */
|
|
33
77
|
getDatabase?(): any;
|
|
78
|
+
/**
|
|
79
|
+
* Declare how (or whether) this source can materialize a derived column. The source-agnostic
|
|
80
|
+
* transform/clean surfaces gate on this instead of probing `getDatabase`. A connector that does
|
|
81
|
+
* not implement it is treated as non-deriving.
|
|
82
|
+
*/
|
|
83
|
+
derivationCapabilities?(): DerivationCapabilities;
|
|
84
|
+
/**
|
|
85
|
+
* Materialize a derived column named `column` on `table` from `expr` — an expression in THIS
|
|
86
|
+
* source's own native language (a SQL expression for a SQL source, a Mongo `$set` aggregation
|
|
87
|
+
* expression for Mongo). The derived column must become visible to arbitrary subsequent
|
|
88
|
+
* `executeQuery` calls WITHOUT mutating the base table/collection (a session-local temp view on
|
|
89
|
+
* Postgres, a prepended `$set` on Mongo). Only implemented by connectors that declare
|
|
90
|
+
* `serverSideQueryable` derivation. Throws on an unsafe/invalid expression.
|
|
91
|
+
*/
|
|
92
|
+
applyDerivation?(table: string, column: string, expr: string): Promise<void>;
|
|
34
93
|
/** Invalidate cached schema so the next getSchema() rebuilds from the live database. */
|
|
35
94
|
invalidateSchema?(): void;
|
|
36
95
|
/** Close the connection and free resources. */
|
|
@@ -1,4 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Connector-specific types for Dolex data source connectors.
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
const SECRET_MASK = '•••';
|
|
5
|
+
/** Strip inline userinfo (`user:pass@`) from a connection string / URI. */
|
|
6
|
+
export function redactUri(uri) {
|
|
7
|
+
return uri.replace(/(:\/\/)[^/@]*@/, `$1${SECRET_MASK}@`);
|
|
8
|
+
}
|
|
9
|
+
/** Redact secrets from a source config so it can safely reach a model context, a terminal, or a
|
|
10
|
+
* log. `list_data` and `dolex sources list` MUST pass configs through this — the registry stores
|
|
11
|
+
* passwords/URIs in plaintext (owner-only file), but they must never be echoed back out. */
|
|
12
|
+
export function redactConfig(config) {
|
|
13
|
+
const c = { ...config };
|
|
14
|
+
if (typeof c.password === 'string' && c.password)
|
|
15
|
+
c.password = SECRET_MASK;
|
|
16
|
+
if (typeof c.connectionString === 'string')
|
|
17
|
+
c.connectionString = redactUri(c.connectionString);
|
|
18
|
+
if (typeof c.uri === 'string')
|
|
19
|
+
c.uri = redactUri(c.uri);
|
|
20
|
+
return c;
|
|
21
|
+
}
|
|
22
|
+
/** Registry entry with its config secrets redacted (see redactConfig). */
|
|
23
|
+
export function redactEntry(entry) {
|
|
24
|
+
return { ...entry, config: redactConfig(entry.config) };
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Reflect a session-derived column in a connector's cached schema, so downstream consumers
|
|
28
|
+
* (schemaText, describe_data) see it. Shared by the live connectors' applyDerivation
|
|
29
|
+
* (Postgres shadow view / Mongo $set) — idempotent; a no-op if the column already exists.
|
|
30
|
+
*/
|
|
31
|
+
export function registerDerivedColumn(schema, table, column) {
|
|
32
|
+
const t = schema.tables.find((tt) => tt.name === table);
|
|
33
|
+
if (t && !t.columns.find((cc) => cc.name === column)) {
|
|
34
|
+
t.columns.push({ name: column, type: 'text', sampleValues: [], uniqueCount: 0, nullCount: 0, totalCount: t.rowCount, layer: 'derived' });
|
|
35
|
+
}
|
|
36
|
+
}
|
package/dist/src/mcp/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
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
|
|
12
|
-
*
|
|
12
|
+
* load_source — Load a CSV / Postgres / MongoDB source
|
|
13
13
|
* list_data — List loaded datasets
|
|
14
14
|
* remove_data — Remove a loaded dataset
|
|
15
15
|
* describe_data — Re-examine column profiles and sample rows for a dataset
|
package/dist/src/mcp/index.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
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
|
|
12
|
-
*
|
|
12
|
+
* load_source — Load a CSV / Postgres / MongoDB source
|
|
13
13
|
* list_data — List loaded datasets
|
|
14
14
|
* remove_data — Remove a loaded dataset
|
|
15
15
|
* describe_data — Re-examine column profiles and sample rows for a dataset
|
|
@@ -28,15 +28,16 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
30
30
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
31
|
-
import { registerAppTool, registerAppResource, RESOURCE_MIME_TYPE, } from '@modelcontextprotocol/ext-apps/server';
|
|
31
|
+
import { registerAppTool, registerAppResource, getUiCapability, RESOURCE_MIME_TYPE, } from '@modelcontextprotocol/ext-apps/server';
|
|
32
32
|
import { visualizeInputSchema, handleVisualize } from './tools/visualize.js';
|
|
33
33
|
import { handleListPatterns } from './tools/list-patterns.js';
|
|
34
34
|
import { refineInputSchema, handleRefine } from './tools/refine.js';
|
|
35
|
-
import { addSourceInputSchema, removeSourceInputSchema, describeSourceInputSchema, handleListSources, handleAddSource, handleRemoveSource, handleDescribeSource, } from './tools/sources.js';
|
|
35
|
+
import { addSourceInputSchema, removeSourceInputSchema, describeSourceInputSchema, testSourceInputSchema, handleListSources, handleAddSource, handleRemoveSource, handleDescribeSource, handleTestSource, } from './tools/sources.js';
|
|
36
36
|
import { analyzeSourceInputSchema, handleAnalyzeSource } from './tools/analyze.js';
|
|
37
37
|
import { querySourceInputSchema, handleQuerySource } from './tools/query-source.js';
|
|
38
38
|
import { clearCacheInputSchema, handleServerStatus, handleClearCache, } from './tools/server-privacy.js';
|
|
39
39
|
import { exportHtmlInputSchema, handleExportHtml } from './tools/export-html.js';
|
|
40
|
+
import { handleCapabilities } from './tools/capabilities.js';
|
|
40
41
|
import { screenshotInputSchema, handleScreenshot, closeBrowser } from './tools/screenshot.js';
|
|
41
42
|
import { visualizeCliInputSchema, handleVisualizeCli } from './tools/visualize-cli.js';
|
|
42
43
|
import { refineCliInputSchema, handleRefineCli } from './tools/refine-cli.js';
|
|
@@ -64,6 +65,7 @@ const dolexDir = join(homedir(), '.dolex');
|
|
|
64
65
|
mkdirSync(dolexDir, { recursive: true });
|
|
65
66
|
const sourceManager = new SourceManager(join(dolexDir, 'sources.json'));
|
|
66
67
|
const serverStartTime = Date.now();
|
|
68
|
+
const { version } = JSON.parse(readFileSync(packagePath(import.meta.url, 'package.json'), 'utf-8'));
|
|
67
69
|
const iconPath = packagePath(import.meta.url, 'assets', 'icon.svg');
|
|
68
70
|
let serverIcons;
|
|
69
71
|
try {
|
|
@@ -74,16 +76,17 @@ catch { }
|
|
|
74
76
|
// ─── CREATE SERVER ──────────────────────────────────────────────────────────
|
|
75
77
|
const server = new McpServer({
|
|
76
78
|
name: 'dolex',
|
|
77
|
-
version
|
|
79
|
+
version,
|
|
78
80
|
...(serverIcons && { icons: serverIcons }),
|
|
79
81
|
}, {
|
|
80
82
|
instructions: [
|
|
81
83
|
"You are a data analyst working on the user's own CSV files: rigorous column profiling, data-quality auditing, a prioritized analysis plan, and findings rendered across 43 chart types as artifacts they keep.",
|
|
82
84
|
'',
|
|
83
85
|
'WORKFLOW:',
|
|
84
|
-
'• Got a CSV file? →
|
|
86
|
+
'• Got a CSV file, Postgres, or MongoDB? → load_source(name, type, path|uri|host+database) — returns smart summary (column names, types, ranges, categorical values)',
|
|
87
|
+
'• For a Postgres/MongoDB source, call capabilities first to confirm its driver is installed here; if not, it tells the user the exact command (e.g. `npm install pg`). Loading a source whose driver is missing returns that same install message, never a crash.',
|
|
85
88
|
'• Got inline data? → visualize(data, intent) directly',
|
|
86
|
-
'• Need to explore? →
|
|
89
|
+
'• Need to explore? → load_source → analyze_data → visualize(sourceId, sql, intent) per step',
|
|
87
90
|
'',
|
|
88
91
|
'CONTINUATION (dataset already loaded):',
|
|
89
92
|
'• Chart from data → visualize(sourceId, sql, intent)',
|
|
@@ -94,7 +97,7 @@ const server = new McpServer({
|
|
|
94
97
|
'• specId expired? → re-run the original visualize call, then continue refining from the new specId',
|
|
95
98
|
'',
|
|
96
99
|
'TOOL GUIDE:',
|
|
97
|
-
'•
|
|
100
|
+
'• load_source: Load a CSV / Postgres / MongoDB source. Returns sourceId + smart summary (columns, types, ranges, categorical values) — enough to query.',
|
|
98
101
|
'• describe_data: Full column stats, top values, sample rows. Call only when you need deep exploration.',
|
|
99
102
|
'• analyze_data: Auto-generate analysis plan with ready SQL queries. Execute each step with visualize; present results one at a time.',
|
|
100
103
|
'• query_data: Run SQL query, get rows. Returns resultId for visualize().',
|
|
@@ -115,6 +118,20 @@ const server = new McpServer({
|
|
|
115
118
|
].join('\n'),
|
|
116
119
|
});
|
|
117
120
|
// ─── REGISTER TOOLS ─────────────────────────────────────────────────────────
|
|
121
|
+
// The chart HTML rides in structuredContent. A host that renders MCP Apps (it says so at
|
|
122
|
+
// initialize) hands that to the chart view and keeps it out of the model's context. Other
|
|
123
|
+
// clients (Claude Code, Cursor) give structuredContent to the model instead, and a chart of
|
|
124
|
+
// a thousand-odd rows is past their tool-output limit, so they get the text result alone.
|
|
125
|
+
function chartForHost(handler) {
|
|
126
|
+
return async (args) => {
|
|
127
|
+
const result = await handler(args);
|
|
128
|
+
if (getUiCapability(server.server.getClientCapabilities())?.mimeTypes?.includes(RESOURCE_MIME_TYPE))
|
|
129
|
+
return result;
|
|
130
|
+
const text = { ...result };
|
|
131
|
+
delete text.structuredContent;
|
|
132
|
+
return text;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
118
135
|
// Inline data visualization tool
|
|
119
136
|
registerAppTool(server, 'visualize', {
|
|
120
137
|
title: 'Visualize Data',
|
|
@@ -128,7 +145,7 @@ registerAppTool(server, 'visualize', {
|
|
|
128
145
|
},
|
|
129
146
|
},
|
|
130
147
|
},
|
|
131
|
-
}, handleVisualize(selectPatternCallback, { sourceManager }));
|
|
148
|
+
}, chartForHost(handleVisualize(selectPatternCallback, { sourceManager })));
|
|
132
149
|
server.registerTool('list_patterns', {
|
|
133
150
|
title: 'List Visualization Patterns',
|
|
134
151
|
description: 'Browse all 43 chart types with data requirements, capabilities, and config options.',
|
|
@@ -145,11 +162,11 @@ registerAppTool(server, 'refine_visualization', {
|
|
|
145
162
|
},
|
|
146
163
|
},
|
|
147
164
|
},
|
|
148
|
-
}, handleRefine());
|
|
165
|
+
}, chartForHost(handleRefine()));
|
|
149
166
|
// CSV data management tools
|
|
150
|
-
server.registerTool('
|
|
151
|
-
title: 'Load
|
|
152
|
-
description: 'Load a CSV file or
|
|
167
|
+
server.registerTool('load_source', {
|
|
168
|
+
title: 'Load a data source',
|
|
169
|
+
description: 'Load a data source: a CSV file/directory (type "csv" + path), a live Postgres database (type "postgres" + uri or host/database/user), or a MongoDB database (type "mongodb" + uri/host + database). Type defaults to "csv". Datasets persist across restarts.\nReturns sourceId + smart summary: column names, types, numeric ranges, categorical values.\nThis gives you enough to query. Call describe_data only if you need full stats.',
|
|
153
170
|
inputSchema: addSourceInputSchema,
|
|
154
171
|
}, handleAddSource({ sourceManager }));
|
|
155
172
|
server.registerTool('list_data', {
|
|
@@ -163,7 +180,7 @@ server.registerTool('remove_data', {
|
|
|
163
180
|
}, handleRemoveSource({ sourceManager }));
|
|
164
181
|
server.registerTool('describe_data', {
|
|
165
182
|
title: 'Describe Data',
|
|
166
|
-
description: 'Full column profiles: stats (min/max/mean/median), top values with counts, sample rows.\nUse only when you need deep exploration —
|
|
183
|
+
description: 'Full column profiles: stats (min/max/mean/median), top values with counts, sample rows.\nUse only when you need deep exploration — load_source already gives you enough to query.',
|
|
167
184
|
inputSchema: describeSourceInputSchema,
|
|
168
185
|
}, handleDescribeSource({ sourceManager }));
|
|
169
186
|
server.registerTool('analyze_data', {
|
|
@@ -208,6 +225,15 @@ server.registerTool('server_status', {
|
|
|
208
225
|
title: 'Server Status',
|
|
209
226
|
description: 'Inspect cached specs, query results, connected sources, and uptime.',
|
|
210
227
|
}, handleServerStatus(privacyDeps));
|
|
228
|
+
server.registerTool('capabilities', {
|
|
229
|
+
title: 'Environment Capabilities',
|
|
230
|
+
description: 'What this Dolex install can do here: which source types are ready (CSV always; Postgres/MongoDB only if their optional driver is installed), whether python3 is present (for clean_column), and the exact command to enable anything missing. Call this before loading a Postgres/Mongo source so you can tell the user how to install a missing driver instead of hitting an error.',
|
|
231
|
+
}, handleCapabilities());
|
|
232
|
+
server.registerTool('test_source', {
|
|
233
|
+
title: 'Test a Source',
|
|
234
|
+
description: 'Health-check a registered Postgres/Mongo source: is its saved database reachable with its credentials? Returns a classified reason (unreachable / auth-failed / db-not-found / driver-missing) so you can tell the user exactly what to fix. A source can be registered even while its DB is down — use this to confirm it once it is up.',
|
|
235
|
+
inputSchema: testSourceInputSchema,
|
|
236
|
+
}, handleTestSource({ sourceManager }));
|
|
211
237
|
server.registerTool('clear_cache', {
|
|
212
238
|
title: 'Clear Cache',
|
|
213
239
|
description: 'Clear cached data from memory. Scope: "all" (specs + results), "specs" (visualization specs), "results" (query cache). Use after working with sensitive data.',
|
|
@@ -275,6 +301,10 @@ async function main() {
|
|
|
275
301
|
};
|
|
276
302
|
process.on('SIGINT', shutdown);
|
|
277
303
|
process.on('SIGTERM', shutdown);
|
|
304
|
+
// A client stops a stdio server by closing its stdin, and a client (or the npx in front of
|
|
305
|
+
// this process) that dies leaves only that behind. Without this the purge interval keeps
|
|
306
|
+
// the process running forever.
|
|
307
|
+
process.stdin.on('end', shutdown);
|
|
278
308
|
}
|
|
279
309
|
main().catch((error) => {
|
|
280
310
|
console.error('Fatal error:', error);
|
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { buildAnalysisPlan } from '../../analysis/planner.js';
|
|
7
|
+
import { plannerDialectForSource, PlannerUnsupportedSourceError } from '../../analysis/rules.js';
|
|
7
8
|
import { errorResponse, jsonResponse } from './shared.js';
|
|
8
9
|
export const analyzeSourceInputSchema = z.object({
|
|
9
|
-
sourceId: z.string().describe('Dataset ID returned by
|
|
10
|
+
sourceId: z.string().describe('Dataset ID returned by load_source'),
|
|
10
11
|
table: z.string().optional().describe('Table to analyze (defaults to first table)'),
|
|
11
12
|
maxSteps: z.number().min(1).max(10).optional().describe('Maximum analysis steps (default: 6)'),
|
|
12
13
|
});
|
|
@@ -27,7 +28,16 @@ export function handleAnalyzeSource(deps) {
|
|
|
27
28
|
: 'No tables found in source';
|
|
28
29
|
return errorResponse(message);
|
|
29
30
|
}
|
|
30
|
-
|
|
31
|
+
let dialect;
|
|
32
|
+
try {
|
|
33
|
+
dialect = plannerDialectForSource(schemaResult.schema.source?.type);
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if (err instanceof PlannerUnsupportedSourceError)
|
|
37
|
+
return errorResponse(err.message);
|
|
38
|
+
throw err;
|
|
39
|
+
}
|
|
40
|
+
const plan = buildAnalysisPlan(targetTable.columns, targetTable.name, schemaResult.schema.source?.name ?? args.sourceId, args.maxSteps ?? 6, dialect);
|
|
31
41
|
return jsonResponse(plan);
|
|
32
42
|
};
|
|
33
43
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function handleCapabilities(): () => Promise<import("./shared.js").McpResponse>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Tool: capabilities — what can Dolex do in THIS environment.
|
|
3
|
+
*
|
|
4
|
+
* An AI assistant calls this once to discover which source types are ready (CSV always; Postgres /
|
|
5
|
+
* MongoDB only if their optional driver is installed) and what to run to enable the rest, so it can
|
|
6
|
+
* drive Dolex within the available capabilities instead of attempting a source and hitting an error.
|
|
7
|
+
* Pairs with the connectors' graceful failure: an unavailable source, if attempted anyway, returns
|
|
8
|
+
* the same actionable "npm install …" message rather than a crash.
|
|
9
|
+
*/
|
|
10
|
+
import { jsonResponse } from './shared.js';
|
|
11
|
+
import { probeCapabilities } from '../../utils/capabilities.js';
|
|
12
|
+
export function handleCapabilities() {
|
|
13
|
+
return async () => jsonResponse(probeCapabilities());
|
|
14
|
+
}
|
|
@@ -6,6 +6,8 @@ export function handleCleanColumn(deps) {
|
|
|
6
6
|
const ctx = await connectAndValidateTable(deps, args.sourceId, args.table);
|
|
7
7
|
if (isTransformError(ctx))
|
|
8
8
|
return ctx;
|
|
9
|
+
if (!ctx.db)
|
|
10
|
+
return errorResponse(`clean_column runs a Python clean() over CSV-backed rows. On a live ${ctx.source.type} source, express the fix as a derived column via transform_data using a native ${ctx.source.type === 'mongodb' ? 'aggregation ($set) expression' : 'SQL expression'} — non-destructive and server-side.`);
|
|
9
11
|
const colNames = ctx.table.columns.map((c) => c.name);
|
|
10
12
|
if (!colNames.includes(args.column))
|
|
11
13
|
return errorResponse(`Column '${args.column}' not found. Available: [${colNames.join(', ')}]`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export const cleanColumnSchema = z.object({
|
|
3
|
-
sourceId: z.string().describe('Dataset ID returned by
|
|
3
|
+
sourceId: z.string().describe('Dataset ID returned by load_source'),
|
|
4
4
|
table: z.string().describe('Table name within the source'),
|
|
5
5
|
column: z.string().describe('The column to clean'),
|
|
6
6
|
code: z.string().describe('A Python 3 function `def clean(value):` taking ONE raw cell value — ALWAYS a string, or None (cast it yourself with int()/float() before any numeric work) — and returning the cleaned value (None for missing/sentinel). May import stdlib (datetime, re). No I/O.'),
|
|
@@ -9,6 +9,8 @@ export function handleDropColumns(deps) {
|
|
|
9
9
|
const ctx = await connectAndValidateTable(deps, args.sourceId, args.table);
|
|
10
10
|
if (isTransformError(ctx))
|
|
11
11
|
return ctx;
|
|
12
|
+
if (!ctx.db)
|
|
13
|
+
return errorResponse(`drop_columns manages CSV-side derived columns. On a live ${ctx.source.type} source, derived columns are session-local — end the session (or overwrite via transform_data) to discard them.`);
|
|
12
14
|
const metadata = new TransformMetadata(ctx.db);
|
|
13
15
|
metadata.init();
|
|
14
16
|
const mgr = new ColumnManager(ctx.db);
|
|
@@ -6,6 +6,28 @@ export function handleListTransforms(deps) {
|
|
|
6
6
|
const ctx = await connectAndValidateTable(deps, args.sourceId, args.table);
|
|
7
7
|
if (isTransformError(ctx))
|
|
8
8
|
return ctx;
|
|
9
|
+
// Live sources (Postgres/Mongo) have no SQLite handle. Their derived columns are
|
|
10
|
+
// session-local (created via transform_data) and surface in the introspected schema
|
|
11
|
+
// tagged layer:'derived'. List those from the schema instead of dereferencing a null
|
|
12
|
+
// db handle (which previously threw "Cannot read properties of undefined").
|
|
13
|
+
if (!ctx.db) {
|
|
14
|
+
const schema = await ctx.source.getSchema();
|
|
15
|
+
const tbl = schema.tables.find((t) => t.name === args.table);
|
|
16
|
+
const cols = tbl?.columns ?? [];
|
|
17
|
+
const derived = cols.filter((c) => c.layer === 'derived');
|
|
18
|
+
const sourceCols = cols.filter((c) => c.layer !== 'derived');
|
|
19
|
+
return jsonResponse({
|
|
20
|
+
source_columns: sourceCols.map((c) => c.name),
|
|
21
|
+
derived_columns: derived.map((c) => ({
|
|
22
|
+
column: c.name,
|
|
23
|
+
layer: 'derived',
|
|
24
|
+
note: 'session-local (created via transform_data); expression not tracked on a live source',
|
|
25
|
+
})),
|
|
26
|
+
working_columns: [],
|
|
27
|
+
total_columns: cols.length,
|
|
28
|
+
note: `Live ${ctx.source.type} source — derived columns are session-local to this connection and are not persisted (no working layer or manifest). Recreate them with transform_data.`,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
9
31
|
const metadata = new TransformMetadata(ctx.db);
|
|
10
32
|
metadata.init();
|
|
11
33
|
const mgr = new ColumnManager(ctx.db);
|
|
@@ -6,6 +6,8 @@ export function handlePromoteColumns(deps) {
|
|
|
6
6
|
const ctx = await connectAndValidateTable(deps, args.sourceId, args.table);
|
|
7
7
|
if (isTransformError(ctx))
|
|
8
8
|
return ctx;
|
|
9
|
+
if (!ctx.db)
|
|
10
|
+
return errorResponse(`promote_columns persists derived columns to a CSV-side manifest. On a live ${ctx.source.type} source, derived columns are session-local (created with transform_data) and are not persisted — nothing to promote.`);
|
|
9
11
|
const metadata = new TransformMetadata(ctx.db);
|
|
10
12
|
metadata.init();
|
|
11
13
|
let columnsToPromote;
|
|
@@ -7,8 +7,8 @@ import { saveResult } from './result-cache.js';
|
|
|
7
7
|
import { errorResponse, jsonResponse } from './shared.js';
|
|
8
8
|
import { logOperation } from './operation-log.js';
|
|
9
9
|
export const querySourceInputSchema = z.object({
|
|
10
|
-
sourceId: z.string().describe('Dataset ID returned by
|
|
11
|
-
sql: z.string().describe('SQL SELECT query. Use table and column names from
|
|
10
|
+
sourceId: z.string().describe('Dataset ID returned by load_source'),
|
|
11
|
+
sql: z.string().describe('SQL SELECT query. Use table and column names from load_source/describe_data. Supports JOINs, GROUP BY, HAVING, window functions, CTEs. Custom aggregates: MEDIAN, STDDEV, CV (coeff. of variation), MAD (median abs. deviation), P1/P5/P10/P25/P75/P90/P95/P99.'),
|
|
12
12
|
maxRows: z.number().optional().describe('Max rows to return (default: 10000)'),
|
|
13
13
|
});
|
|
14
14
|
export function handleQuerySource(deps) {
|
|
@@ -90,7 +90,7 @@ export declare const refineCliInputSchema: z.ZodObject<{
|
|
|
90
90
|
direction: "asc" | "desc";
|
|
91
91
|
field?: string | undefined;
|
|
92
92
|
} | null | undefined;
|
|
93
|
-
format?: "compact" | "integer" | "
|
|
93
|
+
format?: "compact" | "integer" | "decimal" | "percent" | "dollar" | undefined;
|
|
94
94
|
colorField?: string | undefined;
|
|
95
95
|
palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
|
|
96
96
|
filter?: {
|
|
@@ -98,9 +98,9 @@ export declare const refineCliInputSchema: z.ZodObject<{
|
|
|
98
98
|
values: (string | number)[];
|
|
99
99
|
op: "in" | "not_in" | "gt" | "gte" | "lt" | "lte";
|
|
100
100
|
}[] | undefined;
|
|
101
|
+
limit?: number | undefined;
|
|
101
102
|
layout?: "rows" | "columns" | undefined;
|
|
102
103
|
subtitle?: string | undefined;
|
|
103
|
-
limit?: number | undefined;
|
|
104
104
|
flip?: boolean | undefined;
|
|
105
105
|
xLabel?: string | undefined;
|
|
106
106
|
yLabel?: string | undefined;
|
|
@@ -122,7 +122,7 @@ export declare const refineCliInputSchema: z.ZodObject<{
|
|
|
122
122
|
direction: "asc" | "desc";
|
|
123
123
|
field?: string | undefined;
|
|
124
124
|
} | null | undefined;
|
|
125
|
-
format?: "compact" | "integer" | "
|
|
125
|
+
format?: "compact" | "integer" | "decimal" | "percent" | "dollar" | undefined;
|
|
126
126
|
colorField?: string | undefined;
|
|
127
127
|
palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
|
|
128
128
|
filter?: {
|
|
@@ -130,9 +130,9 @@ export declare const refineCliInputSchema: z.ZodObject<{
|
|
|
130
130
|
values: (string | number)[];
|
|
131
131
|
op?: "=" | "!=" | "in" | "not_in" | "gt" | "gte" | "lt" | "lte" | undefined;
|
|
132
132
|
}[] | undefined;
|
|
133
|
+
limit?: number | undefined;
|
|
133
134
|
layout?: "rows" | "columns" | undefined;
|
|
134
135
|
subtitle?: string | undefined;
|
|
135
|
-
limit?: number | undefined;
|
|
136
136
|
flip?: boolean | undefined;
|
|
137
137
|
xLabel?: string | undefined;
|
|
138
138
|
yLabel?: string | undefined;
|
|
@@ -77,7 +77,7 @@ export declare const refineInputSchema: z.ZodObject<{
|
|
|
77
77
|
direction: "asc" | "desc";
|
|
78
78
|
field?: string | undefined;
|
|
79
79
|
} | null | undefined;
|
|
80
|
-
format?: "compact" | "integer" | "
|
|
80
|
+
format?: "compact" | "integer" | "decimal" | "percent" | "dollar" | undefined;
|
|
81
81
|
colorField?: string | undefined;
|
|
82
82
|
palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
|
|
83
83
|
filter?: {
|
|
@@ -85,9 +85,9 @@ export declare const refineInputSchema: z.ZodObject<{
|
|
|
85
85
|
values: (string | number)[];
|
|
86
86
|
op: "in" | "not_in" | "gt" | "gte" | "lt" | "lte";
|
|
87
87
|
}[] | undefined;
|
|
88
|
+
limit?: number | undefined;
|
|
88
89
|
layout?: "rows" | "columns" | undefined;
|
|
89
90
|
subtitle?: string | undefined;
|
|
90
|
-
limit?: number | undefined;
|
|
91
91
|
flip?: boolean | undefined;
|
|
92
92
|
xLabel?: string | undefined;
|
|
93
93
|
yLabel?: string | undefined;
|
|
@@ -108,7 +108,7 @@ export declare const refineInputSchema: z.ZodObject<{
|
|
|
108
108
|
direction: "asc" | "desc";
|
|
109
109
|
field?: string | undefined;
|
|
110
110
|
} | null | undefined;
|
|
111
|
-
format?: "compact" | "integer" | "
|
|
111
|
+
format?: "compact" | "integer" | "decimal" | "percent" | "dollar" | undefined;
|
|
112
112
|
colorField?: string | undefined;
|
|
113
113
|
palette?: "categorical" | "blue" | "green" | "purple" | "warm" | "blueRed" | "greenPurple" | "tealOrange" | "redGreen" | "traffic-light" | "profit-loss" | "temperature" | undefined;
|
|
114
114
|
filter?: {
|
|
@@ -116,9 +116,9 @@ export declare const refineInputSchema: z.ZodObject<{
|
|
|
116
116
|
values: (string | number)[];
|
|
117
117
|
op?: "=" | "!=" | "in" | "not_in" | "gt" | "gte" | "lt" | "lte" | undefined;
|
|
118
118
|
}[] | undefined;
|
|
119
|
+
limit?: number | undefined;
|
|
119
120
|
layout?: "rows" | "columns" | undefined;
|
|
120
121
|
subtitle?: string | undefined;
|
|
121
|
-
limit?: number | undefined;
|
|
122
122
|
flip?: boolean | undefined;
|
|
123
123
|
xLabel?: string | undefined;
|
|
124
124
|
yLabel?: string | undefined;
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* - Color preference application to visualization specs
|
|
8
8
|
*/
|
|
9
9
|
import type { DataColumn, VisualizationSpec, CompoundVisualizationSpec } from '../../types.js';
|
|
10
|
+
import type { DerivationCapabilities } from '../../connectors/types.js';
|
|
10
11
|
type McpTextContent = {
|
|
11
12
|
type: 'text';
|
|
12
13
|
text: string;
|
|
@@ -80,8 +81,12 @@ export declare function resolveData(args: {
|
|
|
80
81
|
export declare function isErrorResponse(result: ResolvedData | McpResponse): result is McpResponse;
|
|
81
82
|
export interface TransformContext {
|
|
82
83
|
source: any;
|
|
84
|
+
/** The raw SQLite handle — present only for the CSV/sqlite-alter materialization; undefined for
|
|
85
|
+
* a live source (PG/Mongo), which materializes via `source.applyDerivation`. */
|
|
83
86
|
db: any;
|
|
84
87
|
table: any;
|
|
88
|
+
/** The source's declared derivation contract (materialization / rowKey / server-side-queryable). */
|
|
89
|
+
caps: DerivationCapabilities;
|
|
85
90
|
}
|
|
86
91
|
/**
|
|
87
92
|
* Shared setup for all transform tools: connect to source, get database handle,
|
|
@@ -240,10 +240,17 @@ export async function connectAndValidateTable(deps, sourceId, tableName) {
|
|
|
240
240
|
return errorResponse(`Source not found: ${sourceId}`);
|
|
241
241
|
}
|
|
242
242
|
const source = connResult.source;
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
243
|
+
// Source-agnostic derivation gate: the connector DECLARES whether/how it can derive a column
|
|
244
|
+
// (no longer a getDatabase-truthiness probe). A source that doesn't implement the seam is treated
|
|
245
|
+
// as non-deriving.
|
|
246
|
+
const caps = source.derivationCapabilities?.() ?? { canDerive: false, materialization: 'none', rowKey: null, serverSideQueryable: false };
|
|
247
|
+
if (!caps.canDerive) {
|
|
248
|
+
return errorResponse('Source does not support transforms');
|
|
246
249
|
}
|
|
250
|
+
// CSV/sqlite-alter exposes a raw SQLite handle for the ALTER+rowid work; a live source (PG/Mongo)
|
|
251
|
+
// has no handle and materializes via source.applyDerivation. db may be undefined — each tool guards
|
|
252
|
+
// on what it needs (transform_data handles both; promote/drop/clean require the SQLite handle).
|
|
253
|
+
const db = source.getDatabase?.();
|
|
247
254
|
let schema;
|
|
248
255
|
try {
|
|
249
256
|
schema = await source.getSchema();
|
|
@@ -256,7 +263,7 @@ export async function connectAndValidateTable(deps, sourceId, tableName) {
|
|
|
256
263
|
const available = schema.tables.map((t) => t.name);
|
|
257
264
|
return errorResponse(`Table '${tableName}' not found. Available: [${available.join(', ')}]`);
|
|
258
265
|
}
|
|
259
|
-
return { source, db, table };
|
|
266
|
+
return { source, db, table, caps };
|
|
260
267
|
}
|
|
261
268
|
/** Type guard: checks if a connectAndValidateTable result is an error response. */
|
|
262
269
|
export function isTransformError(result) {
|
|
@@ -1,18 +1,48 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* MCP Tools: list_data,
|
|
2
|
+
* MCP Tools: list_data, load_source, remove_data, describe_data, test_source
|
|
3
3
|
* Manage CSV datasets.
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
export declare function isSandboxPath(filePath: string): boolean;
|
|
7
7
|
export declare const addSourceInputSchema: z.ZodObject<{
|
|
8
8
|
name: z.ZodString;
|
|
9
|
-
|
|
9
|
+
type: z.ZodOptional<z.ZodEnum<["csv", "postgres", "mongodb"]>>;
|
|
10
|
+
path: z.ZodOptional<z.ZodString>;
|
|
11
|
+
uri: z.ZodOptional<z.ZodString>;
|
|
12
|
+
host: z.ZodOptional<z.ZodString>;
|
|
13
|
+
port: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
database: z.ZodOptional<z.ZodString>;
|
|
15
|
+
user: z.ZodOptional<z.ZodString>;
|
|
16
|
+
password: z.ZodOptional<z.ZodString>;
|
|
17
|
+
passwordEnv: z.ZodOptional<z.ZodString>;
|
|
18
|
+
schema: z.ZodOptional<z.ZodString>;
|
|
19
|
+
collections: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
10
20
|
}, "strip", z.ZodTypeAny, {
|
|
11
21
|
name: string;
|
|
12
|
-
|
|
22
|
+
type?: "csv" | "postgres" | "mongodb" | undefined;
|
|
23
|
+
path?: string | undefined;
|
|
24
|
+
host?: string | undefined;
|
|
25
|
+
port?: number | undefined;
|
|
26
|
+
database?: string | undefined;
|
|
27
|
+
user?: string | undefined;
|
|
28
|
+
password?: string | undefined;
|
|
29
|
+
passwordEnv?: string | undefined;
|
|
30
|
+
schema?: string | undefined;
|
|
31
|
+
uri?: string | undefined;
|
|
32
|
+
collections?: string[] | undefined;
|
|
13
33
|
}, {
|
|
14
34
|
name: string;
|
|
15
|
-
|
|
35
|
+
type?: "csv" | "postgres" | "mongodb" | undefined;
|
|
36
|
+
path?: string | undefined;
|
|
37
|
+
host?: string | undefined;
|
|
38
|
+
port?: number | undefined;
|
|
39
|
+
database?: string | undefined;
|
|
40
|
+
user?: string | undefined;
|
|
41
|
+
password?: string | undefined;
|
|
42
|
+
passwordEnv?: string | undefined;
|
|
43
|
+
schema?: string | undefined;
|
|
44
|
+
uri?: string | undefined;
|
|
45
|
+
collections?: string[] | undefined;
|
|
16
46
|
}>;
|
|
17
47
|
export declare const removeSourceInputSchema: z.ZodObject<{
|
|
18
48
|
sourceId: z.ZodString;
|
|
@@ -37,6 +67,19 @@ export declare const describeSourceInputSchema: z.ZodObject<{
|
|
|
37
67
|
export declare function handleListSources(deps: {
|
|
38
68
|
sourceManager: any;
|
|
39
69
|
}): () => Promise<import("./shared.js").McpResponse>;
|
|
70
|
+
export declare const testSourceInputSchema: z.ZodObject<{
|
|
71
|
+
sourceId: z.ZodString;
|
|
72
|
+
}, "strip", z.ZodTypeAny, {
|
|
73
|
+
sourceId: string;
|
|
74
|
+
}, {
|
|
75
|
+
sourceId: string;
|
|
76
|
+
}>;
|
|
77
|
+
/** Connectivity health-check for a registered source — is the saved DB reachable with its credentials?
|
|
78
|
+
* Returns a classified kind (unreachable / auth-failed / db-not-found / driver-missing / …) so the
|
|
79
|
+
* assistant can give the user a specific fix, and repair via load_source (re-register) if needed. */
|
|
80
|
+
export declare function handleTestSource(deps: {
|
|
81
|
+
sourceManager: any;
|
|
82
|
+
}): (args: z.infer<typeof testSourceInputSchema>) => Promise<import("./shared.js").McpResponse>;
|
|
40
83
|
export declare function handleAddSource(deps: {
|
|
41
84
|
sourceManager: any;
|
|
42
85
|
}): (args: z.infer<typeof addSourceInputSchema>) => Promise<import("./shared.js").McpResponse>;
|