@smallwebco/tinypivot-mcp 0.2.6 → 0.2.7

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.
@@ -7405,6 +7405,20 @@ var CHART_COLORS = CHART_THEME_PRESETS.code.colors;
7405
7405
  function formatFieldLabel(field) {
7406
7406
  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
7407
  }
7408
+ function createMeasureReader(aggregation) {
7409
+ if (aggregation === "count")
7410
+ return () => 1;
7411
+ if (aggregation === "countDistinct") {
7412
+ const ids = /* @__PURE__ */ new Map();
7413
+ return (raw) => {
7414
+ const key = String(raw);
7415
+ if (!ids.has(key))
7416
+ ids.set(key, ids.size);
7417
+ return ids.get(key);
7418
+ };
7419
+ }
7420
+ return (raw) => Number(raw);
7421
+ }
7408
7422
  function aggregateValues(values, aggregation) {
7409
7423
  if (values.length === 0)
7410
7424
  return 0;
@@ -7517,6 +7531,7 @@ function processChartData(data, config) {
7517
7531
  const xField = config.xAxis.field;
7518
7532
  const yField = config.yAxis.field;
7519
7533
  const yAggregation = config.yAxis.aggregation || "sum";
7534
+ const readMeasure = createMeasureReader(yAggregation);
7520
7535
  const seriesField = config.seriesField?.field;
7521
7536
  const grouped = /* @__PURE__ */ new Map();
7522
7537
  for (const row of data) {
@@ -7524,7 +7539,7 @@ function processChartData(data, config) {
7524
7539
  if (rawY === null || rawY === void 0 || rawY === "")
7525
7540
  continue;
7526
7541
  const xValue = String(row[xField] ?? "(blank)");
7527
- const yValue = Number(rawY);
7542
+ const yValue = readMeasure(rawY);
7528
7543
  const seriesValue = seriesField ? String(row[seriesField] ?? "(blank)") : "_default";
7529
7544
  if (Number.isNaN(yValue))
7530
7545
  continue;
@@ -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.`,
@@ -11334,7 +11371,7 @@ import fsSync2 from "fs";
11334
11371
  import os4 from "os";
11335
11372
  import path5 from "path";
11336
11373
  var DEFAULT_TELEMETRY_URL = "https://tiny-pivot.com/api/telemetry";
11337
- var PACKAGE_VERSION = "0.2.6";
11374
+ var PACKAGE_VERSION = "0.2.7";
11338
11375
  function isTelemetryEnabled() {
11339
11376
  if (process.env.TINYPIVOT_TELEMETRY === "0" || process.env.TINYPIVOT_TELEMETRY === "false")
11340
11377
  return false;
@@ -11452,6 +11489,10 @@ var pivotValueSchema = z.object({
11452
11489
  field: z.string().describe("Numeric or countable column name to aggregate"),
11453
11490
  aggregation: z.enum(AGGREGATION_VALUES).default("sum")
11454
11491
  });
11492
+ var rowFilterSchema = z.object({
11493
+ field: z.string().describe("Column to filter on"),
11494
+ equals: z.array(z.union([z.string(), z.number(), z.boolean()])).min(1).describe("Keep rows whose value is any of these")
11495
+ });
11455
11496
  var pivotConfigSchema = z.object({
11456
11497
  rowFields: z.array(z.string()).default([]).describe("Columns to group as pivot rows"),
11457
11498
  columnFields: z.array(z.string()).default([]).describe("Columns to spread across pivot columns"),
@@ -11490,6 +11531,9 @@ function clientSupportsMcpAppsUi(capabilities) {
11490
11531
  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
11532
  );
11492
11533
  }
11534
+ function initialViewMode(requested, hasPivot, hasChart) {
11535
+ return requested ?? (hasPivot && !hasChart ? "pivot" : "chart");
11536
+ }
11493
11537
  function toCoreChartConfig(input) {
11494
11538
  return {
11495
11539
  type: input.type,
@@ -11619,7 +11663,7 @@ function createTinyPivotMcpServer(options = {}) {
11619
11663
  const server = new McpServer(
11620
11664
  {
11621
11665
  name: "tinypivot",
11622
- version: "0.2.6"
11666
+ version: "0.2.7"
11623
11667
  },
11624
11668
  {
11625
11669
  capabilities: {
@@ -11776,6 +11820,7 @@ function createTinyPivotMcpServer(options = {}) {
11776
11820
  inputSchema: {
11777
11821
  filePath: z.string().describe("Absolute or relative path to a .csv, .tsv, .json, or .jsonl file"),
11778
11822
  name: z.string().optional().describe("Optional display name for the dataset"),
11823
+ 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
11824
  viewMode: z.enum(VIEW_MODE_VALUES).optional().describe("Initial view mode (default: chart)"),
11780
11825
  pivotConfig: pivotConfigSchema.optional().describe("Optional initial pivot configuration (also derives a matching chart if chartConfig is omitted)"),
11781
11826
  chartConfig: chartConfigSchema.optional().describe("Optional explicit chart configuration (lets you load + configure a specific chart type in one single call)"),
@@ -11784,10 +11829,10 @@ function createTinyPivotMcpServer(options = {}) {
11784
11829
  },
11785
11830
  _meta: INLINE_UI_META
11786
11831
  },
11787
- async ({ filePath, name, viewMode, pivotConfig, chartConfig, model, keepExisting }, extra) => {
11832
+ async ({ filePath, name, where, viewMode, pivotConfig, chartConfig, model, keepExisting }, extra) => {
11788
11833
  try {
11789
11834
  const { sessionKey, keepExisting: shouldKeep } = resolveSessionContext(extra, keepExisting);
11790
- const ds = await store.loadFromFile(filePath, name, { sessionKey, keepExisting: shouldKeep });
11835
+ const ds = await store.loadFromFile(filePath, name, { sessionKey, keepExisting: shouldKeep, where });
11791
11836
  const explicitChart = chartConfig ? toCoreChartConfig(chartConfig) : void 0;
11792
11837
  if (pivotConfig) {
11793
11838
  const normalizedPivot = {
@@ -11798,7 +11843,7 @@ function createTinyPivotMcpServer(options = {}) {
11798
11843
  }))
11799
11844
  };
11800
11845
  store.updateView(ds.id, {
11801
- viewMode: viewMode ?? "chart",
11846
+ viewMode: initialViewMode(viewMode, true, Boolean(explicitChart)),
11802
11847
  pivotConfig: normalizedPivot,
11803
11848
  chartConfig: explicitChart ?? chartConfigFromPivot(normalizedPivot, ds.name) ?? ds.chartConfig
11804
11849
  }, sessionKey);
@@ -11860,7 +11905,7 @@ function createTinyPivotMcpServer(options = {}) {
11860
11905
  source: source ?? "inline JSON",
11861
11906
  ingestionMode: "inline",
11862
11907
  rows,
11863
- viewMode: viewMode ?? "chart",
11908
+ viewMode: initialViewMode(viewMode, Boolean(pivotConfig), Boolean(chartConfig)),
11864
11909
  pivotConfig: normalizedPivot,
11865
11910
  chartConfig: chartConfig ? toCoreChartConfig(chartConfig) : void 0,
11866
11911
  sessionKey,
@@ -12060,7 +12105,7 @@ function createTinyPivotMcpServer(options = {}) {
12060
12105
  source: "postgresql",
12061
12106
  ingestionMode: "direct",
12062
12107
  rows: res.rows,
12063
- viewMode: viewMode ?? "chart",
12108
+ viewMode: initialViewMode(viewMode, Boolean(pivotConfig), false),
12064
12109
  pivotConfig: pivotConfig ? {
12065
12110
  ...pivotConfig,
12066
12111
  valueFields: pivotConfig.valueFields.map((v) => ({
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-F2NOTK7R.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-F2NOTK7R.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.7",
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,8 +79,8 @@
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
82
  "@smallwebco/tinypivot-server": "1.4.2",
83
+ "@smallwebco/tinypivot-core": "1.4.2",
84
84
  "@smallwebco/tinypivot-react": "1.4.2"
85
85
  },
86
86
  "scripts": {
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.7",
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.7",
18
18
  "transport": {
19
19
  "type": "stdio"
20
20
  },