@smallwebco/tinypivot-mcp 0.3.0 → 0.4.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/.claude-plugin/plugin.json +2 -2
- package/README.md +21 -6
- package/dist/app/index.html +87 -86
- package/dist/{chunk-AFGC2C4J.js → chunk-ZZOVYGIU.js} +484 -113
- package/dist/cli.js +37 -18
- package/dist/index.d.ts +215 -83
- package/dist/index.js +9 -1
- package/package.json +2 -2
- package/server.json +3 -3
- package/skills/tinypivot/SKILL.md +6 -3
package/dist/cli.js
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
CHART_THEME_IDS,
|
|
4
4
|
DatasetStore,
|
|
5
5
|
FREE_TIER_ROW_LIMIT,
|
|
6
|
+
Studio,
|
|
6
7
|
TERMINAL_PALETTES,
|
|
7
8
|
createTinyPivotMcpServer,
|
|
8
9
|
formatDatasetSummary,
|
|
@@ -18,7 +19,7 @@ import {
|
|
|
18
19
|
runTuiCommand,
|
|
19
20
|
saveVisualThemePreference,
|
|
20
21
|
startCompanionServer
|
|
21
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-ZZOVYGIU.js";
|
|
22
23
|
import "./chunk-2ESYSVXG.js";
|
|
23
24
|
|
|
24
25
|
// src/cli.ts
|
|
@@ -34,6 +35,8 @@ function openInBrowser(url) {
|
|
|
34
35
|
} catch {
|
|
35
36
|
}
|
|
36
37
|
}
|
|
38
|
+
var STUDIO_PORT = 47317;
|
|
39
|
+
var STUDIO_RECONNECT_MS = 2500;
|
|
37
40
|
function normalizeJsonRow(input) {
|
|
38
41
|
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
39
42
|
return { value: input ?? null };
|
|
@@ -171,7 +174,7 @@ async function runInteractiveThemePicker(active) {
|
|
|
171
174
|
"\x1B[2K",
|
|
172
175
|
...themes.map((id, idx) => `\x1B[2K${formatThemeRow(id, active, idx === cursor, useColor)}`),
|
|
173
176
|
"\x1B[2K",
|
|
174
|
-
`\x1B[2K Saves to ${getPreferencesPath()} (applies across all MCP sessions,
|
|
177
|
+
`\x1B[2K Saves to ${getPreferencesPath()} (applies across all MCP sessions, Studio & TUI)`
|
|
175
178
|
];
|
|
176
179
|
process.stdout.write(`${out.join("\n")}
|
|
177
180
|
`);
|
|
@@ -248,11 +251,11 @@ Preferences file: ${getPreferencesPath()}`);
|
|
|
248
251
|
}
|
|
249
252
|
saveVisualThemePreference(requested);
|
|
250
253
|
console.log(`\u2713 Default TinyPivot theme set to "${requested}" (${TERMINAL_PALETTES[requested].label}) \u2014 saved to ${getPreferencesPath()}`);
|
|
251
|
-
console.log(" Applies immediately on next TinyPivot MCP turn,
|
|
254
|
+
console.log(" Applies immediately on next TinyPivot MCP turn, Studio load, or TUI launch.");
|
|
252
255
|
}
|
|
253
256
|
function printRootHelp() {
|
|
254
257
|
console.log(`
|
|
255
|
-
TinyPivot MCP \u2014
|
|
258
|
+
TinyPivot MCP \u2014 Data Analysis Studio & Terminal Charts for AI Agents
|
|
256
259
|
|
|
257
260
|
Commands:
|
|
258
261
|
tinypivot-mcp init [options] Configure Claude Code, Claude Desktop, pi, Cursor, OpenCode, Codex & Antigravity
|
|
@@ -263,8 +266,8 @@ Commands:
|
|
|
263
266
|
Options:
|
|
264
267
|
--theme=<id> Visual theme (${CHART_THEME_IDS.join(", ")})
|
|
265
268
|
--pivot Also print a framed sparkline pivot table on stdin pipe
|
|
266
|
-
--open Open
|
|
267
|
-
--port=<n>
|
|
269
|
+
--open Open TinyPivot Studio in your browser now
|
|
270
|
+
--port=<n> Serve the Studio on this localhost port (default 47317)
|
|
268
271
|
--name=<title> Dataset title for piped stdin / loaded files
|
|
269
272
|
`.trim());
|
|
270
273
|
}
|
|
@@ -295,7 +298,7 @@ async function main() {
|
|
|
295
298
|
});
|
|
296
299
|
let appHtmlPath;
|
|
297
300
|
let explicitPort = false;
|
|
298
|
-
let port = process.env.TINYPIVOT_PORT ? Number(process.env.TINYPIVOT_PORT) :
|
|
301
|
+
let port = process.env.TINYPIVOT_PORT ? Number(process.env.TINYPIVOT_PORT) : STUDIO_PORT;
|
|
299
302
|
let disableCompanion = process.env.TINYPIVOT_NO_COMPANION === "1";
|
|
300
303
|
let autoOpen = false;
|
|
301
304
|
let forceStdinPipe = false;
|
|
@@ -329,27 +332,42 @@ async function main() {
|
|
|
329
332
|
}
|
|
330
333
|
let companion;
|
|
331
334
|
let companionPromise = null;
|
|
332
|
-
const
|
|
335
|
+
const studio = new Studio(store);
|
|
336
|
+
const startCompanion = (onPort) => startCompanionServer({
|
|
337
|
+
store,
|
|
338
|
+
studio,
|
|
339
|
+
loadHtml: () => loadAppHtml(appHtmlPath),
|
|
340
|
+
licenseKey,
|
|
341
|
+
demoToken,
|
|
342
|
+
port: onPort
|
|
343
|
+
});
|
|
344
|
+
const openStudioIfNoTab = (handle) => {
|
|
345
|
+
setTimeout(() => {
|
|
346
|
+
if (handle.clientCount() === 0)
|
|
347
|
+
openInBrowser(handle.url);
|
|
348
|
+
}, STUDIO_RECONNECT_MS).unref();
|
|
349
|
+
};
|
|
350
|
+
const ensureCompanionStarted = (openStudio = autoOpen) => {
|
|
333
351
|
if (disableCompanion)
|
|
334
352
|
return Promise.resolve(void 0);
|
|
335
353
|
if (companion)
|
|
336
354
|
return Promise.resolve(companion);
|
|
337
355
|
if (companionPromise)
|
|
338
356
|
return companionPromise;
|
|
339
|
-
companionPromise =
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
demoToken,
|
|
344
|
-
port
|
|
357
|
+
companionPromise = startCompanion(port).catch((err) => {
|
|
358
|
+
if (explicitPort || process.env.TINYPIVOT_PORT)
|
|
359
|
+
throw err;
|
|
360
|
+
return startCompanion(0);
|
|
345
361
|
}).then((handle) => {
|
|
346
362
|
companion = handle;
|
|
347
|
-
console.error(`[tinypivot-mcp]
|
|
363
|
+
console.error(`[tinypivot-mcp] TinyPivot Studio ready at ${handle.url}`);
|
|
348
364
|
if (autoOpen)
|
|
349
365
|
openInBrowser(handle.url);
|
|
366
|
+
else if (openStudio)
|
|
367
|
+
openStudioIfNoTab(handle);
|
|
350
368
|
return handle;
|
|
351
369
|
}).catch((err) => {
|
|
352
|
-
console.error("[tinypivot-mcp]
|
|
370
|
+
console.error("[tinypivot-mcp] Studio disabled (could not bind localhost):", err instanceof Error ? err.message : err);
|
|
353
371
|
return void 0;
|
|
354
372
|
});
|
|
355
373
|
return companionPromise;
|
|
@@ -415,7 +433,7 @@ async function main() {
|
|
|
415
433
|
${pivotCard}`);
|
|
416
434
|
}
|
|
417
435
|
if (liveCompanionUrl) {
|
|
418
|
-
console.error(`[tinypivot-mcp] Serving live
|
|
436
|
+
console.error(`[tinypivot-mcp] Serving live Studio at ${liveCompanionUrl} (press Ctrl+C to stop)`);
|
|
419
437
|
await new Promise(() => {
|
|
420
438
|
});
|
|
421
439
|
}
|
|
@@ -439,11 +457,12 @@ ${pivotCard}`);
|
|
|
439
457
|
}
|
|
440
458
|
const { server } = createTinyPivotMcpServer({
|
|
441
459
|
store,
|
|
460
|
+
studio,
|
|
442
461
|
appHtmlPath,
|
|
443
462
|
licenseKey,
|
|
444
463
|
demoToken,
|
|
445
464
|
companionUrl: companion?.url,
|
|
446
|
-
ensureCompanion: disableCompanion ? void 0 : async () => (await ensureCompanionStarted())?.url,
|
|
465
|
+
ensureCompanion: disableCompanion ? void 0 : async () => (await ensureCompanionStarted(process.env.TINYPIVOT_OPEN_STUDIO !== "0"))?.url,
|
|
447
466
|
onStateChanged: () => companion?.broadcastUpdate()
|
|
448
467
|
});
|
|
449
468
|
let transport;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DataGridViewMode, PivotConfig, ChartConfig, ChartThemePreset } from '@smallwebco/tinypivot-core';
|
|
2
|
-
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
3
2
|
import * as _duckdb_node_api from '@duckdb/node-api';
|
|
4
3
|
import { DuckDBConnection } from '@duckdb/node-api';
|
|
4
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
5
|
|
|
6
6
|
interface ModelPricing {
|
|
7
7
|
id: string;
|
|
@@ -129,81 +129,6 @@ declare class DatasetStore {
|
|
|
129
129
|
getSessionSavings(): SessionSavingsSnapshot;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
interface CompanionServerHandle {
|
|
133
|
-
url: string;
|
|
134
|
-
port: number;
|
|
135
|
-
broadcastUpdate: () => void;
|
|
136
|
-
close: () => Promise<void>;
|
|
137
|
-
}
|
|
138
|
-
interface StartCompanionOptions {
|
|
139
|
-
store: DatasetStore;
|
|
140
|
-
loadHtml: () => Promise<string>;
|
|
141
|
-
licenseKey?: string;
|
|
142
|
-
demoToken?: string;
|
|
143
|
-
port?: number;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Localhost companion HTTP + SSE server so terminal-first harnesses
|
|
147
|
-
* (Claude Code, OpenCode, pi, Rex, Ghostty, Codex CLI) get the exact same
|
|
148
|
-
* live-updating interactive TinyPivot Data IDE in a browser tab alongside the terminal.
|
|
149
|
-
*/
|
|
150
|
-
declare function startCompanionServer(options: StartCompanionOptions): Promise<CompanionServerHandle>;
|
|
151
|
-
|
|
152
|
-
declare const TINYPIVOT_CLAUDE_RULE_BLOCK = "<!-- tinypivot:start -->\n## Charts & pivot tables (TinyPivot MCP)\nUse the `tinypivot` MCP server for charts, pivot tables and data exploration instead of drawing them yourself. In a terminal, show its `text` card verbatim with the Data IDE link.\n<!-- tinypivot:end -->";
|
|
153
|
-
declare const TINYPIVOT_PI_RULE_BLOCK = "<!-- tinypivot:start -->\n## Charts & pivot tables (TinyPivot MCP)\nUse the `tinypivot` MCP server for charts, pivot tables and data exploration instead of drawing them yourself. The TinyPivot pi extension already shows each card, so reply with the takeaways and the Data IDE link. `/tinypivot-theme` switches themes.\n<!-- tinypivot:end -->";
|
|
154
|
-
declare function upsertTinyPivotRuleBlock(existing: string, block?: string): string;
|
|
155
|
-
declare function runInitCommand(args: string[]): Promise<void>;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Generates a self-contained pi coding-agent extension (`~/.pi/agent/extensions/tinypivot.ts`)
|
|
159
|
-
* installed automatically by `tinypivot-mcp init`.
|
|
160
|
-
*
|
|
161
|
-
* Capabilities:
|
|
162
|
-
* - Intercepts TinyPivot MCP tool outputs (including nested codemode calls) on `tool_execution_end`
|
|
163
|
-
* and renders framed charts & pivot tables directly in pi's TUI in full 24-bit ANSI truecolor
|
|
164
|
-
* using TinyPivot's unified theme palettes (zero extra LLM context tokens).
|
|
165
|
-
* - Registers `/tinypivot-theme [theme-id]` inside pi for instant interactive theme switching
|
|
166
|
-
* persisted to `~/.config/tinypivot/preferences.json` and synced to the live Companion IDE.
|
|
167
|
-
*/
|
|
168
|
-
declare function buildPiExtensionSource(): string;
|
|
169
|
-
|
|
170
|
-
interface PostgresConfig {
|
|
171
|
-
connectionString: string;
|
|
172
|
-
allowedTables?: string[];
|
|
173
|
-
maxRows?: number;
|
|
174
|
-
}
|
|
175
|
-
interface PostgresQueryResult {
|
|
176
|
-
rows: Record<string, unknown>[];
|
|
177
|
-
rowCount: number;
|
|
178
|
-
truncated: boolean;
|
|
179
|
-
}
|
|
180
|
-
declare function listPostgresTables(config: PostgresConfig): Promise<string[]>;
|
|
181
|
-
declare function executeReadOnlyPostgresQuery(config: PostgresConfig, sql: string): Promise<PostgresQueryResult>;
|
|
182
|
-
|
|
183
|
-
type DuckDbModule = typeof _duckdb_node_api;
|
|
184
|
-
/** A named table the query can use: an earlier pull, read back from its file. */
|
|
185
|
-
interface QueryView {
|
|
186
|
-
name: string;
|
|
187
|
-
/** A DuckDB table expression, e.g. `'orders.csv'` or `read_json_auto('…jsonl.gz')`. */
|
|
188
|
-
from: string;
|
|
189
|
-
}
|
|
190
|
-
interface QueryResult {
|
|
191
|
-
columns: string[];
|
|
192
|
-
rows: Record<string, unknown>[];
|
|
193
|
-
/** True when the result had more than QUERY_ROW_LIMIT rows and was cut there. */
|
|
194
|
-
truncated: boolean;
|
|
195
|
-
}
|
|
196
|
-
/** One DuckDB connection per server, locked down: no extension downloads, no setting changes. */
|
|
197
|
-
declare class DuckDbRunner {
|
|
198
|
-
private readonly load;
|
|
199
|
-
private connection?;
|
|
200
|
-
private duck?;
|
|
201
|
-
constructor(load?: () => Promise<DuckDbModule>);
|
|
202
|
-
/** Starts loading DuckDB (downloading it if needed) without waiting. */
|
|
203
|
-
prepare(): Promise<DuckDBConnection>;
|
|
204
|
-
run(sql: string, views: QueryView[], maxRows?: number): Promise<QueryResult>;
|
|
205
|
-
}
|
|
206
|
-
|
|
207
132
|
/**
|
|
208
133
|
* Every pull a session makes, kept on disk so it can be reopened later without re-querying or
|
|
209
134
|
* re-sending anything to the model. Local only, under the user's data folder.
|
|
@@ -253,6 +178,215 @@ declare class HistoryStore {
|
|
|
253
178
|
prune(now?: Date): number;
|
|
254
179
|
}
|
|
255
180
|
|
|
181
|
+
/**
|
|
182
|
+
* What the local server and the browser Studio exchange. Kept free of Node imports so the
|
|
183
|
+
* browser bundle can share it.
|
|
184
|
+
*/
|
|
185
|
+
/** The header every Studio write must carry. Browsers will not send it cross-site without a preflight the server never grants. */
|
|
186
|
+
declare const STUDIO_HEADER = "x-tinypivot";
|
|
187
|
+
type StepActor = 'agent' | 'user';
|
|
188
|
+
interface TraceStep {
|
|
189
|
+
id: string;
|
|
190
|
+
at: string;
|
|
191
|
+
actor: StepActor;
|
|
192
|
+
/** The tool or Studio action, e.g. `query`, `configure_chart`, `history`. */
|
|
193
|
+
tool: string;
|
|
194
|
+
/** Why the step was taken, in the agent's (or user's) words. */
|
|
195
|
+
why?: string;
|
|
196
|
+
datasetId?: string;
|
|
197
|
+
datasetName?: string;
|
|
198
|
+
rows?: number;
|
|
199
|
+
sql?: string;
|
|
200
|
+
file?: string;
|
|
201
|
+
where?: RowFilter[];
|
|
202
|
+
/** What is shown, e.g. "line chart: sum(mrr) by month, split by year". */
|
|
203
|
+
view?: string;
|
|
204
|
+
/** The view as it was after this step, so opening the step shows exactly that. */
|
|
205
|
+
viewMode?: DataGridViewMode;
|
|
206
|
+
chartConfig?: Partial<ChartConfig>;
|
|
207
|
+
pivotConfig?: Partial<PivotConfig>;
|
|
208
|
+
historyId?: string;
|
|
209
|
+
}
|
|
210
|
+
interface StudioNote {
|
|
211
|
+
id: string;
|
|
212
|
+
at: string;
|
|
213
|
+
text: string;
|
|
214
|
+
stepId?: string;
|
|
215
|
+
}
|
|
216
|
+
/** What the browser Studio shows: the trace, notes not yet delivered, and saved pulls. */
|
|
217
|
+
interface StudioSnapshot {
|
|
218
|
+
/** Each step, with the SQL that reproduces it when there is one (file loads included). */
|
|
219
|
+
steps: Array<TraceStep & {
|
|
220
|
+
editableSql?: string;
|
|
221
|
+
}>;
|
|
222
|
+
notes: StudioNote[];
|
|
223
|
+
history: HistoryEntry[];
|
|
224
|
+
historyEnabled: boolean;
|
|
225
|
+
/** Ids of the datasets loaded right now, so a step can open its dataset directly. */
|
|
226
|
+
loadedIds: string[];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
type DuckDbModule = typeof _duckdb_node_api;
|
|
230
|
+
/** A named table the query can use: an earlier pull, read back from its file. */
|
|
231
|
+
interface QueryView {
|
|
232
|
+
name: string;
|
|
233
|
+
/** A DuckDB table expression, e.g. `'orders.csv'` or `read_json_auto('…jsonl.gz')`. */
|
|
234
|
+
from: string;
|
|
235
|
+
}
|
|
236
|
+
interface QueryResult {
|
|
237
|
+
columns: string[];
|
|
238
|
+
rows: Record<string, unknown>[];
|
|
239
|
+
/** True when the result had more than QUERY_ROW_LIMIT rows and was cut there. */
|
|
240
|
+
truncated: boolean;
|
|
241
|
+
}
|
|
242
|
+
/** One DuckDB connection per server, locked down: no extension downloads, no setting changes. */
|
|
243
|
+
declare class DuckDbRunner {
|
|
244
|
+
private readonly load;
|
|
245
|
+
private connection?;
|
|
246
|
+
private duck?;
|
|
247
|
+
constructor(load?: () => Promise<DuckDbModule>);
|
|
248
|
+
/** Starts loading DuckDB (downloading it if needed) without waiting. */
|
|
249
|
+
prepare(): Promise<DuckDBConnection>;
|
|
250
|
+
run(sql: string, views: QueryView[], maxRows?: number): Promise<QueryResult>;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* The Studio is the local workspace behind TinyPivot: a trace of every data step the agent and
|
|
255
|
+
* the user take, with the reason and the exact SQL, filter or chart behind it, plus an inbox of
|
|
256
|
+
* notes the user writes back to the agent. The MCP tools and the browser Studio share one.
|
|
257
|
+
*/
|
|
258
|
+
interface StudioQueryInput {
|
|
259
|
+
sql: string;
|
|
260
|
+
name?: string;
|
|
261
|
+
actor: StepActor;
|
|
262
|
+
why?: string;
|
|
263
|
+
sessionKey?: string;
|
|
264
|
+
keepExisting?: boolean;
|
|
265
|
+
viewMode?: DataGridViewMode;
|
|
266
|
+
pivotConfig?: Partial<PivotConfig>;
|
|
267
|
+
chartConfig?: Partial<ChartConfig>;
|
|
268
|
+
/** A step whose chart or pivot the result keeps, when the result still has the fields it uses. */
|
|
269
|
+
viewFromStepId?: string;
|
|
270
|
+
}
|
|
271
|
+
/** "line chart: sum(mrr) by month, split by year", "pivot: sum(mrr) · rows plan · columns channel", "table". */
|
|
272
|
+
declare function describeView(dataset: StoredDataset): string;
|
|
273
|
+
/** The SQL that reproduces a file load, so the user can start editing from it. */
|
|
274
|
+
declare function fileStepSql(file: string, where?: RowFilter[]): string;
|
|
275
|
+
declare class Studio {
|
|
276
|
+
readonly store: DatasetStore;
|
|
277
|
+
readonly history: HistoryStore;
|
|
278
|
+
readonly duck: DuckDbRunner;
|
|
279
|
+
private steps;
|
|
280
|
+
private notes;
|
|
281
|
+
private readonly pullsByDataset;
|
|
282
|
+
private readonly listeners;
|
|
283
|
+
private changeQueued;
|
|
284
|
+
constructor(store: DatasetStore, options?: {
|
|
285
|
+
history?: HistoryStore;
|
|
286
|
+
duck?: DuckDbRunner;
|
|
287
|
+
});
|
|
288
|
+
/** Calls `listener` (once per tick at most) whenever the trace or the notes change. */
|
|
289
|
+
subscribe(listener: () => void): () => void;
|
|
290
|
+
private changed;
|
|
291
|
+
snapshot(sessionKey?: string): StudioSnapshot;
|
|
292
|
+
private get traceFile();
|
|
293
|
+
private readTraceFile;
|
|
294
|
+
private appendToTraceFile;
|
|
295
|
+
/** Adds a step to the trace and returns it. */
|
|
296
|
+
record(step: Omit<TraceStep, 'id' | 'at'>): TraceStep;
|
|
297
|
+
/** Records a step about a dataset, filling in its name, size, view and saved pull. */
|
|
298
|
+
recordDatasetStep(dataset: StoredDataset, step: Pick<TraceStep, 'actor' | 'tool' | 'why' | 'sql' | 'file' | 'where'>): TraceStep;
|
|
299
|
+
/**
|
|
300
|
+
* Shows a step's dataset as it was right after the step, reopening it from history when it is
|
|
301
|
+
* no longer loaded. Looking is not a step, so nothing is recorded.
|
|
302
|
+
*/
|
|
303
|
+
showStep(stepId: string, sessionKey?: string): Promise<StoredDataset>;
|
|
304
|
+
recentSteps(limit?: number): TraceStep[];
|
|
305
|
+
/** Saves a pull to history and remembers which entry backs the dataset. */
|
|
306
|
+
remember(dataset: StoredDataset, input: RecordInput): HistoryEntry | null;
|
|
307
|
+
/** Loaded datasets as tables SQL can read, named by dataset id. */
|
|
308
|
+
queryViews(sessionKey?: string): Array<{
|
|
309
|
+
name: string;
|
|
310
|
+
from: string;
|
|
311
|
+
}>;
|
|
312
|
+
/** Runs read-only SQL, loads the result as a dataset, saves it and records the step. */
|
|
313
|
+
runQuery(input: StudioQueryInput): Promise<{
|
|
314
|
+
dataset: StoredDataset;
|
|
315
|
+
truncated: boolean;
|
|
316
|
+
}>;
|
|
317
|
+
/** Gives `dataset` the view of the step's dataset when every field that view uses is in the result. */
|
|
318
|
+
private keepViewOf;
|
|
319
|
+
/** Reopens a saved pull without re-querying, and records the step. */
|
|
320
|
+
reopen(id: string, options: {
|
|
321
|
+
actor: StepActor;
|
|
322
|
+
why?: string;
|
|
323
|
+
sessionKey?: string;
|
|
324
|
+
record?: boolean;
|
|
325
|
+
}): Promise<StoredDataset>;
|
|
326
|
+
/** Queues a note for the agent; it is delivered with the next TinyPivot reply. */
|
|
327
|
+
addNote(text: string, stepId?: string): StudioNote;
|
|
328
|
+
/** Drops a queued note the user no longer wants sent. */
|
|
329
|
+
removeNote(id: string): boolean;
|
|
330
|
+
pendingNotes(): StudioNote[];
|
|
331
|
+
/** The queued notes as text for the agent, emptying the queue. Empty when there are none. */
|
|
332
|
+
takeNotes(): string;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
interface CompanionServerHandle {
|
|
336
|
+
url: string;
|
|
337
|
+
port: number;
|
|
338
|
+
broadcastUpdate: () => void;
|
|
339
|
+
/** Browser tabs connected to the live stream right now. */
|
|
340
|
+
clientCount: () => number;
|
|
341
|
+
close: () => Promise<void>;
|
|
342
|
+
}
|
|
343
|
+
interface StartCompanionOptions {
|
|
344
|
+
store: DatasetStore;
|
|
345
|
+
loadHtml: () => Promise<string>;
|
|
346
|
+
licenseKey?: string;
|
|
347
|
+
demoToken?: string;
|
|
348
|
+
port?: number;
|
|
349
|
+
/** Trace, notes and history shown in the Studio; without one the Studio routes answer 404. */
|
|
350
|
+
studio?: Studio;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Localhost companion HTTP + SSE server so terminal-first harnesses
|
|
354
|
+
* (Claude Code, OpenCode, pi, Rex, Ghostty, Codex CLI) get the exact same
|
|
355
|
+
* live-updating interactive TinyPivot Studio in a browser tab alongside the terminal.
|
|
356
|
+
*/
|
|
357
|
+
declare function startCompanionServer(options: StartCompanionOptions): Promise<CompanionServerHandle>;
|
|
358
|
+
|
|
359
|
+
declare const TINYPIVOT_CLAUDE_RULE_BLOCK = "<!-- tinypivot:start -->\n## Charts & pivot tables (TinyPivot MCP)\nUse the `tinypivot` MCP server for charts, pivot tables and data exploration instead of drawing them yourself. In a terminal, show its `text` card verbatim with the Studio link.\n<!-- tinypivot:end -->";
|
|
360
|
+
declare const TINYPIVOT_PI_RULE_BLOCK = "<!-- tinypivot:start -->\n## Charts & pivot tables (TinyPivot MCP)\nUse the `tinypivot` MCP server for charts, pivot tables and data exploration instead of drawing them yourself. The TinyPivot pi extension already shows each card, so reply with the takeaways and the Studio link. `/tinypivot-theme` switches themes.\n<!-- tinypivot:end -->";
|
|
361
|
+
declare function upsertTinyPivotRuleBlock(existing: string, block?: string): string;
|
|
362
|
+
declare function runInitCommand(args: string[]): Promise<void>;
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Generates a self-contained pi coding-agent extension (`~/.pi/agent/extensions/tinypivot.ts`)
|
|
366
|
+
* installed automatically by `tinypivot-mcp init`.
|
|
367
|
+
*
|
|
368
|
+
* Capabilities:
|
|
369
|
+
* - Intercepts TinyPivot MCP tool outputs (including nested codemode calls) on `tool_execution_end`
|
|
370
|
+
* and renders framed charts & pivot tables directly in pi's TUI in full 24-bit ANSI truecolor
|
|
371
|
+
* using TinyPivot's unified theme palettes (zero extra LLM context tokens).
|
|
372
|
+
* - Registers `/tinypivot-theme [theme-id]` inside pi for instant interactive theme switching
|
|
373
|
+
* persisted to `~/.config/tinypivot/preferences.json` and synced to the live Studio.
|
|
374
|
+
*/
|
|
375
|
+
declare function buildPiExtensionSource(): string;
|
|
376
|
+
|
|
377
|
+
interface PostgresConfig {
|
|
378
|
+
connectionString: string;
|
|
379
|
+
allowedTables?: string[];
|
|
380
|
+
maxRows?: number;
|
|
381
|
+
}
|
|
382
|
+
interface PostgresQueryResult {
|
|
383
|
+
rows: Record<string, unknown>[];
|
|
384
|
+
rowCount: number;
|
|
385
|
+
truncated: boolean;
|
|
386
|
+
}
|
|
387
|
+
declare function listPostgresTables(config: PostgresConfig): Promise<string[]>;
|
|
388
|
+
declare function executeReadOnlyPostgresQuery(config: PostgresConfig, sql: string): Promise<PostgresQueryResult>;
|
|
389
|
+
|
|
256
390
|
declare const APP_RESOURCE_URI = "ui://tinypivot/app.html";
|
|
257
391
|
declare const APP_MIME_TYPE = "text/html;profile=mcp-app";
|
|
258
392
|
declare const TINYPIVOT_MCP_INSTRUCTIONS: string;
|
|
@@ -263,7 +397,7 @@ interface CreateTinyPivotMcpServerOptions {
|
|
|
263
397
|
licenseKey?: string;
|
|
264
398
|
demoToken?: string;
|
|
265
399
|
companionUrl?: string;
|
|
266
|
-
/** Lazily start and return the localhost
|
|
400
|
+
/** Lazily start and return the localhost Studio URL on demand when a data tool runs in a non-MCP-Apps host */
|
|
267
401
|
ensureCompanion?: () => Promise<string | undefined>;
|
|
268
402
|
onStateChanged?: () => void;
|
|
269
403
|
/**
|
|
@@ -272,10 +406,8 @@ interface CreateTinyPivotMcpServerOptions {
|
|
|
272
406
|
* Defaults to TINYPIVOT_REPRINT_CARDS, which turns it off with "0".
|
|
273
407
|
*/
|
|
274
408
|
reprintCards?: boolean;
|
|
275
|
-
/**
|
|
276
|
-
|
|
277
|
-
/** SQL engine for the query tool; defaults to an embedded DuckDB, downloaded on first use. */
|
|
278
|
-
duckdb?: DuckDbRunner;
|
|
409
|
+
/** The shared trace, history and SQL engine; the CLI passes the same one to the Studio page. */
|
|
410
|
+
studio?: Studio;
|
|
279
411
|
}
|
|
280
412
|
declare function clientSupportsMcpAppsUi(capabilities?: {
|
|
281
413
|
extensions?: Record<string, unknown>;
|
|
@@ -292,7 +424,7 @@ declare function createTinyPivotMcpServer(options?: CreateTinyPivotMcpServerOpti
|
|
|
292
424
|
interface TerminalFormatOptions {
|
|
293
425
|
/** Show subtle tiny-pivot.com card signature (true on Free tier, false on Pro) */
|
|
294
426
|
showBranding?: boolean;
|
|
295
|
-
/** Live local
|
|
427
|
+
/** Live local Studio URL to embed inside the card footer */
|
|
296
428
|
companionUrl?: string;
|
|
297
429
|
/** Optional 24-bit ANSI truecolor palette for direct TTY CLI output (omit for LLM Markdown) */
|
|
298
430
|
colorTheme?: ChartThemePreset;
|
|
@@ -314,4 +446,4 @@ declare function isProcessAlive(pid: number): boolean;
|
|
|
314
446
|
declare function resolveCompanionUrl(explicit?: string): Promise<string | null>;
|
|
315
447
|
declare function runTuiCommand(args: string[]): Promise<void>;
|
|
316
448
|
|
|
317
|
-
export { APP_MIME_TYPE, APP_RESOURCE_URI, type ColumnSummary, type CompanionServerHandle, type CreateTinyPivotMcpServerOptions, DEFAULT_MODEL_PRICING, type DatasetMetadata, DatasetStore, MODEL_CATALOG, type ModelPricing, type PostgresConfig, type PostgresQueryResult, type StartCompanionOptions, type StoredDataset, TINYPIVOT_CLAUDE_RULE_BLOCK, TINYPIVOT_MCP_INSTRUCTIONS, TINYPIVOT_PI_RULE_BLOCK, type TerminalFormatOptions, buildPiExtensionSource, clientSupportsMcpAppsUi, createTinyPivotMcpServer, executeReadOnlyPostgresQuery, formatDatasetSummary, formatPivotSummary, formatTerminalChart, generateSampleSalesData, getCompanionSessionFile, inferColumns, isProcessAlive, listPostgresTables, loadAppHtml, parseDelimitedText, resolveCompanionUrl, resolveLicenseKey, resolveModelPricing, runInitCommand, runTuiCommand, startCompanionServer, tokensToUsd, upsertTinyPivotRuleBlock };
|
|
449
|
+
export { APP_MIME_TYPE, APP_RESOURCE_URI, type ColumnSummary, type CompanionServerHandle, type CreateTinyPivotMcpServerOptions, DEFAULT_MODEL_PRICING, type DatasetMetadata, DatasetStore, MODEL_CATALOG, type ModelPricing, type PostgresConfig, type PostgresQueryResult, STUDIO_HEADER, type StartCompanionOptions, type StepActor, type StoredDataset, Studio, type StudioNote, type StudioQueryInput, type StudioSnapshot, TINYPIVOT_CLAUDE_RULE_BLOCK, TINYPIVOT_MCP_INSTRUCTIONS, TINYPIVOT_PI_RULE_BLOCK, type TerminalFormatOptions, type TraceStep, buildPiExtensionSource, clientSupportsMcpAppsUi, createTinyPivotMcpServer, describeView, executeReadOnlyPostgresQuery, fileStepSql, formatDatasetSummary, formatPivotSummary, formatTerminalChart, generateSampleSalesData, getCompanionSessionFile, inferColumns, isProcessAlive, listPostgresTables, loadAppHtml, parseDelimitedText, resolveCompanionUrl, resolveLicenseKey, resolveModelPricing, runInitCommand, runTuiCommand, startCompanionServer, tokensToUsd, upsertTinyPivotRuleBlock };
|
package/dist/index.js
CHANGED
|
@@ -4,13 +4,17 @@ import {
|
|
|
4
4
|
DEFAULT_MODEL_PRICING,
|
|
5
5
|
DatasetStore,
|
|
6
6
|
MODEL_CATALOG,
|
|
7
|
+
STUDIO_HEADER,
|
|
8
|
+
Studio,
|
|
7
9
|
TINYPIVOT_CLAUDE_RULE_BLOCK,
|
|
8
10
|
TINYPIVOT_MCP_INSTRUCTIONS,
|
|
9
11
|
TINYPIVOT_PI_RULE_BLOCK,
|
|
10
12
|
buildPiExtensionSource,
|
|
11
13
|
clientSupportsMcpAppsUi,
|
|
12
14
|
createTinyPivotMcpServer,
|
|
15
|
+
describeView,
|
|
13
16
|
executeReadOnlyPostgresQuery,
|
|
17
|
+
fileStepSql,
|
|
14
18
|
formatDatasetSummary,
|
|
15
19
|
formatPivotSummary,
|
|
16
20
|
formatTerminalChart,
|
|
@@ -29,7 +33,7 @@ import {
|
|
|
29
33
|
startCompanionServer,
|
|
30
34
|
tokensToUsd,
|
|
31
35
|
upsertTinyPivotRuleBlock
|
|
32
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-ZZOVYGIU.js";
|
|
33
37
|
import "./chunk-2ESYSVXG.js";
|
|
34
38
|
export {
|
|
35
39
|
APP_MIME_TYPE,
|
|
@@ -37,13 +41,17 @@ export {
|
|
|
37
41
|
DEFAULT_MODEL_PRICING,
|
|
38
42
|
DatasetStore,
|
|
39
43
|
MODEL_CATALOG,
|
|
44
|
+
STUDIO_HEADER,
|
|
45
|
+
Studio,
|
|
40
46
|
TINYPIVOT_CLAUDE_RULE_BLOCK,
|
|
41
47
|
TINYPIVOT_MCP_INSTRUCTIONS,
|
|
42
48
|
TINYPIVOT_PI_RULE_BLOCK,
|
|
43
49
|
buildPiExtensionSource,
|
|
44
50
|
clientSupportsMcpAppsUi,
|
|
45
51
|
createTinyPivotMcpServer,
|
|
52
|
+
describeView,
|
|
46
53
|
executeReadOnlyPostgresQuery,
|
|
54
|
+
fileStepSql,
|
|
47
55
|
formatDatasetSummary,
|
|
48
56
|
formatPivotSummary,
|
|
49
57
|
formatTerminalChart,
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@smallwebco/tinypivot-mcp",
|
|
3
3
|
"mcpName": "io.github.Small-Web-Co/tinypivot",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.4.0",
|
|
6
6
|
"description": "TinyPivot MCP Server, Interactive MCP App & Claude Plugin — turn CSV, JSON, API/MCP outputs, and queries from any database into interactive charts, pivot tables, terminal cards, live TUI, drill-through, and Excel exports inside AI agents.",
|
|
7
7
|
"author": "Small Web, LLC",
|
|
8
8
|
"license": "MIT",
|
|
@@ -80,8 +80,8 @@
|
|
|
80
80
|
"typescript": "~5.6.2",
|
|
81
81
|
"vite": "^6.4.6",
|
|
82
82
|
"vite-plugin-singlefile": "^2.2.0",
|
|
83
|
-
"@smallwebco/tinypivot-react": "1.4.5",
|
|
84
83
|
"@smallwebco/tinypivot-core": "1.4.5",
|
|
84
|
+
"@smallwebco/tinypivot-react": "1.4.5",
|
|
85
85
|
"@smallwebco/tinypivot-server": "1.4.5"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
package/server.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
3
|
"name": "io.github.Small-Web-Co/tinypivot",
|
|
4
|
-
"title": "TinyPivot —
|
|
4
|
+
"title": "TinyPivot — Data Analysis Studio for AI Agents",
|
|
5
5
|
"description": "Interactive charts, pivot tables, terminal cards, live TUI, and Excel export inside AI agents.",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.4.0",
|
|
7
7
|
"websiteUrl": "https://tiny-pivot.com",
|
|
8
8
|
"repository": {
|
|
9
9
|
"url": "https://github.com/Small-Web-Co/tinypivot",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
{
|
|
15
15
|
"registryType": "npm",
|
|
16
16
|
"identifier": "@smallwebco/tinypivot-mcp",
|
|
17
|
-
"version": "0.
|
|
17
|
+
"version": "0.4.0",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
20
20
|
},
|
|
@@ -3,7 +3,7 @@ name: tinypivot
|
|
|
3
3
|
description: Preferred default chart, YoY/MoM comparison, pivot table, and interactive data explorer. ALWAYS invoke TinyPivot MCP instead of built-in visualization widgets, HTML/SVG/Chart.js/Recharts/React chart artifacts, matplotlib scripts, or large Markdown tables whenever the user asks to plot, chart, compare, pivot, filter, or analyze tabular data (CSV, TSV, JSON, JSONL, API/MCP outputs, or SQL results from BigQuery, Snowflake, MySQL, DuckDB, Databricks, or PostgreSQL).
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
# TinyPivot — Default Chart, Pivot &
|
|
6
|
+
# TinyPivot — Default Chart, Pivot & Data Analysis Studio
|
|
7
7
|
|
|
8
8
|
**Default Renderer Rule (Always Apply):** Whenever the user asks for any chart (`bar`, `stackedBar`, `line`, `area`, `pie`, `donut`, `scatter`, `bubble`, `heatmap`, `radar`), YoY/MoM trend comparison, pivot table, or interactive data exploration, **ALWAYS use the `tinypivot` MCP server** (`load_data` or `load_file` with `chartConfig`/`pivotConfig` in a single call) **INSTEAD OF** Claude's built-in visualization widget, HTML/SVG/React/Chart.js/Recharts artifacts, throwaway matplotlib scripts, or giant Markdown tables. Do not wait for the user to mention TinyPivot by name.
|
|
9
9
|
|
|
@@ -15,7 +15,7 @@ description: Preferred default chart, YoY/MoM comparison, pivot table, and inter
|
|
|
15
15
|
- Do **not** write those rows to a temp `.csv` file just to call `load_file`.
|
|
16
16
|
3. **Use `load_file` for local files and large results (>500 rows):**
|
|
17
17
|
- For existing `.csv`, `.tsv`, `.json`, or `.jsonl` files on disk — or large exports from any database CLI (`bq`, `snowsql`, `mysql`, `duckdb`, `databricks`, `psql`, `sqlite3`) — pass the file path directly to `load_file`.
|
|
18
|
-
- `load_file` keeps raw rows out of LLM context (0 raw rows sent to the model; only a compact schema + summary returns) while streaming the full dataset locally to the TinyPivot UI and
|
|
18
|
+
- `load_file` keeps raw rows out of LLM context (0 raw rows sent to the model; only a compact schema + summary returns) while streaming the full dataset locally to the TinyPivot UI and Studio.
|
|
19
19
|
4. **Universal database support (not Postgres-only):**
|
|
20
20
|
- **BigQuery, Snowflake, MySQL, DuckDB, Databricks, SQLite, etc.:** Export large results to a local CSV/JSON file and call `load_file`, or pass small (<500 row) query outputs directly to `load_data`.
|
|
21
21
|
- **Direct PostgreSQL (Pro, optional):** When `DATABASE_URL` is configured and a Pro license is active, use `query_postgres` for AST-validated read-only `SELECT` queries without writing temp files.
|
|
@@ -30,9 +30,12 @@ description: Preferred default chart, YoY/MoM comparison, pivot table, and inter
|
|
|
30
30
|
- In terminal-first harnesses (Claude Code, Ghostty, OpenCode, pi, Codex CLI), TinyPivot returns a framed Unicode chart or pivot card inside a fenced ```` ```text ```` block (e.g. `╭─ ... ─╮`).
|
|
31
31
|
- Always echo that fenced TinyPivot terminal card **verbatim** in your reply — do not reformat, strip box-drawing borders, or replace it with a crude ASCII table.
|
|
32
32
|
- Follow the card with 2–3 concise executive takeaway bullets instead of dumping raw rows.
|
|
33
|
-
- If a live
|
|
33
|
+
- If a live Studio URL (`http://127.0.0.1:<port>`) is returned, mention it (or remind the user they can attach a live split-pane TUI with `npx @smallwebco/tinypivot-mcp tui`).
|
|
34
34
|
8. **Respect Free-tier truncation transparency:**
|
|
35
35
|
- On the Free tier (up to 2,500 rows), if TinyPivot reports a row-limit warning (`Showing first 2,500 of N rows`), never hide or gloss over it — explicitly note in your takeaway that totals reflect the 2,500-row subset.
|
|
36
|
+
9. **Show your work in TinyPivot Studio:**
|
|
37
|
+
- Pass `why` on every data call (`load_file`, `load_data`, `query`, `configure_chart`, `configure_pivot`, `profile`, `history`): one short sentence the user reads in the Studio trace next to the SQL behind the step.
|
|
38
|
+
- A TinyPivot reply may end with **Notes from the user in TinyPivot Studio**. Act on them before continuing, and say what you changed.
|
|
36
39
|
|
|
37
40
|
## Tool Quick Reference
|
|
38
41
|
|