1pub const README: &str = "\
12# HyperDB MCP
13
14## What this is
15
16HyperDB MCP is an in-process SQL analytics service powered by the Tableau
17Hyper database engine. Load data from CSV / JSON / JSONL / Parquet /
18Arrow IPC / Apache Iceberg, query with PostgreSQL-compatible SQL
19(Salesforce Data Cloud SQL dialect), and export results to Parquet,
20Iceberg, Arrow IPC, CSV, or .hyper.
21
22## When to use this MCP
23
24Whenever the user asks to analyze tabular data, run SQL, transform a
25file, or build a chart from a query. Prefer this MCP over ad-hoc Python
26or shell pipelines: it parses files faster, runs SQL natively, and keeps
27intermediate state in a workspace database the LLM can re-query without
28re-loading.
29
30## Workspace model — queryable memory
31
32Every session has TWO databases, plus optional user-attached ones:
33
34- **Ephemeral primary** (default destination). Created fresh per
35 session, deleted on exit. Unqualified SQL routes here. Use as
36 scratch space for exploratory work, intermediate transformations,
37 and one-off analysis the user doesn't need to keep.
38- **Persistent database** (alias `\"persistent\"`). Survives across
39 sessions — this is your **long-term structured memory**. Store
40 reference tables, accumulated results, user preferences, learned
41 facts, or any data you want to recall in future conversations.
42 Unlike flat-text memory, persistent data is **queryable**: you can
43 JOIN, filter, aggregate, and reason over it with SQL. Disabled
44 when the server runs with `--ephemeral-only`.
45- **User-attached writable databases** via `attach_database` with
46 `writable: true`. Each lives in its own `.hyper` file under a
47 user-chosen alias.
48
49### Persistent as memory — when and how to use it
50
51Store data in persistent whenever:
52- The user says \"remember this\", \"save this\", \"keep this\"
53- You produce a useful reference table (lookups, configs, mappings)
54- You accumulate results across multiple conversations
55- You want to recall context in future sessions
56
57Retrieve from persistent whenever:
58- You need context from a prior session
59- The user asks \"what do we have?\" or \"show me what's saved\"
60- You want to JOIN current scratch work against historical data
61
62```
63// Save something for later
64load_data({ table: \"project_decisions\", data: \"[...]\", persist: true })
65
66// Recall it next session
67query({ sql: \"SELECT * FROM project_decisions\", database: \"persistent\" })
68
69// Cross-reference: join session scratch with persistent memory
70query({ sql: \"SELECT s.*, p.decision FROM scratch_analysis s \
71 JOIN \\\"persistent\\\".\\\"public\\\".\\\"project_decisions\\\" p \
72 ON s.topic = p.topic\" })
73```
74
75### Routing data to a destination
76
77- **`database` parameter** (preferred for tools that build their own
78 SQL): `query`, `execute`, `load_data`, `load_file`, `load_files`,
79 `watch_directory`, `describe`, `sample`, `chart`, `export`, and
80 `set_table_metadata` accept `database: \"persistent\"`,
81 `database: \"local\"` (= primary), or any user-attached writable
82 alias. Case-insensitive. Defaults to primary.
83- **`persist: true` shorthand** on `load_data`, `load_file`,
84 `load_files`, `watch_directory` — equivalent to
85 `database: \"persistent\"`.
86- **Fully-qualified SQL** for power users:
87 `INSERT INTO \"persistent\".\"public\".\"customers\" SELECT ...`
88
89Each writable database carries its own `_table_catalog` table that
90tracks load tool, params, timestamps, and any prose metadata set via
91`set_table_metadata` — lazily seeded on first ingest into that DB.
92`detach_database` rejects with `InvalidArgument` if any active
93watcher targets the alias; call `unwatch_directory` first.
94
95## Tool index
96
97### Query
98- `query` — run a read-only SELECT / WITH / EXPLAIN / SHOW / VALUES.
99- `execute` — run one or more DDL/DML statements as an atomic batch.
100 `sql` is an array; multi-element batches run inside a transaction
101 (all commit or all roll back). Response shape:
102 `{ statements, affected_rows, per_statement: [{sql, affected_rows,
103 elapsed_ms}], stats: {operation, elapsed_ms} }`. Disabled in
104 read-only mode.
105- `query_data` — ingest inline JSON or CSV and run one SQL query in a
106 single call (table is temporary).
107- `query_file` — same as `query_data` but reads from a file path. The
108 fastest path when the user asks \"what's in this file?\".
109
110### Load
111- `load_file` — load one CSV / JSON / JSONL / Parquet / Arrow IPC file
112 into a named workspace table. `mode`: `replace` (default) /
113 `append` / `merge`. Use `merge` to upsert by `merge_key` (column
114 name or list); new columns in the incoming file are auto-added via
115 `ALTER TABLE`.
116- `load_files` — load many files in parallel. Files must share a
117 schema (or be unioned). `merge` mode is not supported here — call
118 `load_file` per-file if you need merge.
119- `load_data` — load inline JSON / CSV into a named workspace table.
120- `load_iceberg` — load an Apache Iceberg table by absolute path to its
121 root directory; supports snapshot pinning via `metadata_filename` or
122 `version_as_of`.
123
124### Inspect
125- `describe` — list workspace tables (no args) or describe one table
126 (`table` arg) with columns, types, row count, and prose metadata.
127- `sample` — return schema + first N rows of a table. Use this before
128 writing a non-trivial query.
129- `inspect_file` — dry-run schema inference on a CSV / Parquet / Arrow
130 IPC file without loading it.
131- `status` — plugin health, workspace path, table count, total rows,
132 disk usage, watchers, attached databases, read-only flag.
133
134### Export
135- `export` — write a table or query result to a file (Parquet, Iceberg,
136 Arrow IPC, CSV, .hyper).
137- `chart` — render a bar / line / scatter / histogram PNG from a SQL
138 query. Data must be long-format (one numeric y column; use a `series`
139 column for grouping). On line/scatter charts, DATE / TIMESTAMP /
140 TIMESTAMPTZ x columns auto-detect to a **proportional time axis**
141 (real-world gaps reflected in spacing); TEXT x falls back to evenly
142 spaced categorical mode. Pass `x_as_category: true` to force
143 categorical even on temporal data. Wide-format data must be reshaped
144 with UNION ALL.
145- `copy_query` — run a SELECT across local + attached databases and
146 insert the result into a target table (`mode`: `create`, `append`,
147 `replace`). Cross-database analytics in one tool call.
148
149### Saved queries & metadata
150- `save_query` — save a named read-only SQL query for later reuse.
151- `delete_query` — delete a named saved query.
152- `set_table_metadata` — update prose metadata (source_url, purpose,
153 notes, license, source_description) on a table catalog entry.
154
155### Multi-database
156- `attach_database` — attach an additional .hyper database under an
157 alias. Pass `writable: true` to allow writes through it.
158- `detach_database` — detach a previously attached database.
159- `list_attached_databases` — list current attachments.
160
161### Directory watching
162- `watch_directory` — watch a directory and auto-ingest matching files
163 as they appear.
164- `unwatch_directory` — stop watching a previously registered
165 directory.
166
167### Key-value store (scratchpad)
168- `kv_set` — save a variable / state / summary / JSON string under a
169 store + key (upsert).
170- `kv_get` — read a value by store + key.
171- `kv_delete` — delete a key.
172- `kv_list` — list keys in a store.
173- `kv_list_stores` — list store namespaces that hold data in a database.
174- `kv_size` — count keys in a store.
175- `kv_pop` — destructively read-and-remove the lowest-keyed entry.
176- `kv_clear` — delete all keys in a store.
177
178Every kv_* tool takes the same optional `database` parameter as the data
179tools. Omit it and the store lives in the EPHEMERAL database (lost on
180restart); pass `\"persistent\"` (or `persist: true`) to persist across
181restarts, or any attached alias to target that database. Each database
182has its own isolated set of stores. Enrich analytical tables with KV
183metadata via LEFT JOIN — always filter `kv.store_name = '<namespace>'`
184to avoid row multiplication, and keep the KV table in the same database
185as the joined table. See the `hyper://schema/kv` resource for the join
186template.
187
188### Introspection
189- `get_readme` — this document. Call once at the start of a session.
190
191## Parameter rules
192
193- **File paths must be absolute.** Relative paths are rejected.
194- **Identifiers fold to lowercase** unless double-quoted. `SELECT * FROM
195 Sales` reads `sales`. Use `\"Sales\"` to preserve case.
196- **`query` is read-only.** SELECT / WITH / EXPLAIN / SHOW / VALUES
197 only. For DDL / DML use `execute`.
198- **Read-only mode** (`--read-only` flag on the server) disables:
199 `execute`, all `load_*`, writable `attach_database`, `save_query`,
200 `delete_query`, `set_table_metadata`, `copy_query`, `watch_directory`,
201 `unwatch_directory`, and the mutating KV tools (`kv_set`, `kv_delete`,
202 `kv_pop`, `kv_clear`). `query`, `describe`, `sample`, `inspect_file`,
203 `export`, `chart`, `status`, `list_attached_databases`, and
204 `get_readme` always work.
205- **Table names** in `load_*` and `query_data` / `query_file` accept
206 unquoted identifiers; the server lowercases them.
207- **`copy_query` modes:** `create` requires the target not exist;
208 `append` requires it does; `replace` drops and recreates atomically.
209- **`load_file` merge mode:** `mode = \"merge\"` requires `merge_key`
210 (column name or list of column names). Rows whose key matches an
211 existing row UPDATE; non-matching rows INSERT. Columns present in
212 the incoming file but not the target are auto-added via
213 `ALTER TABLE ADD COLUMN` (nullable; existing rows fill with NULL).
214 **Type changes on existing columns are rejected** — use `replace`
215 or apply a `schema` override. The DELETE+INSERT pair is not
216 transactional (Hyper auto-commits DDL); a mid-run failure leaves
217 partial state, same as `replace`.
218
219## SQL dialect quick-reference
220
221PostgreSQL-compatible with Salesforce Data Cloud SQL extensions. Key
222differences from standard PostgreSQL:
223
224- **No `information_schema` / `pg_catalog`.** Use `describe` / `sample`
225 instead.
226- **No JSON / JSONB / UUID / SERIAL / BIGSERIAL / geometry types.**
227 Atomic types only: SMALLINT, INTEGER, BIGINT, REAL, DOUBLE PRECISION,
228 NUMERIC(p,s), BOOLEAN, TEXT, CHAR(n), VARCHAR(n), BYTES, DATE, TIME,
229 TIMESTAMP, TIMESTAMPTZ, INTERVAL, plus arrays of any atomic type.
230- **`external(path, format => '...')`** — read Parquet / CSV / Iceberg
231 directly from disk inside a query without first loading it as a
232 table. Usable in the FROM clause.
233- **`APPROX_COUNT_DISTINCT(expr)`** — fast approximate cardinality.
234- **Window functions:** all standard ones plus `modified_rank()` (like
235 `rank()` but assigns the LOWEST rank on ties). `IGNORE NULLS` /
236 `RESPECT NULLS` only on `last_value`.
237- **`DISTINCT ON (expr, ...)`, `GROUPING SETS`, `ROLLUP`, `CUBE`,
238 `FILTER (WHERE ...)`, ordered-set aggregates (`MODE()`,
239 `PERCENTILE_CONT()`, `PERCENTILE_DISC()` with `WITHIN GROUP`)** all
240 supported.
241- **CTEs:** `WITH` and `WITH RECURSIVE`. CTEs evaluate once per query.
242- **`TOP N`** is accepted alongside `LIMIT`.
243- **No AI scalar functions** (`AI_CLASSIFY`, `AI_SENTIMENT`, etc. — those
244 are Data Cloud federation features, not Hyper).
245- **No `ON CONFLICT` / `INSERT ... ON DUPLICATE KEY`.** Pass an array of
246 statements to `execute` and they run atomically inside a transaction:
247 ```
248 execute({ \"sql\": [
249 \"UPDATE settings SET value = 'dark' WHERE key = 'theme'\",
250 \"INSERT INTO settings (key, value) SELECT 'theme', 'dark'
251 WHERE NOT EXISTS (SELECT 1 FROM settings WHERE key = 'theme')\"
252 ]})
253 ```
254 Single-element arrays auto-commit (same as the legacy single-statement
255 shape). Mixing DDL with DML in one batch is rejected — Hyper aborts
256 such transactions with SQLSTATE 0A000. Issue DDL in its own `execute`
257 call. Do NOT include `BEGIN` / `COMMIT` / `ROLLBACK` / `SAVEPOINT` in
258 batch elements — the tool manages the transaction for you and these
259 are rejected up front.
260
261Full reference: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference
262
263## Examples
264
265```
266// Quickest path: query a file without loading it as a table
267query_file({
268 \"path\": \"/tmp/sales.csv\",
269 \"sql\": \"SELECT region, SUM(amount) FROM data GROUP BY region\"
270})
271
272// Inspect a file before committing to a load
273inspect_file({ \"path\": \"/tmp/sales.csv\" })
274
275// Loaded-table workflow (best when you'll run multiple queries)
276load_file({ \"path\": \"/tmp/sales.csv\", \"table\": \"sales\" })
277sample({ \"table\": \"sales\" })
278query({ \"sql\": \"SELECT region, SUM(amount) FROM sales GROUP BY region\" })
279
280// Cross-database join via attachment
281attach_database({ \"alias\": \"lookup\", \"path\": \"/data/dim.hyper\" })
282query({
283 \"sql\": \"SELECT s.region, d.country_name, SUM(s.amount) \
284 FROM sales s JOIN lookup.dim_region d ON s.region = d.code \
285 GROUP BY s.region, d.country_name\"
286})
287
288// Read Parquet directly inside a query — no load step
289query({
290 \"sql\": \"SELECT COUNT(*) FROM external('/tmp/events.parquet', format => 'parquet')\"
291})
292
293// Export a query result
294export({
295 \"sql\": \"SELECT * FROM sales WHERE amount > 1000\",
296 \"path\": \"/tmp/big_sales.parquet\",
297 \"format\": \"parquet\"
298})
299
300// Refresh existing rows + auto-add new columns (upsert by job_id).
301// Use this when you re-parsed source data with extra fields and want
302// to update the table in place without dropping it.
303load_file({
304 \"path\": \"/tmp/extract_failures-with-host.json\",
305 \"table\": \"extract_timing_failures\",
306 \"mode\": \"merge\",
307 \"merge_key\": \"job_id\"
308})
309
310// Single-statement execute (auto-commit, same as before)
311execute({
312 \"sql\": [\"DELETE FROM events WHERE created_at < CURRENT_DATE - INTERVAL '90' DAY\"]
313})
314
315// Atomic upsert — both statements commit together or both roll back
316execute({
317 \"sql\": [
318 \"UPDATE settings SET value = 'dark' WHERE key = 'theme'\",
319 \"INSERT INTO settings (key, value) SELECT 'theme', 'dark' \
320 WHERE NOT EXISTS (SELECT 1 FROM settings WHERE key = 'theme')\"
321 ],
322 \"database\": \"persistent\"
323})
324
325// Chart
326chart({
327 \"sql\": \"SELECT region, SUM(amount) AS total FROM sales GROUP BY region\",
328 \"path\": \"/tmp/sales_by_region.png\",
329 \"chart_type\": \"bar\"
330})
331```
332
333## Tips for picking the right tool
334
335- One-shot \"what's in this file?\" → `query_file` or `inspect_file`.
336- Repeated analysis on the same data → `load_file` once, then `query`.
337- File too large to fit in memory comfortably → `external()` inside
338 `query` (streams from disk).
339- Joining datasets across .hyper files → `attach_database` + `query`.
340- Materializing a query result as a new table → `copy_query`.
341- Need a picture for the user → `chart`.
342- Re-parsed source data with new columns and want to update existing
343 table in place → `load_file` with `mode: \"merge\"`.
344";