warehouse-mcp 0.1.0__tar.gz

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.
Files changed (66) hide show
  1. warehouse_mcp-0.1.0/.gitattributes +3 -0
  2. warehouse_mcp-0.1.0/.github/release-notes.md +21 -0
  3. warehouse_mcp-0.1.0/.github/workflows/ci.yml +92 -0
  4. warehouse_mcp-0.1.0/.github/workflows/eval-gate.yml +96 -0
  5. warehouse_mcp-0.1.0/.github/workflows/release.yml +80 -0
  6. warehouse_mcp-0.1.0/.gitignore +17 -0
  7. warehouse_mcp-0.1.0/LICENSE +21 -0
  8. warehouse_mcp-0.1.0/PKG-INFO +237 -0
  9. warehouse_mcp-0.1.0/README.md +195 -0
  10. warehouse_mcp-0.1.0/docker/postgres-init.sql +44 -0
  11. warehouse_mcp-0.1.0/docker-compose.yml +34 -0
  12. warehouse_mcp-0.1.0/docs/bigquery-run.md +47 -0
  13. warehouse_mcp-0.1.0/docs/code-standards.md +51 -0
  14. warehouse_mcp-0.1.0/docs/codebase-summary.md +59 -0
  15. warehouse_mcp-0.1.0/docs/deployment-guide.md +141 -0
  16. warehouse_mcp-0.1.0/docs/deployment-playbook.md +110 -0
  17. warehouse_mcp-0.1.0/docs/project-overview-pdr.md +71 -0
  18. warehouse_mcp-0.1.0/docs/project-roadmap.md +37 -0
  19. warehouse_mcp-0.1.0/docs/system-architecture.md +118 -0
  20. warehouse_mcp-0.1.0/evals/baseline.json +2553 -0
  21. warehouse_mcp-0.1.0/evals/cases.jsonl +26 -0
  22. warehouse_mcp-0.1.0/examples/bigquery.yaml +19 -0
  23. warehouse_mcp-0.1.0/examples/postgres.yaml +14 -0
  24. warehouse_mcp-0.1.0/pyproject.toml +82 -0
  25. warehouse_mcp-0.1.0/regressgate.yaml +13 -0
  26. warehouse_mcp-0.1.0/scripts/export_wikipedia_snapshot.py +65 -0
  27. warehouse_mcp-0.1.0/scripts/load_snapshot.py +158 -0
  28. warehouse_mcp-0.1.0/scripts/run_agent_eval.py +72 -0
  29. warehouse_mcp-0.1.0/server.json +27 -0
  30. warehouse_mcp-0.1.0/src/warehouse_mcp/__init__.py +3 -0
  31. warehouse_mcp-0.1.0/src/warehouse_mcp/audit.py +43 -0
  32. warehouse_mcp-0.1.0/src/warehouse_mcp/backends/__init__.py +23 -0
  33. warehouse_mcp-0.1.0/src/warehouse_mcp/backends/base.py +31 -0
  34. warehouse_mcp-0.1.0/src/warehouse_mcp/backends/bigquery_backend.py +63 -0
  35. warehouse_mcp-0.1.0/src/warehouse_mcp/backends/duckdb_backend.py +63 -0
  36. warehouse_mcp-0.1.0/src/warehouse_mcp/backends/postgres_backend.py +61 -0
  37. warehouse_mcp-0.1.0/src/warehouse_mcp/cli.py +59 -0
  38. warehouse_mcp-0.1.0/src/warehouse_mcp/config.py +189 -0
  39. warehouse_mcp-0.1.0/src/warehouse_mcp/demo/__init__.py +53 -0
  40. warehouse_mcp-0.1.0/src/warehouse_mcp/demo/data/bot_activity_daily.parquet +0 -0
  41. warehouse_mcp-0.1.0/src/warehouse_mcp/demo/data/editor_sessions.parquet +0 -0
  42. warehouse_mcp-0.1.0/src/warehouse_mcp/demo/data/editor_sessions_daily.parquet +0 -0
  43. warehouse_mcp-0.1.0/src/warehouse_mcp/demo/data/edits.parquet +0 -0
  44. warehouse_mcp-0.1.0/src/warehouse_mcp/demo/data/edits_per_minute.parquet +0 -0
  45. warehouse_mcp-0.1.0/src/warehouse_mcp/demo/data/trending_articles.parquet +0 -0
  46. warehouse_mcp-0.1.0/src/warehouse_mcp/demo/wikipedia.yaml +132 -0
  47. warehouse_mcp-0.1.0/src/warehouse_mcp/evaluation/__init__.py +26 -0
  48. warehouse_mcp-0.1.0/src/warehouse_mcp/evaluation/agent_loop.py +147 -0
  49. warehouse_mcp-0.1.0/src/warehouse_mcp/evaluation/grading.py +78 -0
  50. warehouse_mcp-0.1.0/src/warehouse_mcp/evaluation/ground_truth.py +125 -0
  51. warehouse_mcp-0.1.0/src/warehouse_mcp/evaluation/pricing.py +29 -0
  52. warehouse_mcp-0.1.0/src/warehouse_mcp/evaluation/regressgate_target.py +116 -0
  53. warehouse_mcp-0.1.0/src/warehouse_mcp/redaction.py +30 -0
  54. warehouse_mcp-0.1.0/src/warehouse_mcp/semantic.py +119 -0
  55. warehouse_mcp-0.1.0/src/warehouse_mcp/server.py +154 -0
  56. warehouse_mcp-0.1.0/src/warehouse_mcp/service.py +258 -0
  57. warehouse_mcp-0.1.0/src/warehouse_mcp/sql_guard.py +212 -0
  58. warehouse_mcp-0.1.0/tests/conftest.py +68 -0
  59. warehouse_mcp-0.1.0/tests/test_auth_redaction_cli.py +63 -0
  60. warehouse_mcp-0.1.0/tests/test_bigquery_parity.py +65 -0
  61. warehouse_mcp-0.1.0/tests/test_error_scrubbing.py +37 -0
  62. warehouse_mcp-0.1.0/tests/test_evaluation.py +278 -0
  63. warehouse_mcp-0.1.0/tests/test_postgres_parity.py +235 -0
  64. warehouse_mcp-0.1.0/tests/test_red_team.py +300 -0
  65. warehouse_mcp-0.1.0/tests/test_server.py +110 -0
  66. warehouse_mcp-0.1.0/tests/test_sql_guard.py +170 -0
@@ -0,0 +1,3 @@
1
+ * text=auto eol=lf
2
+ *.parquet binary
3
+ *.png binary
@@ -0,0 +1,21 @@
1
+ First release of warehouse-mcp: governed, read-only MCP access to DuckDB, Postgres and BigQuery
2
+ for AI agents.
3
+
4
+ - **Install:** `uvx warehouse-mcp --demo` serves about 100k live Wikipedia edits with no setup.
5
+ `--config` serves your own warehouse.
6
+ - **Guard:**
7
+ - one read-only statement over declared datasets only;
8
+ - a function allowlist;
9
+ - CTE references resolved by scope;
10
+ - every dataset rewritten into a policy subquery with declared columns, salted pseudonyms
11
+ for personal data (conditional with `pii_when`) and the role's row filter.
12
+ - **Safeguards in each engine:**
13
+ - DuckDB is read-only with file access disabled;
14
+ - Postgres uses read-only transactions and grants;
15
+ - BigQuery queries are dry-run and capped with `maximum_bytes_billed`.
16
+ - **Evidence:**
17
+ - 104 red-team attempts per engine with 0 leaks;
18
+ - 15 parity queries return identical results on DuckDB, Postgres and BigQuery;
19
+ - the Claude Haiku 5.5 agent eval scored 78/78 at $0.0016 per question, gated by regressgate.
20
+ - **Fixed before release:** the red-team suite and an independent review found five gaps, all
21
+ now covered by regression tests. Details are in the README.
@@ -0,0 +1,92 @@
1
+ name: ci
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ concurrency:
12
+ group: ci-${{ github.ref }}
13
+ cancel-in-progress: true
14
+
15
+ jobs:
16
+ lint-and-types:
17
+ runs-on: ubuntu-latest
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ - uses: actions/setup-python@v5
21
+ with:
22
+ python-version: "3.11"
23
+ cache: pip
24
+ cache-dependency-path: pyproject.toml
25
+ - run: python -m pip install -e ".[dev,eval]"
26
+ - run: ruff check src tests scripts
27
+ - run: mypy
28
+
29
+ tests:
30
+ runs-on: ubuntu-latest
31
+ strategy:
32
+ fail-fast: false
33
+ matrix:
34
+ python-version: ["3.11", "3.13"]
35
+ services:
36
+ # Same image and credentials as docker-compose.yml. Passwords are local-only
37
+ # placeholders: this container lives for one job and is reachable only from the runner.
38
+ postgres:
39
+ image: postgres:16.4-alpine
40
+ env:
41
+ POSTGRES_DB: warehouse
42
+ POSTGRES_USER: postgres
43
+ POSTGRES_PASSWORD: local-only-superuser-password
44
+ ports:
45
+ - 55432:5432
46
+ options: >-
47
+ --health-cmd "pg_isready -h 127.0.0.1 -U postgres -d warehouse"
48
+ --health-interval 2s --health-timeout 3s --health-retries 30
49
+ env:
50
+ # Set for the whole job, so the Postgres parity and red-team tests run instead of skipping.
51
+ WAREHOUSE_MCP_POSTGRES_DSN: postgresql://mcp_reader:local-only-reader-password@127.0.0.1:55432/warehouse
52
+ steps:
53
+ - uses: actions/checkout@v4
54
+ - uses: actions/setup-python@v5
55
+ with:
56
+ python-version: ${{ matrix.python-version }}
57
+ cache: pip
58
+ cache-dependency-path: pyproject.toml
59
+ - run: python -m pip install -e ".[dev,eval]"
60
+ - name: Create schema and roles
61
+ # Service containers start before checkout, so the init script cannot be mounted.
62
+ env:
63
+ PGPASSWORD: local-only-superuser-password
64
+ run: psql -v ON_ERROR_STOP=1 -h 127.0.0.1 -p 55432 -U postgres -d warehouse
65
+ -f docker/postgres-init.sql
66
+ - name: Load the snapshot into Postgres
67
+ run: python scripts/load_snapshot.py
68
+ - run: pytest -rxXs
69
+
70
+ build:
71
+ runs-on: ubuntu-latest
72
+ steps:
73
+ - uses: actions/checkout@v4
74
+ - uses: actions/setup-python@v5
75
+ with:
76
+ python-version: "3.11"
77
+ - run: python -m pip install build
78
+ - run: python -m build
79
+ - name: Wheel ships the demo snapshot and config
80
+ run: |
81
+ set -euo pipefail
82
+ listing=$(unzip -l dist/*.whl)
83
+ for file in wikipedia.yaml data/edits.parquet data/editor_sessions.parquet \
84
+ data/edits_per_minute.parquet data/bot_activity_daily.parquet \
85
+ data/trending_articles.parquet data/editor_sessions_daily.parquet; do
86
+ grep -q "warehouse_mcp/demo/$file" <<<"$listing" || { echo "missing: $file"; exit 1; }
87
+ done
88
+ echo "$listing" | grep warehouse_mcp/demo/
89
+ - uses: actions/upload-artifact@v4
90
+ with:
91
+ name: dist
92
+ path: dist/
@@ -0,0 +1,96 @@
1
+ name: eval-gate
2
+
3
+ # Live agent evals spend LLM credits (Haiku 5.5: well under $0.01 per question per trial),
4
+ # so they run on demand: manually, or on a pull request when it gets the `run-evals` label.
5
+ # mode=baseline run the suite and upload the report as an artifact; commit it as
6
+ # evals/baseline.json to set the reference.
7
+ # mode=gate run the suite and compare it against the committed evals/baseline.json.
8
+ on:
9
+ workflow_dispatch:
10
+ inputs:
11
+ mode:
12
+ description: baseline (produce evals/baseline.json) or gate (compare against it)
13
+ type: choice
14
+ options: [gate, baseline]
15
+ default: gate
16
+ repeats:
17
+ description: Trials per question
18
+ default: "3"
19
+ model:
20
+ description: Anthropic model id
21
+ default: claude-haiku-5-5
22
+ pull_request:
23
+ types: [labeled]
24
+
25
+ permissions:
26
+ contents: read
27
+ pull-requests: write
28
+
29
+ concurrency:
30
+ group: eval-gate-${{ github.ref }}
31
+ cancel-in-progress: true
32
+
33
+ jobs:
34
+ eval:
35
+ if: github.event_name == 'workflow_dispatch' || github.event.label.name == 'run-evals'
36
+ runs-on: ubuntu-latest
37
+ timeout-minutes: 30
38
+ env:
39
+ ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
40
+ WAREHOUSE_MCP_EVAL_MODEL: ${{ inputs.model || 'claude-haiku-5-5' }}
41
+ MODE: ${{ inputs.mode || 'gate' }}
42
+ REPEATS: ${{ inputs.repeats || '3' }}
43
+ steps:
44
+ - uses: actions/checkout@v4
45
+ - uses: actions/setup-python@v5
46
+ with:
47
+ python-version: "3.12"
48
+ cache: pip
49
+ - name: Check the API key secret is set
50
+ run: |
51
+ if [ -z "$ANTHROPIC_API_KEY" ]; then
52
+ echo "::error::Add an ANTHROPIC_API_KEY repository secret to run the eval gate."
53
+ exit 1
54
+ fi
55
+ - name: Check the baseline exists
56
+ if: env.MODE == 'gate'
57
+ run: |
58
+ if [ ! -f evals/baseline.json ]; then
59
+ echo "::error::evals/baseline.json is missing. Run this workflow with mode=baseline, download the eval-report artifact and commit it as evals/baseline.json."
60
+ exit 1
61
+ fi
62
+ - run: pip install -e ".[eval]"
63
+ - name: Build the demo database
64
+ run: python -c "from warehouse_mcp.demo import demo_config_path; demo_config_path()"
65
+
66
+ - name: Run the suite (baseline)
67
+ if: env.MODE == 'baseline'
68
+ run: |
69
+ regressgate run --repeats "$REPEATS" --out .regressgate/baseline.json \
70
+ --markdown .regressgate/baseline.md
71
+ cat .regressgate/baseline.md >> "$GITHUB_STEP_SUMMARY"
72
+ - name: Upload the baseline report
73
+ if: env.MODE == 'baseline'
74
+ uses: actions/upload-artifact@v4
75
+ with:
76
+ name: eval-report
77
+ path: |
78
+ .regressgate/baseline.json
79
+ .regressgate/baseline.md
80
+ .regressgate/eval-audit.jsonl
81
+ if-no-files-found: error
82
+
83
+ - name: Run the suite and gate against the baseline
84
+ if: env.MODE == 'gate'
85
+ uses: tantn89/regressgate@v0.1.0
86
+ with:
87
+ install: regressgate==0.1.0
88
+ baseline: evals/baseline.json
89
+ repeats: ${{ env.REPEATS }}
90
+ - name: Upload the gate report
91
+ if: always() && env.MODE == 'gate'
92
+ uses: actions/upload-artifact@v4
93
+ with:
94
+ name: eval-gate-report
95
+ path: .regressgate/
96
+ if-no-files-found: ignore
@@ -0,0 +1,80 @@
1
+ name: release
2
+
3
+ # Push a tag like v0.1.0 to build the wheel, publish it to PyPI (trusted publishing: no stored
4
+ # token), list the server in the MCP Registry (GitHub OIDC) and create the GitHub release.
5
+ on:
6
+ push:
7
+ tags: ["v*"]
8
+
9
+ permissions:
10
+ contents: read
11
+
12
+ jobs:
13
+ build:
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: "3.12"
20
+ - name: Check the tag matches the package and server.json versions
21
+ run: |
22
+ version=$(python -c "import re,pathlib;print(re.search(r'__version__ = \"(.+?)\"', pathlib.Path('src/warehouse_mcp/__init__.py').read_text()).group(1))")
23
+ test "v$version" = "$GITHUB_REF_NAME" || { echo "::error::tag $GITHUB_REF_NAME != package $version"; exit 1; }
24
+ python -c "import json,sys;d=json.load(open('server.json'));v=sys.argv[1];assert d['version']==v and all(p['version']==v for p in d['packages']), 'server.json version mismatch'" "$version"
25
+ - run: pip install build
26
+ - run: python -m build
27
+ - name: The wheel carries the demo data
28
+ run: |
29
+ for f in edits editor_sessions edits_per_minute bot_activity_daily trending_articles editor_sessions_daily; do
30
+ unzip -l dist/*.whl | grep -q "warehouse_mcp/demo/data/$f.parquet" || { echo "::error::missing $f.parquet"; exit 1; }
31
+ done
32
+ - uses: actions/upload-artifact@v4
33
+ with:
34
+ name: dist
35
+ path: dist/
36
+
37
+ pypi:
38
+ needs: build
39
+ runs-on: ubuntu-latest
40
+ environment:
41
+ name: pypi
42
+ url: https://pypi.org/p/warehouse-mcp
43
+ permissions:
44
+ id-token: write
45
+ steps:
46
+ - uses: actions/download-artifact@v4
47
+ with:
48
+ name: dist
49
+ path: dist/
50
+ - uses: pypa/gh-action-pypi-publish@release/v1
51
+
52
+ mcp-registry:
53
+ needs: pypi
54
+ runs-on: ubuntu-latest
55
+ permissions:
56
+ id-token: write
57
+ contents: read
58
+ steps:
59
+ - uses: actions/checkout@v4
60
+ - name: Install mcp-publisher
61
+ run: |
62
+ curl -fsSL "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_linux_amd64.tar.gz" | tar xz mcp-publisher
63
+ - run: ./mcp-publisher login github-oidc
64
+ # The registry checks that the PyPI package README carries `mcp-name: <server name>`.
65
+ - run: ./mcp-publisher publish
66
+
67
+ github-release:
68
+ needs: pypi
69
+ runs-on: ubuntu-latest
70
+ permissions:
71
+ contents: write
72
+ steps:
73
+ - uses: actions/checkout@v4
74
+ - uses: actions/download-artifact@v4
75
+ with:
76
+ name: dist
77
+ path: dist/
78
+ - env:
79
+ GH_TOKEN: ${{ github.token }}
80
+ run: gh release create "$GITHUB_REF_NAME" dist/* --title "$GITHUB_REF_NAME" --notes-file .github/release-notes.md
@@ -0,0 +1,17 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .env
5
+ .env.*
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ .pytest_cache/
10
+ .mypy_cache/
11
+ .ruff_cache/
12
+ *.duckdb
13
+ *.duckdb.wal
14
+ audit*.jsonl
15
+ .claude/
16
+ plans/
17
+ .regressgate/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tan Tran
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,237 @@
1
+ Metadata-Version: 2.5
2
+ Name: warehouse-mcp
3
+ Version: 0.1.0
4
+ Summary: Governed, read-only MCP access to DuckDB, Postgres and BigQuery for AI agents: semantic layer, SQL guard, row policies, PII pseudonymization, audit log.
5
+ Project-URL: Homepage, https://github.com/tantn89/warehouse-mcp
6
+ Project-URL: Issues, https://github.com/tantn89/warehouse-mcp/issues
7
+ Author: Tan Tran
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: ai-agents,bigquery,data-governance,data-warehouse,duckdb,mcp,model-context-protocol,pii,postgres,text-to-sql
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Topic :: Database
18
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
19
+ Classifier: Typing :: Typed
20
+ Requires-Python: >=3.11
21
+ Requires-Dist: duckdb>=1.4
22
+ Requires-Dist: mcp<3,>=2.3
23
+ Requires-Dist: pydantic>=2.8
24
+ Requires-Dist: pyyaml>=6.0
25
+ Requires-Dist: sqlglot<31,>=30.27
26
+ Provides-Extra: bigquery
27
+ Requires-Dist: google-cloud-bigquery>=3.25; extra == 'bigquery'
28
+ Provides-Extra: dev
29
+ Requires-Dist: anyio>=4.4; extra == 'dev'
30
+ Requires-Dist: google-cloud-bigquery>=3.25; extra == 'dev'
31
+ Requires-Dist: mypy>=1.11; extra == 'dev'
32
+ Requires-Dist: psycopg[binary]>=3.2; extra == 'dev'
33
+ Requires-Dist: pytest>=8.3; extra == 'dev'
34
+ Requires-Dist: ruff>=0.6; extra == 'dev'
35
+ Requires-Dist: types-pyyaml>=6.0; extra == 'dev'
36
+ Provides-Extra: eval
37
+ Requires-Dist: anthropic>=0.70; extra == 'eval'
38
+ Requires-Dist: regressgate>=0.1; extra == 'eval'
39
+ Provides-Extra: postgres
40
+ Requires-Dist: psycopg[binary]>=3.2; extra == 'postgres'
41
+ Description-Content-Type: text/markdown
42
+
43
+ # warehouse-mcp
44
+
45
+ **Give AI agents your warehouse without giving them your warehouse.**
46
+
47
+ An MCP server that lets Claude, Cursor or any MCP client query DuckDB, Postgres or BigQuery
48
+ through a governed, read-only layer:
49
+ - a semantic model, so agents ask in business terms;
50
+ - a SQL guard that an agent cannot talk into writing, reading files or leaving its lane;
51
+ - per-role row policies;
52
+ - pseudonymized personal data;
53
+ - an audit log;
54
+ - a cost cap.
55
+
56
+ Every claim below is backed by a test or a measured run.
57
+
58
+ <!-- mcp-name: io.github.tantn89/warehouse-mcp -->
59
+
60
+ ![ci](https://github.com/tantn89/warehouse-mcp/actions/workflows/ci.yml/badge.svg)
61
+ ![python](https://img.shields.io/badge/python-3.11%E2%80%933.13-blue)
62
+ ![mcp](https://img.shields.io/badge/MCP-2026--07--28-purple)
63
+ ![license](https://img.shields.io/badge/license-MIT-green)
64
+
65
+ | What was checked | Result | Evidence |
66
+ |---|---|---|
67
+ | 104 bypass attempts (exfiltration, row-filter escapes, PII probes, file and system access, statement smuggling, resource abuse) | **0 leaks on DuckDB and on Postgres** | [`tests/test_red_team.py`](tests/test_red_team.py), run in CI |
68
+ | Same 15 queries on three engines | **Identical results** on DuckDB, Postgres and BigQuery | [parity tests](tests/test_postgres_parity.py), [BigQuery run](docs/bigquery-run.md) |
69
+ | Writes with the SQL guard bypassed | Refused by the engine itself: read-only transaction, then grants | [`test_postgres_parity.py`](tests/test_postgres_parity.py) |
70
+ | A careless agent query on a multi-terabyte table | Refused before billing: *"would scan 4.65 GB, above the 1.00 GB cap"* | [BigQuery run](docs/bigquery-run.md) |
71
+ | A Claude Haiku 5.5 agent answering over MCP, graded against SQL ground truth (26 cases, 3 trials each) | **78/78 correct**, including 6 governance cases, at **$0.0016 per question**, p95 6.3 s. Gated by [regressgate](https://github.com/tantn89/regressgate) | [`evals/cases.jsonl`](evals/cases.jsonl) |
72
+
73
+ ---
74
+
75
+ ## Try it in one line
76
+
77
+ The bundled demo serves about 100k live Wikipedia edits, captured by
78
+ [realtime-lakehouse](https://github.com/tantn89/realtime-lakehouse), from a local DuckDB file.
79
+ No keys are needed.
80
+
81
+ ```json
82
+ {
83
+ "mcpServers": {
84
+ "warehouse": { "command": "uvx", "args": ["warehouse-mcp", "--demo"] }
85
+ }
86
+ }
87
+ ```
88
+
89
+ Put that in Claude Desktop's config, or run `claude mcp add warehouse -- uvx warehouse-mcp --demo`.
90
+ Then ask *"Which wikis had the most bot activity, and how many distinct editors did each have?"*
91
+
92
+ What the agent sees, taken from real tool calls on the demo:
93
+
94
+ ```text
95
+ warehouse_query_metrics(dataset="edits", metrics=["edits","editors","bot_share"], dimensions=["wiki"])
96
+ wiki edits editors bot_share
97
+ enwiktionary 41594 46 0.994
98
+ commonswiki 16053 224 0.849
99
+ enwiki 9576 1401 0.489
100
+
101
+ warehouse_run_sql("SELECT editor, count(*) AS edits FROM edits GROUP BY editor ORDER BY edits DESC")
102
+ pii_6b19c4a15ccf 41335 <- a pseudonym: counts and joins are exact, the name never leaves
103
+ pii_6a8d5fd6c44b 9638
104
+
105
+ warehouse_run_sql("SELECT * FROM edits; DROP TABLE edits")
106
+ Error: Send exactly one statement; multiple statements are not allowed.
107
+ warehouse_run_sql("SELECT pg_read_file('/etc/passwd') FROM edits")
108
+ Error: Function pg_read_file() is not allowed. Use standard SQL functions (...)
109
+ ```
110
+
111
+ ## How it works
112
+
113
+ ```mermaid
114
+ flowchart LR
115
+ A[Agent] -->|MCP: stdio, or HTTP + bearer key| T[4 read-only tools]
116
+ T --> R[Role<br/>from the key]
117
+ R --> G[SQL guard<br/>sqlglot, backend dialect]
118
+ G -->|rewrite each dataset into| P[Policy subquery<br/>declared columns only<br/>salted pseudonyms<br/>role row filter]
119
+ P --> B[(Backend safeguards<br/>DuckDB: read-only, no file access<br/>Postgres: read-only txn + grants<br/>BigQuery: dry run + byte cap)]
120
+ B --> X[Cell cap + email/phone redaction]
121
+ X --> L[Audit log<br/>no values, no salt]
122
+ L --> A
123
+ ```
124
+
125
+ **Pseudonymize at the source, not in the output.** The guard rewrites every dataset reference
126
+ into a subquery that replaces personal columns with a salted hash, inside the warehouse. As a
127
+ result:
128
+ - `count(DISTINCT editor)` stays exact;
129
+ - joins on pseudonyms work across datasets;
130
+ - a probe like `WHERE editor = 'Alice'` matches nothing, because the comparison runs against
131
+ the hash;
132
+ - names never cross the wire.
133
+
134
+ Masking the output after lineage analysis can be bypassed with aliases, expressions or
135
+ functions. Here the raw column is simply not reachable.
136
+
137
+ **Each layer is designed to hold if the layer before it fails.** The guard is the first layer:
138
+ - single statements only;
139
+ - SELECT only;
140
+ - declared datasets only;
141
+ - function allowlist;
142
+ - CTE references resolved by scope, so `WITH t AS (SELECT * FROM t)` cannot reach the real
143
+ table `t`;
144
+ - capped LIMIT.
145
+
146
+ Behind it, each engine is locked down on its own, and the tests prove it with the guard
147
+ bypassed.
148
+
149
+ The tools:
150
+
151
+ | Tool | Use |
152
+ |---|---|
153
+ | `warehouse_list_datasets` | What the caller's role may query, with each dataset's grain and metrics |
154
+ | `warehouse_describe_dataset` | Columns, which are pseudonymized, row policy, and 3 sample rows |
155
+ | `warehouse_query_metrics` | **Preferred path.** Named metrics by dimensions and time buckets. The SQL is built as a syntax tree, so filter values are never SQL |
156
+ | `warehouse_run_sql` | One guarded SELECT, for questions metrics cannot express |
157
+
158
+ ## What the red team found
159
+
160
+ The adversarial suite found three real gaps outside the SQL guard. All three are fixed and kept
161
+ as regression tests:
162
+
163
+ 1. **ReDoS after the timeout.** The email-redaction regex backtracked quadratically, and a
164
+ 1 MB string from `repeat('x', 1000000)` would have held the server for about 12 minutes. It
165
+ ran *after* the warehouse timeout, so nothing stopped it. The fix bounds the regex repeats
166
+ and cuts cells before redaction.
167
+ 2. **A single huge row skipped the result cap.** The fix halves the longest text cells until
168
+ the row fits.
169
+ 3. **Pseudonyms could be linked back to names.** An edit to one's own `User:` page pairs a
170
+ pseudonym with a title that contains the name. That re-identified 5.7% of editors in the
171
+ snapshot where it was found. The fix
172
+ adds conditional PII (`pii_when: "namespace IN (2, 3)"`) for user-page titles and
173
+ pseudonymizes edit summaries.
174
+
175
+ An independent review by a second model then found a gap the suite had missed, this time *in*
176
+ the guard:
177
+
178
+ 4. **An alias could disguise a real table as a CTE.** In
179
+ `WITH x AS (...) SELECT * FROM edits_raw x, x`, the guard matched CTE references by alias,
180
+ so the physical table skipped the policy rewrite. CTE references are now resolved by table
181
+ name within each scope, and aliasing a real table to a visible CTE name is refused.
182
+ 5. **Engine errors quoted data.** A message such as `Could not convert string '<value>'`
183
+ bypassed result redaction and reached both the agent and the audit log. Error messages now
184
+ lose their quoted values and are redacted and capped.
185
+
186
+ Running the parity cases on BigQuery found one more problem, a correctness bug rather than a
187
+ leak: time literals were cast to `DATETIME` against `TIMESTAMP` columns. It is fixed.
188
+
189
+ ## Configure your own warehouse
190
+
191
+ ```yaml
192
+ extends: demo:wikipedia # or write datasets/roles from scratch
193
+ connection: {kind: postgres, dsn_env: WAREHOUSE_MCP_POSTGRES_DSN}
194
+
195
+ roles:
196
+ - {name: analyst, datasets: "*", api_key_env: KEY_ANALYST}
197
+ - name: enwiki_partner # an external partner sees one wiki only
198
+ datasets: [edits, edits_per_minute]
199
+ row_filters: {edits: "wiki = 'enwiki'", edits_per_minute: "wiki = 'enwiki'"}
200
+ api_key_env: KEY_PARTNER
201
+ - {name: trust_and_safety, datasets: "*", pii_clearance: true, api_key_env: KEY_TS}
202
+ ```
203
+
204
+ Datasets declare their columns, which ones are `pii` or `pii_when`, which are `free_text`, and
205
+ named metrics. Undeclared columns do not exist for the agent. Over HTTP
206
+ (`warehouse-mcp --config my.yaml --transport http`) each bearer key selects a role. Keys come
207
+ from environment variables; the config holds no secrets.
208
+
209
+ Setup for each backend, Claude Desktop snippets and the eval workflow are in
210
+ [docs/deployment-guide.md](docs/deployment-guide.md). For rolling this out at a company
211
+ (discovery, access model, staged rollout, success metrics, incident runbook), see
212
+ [docs/deployment-playbook.md](docs/deployment-playbook.md).
213
+
214
+ ## Development
215
+
216
+ ```bash
217
+ pip install -e ".[dev]"
218
+ pytest # DuckDB; Postgres/BigQuery suites skip without a DSN
219
+ docker compose up -d && python scripts/load_snapshot.py --target postgres
220
+ WAREHOUSE_MCP_POSTGRES_DSN=postgresql://mcp_reader:local-only-reader-password@127.0.0.1:55432/warehouse pytest
221
+ ```
222
+
223
+ [Architecture and threat model](docs/system-architecture.md) ·
224
+ [codebase map](docs/codebase-summary.md) · [roadmap](docs/project-roadmap.md)
225
+
226
+ ## Limits
227
+
228
+ - Phone-number redaction applies to columns tagged `free_text`. An alias such as `comment AS c`
229
+ loses the phone pass; it keeps email redaction, which applies everywhere.
230
+ - HTTP uses static bearer keys and plain HTTP. Put TLS in front of it. OAuth resource-server
231
+ mode is on the roadmap.
232
+ - Snowflake is on the roadmap.
233
+
234
+ ## Data
235
+
236
+ The demo data comes from Wikimedia's public recent-changes stream, licensed CC BY-SA 4.0.
237
+ Code is MIT.