@smallwebco/tinypivot-mcp 0.2.8 → 0.2.10
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 +1 -1
- package/README.md +4 -3
- package/dist/app/index.html +39 -39
- package/dist/{chunk-L3TB5DJ7.js → chunk-6I4RP5QJ.js} +181 -209
- package/dist/cli.js +1 -1
- package/dist/index.d.ts +10 -2
- package/dist/index.js +1 -1
- package/package.json +4 -4
- package/server.json +2 -2
|
@@ -7427,6 +7427,7 @@ var CHART_COLORS = CHART_THEME_PRESETS.code.colors;
|
|
|
7427
7427
|
function formatFieldLabel(field) {
|
|
7428
7428
|
return field.replace(/([A-Z])/g, " $1").replace(/[_-]/g, " ").replace(/\s+/g, " ").trim().split(" ").map((word2) => word2.charAt(0).toUpperCase() + word2.slice(1).toLowerCase()).join(" ");
|
|
7429
7429
|
}
|
|
7430
|
+
var GAPPED_CHART_TYPES = /* @__PURE__ */ new Set(["line", "area"]);
|
|
7430
7431
|
function createMeasureReader(aggregation) {
|
|
7431
7432
|
if (aggregation === "count")
|
|
7432
7433
|
return () => 1;
|
|
@@ -7606,13 +7607,12 @@ function processChartData(data, config) {
|
|
|
7606
7607
|
categories = [...rawCategories].sort((a, b) => compareLabels(a, b) * dir);
|
|
7607
7608
|
}
|
|
7608
7609
|
const series = [];
|
|
7610
|
+
const missingValue = GAPPED_CHART_TYPES.has(config.type) ? null : 0;
|
|
7609
7611
|
for (const seriesName of seriesNames) {
|
|
7610
|
-
const seriesData =
|
|
7611
|
-
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
seriesData.push(aggregateValues(values, yAggregation));
|
|
7615
|
-
}
|
|
7612
|
+
const seriesData = categories.map((category) => {
|
|
7613
|
+
const values = grouped.get(category)?.get(seriesName);
|
|
7614
|
+
return values ? aggregateValues(values, yAggregation) : missingValue;
|
|
7615
|
+
});
|
|
7616
7616
|
series.push({
|
|
7617
7617
|
name: seriesName === "_default" ? formatFieldLabel(yField) : seriesName,
|
|
7618
7618
|
data: seriesData
|
|
@@ -9183,19 +9183,6 @@ function renderBrailleLineBody(categories, seriesList, filledArea = false, nonAd
|
|
|
9183
9183
|
}
|
|
9184
9184
|
return lines;
|
|
9185
9185
|
}
|
|
9186
|
-
function buildPresentSeriesPairs(rows, xField, seriesField) {
|
|
9187
|
-
if (!seriesField)
|
|
9188
|
-
return null;
|
|
9189
|
-
const present = /* @__PURE__ */ new Set();
|
|
9190
|
-
for (const row of rows) {
|
|
9191
|
-
const xRaw = row[xField];
|
|
9192
|
-
const sRaw = row[seriesField];
|
|
9193
|
-
const xKey = xRaw === null || xRaw === void 0 ? "(blank)" : String(xRaw);
|
|
9194
|
-
const sKey = sRaw === null || sRaw === void 0 ? "(blank)" : String(sRaw);
|
|
9195
|
-
present.add(`${xKey}\0${sKey}`);
|
|
9196
|
-
}
|
|
9197
|
-
return present;
|
|
9198
|
-
}
|
|
9199
9186
|
function formatTrendDelta(values) {
|
|
9200
9187
|
if (values.length < 2)
|
|
9201
9188
|
return "";
|
|
@@ -9243,15 +9230,9 @@ function formatTerminalChart(dataset, chartConfig, options = {}) {
|
|
|
9243
9230
|
const statsLine = `\u25B2 Peak: ${peakCat} (${formatCompactNumber(totalsPerCat[peakIdx])}) \xB7 \u25BC Low: ${lowCat} (${formatCompactNumber(totalsPerCat[lowIdx])}) \xB7 \u25C6 Avg: ${formatCompactNumber(avgVal)}`;
|
|
9244
9231
|
if ((fullConfig.type === "line" || fullConfig.type === "area") && processed.categories.length >= 3) {
|
|
9245
9232
|
const categoriesStr = processed.categories.map(String);
|
|
9246
|
-
const presentPairs = processed.series.length > 1 ? buildPresentSeriesPairs(dataset.rows, chartConfig.xAxis.field, chartConfig.seriesField?.field) : null;
|
|
9247
9233
|
const brailleSeries = processed.series.map((s) => ({
|
|
9248
9234
|
name: s.name,
|
|
9249
|
-
values:
|
|
9250
|
-
if (presentPairs && !presentPairs.has(`${cat}\0${s.name}`))
|
|
9251
|
-
return null;
|
|
9252
|
-
const val = Number(s.data[idx]);
|
|
9253
|
-
return Number.isFinite(val) ? val : null;
|
|
9254
|
-
})
|
|
9235
|
+
values: s.data.map((val) => val !== null && Number.isFinite(val) ? val : null)
|
|
9255
9236
|
}));
|
|
9256
9237
|
const body2 = renderBrailleLineBody(categoriesStr, brailleSeries, fullConfig.type === "area", nonAdditive).map((row, rIdx) => {
|
|
9257
9238
|
if (!pal)
|
|
@@ -9410,19 +9391,26 @@ function pivotTableCard(dataset, options) {
|
|
|
9410
9391
|
function formatDistinctCount(count) {
|
|
9411
9392
|
return count >= DISTINCT_COUNT_CAP ? `${DISTINCT_COUNT_CAP.toLocaleString("en-US")}+` : String(count);
|
|
9412
9393
|
}
|
|
9394
|
+
var LISTED_VALUES_MAX = 5;
|
|
9395
|
+
function formatColumnNotes(columns) {
|
|
9396
|
+
const notes = columns.map((column) => {
|
|
9397
|
+
const values = column.distinctCount <= LISTED_VALUES_MAX ? `: ${column.sampleValues.join(", ")}` : ` (${formatDistinctCount(column.distinctCount)} values)`;
|
|
9398
|
+
return `\`${column.name}\` ${column.type}${values}`;
|
|
9399
|
+
});
|
|
9400
|
+
return `Columns: ${notes.join(" \xB7 ") || "none"}`;
|
|
9401
|
+
}
|
|
9402
|
+
var REPRINT_NOTE = "Show the card above to the user verbatim.";
|
|
9413
9403
|
function formatDatasetSummary(dataset, companionUrl, options = {}) {
|
|
9414
|
-
const cols = dataset.columns.map((c) => `- \`${c.name}\` (${c.type}, ${formatDistinctCount(c.distinctCount)} distinct; e.g. ${c.sampleValues.slice(0, 3).join(", ")})`).join("\n");
|
|
9415
9404
|
const cardOptions = { ...options, companionUrl: options.companionUrl ?? companionUrl };
|
|
9416
9405
|
const chartBlock = pivotTableCard(dataset, cardOptions) ?? formatTerminalChart(dataset, dataset.chartConfig, cardOptions);
|
|
9417
9406
|
const rowHeadline = dataset.truncatedForFreeTier ? `**${dataset.rows.length.toLocaleString()} of ${dataset.sourceTotalRows.toLocaleString()} rows (Free tier limit)**` : `**${dataset.rows.length.toLocaleString()} rows**`;
|
|
9418
9407
|
const parts = [
|
|
9419
|
-
`Loaded
|
|
9420
|
-
`Source: ${dataset.source}`
|
|
9408
|
+
`Loaded **${dataset.name}** (\`${dataset.id}\`): ${rowHeadline}, ${dataset.columns.length} columns.`
|
|
9421
9409
|
];
|
|
9422
9410
|
if (dataset.truncatedForFreeTier) {
|
|
9423
9411
|
parts.push(
|
|
9424
9412
|
"",
|
|
9425
|
-
`> **
|
|
9413
|
+
`> **Free tier:** showing the first ${dataset.rows.length.toLocaleString()} of ${dataset.sourceTotalRows.toLocaleString()} rows, so totals cover only those. A license key unlocks every row: https://tiny-pivot.com/pricing`
|
|
9426
9414
|
);
|
|
9427
9415
|
}
|
|
9428
9416
|
const integrityWarning = detectNonAdditiveSumWarning(dataset, dataset.chartConfig);
|
|
@@ -9430,18 +9418,13 @@ function formatDatasetSummary(dataset, companionUrl, options = {}) {
|
|
|
9430
9418
|
parts.push("", integrityWarning);
|
|
9431
9419
|
}
|
|
9432
9420
|
if (chartBlock) {
|
|
9433
|
-
|
|
9434
|
-
|
|
9435
|
-
|
|
9436
|
-
chartBlock,
|
|
9437
|
-
"",
|
|
9438
|
-
echoNote
|
|
9439
|
-
);
|
|
9440
|
-
}
|
|
9441
|
-
parts.push("", "Columns:", cols || "(no columns)");
|
|
9442
|
-
if (companionUrl) {
|
|
9443
|
-
parts.push("", `Interactive Data IDE (live-updating): ${companionUrl}`);
|
|
9421
|
+
parts.push("", chartBlock);
|
|
9422
|
+
if (companionUrl && options.reprintNote !== false)
|
|
9423
|
+
parts.push(REPRINT_NOTE);
|
|
9444
9424
|
}
|
|
9425
|
+
parts.push("", formatColumnNotes(dataset.columns));
|
|
9426
|
+
if (companionUrl && !chartBlock)
|
|
9427
|
+
parts.push(`Data IDE: ${companionUrl}`);
|
|
9445
9428
|
return parts.join("\n");
|
|
9446
9429
|
}
|
|
9447
9430
|
function formatPivotSummary(dataset, config, companionUrl, options = {}) {
|
|
@@ -9559,20 +9542,9 @@ function formatPivotSummary(dataset, config, companionUrl, options = {}) {
|
|
|
9559
9542
|
tableLines.push("```");
|
|
9560
9543
|
}
|
|
9561
9544
|
const headline = dataset.truncatedForFreeTier ? `Pivot on **${dataset.name}** (**first ${dataset.rows.length.toLocaleString()} of ${dataset.sourceTotalRows.toLocaleString()} rows \u2014 Free tier subset**):` : `Pivot on **${dataset.name}** (${dataset.rows.length.toLocaleString()} source rows):`;
|
|
9562
|
-
const
|
|
9563
|
-
|
|
9564
|
-
|
|
9565
|
-
"",
|
|
9566
|
-
tableLines.join("\n"),
|
|
9567
|
-
"",
|
|
9568
|
-
echoNote
|
|
9569
|
-
];
|
|
9570
|
-
if (result.rowHeaders.length > maxRows) {
|
|
9571
|
-
out.push(`_\u2026and ${result.rowHeaders.length - maxRows} more rows visible interactively in TinyPivot._`);
|
|
9572
|
-
}
|
|
9573
|
-
if (companionUrl) {
|
|
9574
|
-
out.push("", `Interactive Data IDE (live-updating): ${companionUrl}`);
|
|
9575
|
-
}
|
|
9545
|
+
const out = [headline, "", tableLines.join("\n")];
|
|
9546
|
+
if (companionUrl && options.reprintNote !== false)
|
|
9547
|
+
out.push(REPRINT_NOTE);
|
|
9576
9548
|
return out.join("\n");
|
|
9577
9549
|
}
|
|
9578
9550
|
|
|
@@ -10570,17 +10542,15 @@ var RULE_START = "<!-- tinypivot:start -->";
|
|
|
10570
10542
|
var RULE_END = "<!-- tinypivot:end -->";
|
|
10571
10543
|
var RULE_TEST_RE = /<!-- tinypivot(?:-mcp)?:start -->[\s\S]*?<!-- tinypivot(?:-mcp)?:end -->/;
|
|
10572
10544
|
var RULE_REPLACE_RE = /<!-- tinypivot(?:-mcp)?:start -->[\s\S]*?<!-- tinypivot(?:-mcp)?:end -->/g;
|
|
10545
|
+
var RULE_HEADING = "## Charts & pivot tables (TinyPivot MCP)";
|
|
10546
|
+
var RULE_USE = "Use the `tinypivot` MCP server for charts, pivot tables and data exploration instead of drawing them yourself.";
|
|
10573
10547
|
var TINYPIVOT_CLAUDE_RULE_BLOCK = `${RULE_START}
|
|
10574
|
-
|
|
10575
|
-
|
|
10576
|
-
TinyPivot is a deterministic presentation & additive-rollup layer: for non-additive shares, rates, margins, or ratios over time (e.g. monthly share %, conversion rate, YoY %), pre-compute exact \`numerator / denominator\` ratios at the target chart grain (1 row per X \xD7 series) in SQL/Python before passing rows to TinyPivot\u2014never sum \`%\` columns across sub-segments and never use \`percentOfTotal\` for within-period share. Pass \`keepExisting: true\` only when comparing multiple datasets in the SAME conversation; use \`clear_datasets\` to reset.
|
|
10577
|
-
In terminal harnesses (pi, Claude Code, OpenCode, Codex CLI), there is NO inline GUI widget: ALWAYS include the returned fenced \`text\` TinyPivot chart/table card verbatim AND the localhost Companion IDE URL in your VERY FIRST reply\u2014never say "it is open in TinyPivot" without printing the card.
|
|
10548
|
+
${RULE_HEADING}
|
|
10549
|
+
${RULE_USE} In a terminal, show its \`text\` card verbatim with the Data IDE link.
|
|
10578
10550
|
${RULE_END}`;
|
|
10579
10551
|
var TINYPIVOT_PI_RULE_BLOCK = `${RULE_START}
|
|
10580
|
-
|
|
10581
|
-
|
|
10582
|
-
TinyPivot is a deterministic presentation & additive-rollup layer: for non-additive shares, rates, margins, or ratios over time (e.g. monthly share %, conversion rate, YoY %), pre-compute exact \`numerator / denominator\` ratios at the target chart grain (1 row per X \xD7 series) in SQL/Python before passing rows to TinyPivot\u2014never sum \`%\` columns across sub-segments and never use \`percentOfTotal\` for within-period share. Pass \`keepExisting: true\` only when comparing multiple datasets in the SAME conversation; use \`clear_datasets\` to reset.
|
|
10583
|
-
The TinyPivot pi extension automatically renders every TinyPivot chart/pivot card in full 24-bit color right in the terminal UI after the tool call\u2014follow up with 2\u20133 concise analytical takeaways and the live Companion IDE URL (no need to repeat a plain monochrome ASCII box unless the user asks). Users can switch themes anytime with \`/tinypivot-theme\` or \`set_visual_theme\`.
|
|
10552
|
+
${RULE_HEADING}
|
|
10553
|
+
${RULE_USE} The TinyPivot pi extension already shows each card, so reply with the takeaways and the Data IDE link. \`/tinypivot-theme\` switches themes.
|
|
10584
10554
|
${RULE_END}`;
|
|
10585
10555
|
function upsertTinyPivotRuleBlock(existing, block = TINYPIVOT_CLAUDE_RULE_BLOCK) {
|
|
10586
10556
|
if (RULE_TEST_RE.test(existing)) {
|
|
@@ -10606,7 +10576,7 @@ Usage:
|
|
|
10606
10576
|
Options:
|
|
10607
10577
|
--local Wire this local build (node <path>/dist/cli.js) instead of npx
|
|
10608
10578
|
--targets=<list> Comma-separated harnesses to configure:
|
|
10609
|
-
claude, claude-desktop, cursor, opencode, antigravity, pi, codex
|
|
10579
|
+
claude, claude-desktop, cursor, opencode, antigravity, antigravity-cli, pi, codex
|
|
10610
10580
|
--all Configure all supported harnesses even if not yet detected
|
|
10611
10581
|
--license=<key> Write TINYPIVOT_LICENSE_KEY into each configured server env
|
|
10612
10582
|
--theme=<id> Set default visual theme (${CHART_THEME_IDS.join(", ")})
|
|
@@ -10995,6 +10965,15 @@ TinyPivot MCP Installer (${opts.local ? `local: ${cliPath}` : `npx ${MCP_NPX_SPE
|
|
|
10995
10965
|
opts,
|
|
10996
10966
|
cliPath
|
|
10997
10967
|
),
|
|
10968
|
+
// The Antigravity CLI (`agy`) keeps its own MCP list, separate from the IDE's.
|
|
10969
|
+
await upsertStandardMcpJson(
|
|
10970
|
+
"antigravity-cli",
|
|
10971
|
+
"Antigravity CLI",
|
|
10972
|
+
path4.join(home, ".gemini", "config", "mcp_config.json"),
|
|
10973
|
+
path4.join(home, ".gemini", "antigravity-cli"),
|
|
10974
|
+
opts,
|
|
10975
|
+
cliPath
|
|
10976
|
+
),
|
|
10998
10977
|
await upsertStandardMcpJson(
|
|
10999
10978
|
"pi",
|
|
11000
10979
|
"pi",
|
|
@@ -11377,7 +11356,7 @@ import fsSync2 from "fs";
|
|
|
11377
11356
|
import os4 from "os";
|
|
11378
11357
|
import path5 from "path";
|
|
11379
11358
|
var DEFAULT_TELEMETRY_URL = "https://tiny-pivot.com/api/telemetry";
|
|
11380
|
-
var PACKAGE_VERSION = "0.2.
|
|
11359
|
+
var PACKAGE_VERSION = "0.2.10";
|
|
11381
11360
|
function isTelemetryEnabled() {
|
|
11382
11361
|
if (process.env.TINYPIVOT_TELEMETRY === "0" || process.env.TINYPIVOT_TELEMETRY === "false")
|
|
11383
11362
|
return false;
|
|
@@ -11455,14 +11434,18 @@ function recordTelemetry(ev) {
|
|
|
11455
11434
|
// src/server.ts
|
|
11456
11435
|
var APP_RESOURCE_URI = "ui://tinypivot/app.html";
|
|
11457
11436
|
var APP_MIME_TYPE = "text/html;profile=mcp-app";
|
|
11458
|
-
var
|
|
11459
|
-
|
|
11460
|
-
|
|
11461
|
-
|
|
11462
|
-
|
|
11463
|
-
|
|
11464
|
-
|
|
11465
|
-
|
|
11437
|
+
var LOAD_DATA_ROW_GUIDE = 50;
|
|
11438
|
+
function buildInstructions({ reprintCards = true } = {}) {
|
|
11439
|
+
const cards = reprintCards ? "In a terminal, show the returned ```text card verbatim with the Data IDE link in your reply, except in pi, whose TinyPivot extension already displays it." : "Do not reprint the ```text card: the user sees it in TinyPivot. Reply with the takeaways and the Data IDE link.";
|
|
11440
|
+
return [
|
|
11441
|
+
"Use TinyPivot for charts, pivot tables, period comparisons and tabular exploration instead of drawing them yourself (HTML, SVG, matplotlib, Markdown tables), passing chartConfig or pivotConfig in the same call.",
|
|
11442
|
+
`For files use load_file, so the rows stay out of your context. Use load_data only for rows you already have, up to about ${LOAD_DATA_ROW_GUIDE}; write larger sets to a file first.`,
|
|
11443
|
+
"Totals are exact. Compute ratios, shares and rates as numerator / denominator, one row per chart point, before loading; never add up percentage columns, and do not use percentOfTotal for a share within a period.",
|
|
11444
|
+
"Use keepExisting: true only to compare datasets in one conversation; clear_datasets resets.",
|
|
11445
|
+
cards
|
|
11446
|
+
].join(" ");
|
|
11447
|
+
}
|
|
11448
|
+
var TINYPIVOT_MCP_INSTRUCTIONS = buildInstructions();
|
|
11466
11449
|
var INLINE_PREVIEW_ROW_LIMIT = 200;
|
|
11467
11450
|
var AGGREGATION_VALUES = [
|
|
11468
11451
|
"sum",
|
|
@@ -11490,28 +11473,27 @@ var CHART_TYPE_VALUES = [
|
|
|
11490
11473
|
var CHART_AGG_VALUES = ["sum", "avg", "count", "min", "max"];
|
|
11491
11474
|
var VIEW_MODE_VALUES = ["grid", "pivot", "chart"];
|
|
11492
11475
|
var VISUAL_THEME_VALUES = CHART_THEME_IDS;
|
|
11493
|
-
var VISUAL_THEME_LIST = CHART_THEME_IDS.join(", ");
|
|
11494
11476
|
var pivotValueSchema = z.object({
|
|
11495
|
-
field: z.string()
|
|
11477
|
+
field: z.string(),
|
|
11496
11478
|
aggregation: z.enum(AGGREGATION_VALUES).default("sum")
|
|
11497
11479
|
});
|
|
11498
11480
|
var rowFilterSchema = z.object({
|
|
11499
|
-
field: z.string()
|
|
11500
|
-
equals: z.array(z.union([z.string(), z.number(), z.boolean()])).min(1).describe("Keep rows
|
|
11481
|
+
field: z.string(),
|
|
11482
|
+
equals: z.array(z.union([z.string(), z.number(), z.boolean()])).min(1).describe("Keep rows matching any of these")
|
|
11501
11483
|
});
|
|
11502
11484
|
var pivotConfigSchema = z.object({
|
|
11503
|
-
rowFields: z.array(z.string()).default([])
|
|
11504
|
-
columnFields: z.array(z.string()).default([])
|
|
11505
|
-
valueFields: z.array(pivotValueSchema).default([])
|
|
11485
|
+
rowFields: z.array(z.string()).default([]),
|
|
11486
|
+
columnFields: z.array(z.string()).default([]),
|
|
11487
|
+
valueFields: z.array(pivotValueSchema).default([]),
|
|
11506
11488
|
showRowTotals: z.boolean().default(true),
|
|
11507
11489
|
showColumnTotals: z.boolean().default(true)
|
|
11508
11490
|
});
|
|
11509
11491
|
var chartConfigSchema = z.object({
|
|
11510
11492
|
type: z.enum(CHART_TYPE_VALUES).default("bar"),
|
|
11511
|
-
xAxisField: z.string().describe("
|
|
11512
|
-
yAxisField: z.string().describe("
|
|
11513
|
-
aggregation: z.enum(CHART_AGG_VALUES).default("sum")
|
|
11514
|
-
seriesField: z.string().optional().describe("
|
|
11493
|
+
xAxisField: z.string().describe("Category or date column"),
|
|
11494
|
+
yAxisField: z.string().describe("Column to aggregate"),
|
|
11495
|
+
aggregation: z.enum(CHART_AGG_VALUES).default("sum"),
|
|
11496
|
+
seriesField: z.string().optional().describe("Column to split into series"),
|
|
11515
11497
|
title: z.string().optional()
|
|
11516
11498
|
});
|
|
11517
11499
|
function extractSessionKey(extra) {
|
|
@@ -11565,7 +11547,7 @@ function buildAppPayload(dataset, store, options) {
|
|
|
11565
11547
|
const summaryTokens = Math.round(summaryBytes / 4);
|
|
11566
11548
|
const defaultTurnBypass = dataset.ingestionMode === "direct" ? Math.max(0, dataset.estimatedDatasetTokens - summaryTokens) : 0;
|
|
11567
11549
|
const turnTokensSaved = options.overrideTurnTokensSaved ?? defaultTurnBypass;
|
|
11568
|
-
const sessionSavings = options.recordTurn !== false ? store.recordTurnSavings(turnTokensSaved
|
|
11550
|
+
const sessionSavings = options.recordTurn !== false ? store.recordTurnSavings(turnTokensSaved) : store.getSessionSavings();
|
|
11569
11551
|
const turnUsdSaved = tokensToUsd(turnTokensSaved, sessionSavings.model.ratePerMillion);
|
|
11570
11552
|
const validMcpKey = isMcpLicenseKey(options.licenseKey) ? options.licenseKey : null;
|
|
11571
11553
|
const isPro2 = Boolean(validMcpKey || options.demoToken);
|
|
@@ -11662,6 +11644,8 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
11662
11644
|
const notifyCompanion = () => {
|
|
11663
11645
|
options.onStateChanged?.();
|
|
11664
11646
|
};
|
|
11647
|
+
const reprintCards = options.reprintCards ?? process.env.TINYPIVOT_REPRINT_CARDS !== "0";
|
|
11648
|
+
const cardFormat = { showBranding: !isPro2, reprintNote: reprintCards };
|
|
11665
11649
|
const postgresConfig = options.postgres ?? (process.env.DATABASE_URL ? {
|
|
11666
11650
|
connectionString: process.env.DATABASE_URL,
|
|
11667
11651
|
allowedTables: process.env.TINYPIVOT_ALLOWED_TABLES ? process.env.TINYPIVOT_ALLOWED_TABLES.split(",").map((s) => s.trim()).filter(Boolean) : void 0
|
|
@@ -11669,14 +11653,14 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
11669
11653
|
const server = new McpServer(
|
|
11670
11654
|
{
|
|
11671
11655
|
name: "tinypivot",
|
|
11672
|
-
version: "0.2.
|
|
11656
|
+
version: "0.2.10"
|
|
11673
11657
|
},
|
|
11674
11658
|
{
|
|
11675
11659
|
capabilities: {
|
|
11676
11660
|
resources: {},
|
|
11677
11661
|
tools: {}
|
|
11678
11662
|
},
|
|
11679
|
-
instructions:
|
|
11663
|
+
instructions: buildInstructions({ reprintCards })
|
|
11680
11664
|
}
|
|
11681
11665
|
);
|
|
11682
11666
|
const clientRendersWidget = () => clientSupportsMcpAppsUi(server.server.getClientCapabilities());
|
|
@@ -11780,16 +11764,15 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
11780
11764
|
"open_tinypivot",
|
|
11781
11765
|
{
|
|
11782
11766
|
title: "Open TinyPivot",
|
|
11783
|
-
description: "Open the
|
|
11767
|
+
description: "Open the TinyPivot Data IDE (grid, pivot, chart). Shows sample data when nothing is loaded.",
|
|
11784
11768
|
inputSchema: {
|
|
11785
|
-
datasetId: z.string().optional()
|
|
11786
|
-
viewMode: z.enum(VIEW_MODE_VALUES).optional()
|
|
11787
|
-
|
|
11788
|
-
openBrowser: z.boolean().optional().describe("Set true to explicitly start the localhost Companion Data IDE URL even inside MCP Apps-capable hosts")
|
|
11769
|
+
datasetId: z.string().optional(),
|
|
11770
|
+
viewMode: z.enum(VIEW_MODE_VALUES).optional(),
|
|
11771
|
+
openBrowser: z.boolean().optional().describe("Also start the localhost Data IDE in hosts with an inline widget")
|
|
11789
11772
|
},
|
|
11790
11773
|
_meta: PANE_UI_META
|
|
11791
11774
|
},
|
|
11792
|
-
async ({ datasetId, viewMode,
|
|
11775
|
+
async ({ datasetId, viewMode, openBrowser }, extra) => {
|
|
11793
11776
|
const sessionKey = extractSessionKey(extra) ?? DEFAULT_SESSION_KEY;
|
|
11794
11777
|
const ds = store.get(datasetId, sessionKey);
|
|
11795
11778
|
if (!ds) {
|
|
@@ -11804,8 +11787,8 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
11804
11787
|
store.setActive(ds.id, sessionKey);
|
|
11805
11788
|
}
|
|
11806
11789
|
const liveCompanionUrl = await resolveCompanionUrlForTool(Boolean(openBrowser));
|
|
11807
|
-
const summaryText = formatDatasetSummary(ds, liveCompanionUrl,
|
|
11808
|
-
const payload = buildAppPayload(ds, store, { licenseKey, demoToken, summaryText,
|
|
11790
|
+
const summaryText = formatDatasetSummary(ds, liveCompanionUrl, cardFormat);
|
|
11791
|
+
const payload = buildAppPayload(ds, store, { licenseKey, demoToken, summaryText, sessionKey });
|
|
11809
11792
|
recordTelemetry({
|
|
11810
11793
|
event: "tool_call",
|
|
11811
11794
|
tool: "open_tinypivot",
|
|
@@ -11822,20 +11805,19 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
11822
11805
|
"load_file",
|
|
11823
11806
|
{
|
|
11824
11807
|
title: "Load Data File into TinyPivot",
|
|
11825
|
-
description: "
|
|
11808
|
+
description: "Chart or pivot a local CSV, TSV, JSON or JSONL file without reading it: the rows stay out of your context.",
|
|
11826
11809
|
inputSchema: {
|
|
11827
|
-
filePath: z.string()
|
|
11828
|
-
name: z.string().optional()
|
|
11829
|
-
where: z.array(rowFilterSchema).optional().describe('Keep only rows
|
|
11830
|
-
viewMode: z.enum(VIEW_MODE_VALUES).optional()
|
|
11831
|
-
pivotConfig: pivotConfigSchema.optional()
|
|
11832
|
-
chartConfig: chartConfigSchema.optional()
|
|
11833
|
-
|
|
11834
|
-
keepExisting: z.boolean().optional().describe("Set true to keep previously loaded datasets in this chat switcher (for multi-dataset comparisons in the same conversation). Omit to start clean on shared hosts.")
|
|
11810
|
+
filePath: z.string(),
|
|
11811
|
+
name: z.string().optional(),
|
|
11812
|
+
where: z.array(rowFilterSchema).optional().describe('Keep only matching rows, e.g. [{"field":"year","equals":[2026]}]'),
|
|
11813
|
+
viewMode: z.enum(VIEW_MODE_VALUES).optional(),
|
|
11814
|
+
pivotConfig: pivotConfigSchema.optional(),
|
|
11815
|
+
chartConfig: chartConfigSchema.optional(),
|
|
11816
|
+
keepExisting: z.boolean().optional().describe("Keep earlier datasets loaded, to compare them")
|
|
11835
11817
|
},
|
|
11836
11818
|
_meta: INLINE_UI_META
|
|
11837
11819
|
},
|
|
11838
|
-
async ({ filePath, name, where, viewMode, pivotConfig, chartConfig,
|
|
11820
|
+
async ({ filePath, name, where, viewMode, pivotConfig, chartConfig, keepExisting }, extra) => {
|
|
11839
11821
|
try {
|
|
11840
11822
|
const { sessionKey, keepExisting: shouldKeep } = resolveSessionContext(extra, keepExisting);
|
|
11841
11823
|
const ds = await store.loadFromFile(filePath, name, { sessionKey, keepExisting: shouldKeep, where });
|
|
@@ -11860,8 +11842,8 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
11860
11842
|
}, sessionKey);
|
|
11861
11843
|
}
|
|
11862
11844
|
const liveCompanionUrl = await resolveCompanionUrlForTool();
|
|
11863
|
-
const summaryText = formatDatasetSummary(ds, liveCompanionUrl,
|
|
11864
|
-
const payload = buildAppPayload(ds, store, { licenseKey, demoToken, summaryText,
|
|
11845
|
+
const summaryText = formatDatasetSummary(ds, liveCompanionUrl, cardFormat);
|
|
11846
|
+
const payload = buildAppPayload(ds, store, { licenseKey, demoToken, summaryText, sessionKey });
|
|
11865
11847
|
recordTelemetry({
|
|
11866
11848
|
event: "tool_call",
|
|
11867
11849
|
tool: "load_file",
|
|
@@ -11884,20 +11866,19 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
11884
11866
|
"load_data",
|
|
11885
11867
|
{
|
|
11886
11868
|
title: "Load JSON Rows into TinyPivot",
|
|
11887
|
-
description: "
|
|
11869
|
+
description: "Chart or pivot rows you already have, up to about 50. Every row you pass is billed as output; for more, write a file and use load_file.",
|
|
11888
11870
|
inputSchema: {
|
|
11889
|
-
name: z.string()
|
|
11890
|
-
rows: z.array(z.record(z.string(), z.unknown()))
|
|
11891
|
-
source: z.string().optional()
|
|
11892
|
-
viewMode: z.enum(VIEW_MODE_VALUES).optional()
|
|
11893
|
-
pivotConfig: pivotConfigSchema.optional()
|
|
11871
|
+
name: z.string(),
|
|
11872
|
+
rows: z.array(z.record(z.string(), z.unknown())),
|
|
11873
|
+
source: z.string().optional(),
|
|
11874
|
+
viewMode: z.enum(VIEW_MODE_VALUES).optional(),
|
|
11875
|
+
pivotConfig: pivotConfigSchema.optional(),
|
|
11894
11876
|
chartConfig: chartConfigSchema.optional(),
|
|
11895
|
-
|
|
11896
|
-
keepExisting: z.boolean().optional().describe("Set true to keep previously loaded datasets in this chat switcher (for multi-dataset comparisons in the same conversation). Omit to start clean on shared hosts.")
|
|
11877
|
+
keepExisting: z.boolean().optional().describe("Keep earlier datasets loaded, to compare them")
|
|
11897
11878
|
},
|
|
11898
11879
|
_meta: INLINE_UI_META
|
|
11899
11880
|
},
|
|
11900
|
-
async ({ name, rows, source, viewMode, pivotConfig, chartConfig,
|
|
11881
|
+
async ({ name, rows, source, viewMode, pivotConfig, chartConfig, keepExisting }, extra) => {
|
|
11901
11882
|
const { sessionKey, keepExisting: shouldKeep } = resolveSessionContext(extra, keepExisting);
|
|
11902
11883
|
const normalizedPivot = pivotConfig ? {
|
|
11903
11884
|
...pivotConfig,
|
|
@@ -11918,8 +11899,8 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
11918
11899
|
keepExisting: shouldKeep
|
|
11919
11900
|
});
|
|
11920
11901
|
const liveCompanionUrl = await resolveCompanionUrlForTool();
|
|
11921
|
-
const summaryText = formatDatasetSummary(ds, liveCompanionUrl,
|
|
11922
|
-
const payload = buildAppPayload(ds, store, { licenseKey, demoToken, summaryText,
|
|
11902
|
+
const summaryText = formatDatasetSummary(ds, liveCompanionUrl, cardFormat);
|
|
11903
|
+
const payload = buildAppPayload(ds, store, { licenseKey, demoToken, summaryText, sessionKey });
|
|
11923
11904
|
recordTelemetry({
|
|
11924
11905
|
event: "tool_call",
|
|
11925
11906
|
tool: "load_data",
|
|
@@ -11936,19 +11917,18 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
11936
11917
|
"configure_pivot",
|
|
11937
11918
|
{
|
|
11938
11919
|
title: "Configure Pivot Table",
|
|
11939
|
-
description: "
|
|
11920
|
+
description: "Pivot the active dataset. Aggregations are exact; percentOfTotal divides by the grand total.",
|
|
11940
11921
|
inputSchema: {
|
|
11941
|
-
datasetId: z.string().optional()
|
|
11942
|
-
rowFields: z.array(z.string()).default([])
|
|
11943
|
-
columnFields: z.array(z.string()).default([])
|
|
11944
|
-
valueFields: z.array(pivotValueSchema).min(1)
|
|
11922
|
+
datasetId: z.string().optional(),
|
|
11923
|
+
rowFields: z.array(z.string()).default([]),
|
|
11924
|
+
columnFields: z.array(z.string()).default([]),
|
|
11925
|
+
valueFields: z.array(pivotValueSchema).min(1),
|
|
11945
11926
|
showRowTotals: z.boolean().default(true),
|
|
11946
|
-
showColumnTotals: z.boolean().default(true)
|
|
11947
|
-
model: z.string().optional().describe("Active LLM model name for dollarized token savings")
|
|
11927
|
+
showColumnTotals: z.boolean().default(true)
|
|
11948
11928
|
},
|
|
11949
11929
|
_meta: INLINE_UI_META
|
|
11950
11930
|
},
|
|
11951
|
-
async ({ datasetId, rowFields, columnFields, valueFields, showRowTotals, showColumnTotals
|
|
11931
|
+
async ({ datasetId, rowFields, columnFields, valueFields, showRowTotals, showColumnTotals }, extra) => {
|
|
11952
11932
|
const sessionKey = extractSessionKey(extra) ?? DEFAULT_SESSION_KEY;
|
|
11953
11933
|
const ds = store.get(datasetId, sessionKey);
|
|
11954
11934
|
if (!ds) {
|
|
@@ -11973,13 +11953,12 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
11973
11953
|
chartConfig: chartConfigFromPivot(fullPivotConfig, ds.name) ?? ds.chartConfig
|
|
11974
11954
|
}, sessionKey);
|
|
11975
11955
|
const liveCompanionUrl = await resolveCompanionUrlForTool();
|
|
11976
|
-
const summary = formatPivotSummary(ds, fullPivotConfig, liveCompanionUrl,
|
|
11956
|
+
const summary = formatPivotSummary(ds, fullPivotConfig, liveCompanionUrl, cardFormat);
|
|
11977
11957
|
const pivotTokensSaved = Math.max(0, ds.estimatedDatasetTokens - Math.round(Buffer.byteLength(summary, "utf8") / 4));
|
|
11978
11958
|
const payload = buildAppPayload(ds, store, {
|
|
11979
11959
|
licenseKey,
|
|
11980
11960
|
demoToken,
|
|
11981
11961
|
summaryText: summary,
|
|
11982
|
-
model,
|
|
11983
11962
|
overrideTurnTokensSaved: pivotTokensSaved,
|
|
11984
11963
|
sessionKey
|
|
11985
11964
|
});
|
|
@@ -11999,21 +11978,20 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
11999
11978
|
"configure_chart",
|
|
12000
11979
|
{
|
|
12001
11980
|
title: "Configure Chart",
|
|
12002
|
-
description: "
|
|
11981
|
+
description: "Chart the active dataset.",
|
|
12003
11982
|
inputSchema: {
|
|
12004
|
-
datasetId: z.string().optional()
|
|
11983
|
+
datasetId: z.string().optional(),
|
|
12005
11984
|
type: z.enum(CHART_TYPE_VALUES).default("bar"),
|
|
12006
11985
|
xAxisField: z.string(),
|
|
12007
11986
|
yAxisField: z.string(),
|
|
12008
11987
|
aggregation: z.enum(CHART_AGG_VALUES).default("sum"),
|
|
12009
11988
|
seriesField: z.string().optional(),
|
|
12010
11989
|
title: z.string().optional(),
|
|
12011
|
-
chartTheme: z.enum(VISUAL_THEME_VALUES).optional()
|
|
12012
|
-
model: z.string().optional().describe("Active LLM model name for dollarized token savings")
|
|
11990
|
+
chartTheme: z.enum(VISUAL_THEME_VALUES).optional()
|
|
12013
11991
|
},
|
|
12014
11992
|
_meta: INLINE_UI_META
|
|
12015
11993
|
},
|
|
12016
|
-
async ({ datasetId, type, xAxisField, yAxisField, aggregation, seriesField, title, chartTheme
|
|
11994
|
+
async ({ datasetId, type, xAxisField, yAxisField, aggregation, seriesField, title, chartTheme }, extra) => {
|
|
12017
11995
|
const sessionKey = extractSessionKey(extra) ?? DEFAULT_SESSION_KEY;
|
|
12018
11996
|
const ds = store.get(datasetId, sessionKey);
|
|
12019
11997
|
if (!ds) {
|
|
@@ -12049,14 +12027,13 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
12049
12027
|
if (asciiChart)
|
|
12050
12028
|
summaryParts.push("", asciiChart);
|
|
12051
12029
|
if (liveCompanionUrl)
|
|
12052
|
-
summaryParts.push(
|
|
12030
|
+
summaryParts.push(`Data IDE: ${liveCompanionUrl}`);
|
|
12053
12031
|
const summaryText = summaryParts.join("\n");
|
|
12054
12032
|
const chartTokensSaved = Math.max(0, ds.estimatedDatasetTokens - Math.round(Buffer.byteLength(summaryText, "utf8") / 4));
|
|
12055
12033
|
const payload = buildAppPayload(ds, store, {
|
|
12056
12034
|
licenseKey,
|
|
12057
12035
|
demoToken,
|
|
12058
12036
|
summaryText,
|
|
12059
|
-
model,
|
|
12060
12037
|
overrideTurnTokensSaved: chartTokensSaved,
|
|
12061
12038
|
sessionKey
|
|
12062
12039
|
});
|
|
@@ -12072,83 +12049,78 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
12072
12049
|
return dataToolResult(summaryText, payload);
|
|
12073
12050
|
}
|
|
12074
12051
|
);
|
|
12075
|
-
|
|
12076
|
-
|
|
12077
|
-
|
|
12078
|
-
|
|
12079
|
-
|
|
12080
|
-
|
|
12081
|
-
|
|
12082
|
-
|
|
12083
|
-
|
|
12084
|
-
|
|
12085
|
-
|
|
12086
|
-
|
|
12052
|
+
if (postgresConfig) {
|
|
12053
|
+
server.registerTool(
|
|
12054
|
+
"query_postgres",
|
|
12055
|
+
{
|
|
12056
|
+
title: "Query PostgreSQL Directly (Read-Only, Pro)",
|
|
12057
|
+
description: "Run a read-only SELECT on the configured Postgres database and chart the result.",
|
|
12058
|
+
inputSchema: {
|
|
12059
|
+
sql: z.string(),
|
|
12060
|
+
name: z.string().optional(),
|
|
12061
|
+
viewMode: z.enum(VIEW_MODE_VALUES).optional(),
|
|
12062
|
+
pivotConfig: pivotConfigSchema.optional(),
|
|
12063
|
+
keepExisting: z.boolean().optional().describe("Keep earlier datasets loaded, to compare them")
|
|
12064
|
+
},
|
|
12065
|
+
_meta: INLINE_UI_META
|
|
12087
12066
|
},
|
|
12088
|
-
|
|
12089
|
-
|
|
12090
|
-
|
|
12091
|
-
|
|
12092
|
-
|
|
12093
|
-
|
|
12094
|
-
|
|
12095
|
-
|
|
12096
|
-
|
|
12097
|
-
|
|
12098
|
-
|
|
12099
|
-
|
|
12100
|
-
|
|
12101
|
-
|
|
12102
|
-
|
|
12103
|
-
|
|
12104
|
-
|
|
12105
|
-
|
|
12106
|
-
|
|
12107
|
-
|
|
12108
|
-
|
|
12109
|
-
|
|
12110
|
-
|
|
12111
|
-
|
|
12112
|
-
|
|
12113
|
-
|
|
12114
|
-
|
|
12115
|
-
|
|
12116
|
-
|
|
12117
|
-
|
|
12118
|
-
|
|
12119
|
-
|
|
12120
|
-
|
|
12121
|
-
|
|
12122
|
-
|
|
12123
|
-
|
|
12124
|
-
|
|
12125
|
-
|
|
12126
|
-
|
|
12127
|
-
|
|
12128
|
-
|
|
12129
|
-
|
|
12130
|
-
|
|
12131
|
-
|
|
12132
|
-
|
|
12133
|
-
|
|
12134
|
-
|
|
12135
|
-
|
|
12136
|
-
}
|
|
12137
|
-
notifyCompanion();
|
|
12138
|
-
return dataToolResult(summaryText, payload);
|
|
12139
|
-
} catch (err) {
|
|
12140
|
-
return {
|
|
12141
|
-
isError: true,
|
|
12142
|
-
content: [{ type: "text", text: `PostgreSQL query failed: ${err instanceof Error ? err.message : String(err)}` }]
|
|
12143
|
-
};
|
|
12067
|
+
async ({ sql, name, viewMode, pivotConfig, keepExisting }, extra) => {
|
|
12068
|
+
if (!isPro2) {
|
|
12069
|
+
return {
|
|
12070
|
+
isError: true,
|
|
12071
|
+
content: [{
|
|
12072
|
+
type: "text",
|
|
12073
|
+
text: "Read-only PostgreSQL querying (`query_postgres`) requires a TinyPivot Pro license (TINYPIVOT_LICENSE_KEY). Free tier includes local CSV/TSV/JSON files and inline data up to 2,500 rows. Upgrade at https://tiny-pivot.com/pricing"
|
|
12074
|
+
}]
|
|
12075
|
+
};
|
|
12076
|
+
}
|
|
12077
|
+
try {
|
|
12078
|
+
const { sessionKey, keepExisting: shouldKeep } = resolveSessionContext(extra, keepExisting);
|
|
12079
|
+
const res = await executeReadOnlyPostgresQuery(postgresConfig, sql);
|
|
12080
|
+
const ds = store.register({
|
|
12081
|
+
name: name ?? "PostgreSQL Query",
|
|
12082
|
+
source: "postgresql",
|
|
12083
|
+
ingestionMode: "direct",
|
|
12084
|
+
rows: res.rows,
|
|
12085
|
+
viewMode: initialViewMode(viewMode, Boolean(pivotConfig), false),
|
|
12086
|
+
pivotConfig: pivotConfig ? {
|
|
12087
|
+
...pivotConfig,
|
|
12088
|
+
valueFields: pivotConfig.valueFields.map((v) => ({
|
|
12089
|
+
field: v.field,
|
|
12090
|
+
aggregation: v.aggregation
|
|
12091
|
+
}))
|
|
12092
|
+
} : void 0,
|
|
12093
|
+
sessionKey,
|
|
12094
|
+
keepExisting: shouldKeep
|
|
12095
|
+
});
|
|
12096
|
+
const liveCompanionUrl = await resolveCompanionUrlForTool();
|
|
12097
|
+
const truncNote = res.truncated ? " (capped at max rows)" : "";
|
|
12098
|
+
const summaryText = `${formatDatasetSummary(ds, liveCompanionUrl, cardFormat)}${truncNote}`;
|
|
12099
|
+
const payload = buildAppPayload(ds, store, { licenseKey, demoToken, summaryText, sessionKey });
|
|
12100
|
+
recordTelemetry({
|
|
12101
|
+
event: "tool_call",
|
|
12102
|
+
tool: "query_postgres",
|
|
12103
|
+
rowBucket: bucketRowCount(ds.sourceTotalRows),
|
|
12104
|
+
client: getClientName(),
|
|
12105
|
+
tier,
|
|
12106
|
+
truncated: ds.truncatedForFreeTier
|
|
12107
|
+
});
|
|
12108
|
+
notifyCompanion();
|
|
12109
|
+
return dataToolResult(summaryText, payload);
|
|
12110
|
+
} catch (err) {
|
|
12111
|
+
return {
|
|
12112
|
+
isError: true,
|
|
12113
|
+
content: [{ type: "text", text: `PostgreSQL query failed: ${err instanceof Error ? err.message : String(err)}` }]
|
|
12114
|
+
};
|
|
12115
|
+
}
|
|
12144
12116
|
}
|
|
12145
|
-
|
|
12146
|
-
|
|
12117
|
+
);
|
|
12118
|
+
}
|
|
12147
12119
|
server.registerTool(
|
|
12148
12120
|
"list_datasets",
|
|
12149
12121
|
{
|
|
12150
12122
|
title: "List Datasets",
|
|
12151
|
-
description: "List
|
|
12123
|
+
description: "List loaded datasets with their row counts and columns.",
|
|
12152
12124
|
inputSchema: {}
|
|
12153
12125
|
},
|
|
12154
12126
|
async (_args, extra) => {
|
|
@@ -12182,7 +12154,7 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
12182
12154
|
"clear_datasets",
|
|
12183
12155
|
{
|
|
12184
12156
|
title: "Clear Session Datasets",
|
|
12185
|
-
description: "
|
|
12157
|
+
description: "Unload all datasets.",
|
|
12186
12158
|
inputSchema: {}
|
|
12187
12159
|
},
|
|
12188
12160
|
async (_args, extra) => {
|
|
@@ -12308,9 +12280,9 @@ function createTinyPivotMcpServer(options = {}) {
|
|
|
12308
12280
|
"set_visual_theme",
|
|
12309
12281
|
{
|
|
12310
12282
|
title: "Set Visual Theme",
|
|
12311
|
-
description:
|
|
12283
|
+
description: "Set the theme for charts, tables and the Data IDE.",
|
|
12312
12284
|
inputSchema: {
|
|
12313
|
-
theme: z.enum(VISUAL_THEME_VALUES)
|
|
12285
|
+
theme: z.enum(VISUAL_THEME_VALUES)
|
|
12314
12286
|
},
|
|
12315
12287
|
_meta: {
|
|
12316
12288
|
ui: { visibility: ["model", "app"] }
|