@smallwebco/tinypivot-mcp 0.2.6 → 0.2.8

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.
@@ -7347,6 +7347,28 @@ var require_pgsql_ast_parser = __commonJS({
7347
7347
  }
7348
7348
  });
7349
7349
 
7350
+ // ../core/dist/utils/index.js
7351
+ function formatNumber(value2, format = "us", options) {
7352
+ if (value2 === null)
7353
+ return "-";
7354
+ const maxDigits = options?.maximumFractionDigits ?? (Math.abs(value2) >= 1e3 ? 2 : 4);
7355
+ switch (format) {
7356
+ case "eu":
7357
+ return value2.toLocaleString("de-DE", { maximumFractionDigits: maxDigits });
7358
+ case "plain":
7359
+ return Number.isInteger(value2) ? String(value2) : value2.toFixed(Math.min(maxDigits, 20));
7360
+ case "us":
7361
+ default:
7362
+ return value2.toLocaleString("en-US", { maximumFractionDigits: maxDigits });
7363
+ }
7364
+ }
7365
+ function makeKey(row, fields) {
7366
+ return fields.map((f) => String(row[f] ?? "(blank)")).join("|||");
7367
+ }
7368
+ function parseKey(key) {
7369
+ return key.split("|||");
7370
+ }
7371
+
7350
7372
  // ../core/dist/chart/index.js
7351
7373
  var CHART_THEME_PRESETS = {
7352
7374
  "code": {
@@ -7405,6 +7427,20 @@ var CHART_COLORS = CHART_THEME_PRESETS.code.colors;
7405
7427
  function formatFieldLabel(field) {
7406
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(" ");
7407
7429
  }
7430
+ function createMeasureReader(aggregation) {
7431
+ if (aggregation === "count")
7432
+ return () => 1;
7433
+ if (aggregation === "countDistinct") {
7434
+ const ids = /* @__PURE__ */ new Map();
7435
+ return (raw) => {
7436
+ const key = String(raw);
7437
+ if (!ids.has(key))
7438
+ ids.set(key, ids.size);
7439
+ return ids.get(key);
7440
+ };
7441
+ }
7442
+ return (raw) => Number(raw);
7443
+ }
7408
7444
  function aggregateValues(values, aggregation) {
7409
7445
  if (values.length === 0)
7410
7446
  return 0;
@@ -7517,6 +7553,7 @@ function processChartData(data, config) {
7517
7553
  const xField = config.xAxis.field;
7518
7554
  const yField = config.yAxis.field;
7519
7555
  const yAggregation = config.yAxis.aggregation || "sum";
7556
+ const readMeasure = createMeasureReader(yAggregation);
7520
7557
  const seriesField = config.seriesField?.field;
7521
7558
  const grouped = /* @__PURE__ */ new Map();
7522
7559
  for (const row of data) {
@@ -7524,7 +7561,7 @@ function processChartData(data, config) {
7524
7561
  if (rawY === null || rawY === void 0 || rawY === "")
7525
7562
  continue;
7526
7563
  const xValue = String(row[xField] ?? "(blank)");
7527
- const yValue = Number(rawY);
7564
+ const yValue = readMeasure(rawY);
7528
7565
  const seriesValue = seriesField ? String(row[seriesField] ?? "(blank)") : "_default";
7529
7566
  if (Number.isNaN(yValue))
7530
7567
  continue;
@@ -7719,28 +7756,6 @@ var TERMINAL_PALETTES = {
7719
7756
  }
7720
7757
  };
7721
7758
 
7722
- // ../core/dist/utils/index.js
7723
- function formatNumber(value2, format = "us", options) {
7724
- if (value2 === null)
7725
- return "-";
7726
- const maxDigits = options?.maximumFractionDigits ?? (Math.abs(value2) >= 1e3 ? 2 : 4);
7727
- switch (format) {
7728
- case "eu":
7729
- return value2.toLocaleString("de-DE", { maximumFractionDigits: maxDigits });
7730
- case "plain":
7731
- return Number.isInteger(value2) ? String(value2) : value2.toFixed(Math.min(maxDigits, 20));
7732
- case "us":
7733
- default:
7734
- return value2.toLocaleString("en-US", { maximumFractionDigits: maxDigits });
7735
- }
7736
- }
7737
- function makeKey(row, fields) {
7738
- return fields.map((f) => String(row[f] ?? "(blank)")).join("|||");
7739
- }
7740
- function parseKey(key) {
7741
- return key.split("|||");
7742
- }
7743
-
7744
7759
  // ../core/dist/pivot/index.js
7745
7760
  var PATH_SEP = "\0";
7746
7761
  function pathKey(values) {
@@ -8372,6 +8387,13 @@ function flattenRow(input) {
8372
8387
  }
8373
8388
  return out;
8374
8389
  }
8390
+ function filterRows(rows, filters) {
8391
+ const wanted = filters.map((filter) => ({ field: filter.field, values: new Set(filter.equals.map(String)) }));
8392
+ return rows.filter((row) => wanted.every(({ field, values }) => values.has(String(row[field]))));
8393
+ }
8394
+ function describeFilters(filters) {
8395
+ return filters.map((filter) => `${filter.field} = ${filter.equals.join(" or ")}`).join(", ");
8396
+ }
8375
8397
  var DISTINCT_COUNT_CAP = 1e3;
8376
8398
  function collectDistinct(rows, name) {
8377
8399
  const distinct = /* @__PURE__ */ new Set();
@@ -8672,11 +8694,14 @@ var DatasetStore = class {
8672
8694
  this.activeId = id;
8673
8695
  return dataset;
8674
8696
  }
8697
+ /** Reads a data file from disk. With `where`, only the matching rows become the dataset. */
8675
8698
  async loadFromFile(filePath, name, options) {
8699
+ const where = options?.where ?? [];
8676
8700
  const resolved = path.resolve(filePath);
8677
8701
  const ext = path.extname(resolved).toLowerCase();
8678
8702
  const raw = await fs.readFile(resolved, "utf8");
8679
- const displayName = name || path.basename(resolved);
8703
+ const baseName = name || path.basename(resolved);
8704
+ const displayName = where.length > 0 && !name ? `${baseName} (${describeFilters(where)})` : baseName;
8680
8705
  let rows;
8681
8706
  if (ext === ".json") {
8682
8707
  const parsed = JSON.parse(raw);
@@ -8698,7 +8723,7 @@ var DatasetStore = class {
8698
8723
  return this.register({
8699
8724
  name: displayName,
8700
8725
  source: resolved,
8701
- rows,
8726
+ rows: filterRows(rows, where),
8702
8727
  sessionKey: options?.sessionKey,
8703
8728
  keepExisting: options?.keepExisting
8704
8729
  });
@@ -9368,15 +9393,27 @@ function detectNonAdditiveSumWarning(dataset, chartConfig) {
9368
9393
  const grain = sField ? `\`(${xField}, ${sField})\`` : `\`${xField}\``;
9369
9394
  return `> **Data Integrity Warning:** \`${yField}\` appears to be a non-additive percentage/ratio, and **${collisions}** ${grain} bucket${collisions === 1 ? "" : "s"} contain multiple rows that were summed (\`aggregation: "sum"\`). Re-aggregate in SQL or Python to strictly 1 row per ${grain} using \`SUM(numerator) / SUM(denominator)\` before passing to TinyPivot.`;
9370
9395
  }
9396
+ function pivotTableCard(dataset, options) {
9397
+ const pivot = dataset.pivotConfig;
9398
+ if (dataset.viewMode !== "pivot" || !pivot?.valueFields?.length)
9399
+ return null;
9400
+ const config = {
9401
+ rowFields: [],
9402
+ columnFields: [],
9403
+ showRowTotals: true,
9404
+ showColumnTotals: true,
9405
+ ...pivot,
9406
+ valueFields: pivot.valueFields
9407
+ };
9408
+ return formatPivotSummary(dataset, config, options.companionUrl, options).match(/```text[\s\S]*?```/)?.[0] ?? null;
9409
+ }
9371
9410
  function formatDistinctCount(count) {
9372
9411
  return count >= DISTINCT_COUNT_CAP ? `${DISTINCT_COUNT_CAP.toLocaleString("en-US")}+` : String(count);
9373
9412
  }
9374
9413
  function formatDatasetSummary(dataset, companionUrl, options = {}) {
9375
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");
9376
- const chartBlock = formatTerminalChart(dataset, dataset.chartConfig, {
9377
- ...options,
9378
- companionUrl: options.companionUrl ?? companionUrl
9379
- });
9415
+ const cardOptions = { ...options, companionUrl: options.companionUrl ?? companionUrl };
9416
+ const chartBlock = pivotTableCard(dataset, cardOptions) ?? formatTerminalChart(dataset, dataset.chartConfig, cardOptions);
9380
9417
  const rowHeadline = dataset.truncatedForFreeTier ? `**${dataset.rows.length.toLocaleString()} of ${dataset.sourceTotalRows.toLocaleString()} rows (Free tier limit)**` : `**${dataset.rows.length.toLocaleString()} rows**`;
9381
9418
  const parts = [
9382
9419
  `Loaded dataset **${dataset.name}** (\`${dataset.id}\`) \u2014 ${rowHeadline}, ${dataset.columns.length} columns.`,
@@ -10069,6 +10106,12 @@ async function runTuiCommand(args) {
10069
10106
  import fs3 from "fs/promises";
10070
10107
  import http from "http";
10071
10108
  import path3 from "path";
10109
+
10110
+ // src/limits.ts
10111
+ var INTERACTIVE_ROW_LIMIT = 1e5;
10112
+ var ROW_PAGE_SIZE = 25e3;
10113
+
10114
+ // src/companion.ts
10072
10115
  function readJsonBody(req) {
10073
10116
  return new Promise((resolve) => {
10074
10117
  const chunks = [];
@@ -10100,7 +10143,7 @@ function buildFullCompanionPayload(store, datasetId, opts) {
10100
10143
  sourceTotalRows: ds.sourceTotalRows,
10101
10144
  truncatedForFreeTier: ds.truncatedForFreeTier,
10102
10145
  tier: isPro2 ? "pro" : "free",
10103
- rows: ds.rows.slice(0, 25e3),
10146
+ rows: ds.rows.slice(0, INTERACTIVE_ROW_LIMIT),
10104
10147
  hasMoreRows: false,
10105
10148
  columns: ds.columns,
10106
10149
  viewMode: ds.viewMode,
@@ -11334,7 +11377,7 @@ import fsSync2 from "fs";
11334
11377
  import os4 from "os";
11335
11378
  import path5 from "path";
11336
11379
  var DEFAULT_TELEMETRY_URL = "https://tiny-pivot.com/api/telemetry";
11337
- var PACKAGE_VERSION = "0.2.6";
11380
+ var PACKAGE_VERSION = "0.2.8";
11338
11381
  function isTelemetryEnabled() {
11339
11382
  if (process.env.TINYPIVOT_TELEMETRY === "0" || process.env.TINYPIVOT_TELEMETRY === "false")
11340
11383
  return false;
@@ -11452,6 +11495,10 @@ var pivotValueSchema = z.object({
11452
11495
  field: z.string().describe("Numeric or countable column name to aggregate"),
11453
11496
  aggregation: z.enum(AGGREGATION_VALUES).default("sum")
11454
11497
  });
11498
+ var rowFilterSchema = z.object({
11499
+ field: z.string().describe("Column to filter on"),
11500
+ equals: z.array(z.union([z.string(), z.number(), z.boolean()])).min(1).describe("Keep rows whose value is any of these")
11501
+ });
11455
11502
  var pivotConfigSchema = z.object({
11456
11503
  rowFields: z.array(z.string()).default([]).describe("Columns to group as pivot rows"),
11457
11504
  columnFields: z.array(z.string()).default([]).describe("Columns to spread across pivot columns"),
@@ -11490,6 +11537,9 @@ function clientSupportsMcpAppsUi(capabilities) {
11490
11537
  capabilities.extensions?.["io.modelcontextprotocol/ui"] || capabilities.extensions?.["com.google.antigravity/ui"] || capabilities.experimental?.["io.modelcontextprotocol/ui"] || capabilities.experimental?.["com.google.antigravity/ui"] || capabilities.ui && typeof capabilities.ui === "object"
11491
11538
  );
11492
11539
  }
11540
+ function initialViewMode(requested, hasPivot, hasChart) {
11541
+ return requested ?? (hasPivot && !hasChart ? "pivot" : "chart");
11542
+ }
11493
11543
  function toCoreChartConfig(input) {
11494
11544
  return {
11495
11545
  type: input.type,
@@ -11619,7 +11669,7 @@ function createTinyPivotMcpServer(options = {}) {
11619
11669
  const server = new McpServer(
11620
11670
  {
11621
11671
  name: "tinypivot",
11622
- version: "0.2.6"
11672
+ version: "0.2.8"
11623
11673
  },
11624
11674
  {
11625
11675
  capabilities: {
@@ -11776,6 +11826,7 @@ function createTinyPivotMcpServer(options = {}) {
11776
11826
  inputSchema: {
11777
11827
  filePath: z.string().describe("Absolute or relative path to a .csv, .tsv, .json, or .jsonl file"),
11778
11828
  name: z.string().optional().describe("Optional display name for the dataset"),
11829
+ where: z.array(rowFilterSchema).optional().describe('Keep only rows that match every filter, e.g. [{"field":"year","equals":[2026]},{"field":"channel","equals":["Partner"]}]. Use this to chart or pivot one segment or period. Filtering runs on disk, so the rows still never enter context.'),
11779
11830
  viewMode: z.enum(VIEW_MODE_VALUES).optional().describe("Initial view mode (default: chart)"),
11780
11831
  pivotConfig: pivotConfigSchema.optional().describe("Optional initial pivot configuration (also derives a matching chart if chartConfig is omitted)"),
11781
11832
  chartConfig: chartConfigSchema.optional().describe("Optional explicit chart configuration (lets you load + configure a specific chart type in one single call)"),
@@ -11784,10 +11835,10 @@ function createTinyPivotMcpServer(options = {}) {
11784
11835
  },
11785
11836
  _meta: INLINE_UI_META
11786
11837
  },
11787
- async ({ filePath, name, viewMode, pivotConfig, chartConfig, model, keepExisting }, extra) => {
11838
+ async ({ filePath, name, where, viewMode, pivotConfig, chartConfig, model, keepExisting }, extra) => {
11788
11839
  try {
11789
11840
  const { sessionKey, keepExisting: shouldKeep } = resolveSessionContext(extra, keepExisting);
11790
- const ds = await store.loadFromFile(filePath, name, { sessionKey, keepExisting: shouldKeep });
11841
+ const ds = await store.loadFromFile(filePath, name, { sessionKey, keepExisting: shouldKeep, where });
11791
11842
  const explicitChart = chartConfig ? toCoreChartConfig(chartConfig) : void 0;
11792
11843
  if (pivotConfig) {
11793
11844
  const normalizedPivot = {
@@ -11798,7 +11849,7 @@ function createTinyPivotMcpServer(options = {}) {
11798
11849
  }))
11799
11850
  };
11800
11851
  store.updateView(ds.id, {
11801
- viewMode: viewMode ?? "chart",
11852
+ viewMode: initialViewMode(viewMode, true, Boolean(explicitChart)),
11802
11853
  pivotConfig: normalizedPivot,
11803
11854
  chartConfig: explicitChart ?? chartConfigFromPivot(normalizedPivot, ds.name) ?? ds.chartConfig
11804
11855
  }, sessionKey);
@@ -11860,7 +11911,7 @@ function createTinyPivotMcpServer(options = {}) {
11860
11911
  source: source ?? "inline JSON",
11861
11912
  ingestionMode: "inline",
11862
11913
  rows,
11863
- viewMode: viewMode ?? "chart",
11914
+ viewMode: initialViewMode(viewMode, Boolean(pivotConfig), Boolean(chartConfig)),
11864
11915
  pivotConfig: normalizedPivot,
11865
11916
  chartConfig: chartConfig ? toCoreChartConfig(chartConfig) : void 0,
11866
11917
  sessionKey,
@@ -12060,7 +12111,7 @@ function createTinyPivotMcpServer(options = {}) {
12060
12111
  source: "postgresql",
12061
12112
  ingestionMode: "direct",
12062
12113
  rows: res.rows,
12063
- viewMode: viewMode ?? "chart",
12114
+ viewMode: initialViewMode(viewMode, Boolean(pivotConfig), false),
12064
12115
  pivotConfig: pivotConfig ? {
12065
12116
  ...pivotConfig,
12066
12117
  valueFields: pivotConfig.valueFields.map((v) => ({
@@ -12159,7 +12210,7 @@ function createTinyPivotMcpServer(options = {}) {
12159
12210
  inputSchema: {
12160
12211
  datasetId: z.string().optional(),
12161
12212
  offset: z.number().int().min(0).default(0),
12162
- limit: z.number().int().min(1).max(25e3).default(1e4)
12213
+ limit: z.number().int().min(1).max(ROW_PAGE_SIZE).default(1e4)
12163
12214
  },
12164
12215
  _meta: APP_ONLY_META
12165
12216
  },
package/dist/cli.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  runTuiCommand,
19
19
  saveVisualThemePreference,
20
20
  startCompanionServer
21
- } from "./chunk-GANBTSPY.js";
21
+ } from "./chunk-L3TB5DJ7.js";
22
22
  import "./chunk-2ESYSVXG.js";
23
23
 
24
24
  // src/cli.ts
package/dist/index.d.ts CHANGED
@@ -58,6 +58,11 @@ interface DatasetMetadata {
58
58
  * RFC-4180 compliant CSV/TSV parser supporting quoted fields and escaped quotes.
59
59
  */
60
60
  declare function parseDelimitedText(text: string, delimiter?: string): Record<string, unknown>[];
61
+ /** Keeps rows whose `field` equals any of the listed values. */
62
+ interface RowFilter {
63
+ field: string;
64
+ equals: Array<string | number | boolean>;
65
+ }
61
66
  declare function inferColumns(rows: Record<string, unknown>[]): ColumnSummary[];
62
67
  /**
63
68
  * Deterministic built-in sample dataset so opening TinyPivot with `{}` immediately
@@ -94,9 +99,11 @@ declare class DatasetStore {
94
99
  sessionKey?: string;
95
100
  keepExisting?: boolean;
96
101
  }): StoredDataset;
102
+ /** Reads a data file from disk. With `where`, only the matching rows become the dataset. */
97
103
  loadFromFile(filePath: string, name?: string, options?: {
98
104
  sessionKey?: string;
99
105
  keepExisting?: boolean;
106
+ where?: RowFilter[];
100
107
  }): Promise<StoredDataset>;
101
108
  get(id?: string, sessionKey?: string): StoredDataset | undefined;
102
109
  setActive(id: string, sessionKey?: string): StoredDataset | undefined;
package/dist/index.js CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  startCompanionServer,
30
30
  tokensToUsd,
31
31
  upsertTinyPivotRuleBlock
32
- } from "./chunk-GANBTSPY.js";
32
+ } from "./chunk-L3TB5DJ7.js";
33
33
  import "./chunk-2ESYSVXG.js";
34
34
  export {
35
35
  APP_MIME_TYPE,
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.2.6",
5
+ "version": "0.2.8",
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",
@@ -79,9 +79,9 @@
79
79
  "typescript": "~5.6.2",
80
80
  "vite": "^6.4.6",
81
81
  "vite-plugin-singlefile": "^2.2.0",
82
- "@smallwebco/tinypivot-core": "1.4.2",
83
- "@smallwebco/tinypivot-server": "1.4.2",
84
- "@smallwebco/tinypivot-react": "1.4.2"
82
+ "@smallwebco/tinypivot-core": "1.4.4",
83
+ "@smallwebco/tinypivot-react": "1.4.4",
84
+ "@smallwebco/tinypivot-server": "1.4.4"
85
85
  },
86
86
  "scripts": {
87
87
  "build": "pnpm run build:server && pnpm run build:app",
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "io.github.Small-Web-Co/tinypivot",
4
4
  "title": "TinyPivot — Interactive Data IDE for AI Agents",
5
5
  "description": "Interactive charts, pivot tables, terminal cards, live TUI, and Excel export inside AI agents.",
6
- "version": "0.2.6",
6
+ "version": "0.2.8",
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.2.6",
17
+ "version": "0.2.8",
18
18
  "transport": {
19
19
  "type": "stdio"
20
20
  },