@smallwebco/tinypivot-mcp 0.0.0-stage → 0.1.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.
@@ -0,0 +1,166 @@
1
+ import { DataGridViewMode, PivotConfig, ChartConfig, ChartThemePreset } from '@smallwebco/tinypivot-core';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+
4
+ interface ModelPricing {
5
+ id: string;
6
+ name: string;
7
+ provider: string;
8
+ ratePerMillion: number;
9
+ }
10
+ declare const MODEL_CATALOG: ModelPricing[];
11
+ declare const DEFAULT_MODEL_PRICING: ModelPricing;
12
+ /**
13
+ * Resolve a model ID or human-readable model name (from an AI agent, host, or env var)
14
+ * to its published input token rate. Unknown models preserve their name with a sensible fallback.
15
+ */
16
+ declare function resolveModelPricing(input?: string | null, customRatePerMillion?: number): ModelPricing;
17
+ declare function tokensToUsd(tokens: number, ratePerMillion: number): number;
18
+
19
+ interface SessionSavingsSnapshot {
20
+ model: ModelPricing;
21
+ turns: number;
22
+ localActions: number;
23
+ tokensSaved: number;
24
+ usdSaved: number;
25
+ }
26
+ interface ColumnSummary {
27
+ name: string;
28
+ type: 'number' | 'string' | 'boolean' | 'date' | 'null';
29
+ sampleValues: string[];
30
+ distinctCount: number;
31
+ }
32
+ interface StoredDataset {
33
+ id: string;
34
+ name: string;
35
+ source: string;
36
+ ingestionMode: 'direct' | 'inline';
37
+ rawBytes: number;
38
+ estimatedDatasetTokens: number;
39
+ sourceTotalRows: number;
40
+ truncatedForFreeTier: boolean;
41
+ rows: Record<string, unknown>[];
42
+ columns: ColumnSummary[];
43
+ loadedAt: string;
44
+ viewMode: DataGridViewMode;
45
+ pivotConfig?: Partial<PivotConfig>;
46
+ chartConfig?: Partial<ChartConfig>;
47
+ }
48
+ interface DatasetMetadata {
49
+ id: string;
50
+ name: string;
51
+ source: string;
52
+ rowCount: number;
53
+ columns: ColumnSummary[];
54
+ loadedAt: string;
55
+ viewMode: DataGridViewMode;
56
+ }
57
+ /**
58
+ * RFC-4180 compliant CSV/TSV parser supporting quoted fields and escaped quotes.
59
+ */
60
+ declare function parseDelimitedText(text: string, delimiter?: string): Record<string, unknown>[];
61
+ declare function inferColumns(rows: Record<string, unknown>[]): ColumnSummary[];
62
+ /**
63
+ * Deterministic built-in sample dataset so opening TinyPivot with `{}` immediately
64
+ * shows realistic business data ready for pivoting, charts, and drill-through.
65
+ */
66
+ declare function generateSampleSalesData(count?: number): Record<string, unknown>[];
67
+ declare class DatasetStore {
68
+ private datasets;
69
+ private activeId;
70
+ private activeModel;
71
+ private visualTheme;
72
+ private sessionTurns;
73
+ private sessionLocalActions;
74
+ private sessionTokensSaved;
75
+ private maxRowsPerDataset;
76
+ constructor(options?: {
77
+ maxRowsPerDataset?: number;
78
+ });
79
+ private slugify;
80
+ register(input: {
81
+ id?: string;
82
+ name: string;
83
+ source: string;
84
+ ingestionMode?: 'direct' | 'inline';
85
+ rows: Record<string, unknown>[];
86
+ viewMode?: DataGridViewMode;
87
+ pivotConfig?: Partial<PivotConfig>;
88
+ chartConfig?: Partial<ChartConfig>;
89
+ }): StoredDataset;
90
+ loadFromFile(filePath: string, name?: string): Promise<StoredDataset>;
91
+ get(id?: string): StoredDataset | undefined;
92
+ setActive(id: string): StoredDataset | undefined;
93
+ updateView(id: string | undefined, patch: {
94
+ viewMode?: DataGridViewMode;
95
+ pivotConfig?: Partial<PivotConfig>;
96
+ chartConfig?: Partial<ChartConfig>;
97
+ }): StoredDataset | undefined;
98
+ listMetadata(): DatasetMetadata[];
99
+ getActiveId(): string | null;
100
+ getActiveModel(): ModelPricing;
101
+ getVisualTheme(): ChartThemePreset;
102
+ setVisualTheme(theme: string): ChartThemePreset;
103
+ setActiveModel(modelInput?: string, customRatePerMillion?: number): ModelPricing;
104
+ recordTurnSavings(tokensSaved: number, modelInput?: string): SessionSavingsSnapshot;
105
+ recordLocalAction(datasetId?: string): {
106
+ addedTokens: number;
107
+ session: SessionSavingsSnapshot;
108
+ };
109
+ getSessionSavings(): SessionSavingsSnapshot;
110
+ }
111
+
112
+ interface CompanionServerHandle {
113
+ url: string;
114
+ port: number;
115
+ broadcastUpdate: () => void;
116
+ close: () => Promise<void>;
117
+ }
118
+ interface StartCompanionOptions {
119
+ store: DatasetStore;
120
+ loadHtml: () => Promise<string>;
121
+ licenseKey?: string;
122
+ demoToken?: string;
123
+ port?: number;
124
+ }
125
+ /**
126
+ * Localhost companion HTTP + SSE server so terminal-first harnesses
127
+ * (Claude Code, OpenCode, pi, Rex, Ghostty, Codex CLI) get the exact same
128
+ * live-updating interactive TinyPivot Data IDE in a browser tab alongside the terminal.
129
+ */
130
+ declare function startCompanionServer(options: StartCompanionOptions): Promise<CompanionServerHandle>;
131
+
132
+ interface PostgresConfig {
133
+ connectionString: string;
134
+ allowedTables?: string[];
135
+ maxRows?: number;
136
+ }
137
+ interface PostgresQueryResult {
138
+ rows: Record<string, unknown>[];
139
+ rowCount: number;
140
+ truncated: boolean;
141
+ }
142
+ declare function listPostgresTables(config: PostgresConfig): Promise<string[]>;
143
+ declare function executeReadOnlyPostgresQuery(config: PostgresConfig, sql: string): Promise<PostgresQueryResult>;
144
+
145
+ declare const APP_RESOURCE_URI = "ui://tinypivot/app.html";
146
+ declare const APP_MIME_TYPE = "text/html;profile=mcp-app";
147
+ interface CreateTinyPivotMcpServerOptions {
148
+ store?: DatasetStore;
149
+ appHtmlPath?: string;
150
+ postgres?: PostgresConfig;
151
+ licenseKey?: string;
152
+ demoToken?: string;
153
+ companionUrl?: string;
154
+ onStateChanged?: () => void;
155
+ }
156
+ declare function loadAppHtml(customPath?: string): Promise<string>;
157
+ declare function resolveLicenseKey(explicit?: string): string | undefined;
158
+ declare function createTinyPivotMcpServer(options?: CreateTinyPivotMcpServerOptions): {
159
+ server: McpServer;
160
+ store: DatasetStore;
161
+ };
162
+
163
+ declare function formatDatasetSummary(dataset: StoredDataset, companionUrl?: string): string;
164
+ declare function formatPivotSummary(dataset: StoredDataset, config: PivotConfig, companionUrl?: string): string;
165
+
166
+ 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, createTinyPivotMcpServer, executeReadOnlyPostgresQuery, formatDatasetSummary, formatPivotSummary, generateSampleSalesData, inferColumns, listPostgresTables, loadAppHtml, parseDelimitedText, resolveLicenseKey, resolveModelPricing, startCompanionServer, tokensToUsd };
package/dist/index.js ADDED
@@ -0,0 +1,41 @@
1
+ import {
2
+ APP_MIME_TYPE,
3
+ APP_RESOURCE_URI,
4
+ DEFAULT_MODEL_PRICING,
5
+ DatasetStore,
6
+ MODEL_CATALOG,
7
+ createTinyPivotMcpServer,
8
+ executeReadOnlyPostgresQuery,
9
+ formatDatasetSummary,
10
+ formatPivotSummary,
11
+ generateSampleSalesData,
12
+ inferColumns,
13
+ listPostgresTables,
14
+ loadAppHtml,
15
+ parseDelimitedText,
16
+ resolveLicenseKey,
17
+ resolveModelPricing,
18
+ startCompanionServer,
19
+ tokensToUsd
20
+ } from "./chunk-VLD3SN2I.js";
21
+ import "./chunk-2ESYSVXG.js";
22
+ export {
23
+ APP_MIME_TYPE,
24
+ APP_RESOURCE_URI,
25
+ DEFAULT_MODEL_PRICING,
26
+ DatasetStore,
27
+ MODEL_CATALOG,
28
+ createTinyPivotMcpServer,
29
+ executeReadOnlyPostgresQuery,
30
+ formatDatasetSummary,
31
+ formatPivotSummary,
32
+ generateSampleSalesData,
33
+ inferColumns,
34
+ listPostgresTables,
35
+ loadAppHtml,
36
+ parseDelimitedText,
37
+ resolveLicenseKey,
38
+ resolveModelPricing,
39
+ startCompanionServer,
40
+ tokensToUsd
41
+ };