Warehouse MCP Server
Provides a policy-scoped, read-only interface to a DuckDB data warehouse, allowing AI agents to explore tables, inspect schemas, run SELECT queries, view lineage, and execute data quality checks while enforcing role-based masking and row filters.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Warehouse MCP Server
A Model Context Protocol server that lets AI agents explore and query a data warehouse without being able to see or change anything their role does not allow, however the query is written.
AI agent ──MCP──> warehouse-mcp (one role per process)
│ tools: whoami, list_tables, describe_table,
│ run_query, get_lineage, run_quality_checks
│
├─ 1. static guard one SELECT, known tables, no table functions
├─ 2. private snapshot only the role's tables, already masked and filtered
├─ 3. engine lockdown no files, no network, no config changes
├─ 4. read-only txn the engine refuses every write
├─ 5. limits row cap, timeout, cell and query size
└─ 6. audit log every call, allowed or deniedIt runs locally on DuckDB with a sample warehouse, so anyone can clone it, run the red-team suite and connect an MCP client.
Why this exists
Giving an agent a run_sql tool is easy. Doing it safely is the actual work, and the common
shortcut ("check that the query starts with SELECT") does not hold. While building this, the
red-team suite found two ways past that kind of check on DuckDB:
A write disguised as a SELECT. DuckDB runs
with d as (delete from t returning *) select count(*) from d, and its own statement classifier reports that statement as aSELECT. A filter on statement type lets it through, and it deletes the rows.Leaving the read-only transaction. Wrapping queries in a read-only transaction is not enough if the input may hold several statements:
commit; delete from tends the transaction and then writes outside it.
So the design does not depend on any single check being right:
Layer | What it guarantees | If this layer is bypassed |
Static guard ( | One statement, a SELECT, no write nodes anywhere in the tree, only tables the role can see, no table functions except value generators | The next three layers still hold |
Private snapshot ( | The session contains only the role's tables, with masked columns already replaced and row filters already applied. The warehouse is detached afterwards | There is nothing forbidden left to read |
Engine lockdown |
| No file, network, |
Execution path | Exactly one statement, run inside | The engine itself rejects writes |
Masking is the clearest example of why. Rewriting a user's SQL to mask columns has to get
select *, aliases, expressions, subqueries and joins all right. Here the data is masked
before the query exists, so there is nothing to get wrong at query time.
Related MCP server: sqlgate-mcp
Quick start
git clone https://github.com/Nithinreddy8333/warehouse-mcp-server
cd warehouse-mcp-server
python -m venv .venv && source .venv/bin/activate
make install
make roles # what each role can see
make demo # scripted agent session over stdio: answers and refusals
make redteam # attack the server
make test # 55 testsConnect a real MCP client by registering the server as a stdio command. Most clients take a command, arguments and environment variables, for example:
{
"mcpServers": {
"warehouse": {
"command": "/absolute/path/to/.venv/bin/warehouse-mcp",
"args": ["serve", "--role", "analyst"],
"env": {
"WAREHOUSE_PATH": "/absolute/path/to/warehouse/warehouse.duckdb",
"POLICY_PATH": "/absolute/path/to/config/policy.yaml",
"CHECKS_PATH": "/absolute/path/to/config/checks.yaml",
"MODELS_DIR": "/absolute/path/to/warehouse/models",
"AUDIT_LOG": "/absolute/path/to/logs/audit.jsonl"
}
}
}
}Check your client's documentation for where this configuration lives.
Tools
Tool | Purpose |
| The role, its limits, readable tables, masked columns and row-filtered tables. Agents are told to call this first |
| Readable tables with row counts and descriptions |
| Columns, types, which are masked, and sample rows |
| One read-only DuckDB |
| Upstream and downstream tables, parsed from the SQL that builds the warehouse |
| Declared checks (unique, not null, accepted values, freshness, row counts) |
Resources: warehouse://catalog and warehouse://policy. All tools are annotated read-only.
A refused call returns a tool error with a reason code, such as
Denied (table_not_available): The table 'hr.salaries' is not available to this role.
A forbidden table and a table that does not exist produce the same message.
Access policy
config/policy.yaml is deny-by-default:
roles:
analyst:
tables: ["marts.*", "staging.*"]
masks:
"*.email": email_domain # ***@domain
"*.phone": redact # ***
"*.full_name": hash # salted, stable, still joinable
support_de:
tables: ["marts.dim_customers", "marts.fct_orders"]
masks: {"*.phone": redact}
row_filters:
"marts.dim_customers": "country = 'DE'"
limits: {max_rows: 50}Nobody is granted hr.*, so no role can read salaries. The role is fixed when the server
process starts (--role or MCP_ROLE); a client cannot choose or change it.
What an analyst gets back from select email, phone, full_name, country from marts.dim_customers:
{"email": "***@corp-secret.example", "phone": "***", "full_name": "h_3b8d5fcf2231", "country": "CA"}(The hash depends on the salt, so yours will differ.)
Red-team results
make redteam sends every case in evals/red_team.yaml through a real MCP client and checks
three things. The sample data plants known values where no role should see them, and the
forbidden values for each role are read straight from the warehouse, so a leak is detected by
content, not by trusting the verdict.
Measure | Result |
Attacks sent | 71 |
Attacks denied | 71 |
SQL attacks re-run with the static guard switched off | 66 |
... stopped by the engine layers alone | 55 |
... ran, but leaked nothing and wrote nothing | 11 |
Masking and row-filter probes passed | 11 of 11 |
Legitimate calls allowed | 21 of 21 |
Responses containing a forbidden value | 0 |
Cases that modified data | 0 |
Files written outside the session | 0 |
The attacks cover forbidden tables (plain, quoted, in unions, subqueries, CTEs and joins),
catalog qualifiers, query() and query_table(), metadata functions, file and network
readers, COPY, ATTACH, extensions, every kind of write including the CTE forms above,
multiple statements with comment tricks, COMMIT/ROLLBACK escapes, configuration changes,
a runaway cross join, an oversized query, and injection through tool arguments.
The 11 that ran with the guard off are reads of the session's own metadata
(information_schema, duckdb_tables(), show tables and similar), which lists only the
role's snapshot, plus an explain of a permitted table, a very long but harmless query, and
no-ops such as checkpoint.
As a control, removing the analyst's masks from the policy makes the suite fail with leaks reported, so the detector does detect.
Limits and honest caveats
Passing 71 attacks I wrote is not proof of security. It is a regression suite. It covers what I thought of, on DuckDB, at one version.
Not tested with an LLM client. Everything was exercised with the MCP Python SDK's client, in memory and over stdio. I did not connect Claude Desktop or another agent.
stdio only in practice.
--transport streamable-httpis passed through to the SDK but is untested, and there is no authentication: identity is "whoever started the process". Serving many users from one endpoint needs OAuth and a token-to-role mapping, which is not built.The snapshot is a copy. It is rebuilt when the warehouse file changes. That suits a local or modest warehouse, not a large one. On Snowflake, BigQuery or Postgres the same design maps to native roles, masking policies and row access policies with one service account per MCP role, and no copy. That port is not written.
Hashed columns are salted, but anyone who can read the salt can test guesses. Set
MASK_SALTfrom a secret store; without it, hashes change on every restart.Lineage reveals a count. A role sees how many upstream tables are hidden from it, not their names.
Row filters are trusted SQL written by the policy author and run against the source while the snapshot is built.
Built on MCP Python SDK 2.x (
mcp>=2,<3). The 1.x API differs.The Dockerfile is included but was not built in the environment this was developed in.
Project layout
src/warehouse_mcp/
server.py MCP tools and resources, audit wrapper
workspace.py per-role snapshot, masking, lockdown, read-only execution, limits
guard.py static query checks with reason codes
policy.py roles, table patterns, masks, row filters, limits
lineage.py lineage parsed from the model SQL
checks.py data quality checks
audit.py JSONL audit log
sample.py sample warehouse with planted canary values
cli.py warehouse-mcp command (serve, roles, query, build-sample)
config/ policy.yaml, checks.yaml
warehouse/models SQL that builds staging and marts
evals/ red-team cases, runner, results
examples/ scripted agent session over stdio
tests/ 55 tests, including a real stdio client-server round tripWhat I would do next
Streamable HTTP with OAuth, mapping token claims to roles.
A Snowflake backend using native roles and masking policies instead of a snapshot.
Query cost limits (scan size estimates) in addition to time and row limits.
Run an LLM agent against the server with adversarial prompts, and add what it finds to the red-team suite.
License
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Deterministic safety, correctness & cost gate that vets Postgres SQL before your AI agent runs it.
Governed access to sensitive data, secrets and APIs for AI agents. A signed proof for each decision.
Related MCP Servers
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to inspect schemas, walk Delta table history, run read-only DuckDB queries, and check data-quality and job-run status safely.MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to query Postgres, BigQuery and DuckDB read-only through policy-checked SQL, with AST-based guards that refuse writes and dangerous functions, column masking on the way out, and an audit log of every query. Also exposes schema browsing and query-planning tools so agents can see allowed tables, columns and costs before running anything.MIT
- AlicenseNot gradedqualityBmaintenanceEnables AI agents to query DuckDB, Postgres, and BigQuery through a governed, read-only layer with a semantic model, SQL guard, role-based row policies, PII pseudonymization, audit logging, and cost caps.17 PyPIMIT
- AlicenseNot gradedqualityBmaintenanceGives AI agents governed context about a data warehouse — table meaning, ownership, lineage, freshness, and PII flags — plus read-only, row-limited, PII-protected querying across DuckDB, Snowflake, and Databricks. Guardrails enforced at parsing, connection, and result layers keep agents from writing, running away, or leaking personal data.32 PyPIMIT