Skip to main content

hyperdb_mcp/
readme.rs

1// Copyright (c) 2026, Salesforce, Inc. All rights reserved.
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4//! LLM-facing README returned by the `get_readme` tool.
5//!
6//! Structured as: purpose → tool index → parameter rules → SQL quirks →
7//! examples. Optimized for token efficiency: every sentence earns its
8//! place. When tools or features change, update this string and the
9//! `readme_tests.rs` coverage will fail loudly if a tool name was missed.
10
11pub 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### Introspection
168- `get_readme` — this document. Call once at the start of a session.
169
170## Parameter rules
171
172- **File paths must be absolute.** Relative paths are rejected.
173- **Identifiers fold to lowercase** unless double-quoted. `SELECT * FROM
174  Sales` reads `sales`. Use `\"Sales\"` to preserve case.
175- **`query` is read-only.** SELECT / WITH / EXPLAIN / SHOW / VALUES
176  only. For DDL / DML use `execute`.
177- **Read-only mode** (`--read-only` flag on the server) disables:
178  `execute`, all `load_*`, writable `attach_database`, `save_query`,
179  `delete_query`, `set_table_metadata`, `copy_query`, `watch_directory`,
180  `unwatch_directory`. `query`, `describe`, `sample`, `inspect_file`,
181  `export`, `chart`, `status`, `list_attached_databases`, and
182  `get_readme` always work.
183- **Table names** in `load_*` and `query_data` / `query_file` accept
184  unquoted identifiers; the server lowercases them.
185- **`copy_query` modes:** `create` requires the target not exist;
186  `append` requires it does; `replace` drops and recreates atomically.
187- **`load_file` merge mode:** `mode = \"merge\"` requires `merge_key`
188  (column name or list of column names). Rows whose key matches an
189  existing row UPDATE; non-matching rows INSERT. Columns present in
190  the incoming file but not the target are auto-added via
191  `ALTER TABLE ADD COLUMN` (nullable; existing rows fill with NULL).
192  **Type changes on existing columns are rejected** — use `replace`
193  or apply a `schema` override. The DELETE+INSERT pair is not
194  transactional (Hyper auto-commits DDL); a mid-run failure leaves
195  partial state, same as `replace`.
196
197## SQL dialect quick-reference
198
199PostgreSQL-compatible with Salesforce Data Cloud SQL extensions. Key
200differences from standard PostgreSQL:
201
202- **No `information_schema` / `pg_catalog`.** Use `describe` / `sample`
203  instead.
204- **No JSON / JSONB / UUID / SERIAL / BIGSERIAL / geometry types.**
205  Atomic types only: SMALLINT, INTEGER, BIGINT, REAL, DOUBLE PRECISION,
206  NUMERIC(p,s), BOOLEAN, TEXT, CHAR(n), VARCHAR(n), BYTES, DATE, TIME,
207  TIMESTAMP, TIMESTAMPTZ, INTERVAL, plus arrays of any atomic type.
208- **`external(path, format => '...')`** — read Parquet / CSV / Iceberg
209  directly from disk inside a query without first loading it as a
210  table. Usable in the FROM clause.
211- **`APPROX_COUNT_DISTINCT(expr)`** — fast approximate cardinality.
212- **Window functions:** all standard ones plus `modified_rank()` (like
213  `rank()` but assigns the LOWEST rank on ties). `IGNORE NULLS` /
214  `RESPECT NULLS` only on `last_value`.
215- **`DISTINCT ON (expr, ...)`, `GROUPING SETS`, `ROLLUP`, `CUBE`,
216  `FILTER (WHERE ...)`, ordered-set aggregates (`MODE()`,
217  `PERCENTILE_CONT()`, `PERCENTILE_DISC()` with `WITHIN GROUP`)** all
218  supported.
219- **CTEs:** `WITH` and `WITH RECURSIVE`. CTEs evaluate once per query.
220- **`TOP N`** is accepted alongside `LIMIT`.
221- **No AI scalar functions** (`AI_CLASSIFY`, `AI_SENTIMENT`, etc. — those
222  are Data Cloud federation features, not Hyper).
223- **No `ON CONFLICT` / `INSERT ... ON DUPLICATE KEY`.** Pass an array of
224  statements to `execute` and they run atomically inside a transaction:
225  ```
226  execute({ \"sql\": [
227    \"UPDATE settings SET value = 'dark' WHERE key = 'theme'\",
228    \"INSERT INTO settings (key, value) SELECT 'theme', 'dark'
229       WHERE NOT EXISTS (SELECT 1 FROM settings WHERE key = 'theme')\"
230  ]})
231  ```
232  Single-element arrays auto-commit (same as the legacy single-statement
233  shape). Mixing DDL with DML in one batch is rejected — Hyper aborts
234  such transactions with SQLSTATE 0A000. Issue DDL in its own `execute`
235  call. Do NOT include `BEGIN` / `COMMIT` / `ROLLBACK` / `SAVEPOINT` in
236  batch elements — the tool manages the transaction for you and these
237  are rejected up front.
238
239Full reference: https://developer.salesforce.com/docs/data/data-cloud-query-guide/references/dc-sql-reference
240
241## Examples
242
243```
244// Quickest path: query a file without loading it as a table
245query_file({
246  \"path\": \"/tmp/sales.csv\",
247  \"sql\": \"SELECT region, SUM(amount) FROM data GROUP BY region\"
248})
249
250// Inspect a file before committing to a load
251inspect_file({ \"path\": \"/tmp/sales.csv\" })
252
253// Loaded-table workflow (best when you'll run multiple queries)
254load_file({ \"path\": \"/tmp/sales.csv\", \"table\": \"sales\" })
255sample({ \"table\": \"sales\" })
256query({ \"sql\": \"SELECT region, SUM(amount) FROM sales GROUP BY region\" })
257
258// Cross-database join via attachment
259attach_database({ \"alias\": \"lookup\", \"path\": \"/data/dim.hyper\" })
260query({
261  \"sql\": \"SELECT s.region, d.country_name, SUM(s.amount) \
262          FROM sales s JOIN lookup.dim_region d ON s.region = d.code \
263          GROUP BY s.region, d.country_name\"
264})
265
266// Read Parquet directly inside a query — no load step
267query({
268  \"sql\": \"SELECT COUNT(*) FROM external('/tmp/events.parquet', format => 'parquet')\"
269})
270
271// Export a query result
272export({
273  \"sql\": \"SELECT * FROM sales WHERE amount > 1000\",
274  \"path\": \"/tmp/big_sales.parquet\",
275  \"format\": \"parquet\"
276})
277
278// Refresh existing rows + auto-add new columns (upsert by job_id).
279// Use this when you re-parsed source data with extra fields and want
280// to update the table in place without dropping it.
281load_file({
282  \"path\": \"/tmp/extract_failures-with-host.json\",
283  \"table\": \"extract_timing_failures\",
284  \"mode\": \"merge\",
285  \"merge_key\": \"job_id\"
286})
287
288// Single-statement execute (auto-commit, same as before)
289execute({
290  \"sql\": [\"DELETE FROM events WHERE created_at < CURRENT_DATE - INTERVAL '90' DAY\"]
291})
292
293// Atomic upsert — both statements commit together or both roll back
294execute({
295  \"sql\": [
296    \"UPDATE settings SET value = 'dark' WHERE key = 'theme'\",
297    \"INSERT INTO settings (key, value) SELECT 'theme', 'dark' \
298       WHERE NOT EXISTS (SELECT 1 FROM settings WHERE key = 'theme')\"
299  ],
300  \"database\": \"persistent\"
301})
302
303// Chart
304chart({
305  \"sql\": \"SELECT region, SUM(amount) AS total FROM sales GROUP BY region\",
306  \"path\": \"/tmp/sales_by_region.png\",
307  \"chart_type\": \"bar\"
308})
309```
310
311## Tips for picking the right tool
312
313- One-shot \"what's in this file?\" → `query_file` or `inspect_file`.
314- Repeated analysis on the same data → `load_file` once, then `query`.
315- File too large to fit in memory comfortably → `external()` inside
316  `query` (streams from disk).
317- Joining datasets across .hyper files → `attach_database` + `query`.
318- Materializing a query result as a new table → `copy_query`.
319- Need a picture for the user → `chart`.
320- Re-parsed source data with new columns and want to update existing
321  table in place → `load_file` with `mode: \"merge\"`.
322";