guide
guide7 min read

How to Give an AI Agent Read-Only SQL Access to BigQuery over MCP

Use the read-only SQL tool, deny the general one, and prove the agent cannot write

To make the BigQuery remote MCP server read-only, point your agent at the execute_sql_readonly tool and block execute_sql with an IAM deny policy. Google's BigQuery MCP documentation lists both tools on the same endpoint, https://bigquery.googleapis.com/mcp, and says the read-only variant permits only read operations. The documented control is not a prompt instruction or a client setting. It is an IAM policy that Google enforces on the server side, so the agent cannot talk its way past it.

Key Takeaways

  • •The remote BigQuery MCP server exposes nine tools, and only execute_sql and cancel_job change state; the rest are read-only, per Google's tool reference.
  • •execute_sql_readonly runs SELECT-only queries; DML, DDL and Python UDFs are not supported in it.
  • •Google's docs describe IAM deny and allow policies that can filter on tool name or read-only status, so the safe pattern is to deny execute_sql at the identity level.
  • •Both SQL tools cancel queries after three minutes by default and cap results at 3,000 rows, so read-only access is also bounded access.
  • •Verify the setup by calling tools/list, then by trying a write as the agent's identity and confirming it is refused.

Why a prompt is not a read-only guarantee

Teams often write "never modify data" into a system prompt and call the agent read-only. That is a request, not a control. A model can misread a task, follow instructions embedded in a table description, or retry with a different tool when the first one fails. If the identity behind the agent can write, then a sufficiently confused agent can write. The only durable answer is to make the write path unavailable to the credential, so that a mistaken call fails at the server instead of succeeding quietly.

The BigQuery server makes this practical because it separates the capability into two tools instead of one tool with a flag. The tool reference describes execute_sql_readonly as running a SELECT-only query and being preferred over execute_sql when possible, while execute_sql runs any supported SQL, including DDL, DML and ML/AI functions. Two tools means two distinct names that policy can target, which is the property you need.

This also matches how the protocol is designed. The MCP specification's tools section defines tools as named, discoverable capabilities that a server lists and a client calls. Because the list is explicit, you can reason about exactly which actions an agent could ever take, and compare that list against what your security team approved. The steps below build on that.

Step 1: Use the remote endpoint and list what it offers

Start with the managed remote server rather than running your own. Google's launch post gives the endpoint as https://bigquery.googleapis.com/mcp and the OAuth scope as https://www.googleapis.com/auth/bigquery. The documentation adds that the transport is Streamable HTTP. Nothing runs in your infrastructure, which means there is no local process whose flags you have to audit.

Before configuring anything, ask the server what it exposes. The docs state that a tools/list request to the endpoint returns the tool names and that this method does not require authentication. Save that output. It is the baseline you will compare against after the policy is in place, and it is useful evidence for an approval review.

Expect nine tools: list_dataset_ids, get_dataset_info, list_table_ids, get_table_info, execute_sql_readonly, execute_sql, get_query_results, cancel_job and get_job. Tool sets can change as the product evolves, so treat this list as something to re-check on a schedule rather than a fact to hard-code. If a new tool appears, decide deliberately whether the agent's identity may call it.

Step 2: Grant the smallest set of IAM roles

The documentation names three roles for calling the server: MCP Tool User (roles/mcp.toolUser, which grants mcp.tools.call), BigQuery Job User (roles/bigquery.jobUser, which grants bigquery.jobs.create) and BigQuery Data Viewer (roles/bigquery.dataViewer, which grants bigquery.tables.getData). Give the agent's service account those three and nothing broader. Data Viewer is a read role, so it already limits what the underlying BigQuery permissions allow.

Scope the Data Viewer grant as narrowly as your layout permits. Granting it on a single dataset, such as a curated analytics dataset, is safer than granting it on the whole project. An agent that can only see the gold layer cannot accidentally summarize raw tables that contain unmasked personal data, regardless of how well it writes SQL.

Use a dedicated service account for the agent, not a developer's personal credentials. Personal accounts usually carry editor roles accumulated over years, which defeats the point. A dedicated identity also gives you a clean audit trail: every query the agent runs appears under one principal, so you can answer "what did the agent read last week?" without sifting through human activity.

Step 3: Point the agent at execute_sql_readonly

In your MCP client configuration, register the BigQuery server and give the agent instructions that name execute_sql_readonly as the tool for queries. This is the convenience layer, not the security layer. Its job is to steer the model toward the tool that will succeed, so you avoid a stream of refused calls that waste tokens and confuse users.

Know what the read-only tool will and will not do. The documentation says it permits only read operations, so DML, DDL and Python UDFs are not supported, and it does not support GQL queries. It also does not support querying Google Drive external tables, and that limit applies to both SQL tools. If your analysts depend on Drive-backed sheets, the agent will need those loaded into native tables first.

Document the intended behavior in one sentence for your team: the agent may discover datasets and tables, read metadata, and run SELECT queries. Everything else is out of scope. That sentence becomes the acceptance test for the next two steps.

Step 4: Deny execute_sql with an IAM policy

Now enforce the rule. The documentation notes that the only read-write tool is execute_sql, so you can deny read-write MCP tool use with a deny policy. It also says deny and allow policies can filter on the principal, on tool properties such as the read-only attribute, on the service or tool name, and on the application's OAuth client ID. Attach a deny policy to the agent's service account that blocks the read-write tool.

Two design choices are worth making explicitly. First, deny by the read-only attribute if your policy tooling supports it, because that also covers future read-write tools. Second, remember that cancel_job changes job state. It is not a data write, but decide whether the agent should be able to cancel jobs it did not start. We would normally deny it for a read-only analyst agent and allow it only for an operations agent.

Be accurate about what the docs do not say. They do not describe a per-server tool allowlist inside the MCP client or server configuration; the documented mechanisms are IAM allow and deny policies. Consult the current policy reference for exact syntax, since we have not reproduced it here and field names matter.

Step 5: Verify, then keep verifying

Test the control from the agent's identity, not yours. Call tools/list and record the result. Then, as the agent's service account, attempt execute_sql with a harmless write, such as creating a table in a scratch dataset, and confirm the call is refused. Then call execute_sql_readonly with a SELECT and confirm it succeeds. A policy you have never seen block anything is an assumption, not a control.

Account for the bounds the server applies even to permitted reads. The docs say execute_sql and execute_sql_readonly cancel queries running longer than three minutes by default, and that results are capped at 3,000 rows. The server has no quotas of its own and no limit on MCP calls, but underlying BigQuery API quotas still apply. An agent asked for a full export will receive a truncated answer, so teach it to aggregate in SQL rather than pull rows.

Re-run the verification when roles change and on a regular schedule. Policy drift is the usual failure: someone grants an editor role to unblock a one-off task and never removes it. Reviewing the agent's effective permissions alongside the tools/list baseline catches that before an agent does.

Where this fits in a wider data platform

A read-only BigQuery server answers one question well: can an agent query this warehouse without changing it? It does not tell the agent which table is trustworthy, whether a column holds personal data, or whether yesterday's load finished. Those answers live in your catalog, quality checks and lineage. The Data Workers Insights Agent pairs text-to-SQL with the semantic layer, so queries carry citations and stated assumptions, and the Connectors Agent handles the warehouse connection itself.

The same pattern generalizes beyond BigQuery. Whatever the warehouse, the question to ask is whether the read-only boundary is enforced by the platform's identity system or merely requested in a prompt. Our OSS edition is read-only by default for the same reason, and writes are a separate, approval-gated decision in the Pro tier.

If you prefer an open-source route to database tooling, Google's MCP Toolbox for Databases on GitHub is a public project for exposing databases to agents. Whichever server you choose, apply the same checklist: enumerate the tools, scope the identity, deny the write path, and test the denial.

Frequently Asked Questions

Is execute_sql_readonly enough on its own?

No. It is the right tool to call, but nothing stops an agent from calling execute_sql if its identity is permitted to. Pair it with an IAM deny policy on execute_sql so the restriction is enforced by Google Cloud rather than by the model's choices. Using the read-only tool for convenience and the deny policy for protection gives you both a smooth experience and a hard boundary.

Does read-only mean the agent cannot run up costs?

No. SELECT queries still consume BigQuery resources. The server's three-minute default cancellation and 3,000-row result cap limit individual calls, but the docs say there is no limit on MCP calls and that regular BigQuery quotas apply. Use project-level quotas and budget alerts for cost control, and have the agent filter on partitions where possible.

Which IAM roles does the agent need?

Per the documentation, roles/mcp.toolUser to call tools, roles/bigquery.jobUser to create query jobs and roles/bigquery.dataViewer to read table data. Grant data access on the narrowest dataset that answers the agent's job, and use a dedicated service account so the audit trail stays attributable to the agent.

Can I hide the write tool from the agent entirely?

The documentation describes IAM allow and deny policies, not a client-side tool allowlist. A deny policy makes the call fail, but the tool may still be visible in tools/list, which does not require authentication. If you want the model never to see it, filter tool lists in your MCP client or gateway as an additional layer, and keep the IAM deny as the source of truth.