Connect Claude Code, Cursor or Codex to your data warehouse over MCP, safely
How to let Claude Code, Cursor or Codex query your data warehouse over MCP safely: a read-only setup, a safety checklist, masking and row filters, and a fair look at the Snowflake, BigQuery and Databricks MCP servers.
To let Claude Code, Cursor or Codex query your data warehouse safely, connect it through an MCP server that gives the agent schema discovery and a read-only SQL tool, keeps credentials in the browser instead of the chat, and enforces column masks and row filters on the server. With Contrast, you add the hosted MCP server at https://contrastdb.com/api/mcp, sign in through your browser, choose a workspace and ask your first question. Queries are read-only, and your workspace role and data policies apply to every read. The rows your agent asks for pass through the model you use, so mask sensitive columns before you connect.
This guide covers what an MCP server gives an agent, a checklist to run before you connect anything, setup for each of the three agents, how to limit what the agent can see, and how the MCP servers from Snowflake, BigQuery and Databricks compare.
What does an MCP server give a coding agent?
The Model Context Protocol (MCP) is a standard way for an agent to discover and call tools. A warehouse MCP server turns "go look at the data" into a small set of tool calls the agent can make on its own:
- Find tables. Search the catalog and read column names and types, so the agent writes SQL against tables that exist.
- Run SQL. Send one query and get rows back, with paging for larger results.
- Check status. See whether a query is still running, cancel it, or check whether data is fresh.
Without MCP, the usual pattern is pasting CSVs into a chat or handing the agent a database password in an environment variable. The first is slow and goes stale. The second gives the agent whatever that credential can do, often including writes.
What "read-only" has to mean
A tool description that says "read-only" is a hint to the model, not a control. Snowflake's own docs make this point: MCP tool annotations "don't enforce tool behavior or replace access control" (Snowflake CREATE MCP SERVER). Read-only only counts when the server rejects writes, whatever SQL the agent sends.
A safety checklist before you connect anything
Run through these whichever warehouse or MCP server you use.
1. Use a least-privilege identity, never an admin or app credential
Give the connection its own role or service account with SELECT on the schemas the agent needs and nothing else. Don't reuse your application's database user or a personal admin login.
2. Expose one read-only query tool, with writes blocked on the server
If the server offers both a read-write and a read-only SQL tool, expose only the read-only one, or turn writes off in the server's policy. Check by asking the agent to run an INSERT and confirming the server refuses it.
3. Keep credentials out of the chat
Credentials typed into a prompt end up in the conversation history and in the model provider's logs. Prefer servers that sign in through OAuth in your browser and connect sources through a browser flow.
4. Mask, filter and log on the server
Column masks, column denies and row filters should run where the query runs, so they hold no matter what SQL the agent writes. You also want a log of who ran what.
5. Know where the data goes
When an agent runs a query, the rows come back to the agent and so pass through the model you are using. Snowflake says the same thing about its server: tool results "go to the MCP client and, through the client, to its model provider" (Snowflake-managed MCP server). Decide what each role may return before you expose it.
6. Put a ceiling on cost
Agents retry and loop. Set a per-query timeout, a scan limit, and a daily or monthly spend cap the agent itself can't raise.
How to set up Contrast in Claude Code, Cursor or Codex
Contrast's MCP server is hosted at https://contrastdb.com/api/mcp. It offers 23 tools, read-only SQL and sign-in in your browser, and every client gets the same tools (MCP and plugins). OAuth uses PKCE, and signing in to the website alone does not authorize MCP (MCP guide).
You don't need a Contrast account first: your agent opens sign-up or sign-in in your browser, then asks you to choose a workspace and approve its access.
Claude Code
Run this in your terminal. Your browser opens so you can choose a workspace and approve access.
claude mcp add --transport http --scope user contrast https://contrastdb.com/api/mcp && claude mcp login contrast
In Claude Code, /mcp should list contrast as connected. If it says it needs authentication, sign in from there. You can also install the plugin, which bundles the same connection with a setup skill:
/plugin marketplace add contrastdata/contrast-plugins
/plugin install contrast-warehouse@contrast
Cursor
Use the Add to Cursor button on MCP and plugins. If Cursor doesn't open, add this to ~/.cursor/mcp.json, keeping what is already there:
{
"mcpServers": {
"contrast": {
"url": "https://contrastdb.com/api/mcp"
}
}
}
Then open MCP in Cursor Settings, sign in to contrast, choose a workspace and approve access in your browser.
Codex
Contrast is listed in the plugin directory for ChatGPT and Codex, and the plugin asks you to sign in when you install it. To add the same tools from the Codex CLI without the plugin:
codex mcp add contrast --url https://contrastdb.com/api/mcp && codex mcp login contrast
Any other client, or a client without remote OAuth
Any client that supports remote MCP with OAuth can use https://contrastdb.com/api/mcp. For a client without remote OAuth, the CLI signs in through your browser, keeps the token in your system's credential store, and installs a local bridge your client starts as contrast mcp serve:
npx @contrastlabs/cli@latest setup
See the CLI docs for the other commands.
Ask your first question
The first time, your agent sets up the warehouse and connects the sources you name before it answers:
Set up my data warehouse and help me answer my first question.
Or paste one prompt into any of the three agents and let it read the setup guide itself:
Read https://contrastdb.com/setup/agent.md, set up Contrast and run my first query for me.
A sync job starting doesn't mean the data is ready. Ask the agent to confirm with a query, show you the SQL behind each number, and say which sources it couldn't cover.
What can the agent do, and what can't it?
The tools come in five groups (MCP and plugins):
| Group | Tools | What they do |
|---|---|---|
| Warehouse | warehouse_plan, warehouse_apply, warehouse_status | Preview the setup plan, provision the warehouse, check it is ready and fresh |
| Sources | sources_types, sources_list, sources_status, sources_connect, sources_verify | List and connect sources. Credentials go in the browser, never the chat |
| Ingestion | ingestion_plan, ingestion_start, ingestion_status, ingestion_sync, ingestion_pause, ingestion_resume, ingestion_delete, ingestion_inspect_table, ingestion_edit_table | Choose tables, start, pause or resume a sync, pick the columns that land |
| Catalog | catalog_search, catalog_describe, catalog_list | Find tables and inspect their columns |
| Queries | query_run, query_results, query_cancel | Run read-only SQL and page through results |
What the agent can't do: a query can't change warehouse rows, and no tool deletes warehouse rows. The MCP query tool accepts SELECT, SHOW and DESCRIBE only (SQL reference). Sources sign in through your browser, so the agent never sees a password.
What it can change depends on what you approve. With write access, an agent can start, pause and resume syncs and choose which columns to ingest. Setting up the warehouse, connecting a source and removing a sync need admin access. The approval screen shows what a client is asking for, and your workspace role still applies.
Built-in limits on runaway queries
Every workspace has safety limits that are on by default: 500 GB scanned per day, $100 per day and $1,000 per month of AI and query compute. A query times out after 120 seconds by default and can scan up to 25 GiB, and MCP returns up to 100 rows per page. Owners and admins change the limits from a signed-in session; an agent connection can't change them (Limits).
How do I control what the agent can see?
Workspace roles
Each member has one workspace role, from viewer (browse the catalog, run read-only queries) up to admin and owner. An MCP client signs in as you, with an agent session that admins can revoke under Agent sessions in Settings → Admin (Security and permissions).
Masks, denies and row filters
Data policies in Settings → Admin → Governance apply to every read, whichever surface runs it, including MCP. Contrast checks them when it plans a query and again on every page of results, so a mask you add also covers the next page of a query that already ran (Governance).
- Mask a column with Redact, Last 4, Hash or Null.
- Deny a column, so a query that reads it is refused.
- Filter rows for a role or group, for example
{alias}.region IN ('EU', 'UK').
New workspaces start in Enforce mode, where a query that reads a column labeled restricted is refused. Test a query shows what the policies do to a query for a given role, without running it.
Which permissions apply to which data
Two layers apply, and it's worth being precise about them:
- Tables stored in Contrast. Access follows the signed-in person's workspace role and the workspace's data policies.
- Snowflake or BigQuery queried in place. Queries run as the role or service account configured for that connection, so that identity's grants set the upper limit on what Contrast can read. They don't automatically inherit each person's own warehouse permissions (Security). Snowflake and Databricks connections can use warehouse identity federation so queries run as the member instead.
Audit
Settings → Admin → Data access shows who queried the workspace, what they ran and which tables they used. Audit logs are included with pay as you go. Contrast is SOC 2 Type 2 certified, with the report available under NDA (Security).
Troubleshooting: the tools don't show up
The most common failure is a sign-in that failed quietly. Some clients hide it, so the tools are just missing.
- Run
claude mcp listorcodex mcp list. - Needs authentication (Claude Code) or Not logged in (Codex) means sign in again, with
/mcpin Claude Code orcodex mcp login contrast. - Codex Unknown or Claude Code Failed to connect means the check couldn't reach Contrast. Retry with network access.
- If the client shows a saved sign-in but no tools, check
https://api.contrastdb.com/health. If it returns200, reconnect once. If not, signing in again won't help. - In clients other than Codex, start a new chat or reconnect from
/mcpafter signing in.
The MCP guide covers the remaining cases.
How do other warehouse MCP servers compare?
If your data stays in one warehouse, its own MCP server may be all you need. Here is what each vendor documents today.
| Snowflake-managed MCP server | BigQuery MCP server | Databricks SQL MCP server | Contrast MCP server | |
|---|---|---|---|---|
| What it exposes | Tools you define in a CREATE MCP SERVER spec: Cortex Agents, Cortex Analyst, Cortex Search, SQL execution, UDFs | Dataset and table metadata, execute_sql_readonly, execute_sql, job status and cancel | execute_sql, execute_sql_read_only, poll_sql_result | 23 tools: warehouse setup, sources, ingestion, catalog, read-only SQL |
| Auth | Snowflake OAuth by default, optional External OAuth | Google Cloud authentication for remote MCP servers | Databricks OAuth, governed through Unity Gateway | OAuth with PKCE in the browser |
| Read-only control | read_only: true on the SQL tool (the default); an account parameter can force read-only | Prefer execute_sql_readonly, which allows only SELECT | Reads and writes by default; set disallow_writes in the server policy | Query tool accepts SELECT, SHOW, DESCRIBE only |
| Access model | Snowflake RBAC on the server and each tool | IAM on the project and datasets | Unity Catalog grants and policies | Workspace roles plus masks, denies and row filters |
Databricks lists system.ai.dbsql as Beta. Sources: Snowflake, BigQuery, Databricks.
Snowflake and Databricks both recommend a semantic layer for business questions: a Cortex Agent or Cortex Analyst over a semantic view on Snowflake, and Genie on Databricks. That is good advice. An agent writing SQL against raw tables gets metric definitions wrong more often than one grounded in agreed definitions.
When Contrast is the right MCP server, and when to keep your warehouse's
If your data is spread across Postgres, Stripe, HubSpot and a warehouse, or you want an agent to set up ingestion as well as query, use Contrast. It can query Snowflake, BigQuery, Databricks and Redshift where they are, or copy tables into open Apache Iceberg tables that Spark, Trino and DuckDB can also read (Supported sources). Queries on tables stored in Contrast run on Lakeserve, Contrast's open-source engine.
Keep your vendor's MCP server if all your data is in that warehouse, you already use its semantic layer, and its read-only and RBAC controls cover what you need.
What could go wrong?
- Wrong SQL. Agents misread column meanings. Ask for the query behind every number and spot-check the joins.
- Expensive queries. Even read-only queries cost money. Keep the timeouts and spend caps on.
- Stale data. A sync that has started is not data that is ready. Check
warehouse_statusor freshness before you trust an answer. - Sensitive data in the model. Anything a query returns reaches your model provider. Mask first.
FAQ
Is it safe to connect Claude Code or Cursor to a production database? It's safe enough when the agent connects through a read-only tool enforced on the server, uses a least-privilege identity, never sees credentials, and sensitive columns are masked. Don't give an agent your application's database password.
Can an MCP server run write queries?
Many can. BigQuery's server has both execute_sql and execute_sql_readonly, and Databricks' SQL server permits writes until you set disallow_writes. Contrast's query tool accepts only SELECT, SHOW and DESCRIBE, and no tool deletes warehouse rows.
Does my data go through the model provider? Yes. A tool call returns rows to the agent, so they pass through the model you are using. This is true of every warehouse MCP server.
Do I need dbt or a semantic layer first? Not for a first query. A semantic layer helps later, once agents answer business questions that depend on agreed metric definitions.
How do I stop an agent from running a runaway query? Use per-query timeouts, scan limits and spend caps the agent can't change. In Contrast these are on by default, and only owners and admins can change them, from a signed-in session.
Which agents does Contrast support? Claude Code and Cursor connect to the hosted MCP server, Codex has a plugin in the ChatGPT and Codex directory, and any client with remote MCP and OAuth, or the CLI bridge, works too.
Try it
Add Contrast to your agent. The Free plan is $0 a month with 5 data sources, 10 GB of managed storage and 5 vCPU-hours of compute, and no card is needed (Pricing).
Already on Snowflake or Databricks? Get the free cost audit: a read-only review with a written report on what your warehouse would cost on open Iceberg.
Read https://contrastdb.com/setup/agent.md, set up Contrast and run my first query for me.
Keep reading
Postgres to Iceberg CDC without Kafka: Debezium, Flink CDC, pg2iceberg, Moonlink and Flow
Stream Postgres inserts, updates and deletes into Apache Iceberg without Kafka. A fair comparison of Debezium Server, Flink CDC, pg2iceberg, Moonlink and Contrast Flow: setup, deletes, small files, compaction and freshness.
Snowflake to Iceberg: what it saves and what it doesn't
Does moving Snowflake tables to Apache Iceberg cut your bill? What changes in storage, what stays the same in compute, where the real savings are, and how to test it on your own queries before you migrate.
Can Iceberg do realtime SQL? How fresh and how fast, from Postgres insert to next query
How fresh and how fast can Apache Iceberg be? What limits freshness (commit intervals) and query speed (small files, deletes, metadata caching), and how to get a Postgres insert into the next SQL query in about a second.
Get new posts by email.
Launches, open-source releases and research from the Contrast team, sent when they’re published.


