@smallwebco/tinypivot-mcp 0.3.0 → 0.5.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 +34 -6
- package/dist/app/index.html +78 -75
- package/dist/{chunk-AFGC2C4J.js → chunk-E6DYPT62.js} +933 -119
- package/dist/cli.js +36 -18
- package/dist/index.d.ts +304 -83
- package/dist/index.js +9 -1
- package/package.json +4 -4
- 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-E6DYPT62.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,41 @@ 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
|
-
licenseKey,
|
|
343
|
-
demoToken,
|
|
344
|
-
port
|
|
357
|
+
companionPromise = startCompanion(port).catch((err) => {
|
|
358
|
+
console.error(`[tinypivot-mcp] Port ${port} is taken (${err instanceof Error ? err.message : err}); using a free port for the Studio.`);
|
|
359
|
+
return startCompanion(0);
|
|
345
360
|
}).then((handle) => {
|
|
346
361
|
companion = handle;
|
|
347
|
-
console.error(`[tinypivot-mcp]
|
|
362
|
+
console.error(`[tinypivot-mcp] TinyPivot Studio ready at ${handle.url}`);
|
|
348
363
|
if (autoOpen)
|
|
349
364
|
openInBrowser(handle.url);
|
|
365
|
+
else if (openStudio)
|
|
366
|
+
openStudioIfNoTab(handle);
|
|
350
367
|
return handle;
|
|
351
368
|
}).catch((err) => {
|
|
352
|
-
console.error("[tinypivot-mcp]
|
|
369
|
+
console.error("[tinypivot-mcp] Studio disabled (could not bind localhost):", err instanceof Error ? err.message : err);
|
|
353
370
|
return void 0;
|
|
354
371
|
});
|
|
355
372
|
return companionPromise;
|
|
@@ -415,7 +432,7 @@ async function main() {
|
|
|
415
432
|
${pivotCard}`);
|
|
416
433
|
}
|
|
417
434
|
if (liveCompanionUrl) {
|
|
418
|
-
console.error(`[tinypivot-mcp] Serving live
|
|
435
|
+
console.error(`[tinypivot-mcp] Serving live Studio at ${liveCompanionUrl} (press Ctrl+C to stop)`);
|
|
419
436
|
await new Promise(() => {
|
|
420
437
|
});
|
|
421
438
|
}
|
|
@@ -439,11 +456,12 @@ ${pivotCard}`);
|
|
|
439
456
|
}
|
|
440
457
|
const { server } = createTinyPivotMcpServer({
|
|
441
458
|
store,
|
|
459
|
+
studio,
|
|
442
460
|
appHtmlPath,
|
|
443
461
|
licenseKey,
|
|
444
462
|
demoToken,
|
|
445
463
|
companionUrl: companion?.url,
|
|
446
|
-
ensureCompanion: disableCompanion ? void 0 : async () => (await ensureCompanionStarted())?.url,
|
|
464
|
+
ensureCompanion: disableCompanion ? void 0 : async () => (await ensureCompanionStarted(process.env.TINYPIVOT_OPEN_STUDIO !== "0"))?.url,
|
|
447
465
|
onStateChanged: () => companion?.broadcastUpdate()
|
|
448
466
|
});
|
|
449
467
|
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,302 @@ 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
|
+
/** Data the user sends along with a message: a selected row, a drilled-into slice, a view. */
|
|
211
|
+
interface NoteAttachment {
|
|
212
|
+
label: string;
|
|
213
|
+
text: string;
|
|
214
|
+
}
|
|
215
|
+
interface StudioNote {
|
|
216
|
+
id: string;
|
|
217
|
+
at: string;
|
|
218
|
+
text: string;
|
|
219
|
+
/** A note asks the agent to do something; a question is from the AI Analyst and expects an answer. */
|
|
220
|
+
kind: 'note' | 'question';
|
|
221
|
+
stepId?: string;
|
|
222
|
+
attachment?: NoteAttachment;
|
|
223
|
+
/** `live` when it went straight into the agent's conversation, `queued` when it waits for the next reply. */
|
|
224
|
+
delivery: 'live' | 'queued';
|
|
225
|
+
}
|
|
226
|
+
/** What the browser Studio shows: the trace, notes not yet delivered, and saved pulls. */
|
|
227
|
+
interface StudioSnapshot {
|
|
228
|
+
/** Each step, with the SQL that reproduces it when there is one (file loads included). */
|
|
229
|
+
steps: Array<TraceStep & {
|
|
230
|
+
editableSql?: string;
|
|
231
|
+
}>;
|
|
232
|
+
notes: StudioNote[];
|
|
233
|
+
history: HistoryEntry[];
|
|
234
|
+
historyEnabled: boolean;
|
|
235
|
+
/** Ids of the datasets loaded right now, so a step can open its dataset directly. */
|
|
236
|
+
loadedIds: string[];
|
|
237
|
+
/** The agent the Studio talks to, and the ways it reaches it live right now (empty when only queued). */
|
|
238
|
+
agent: {
|
|
239
|
+
name?: string;
|
|
240
|
+
live: string[];
|
|
241
|
+
busy: boolean;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* How the Studio reaches the user's own agent. Each harness offers something different:
|
|
247
|
+
* pi's extension and Claude Code's channels put a message into the live conversation, MCP sampling
|
|
248
|
+
* answers with the agent's model outside it, and every other agent gets Studio messages with its
|
|
249
|
+
* next TinyPivot reply. The bridge keeps whichever ways are connected and waits for answers.
|
|
250
|
+
*/
|
|
251
|
+
interface ChatTurn {
|
|
252
|
+
role: 'user' | 'assistant';
|
|
253
|
+
content: string;
|
|
254
|
+
}
|
|
255
|
+
interface AgentConnector {
|
|
256
|
+
/** Shown to the user, e.g. "pi" or "Claude Code channel". */
|
|
257
|
+
name: string;
|
|
258
|
+
/** Puts a message into the agent's conversation now. Returns false when it could not. */
|
|
259
|
+
push?: (note: StudioNote, text: string) => boolean;
|
|
260
|
+
/** Answers with the agent's own model, outside the conversation (MCP sampling). */
|
|
261
|
+
complete?: (turns: ChatTurn[]) => Promise<string>;
|
|
262
|
+
}
|
|
263
|
+
declare class AgentBridge {
|
|
264
|
+
private readonly onChange;
|
|
265
|
+
private readonly connectors;
|
|
266
|
+
private readonly waiters;
|
|
267
|
+
constructor(onChange: () => void);
|
|
268
|
+
/** Adds a way to reach the agent; the returned function removes it. */
|
|
269
|
+
connect(connector: AgentConnector): () => void;
|
|
270
|
+
/** Names of the ways that reach the agent right now. */
|
|
271
|
+
live(): string[];
|
|
272
|
+
/** Delivers into the conversation through the first connector that can. */
|
|
273
|
+
push(note: StudioNote, text: string): string | undefined;
|
|
274
|
+
completer(): AgentConnector['complete'];
|
|
275
|
+
/** Resolves with the agent's answer to `id`, or undefined after `ms`. */
|
|
276
|
+
waitForReply(id: string, ms: number): Promise<string | undefined>;
|
|
277
|
+
/** Hands an answer to whoever waits for `re`, or to the oldest waiter when `re` is unknown. */
|
|
278
|
+
answer(text: string, re?: string): boolean;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
type DuckDbModule = typeof _duckdb_node_api;
|
|
282
|
+
/** A named table the query can use: an earlier pull, read back from its file. */
|
|
283
|
+
interface QueryView {
|
|
284
|
+
name: string;
|
|
285
|
+
/** A DuckDB table expression, e.g. `'orders.csv'` or `read_json_auto('…jsonl.gz')`. */
|
|
286
|
+
from: string;
|
|
287
|
+
}
|
|
288
|
+
interface QueryResult {
|
|
289
|
+
columns: string[];
|
|
290
|
+
rows: Record<string, unknown>[];
|
|
291
|
+
/** True when the result had more than QUERY_ROW_LIMIT rows and was cut there. */
|
|
292
|
+
truncated: boolean;
|
|
293
|
+
}
|
|
294
|
+
/** One DuckDB connection per server, locked down: no extension downloads, no setting changes. */
|
|
295
|
+
declare class DuckDbRunner {
|
|
296
|
+
private readonly load;
|
|
297
|
+
private connection?;
|
|
298
|
+
private duck?;
|
|
299
|
+
constructor(load?: () => Promise<DuckDbModule>);
|
|
300
|
+
/** Starts loading DuckDB (downloading it if needed) without waiting. */
|
|
301
|
+
prepare(): Promise<DuckDBConnection>;
|
|
302
|
+
run(sql: string, views: QueryView[], maxRows?: number): Promise<QueryResult>;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The Studio is the local workspace behind TinyPivot: a trace of every data step the agent and
|
|
307
|
+
* the user take, with the reason and the exact SQL, filter or chart behind it, plus an inbox of
|
|
308
|
+
* notes the user writes back to the agent. The MCP tools and the browser Studio share one.
|
|
309
|
+
*/
|
|
310
|
+
interface StudioQueryInput {
|
|
311
|
+
sql: string;
|
|
312
|
+
name?: string;
|
|
313
|
+
actor: StepActor;
|
|
314
|
+
why?: string;
|
|
315
|
+
sessionKey?: string;
|
|
316
|
+
keepExisting?: boolean;
|
|
317
|
+
viewMode?: DataGridViewMode;
|
|
318
|
+
pivotConfig?: Partial<PivotConfig>;
|
|
319
|
+
chartConfig?: Partial<ChartConfig>;
|
|
320
|
+
/** A step whose chart or pivot the result keeps, when the result still has the fields it uses. */
|
|
321
|
+
viewFromStepId?: string;
|
|
322
|
+
}
|
|
323
|
+
/** "line chart: sum(mrr) by month, split by year", "pivot: sum(mrr) · rows plan · columns channel", "table". */
|
|
324
|
+
declare function describeView(dataset: StoredDataset): string;
|
|
325
|
+
/** The SQL that reproduces a file load, so the user can start editing from it. */
|
|
326
|
+
declare function fileStepSql(file: string, where?: RowFilter[]): string;
|
|
327
|
+
declare class Studio {
|
|
328
|
+
readonly store: DatasetStore;
|
|
329
|
+
readonly history: HistoryStore;
|
|
330
|
+
readonly duck: DuckDbRunner;
|
|
331
|
+
private steps;
|
|
332
|
+
private notes;
|
|
333
|
+
private readonly pullsByDataset;
|
|
334
|
+
private readonly listeners;
|
|
335
|
+
private changeQueued;
|
|
336
|
+
/** Ways to reach the user's agent: live channels, sampling, or nothing (queued notes). */
|
|
337
|
+
readonly agent: AgentBridge;
|
|
338
|
+
private agentName?;
|
|
339
|
+
private agentBusy;
|
|
340
|
+
constructor(store: DatasetStore, options?: {
|
|
341
|
+
history?: HistoryStore;
|
|
342
|
+
duck?: DuckDbRunner;
|
|
343
|
+
});
|
|
344
|
+
/** Calls `listener` (once per tick at most) whenever the trace or the notes change. */
|
|
345
|
+
subscribe(listener: () => void): () => void;
|
|
346
|
+
private changed;
|
|
347
|
+
snapshot(sessionKey?: string): StudioSnapshot;
|
|
348
|
+
/** Whether the agent is in the middle of a turn, as its extension reports it. */
|
|
349
|
+
setAgentBusy(busy: boolean): void;
|
|
350
|
+
/** The MCP client's name, e.g. `claude-code`, shown in the Studio. */
|
|
351
|
+
setAgentName(name: string | undefined): void;
|
|
352
|
+
private get traceFile();
|
|
353
|
+
private readTraceFile;
|
|
354
|
+
private appendToTraceFile;
|
|
355
|
+
/** Adds a step to the trace and returns it. */
|
|
356
|
+
record(step: Omit<TraceStep, 'id' | 'at'>): TraceStep;
|
|
357
|
+
/** Records a step about a dataset, filling in its name, size, view and saved pull. */
|
|
358
|
+
recordDatasetStep(dataset: StoredDataset, step: Pick<TraceStep, 'actor' | 'tool' | 'why' | 'sql' | 'file' | 'where'>): TraceStep;
|
|
359
|
+
/**
|
|
360
|
+
* Shows a step's dataset as it was right after the step, reopening it from history when it is
|
|
361
|
+
* no longer loaded. Looking is not a step, so nothing is recorded.
|
|
362
|
+
*/
|
|
363
|
+
showStep(stepId: string, sessionKey?: string): Promise<StoredDataset>;
|
|
364
|
+
recentSteps(limit?: number): TraceStep[];
|
|
365
|
+
/** Saves a pull to history and remembers which entry backs the dataset. */
|
|
366
|
+
remember(dataset: StoredDataset, input: RecordInput): HistoryEntry | null;
|
|
367
|
+
/** Loaded datasets as tables SQL can read, named by dataset id. */
|
|
368
|
+
queryViews(sessionKey?: string): Array<{
|
|
369
|
+
name: string;
|
|
370
|
+
from: string;
|
|
371
|
+
}>;
|
|
372
|
+
/** Runs read-only SQL, loads the result as a dataset, saves it and records the step. */
|
|
373
|
+
runQuery(input: StudioQueryInput): Promise<{
|
|
374
|
+
dataset: StoredDataset;
|
|
375
|
+
truncated: boolean;
|
|
376
|
+
}>;
|
|
377
|
+
/** Gives `dataset` the view of the step's dataset when every field that view uses is in the result. */
|
|
378
|
+
private keepViewOf;
|
|
379
|
+
/** Reopens a saved pull without re-querying, and records the step. */
|
|
380
|
+
reopen(id: string, options: {
|
|
381
|
+
actor: StepActor;
|
|
382
|
+
why?: string;
|
|
383
|
+
sessionKey?: string;
|
|
384
|
+
record?: boolean;
|
|
385
|
+
}): Promise<StoredDataset>;
|
|
386
|
+
/**
|
|
387
|
+
* Sends the user's message to the agent: straight into its conversation when a live connector
|
|
388
|
+
* takes it, otherwise queued for its next TinyPivot reply.
|
|
389
|
+
*/
|
|
390
|
+
addNote(text: string, options?: {
|
|
391
|
+
stepId?: string;
|
|
392
|
+
attachment?: NoteAttachment;
|
|
393
|
+
kind?: StudioNote['kind'];
|
|
394
|
+
}): StudioNote;
|
|
395
|
+
/**
|
|
396
|
+
* How a message reads to the agent: the text, the step it is about, and any attached data.
|
|
397
|
+
* `withSource` says where it came from, for messages that arrive on their own in the conversation.
|
|
398
|
+
*/
|
|
399
|
+
describeNote(note: StudioNote, { withSource }?: {
|
|
400
|
+
withSource?: boolean | undefined;
|
|
401
|
+
}): string;
|
|
402
|
+
/**
|
|
403
|
+
* Answers an AI Analyst question with the user's own agent: its model directly when the host
|
|
404
|
+
* offers sampling, otherwise through its conversation, waiting for the reply.
|
|
405
|
+
*/
|
|
406
|
+
ask(question: string, options?: {
|
|
407
|
+
turns?: ChatTurn[];
|
|
408
|
+
attachment?: NoteAttachment;
|
|
409
|
+
waitMs?: number;
|
|
410
|
+
}): Promise<string>;
|
|
411
|
+
/** The agent's answer to a Studio message: recorded in the trace and handed to whoever waits for it. */
|
|
412
|
+
reply(text: string, re?: string): TraceStep;
|
|
413
|
+
/** Drops a queued note the user no longer wants sent. */
|
|
414
|
+
removeNote(id: string): boolean;
|
|
415
|
+
pendingNotes(): StudioNote[];
|
|
416
|
+
/** The queued notes as text for the agent, emptying the queue. Empty when there are none. */
|
|
417
|
+
takeNotes(): string;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
interface CompanionServerHandle {
|
|
421
|
+
url: string;
|
|
422
|
+
port: number;
|
|
423
|
+
broadcastUpdate: () => void;
|
|
424
|
+
/** Browser tabs connected to the live stream right now. */
|
|
425
|
+
clientCount: () => number;
|
|
426
|
+
close: () => Promise<void>;
|
|
427
|
+
}
|
|
428
|
+
interface StartCompanionOptions {
|
|
429
|
+
store: DatasetStore;
|
|
430
|
+
loadHtml: () => Promise<string>;
|
|
431
|
+
licenseKey?: string;
|
|
432
|
+
demoToken?: string;
|
|
433
|
+
port?: number;
|
|
434
|
+
/** Trace, notes and history shown in the Studio; without one the Studio routes answer 404. */
|
|
435
|
+
studio?: Studio;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Localhost companion HTTP + SSE server so terminal-first harnesses
|
|
439
|
+
* (Claude Code, OpenCode, pi, Rex, Ghostty, Codex CLI) get the exact same
|
|
440
|
+
* live-updating interactive TinyPivot Studio in a browser tab alongside the terminal.
|
|
441
|
+
*/
|
|
442
|
+
declare function startCompanionServer(options: StartCompanionOptions): Promise<CompanionServerHandle>;
|
|
443
|
+
|
|
444
|
+
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 -->";
|
|
445
|
+
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 -->";
|
|
446
|
+
declare function upsertTinyPivotRuleBlock(existing: string, block?: string): string;
|
|
447
|
+
declare function runInitCommand(args: string[]): Promise<void>;
|
|
448
|
+
|
|
449
|
+
/**
|
|
450
|
+
* Generates a self-contained pi coding-agent extension (`~/.pi/agent/extensions/tinypivot.ts`)
|
|
451
|
+
* installed automatically by `tinypivot-mcp init`.
|
|
452
|
+
*
|
|
453
|
+
* Capabilities:
|
|
454
|
+
* - Intercepts TinyPivot MCP tool outputs (including nested codemode calls) on `tool_execution_end`
|
|
455
|
+
* and renders framed charts & pivot tables directly in pi's TUI in full 24-bit ANSI truecolor
|
|
456
|
+
* using TinyPivot's unified theme palettes (zero extra LLM context tokens).
|
|
457
|
+
* - Connects pi to TinyPivot Studio: Studio messages start a turn here, and the agent's answer
|
|
458
|
+
* goes back to the Studio.
|
|
459
|
+
* - Registers `/tinypivot-theme [theme-id]` inside pi for instant interactive theme switching
|
|
460
|
+
* persisted to `~/.config/tinypivot/preferences.json` and synced to the live Studio.
|
|
461
|
+
*/
|
|
462
|
+
declare function buildPiExtensionSource(): string;
|
|
463
|
+
|
|
464
|
+
interface PostgresConfig {
|
|
465
|
+
connectionString: string;
|
|
466
|
+
allowedTables?: string[];
|
|
467
|
+
maxRows?: number;
|
|
468
|
+
}
|
|
469
|
+
interface PostgresQueryResult {
|
|
470
|
+
rows: Record<string, unknown>[];
|
|
471
|
+
rowCount: number;
|
|
472
|
+
truncated: boolean;
|
|
473
|
+
}
|
|
474
|
+
declare function listPostgresTables(config: PostgresConfig): Promise<string[]>;
|
|
475
|
+
declare function executeReadOnlyPostgresQuery(config: PostgresConfig, sql: string): Promise<PostgresQueryResult>;
|
|
476
|
+
|
|
256
477
|
declare const APP_RESOURCE_URI = "ui://tinypivot/app.html";
|
|
257
478
|
declare const APP_MIME_TYPE = "text/html;profile=mcp-app";
|
|
258
479
|
declare const TINYPIVOT_MCP_INSTRUCTIONS: string;
|
|
@@ -263,7 +484,7 @@ interface CreateTinyPivotMcpServerOptions {
|
|
|
263
484
|
licenseKey?: string;
|
|
264
485
|
demoToken?: string;
|
|
265
486
|
companionUrl?: string;
|
|
266
|
-
/** Lazily start and return the localhost
|
|
487
|
+
/** Lazily start and return the localhost Studio URL on demand when a data tool runs in a non-MCP-Apps host */
|
|
267
488
|
ensureCompanion?: () => Promise<string | undefined>;
|
|
268
489
|
onStateChanged?: () => void;
|
|
269
490
|
/**
|
|
@@ -272,10 +493,10 @@ interface CreateTinyPivotMcpServerOptions {
|
|
|
272
493
|
* Defaults to TINYPIVOT_REPRINT_CARDS, which turns it off with "0".
|
|
273
494
|
*/
|
|
274
495
|
reprintCards?: boolean;
|
|
275
|
-
/**
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
|
|
496
|
+
/** The shared trace, history and SQL engine; the CLI passes the same one to the Studio page. */
|
|
497
|
+
studio?: Studio;
|
|
498
|
+
/** Offer Claude Code channels; defaults to whether Claude Code was started with this server's channel flag. */
|
|
499
|
+
claudeChannel?: boolean;
|
|
279
500
|
}
|
|
280
501
|
declare function clientSupportsMcpAppsUi(capabilities?: {
|
|
281
502
|
extensions?: Record<string, unknown>;
|
|
@@ -292,7 +513,7 @@ declare function createTinyPivotMcpServer(options?: CreateTinyPivotMcpServerOpti
|
|
|
292
513
|
interface TerminalFormatOptions {
|
|
293
514
|
/** Show subtle tiny-pivot.com card signature (true on Free tier, false on Pro) */
|
|
294
515
|
showBranding?: boolean;
|
|
295
|
-
/** Live local
|
|
516
|
+
/** Live local Studio URL to embed inside the card footer */
|
|
296
517
|
companionUrl?: string;
|
|
297
518
|
/** Optional 24-bit ANSI truecolor palette for direct TTY CLI output (omit for LLM Markdown) */
|
|
298
519
|
colorTheme?: ChartThemePreset;
|
|
@@ -314,4 +535,4 @@ declare function isProcessAlive(pid: number): boolean;
|
|
|
314
535
|
declare function resolveCompanionUrl(explicit?: string): Promise<string | null>;
|
|
315
536
|
declare function runTuiCommand(args: string[]): Promise<void>;
|
|
316
537
|
|
|
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 };
|
|
538
|
+
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-E6DYPT62.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.5.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,9 +80,9 @@
|
|
|
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.
|
|
84
|
-
"@smallwebco/tinypivot-core": "1.4.
|
|
85
|
-
"@smallwebco/tinypivot-server": "1.4.
|
|
83
|
+
"@smallwebco/tinypivot-react": "1.4.6",
|
|
84
|
+
"@smallwebco/tinypivot-core": "1.4.6",
|
|
85
|
+
"@smallwebco/tinypivot-server": "1.4.6"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"build": "pnpm run build:server && pnpm run build:app",
|
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.5.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.5.0",
|
|
18
18
|
"transport": {
|
|
19
19
|
"type": "stdio"
|
|
20
20
|
},
|