Blog
guide

MCP Security and Governance: Auth, Read-Only Roles, and Audit Logs

Musthaq Ahamad
Musthaq Ahamad

In 2025, security researchers showed a Cursor agent connected to a Supabase database through MCP could be tricked into leaking a private tokens table. The attack did not exploit a bug. A support ticket contained hidden instructions, and the agent, running with a database role that bypassed row-level security, followed them.

That incident is the whole lesson in one story. MCP makes it easy to connect AI to your database. The risk is not the protocol. It is the permissions you give it and the untrusted data it reads. This guide covers the real threats and the controls that contain them. If MCP is new to you, start with what MCP is.

The root problem: models cannot tell instructions from data

Every MCP security issue traces back to one fact. A language model reads instructions and data in the same stream, and it cannot reliably tell them apart. So text that arrives as "data," a database row, a ticket, a web page, can carry instructions the model obeys.

This is prompt injection, and on Hacker News one commenter stated the core of it: the model "needs an ironclad distinction between 'this is input from the user telling me what to do' and 'this is input from the outside that must not be obeyed.' Until that's figured out, any attempt at security is going to be full of holes."

Simon Willison named the dangerous combination the "lethal trifecta": access to private data, exposure to untrusted content, and a way to communicate externally. A database MCP server gives the first. Your data gives the second. Avoiding the third, and limiting the first, is the job.

The attack classes worth knowing

You do not need to be a security engineer to govern this well. You do need to recognize the main attack shapes.

AttackHow it worksWho showed it
Prompt injectionUntrusted content carries hidden instructions the model followsWidely documented
Tool poisoningMalicious instructions hidden in a tool's descriptionInvariant Labs, Apr 2025
Toxic agent flowA trusted tool is steered to exfiltrate dataInvariant Labs, May 2025
Rug pullA server changes a tool's behavior after you approve itInvariant Labs
Over-broad permissionsThe AI's database user can do more than readOWASP LLM06

Tool poisoning is the sneaky one. The model reads a tool's full description; the user usually sees only its name. A description can quietly instruct the agent to read a private file and pass its contents through an innocent-looking parameter.

The GitHub MCP exploit showed the toxic agent flow. A malicious issue in a public repo coerced an agent into pulling private-repo data into a public pull request. No tool was compromised. The trusted tools were simply pointed at the wrong target.

Real incidents, not hypotheticals

These are documented, dated, and worth citing when you make the case for governance internally.

IncidentWhat happenedDate
MCP Inspector RCECVE-2025-49596, CVSS 9.4: remote code execution on developer machines via the Inspector proxyJun 2025
Supabase data leakAn agent with a privileged role was tricked into dumping a tokens tableMid 2025
GitHub MCP exploitPrivate-repo data leaked through a toxic agent flowMay 2025

The community sees the pattern. On r/mcp, one practitioner described the ecosystem as "the wild Wild West of npm all over again," and said they treat "every piece of open software in this ecosystem as a virus." Caution is the correct default.

The control layer that contains it

Good governance puts a layer of controls between the AI tool and your database. Nothing reaches the data without passing through it.

Flowchart: requests from an AI tool pass through a guardrails layer of auth, a read-only role, schema scoping, and an audit log before reaching the database, which returns rows read-only

Each control answers a specific risk. The mapping below is the practical core of this article.

RiskControl
Destructive query (DELETE, DROP)Read-only database user
Agent reaches data it should notScope the connection to one schema
Runaway or expensive queryStatement timeouts and row limits
Production blast radiusPoint at a read replica, not prod
Silent misuseAudit log every query, with who and when
Bad result acted on blindlyHuman review for anything that matters

Read-only is the single most important control

If you do one thing, do this. Connect the AI through a read-only database user.

A read-only role runs SELECT and nothing else. It cannot INSERT, UPDATE, DELETE, or DROP. So even a successful prompt injection hits a wall: the database refuses the destructive statement. OWASP's excessive agency guidance names the exact anti-pattern, an extension meant to read data that connects "using an identity that not only has SELECT permissions, but also UPDATE, INSERT and DELETE permissions."

The Supabase incident was this mistake. The agent ran with a role that bypassed row-level security. Our guide on read-only users in Postgres shows the few lines it takes to do this right. Sequel runs read-only by default, so the safe path is the default path.

Scope, limit, and log

Read-only is the floor, not the ceiling. Three more controls round out database governance.

  • Scope the access. Limit the connection to the schema the AI should see. Supabase's own defense-in-depth guidance recommends project and schema scoping, plus pointing at non-production data.
  • Limit the queries. Statement timeouts and row limits stop a runaway query from straining the database. These are standard database hygiene, applied here.
  • Log everything. Record every query the AI runs, with who asked and when. Supabase puts it plainly: "Monitor and log all MCP queries." An audit trail is how you review activity and catch the unexpected.

How authentication works

For remote MCP servers over HTTP, the current spec defines an OAuth 2.1 model. The MCP server acts as a resource server, with a separate authorization server. It requires PKCE and audience-bound tokens, and it forbids token passthrough, so a server must reject tokens not issued for it.

Local stdio servers do not use this. They read credentials from the environment instead. The distinction matters: a remote database server needs real authorization, while a local one inherits the trust of the machine it runs on.

Govern it like any data access

MCP database access is data access. The same governance you apply to a BI tool or a new analyst applies here. The OWASP Top 10 for LLM Applications is the right framework, with prompt injection, sensitive information disclosure, and excessive agency as the entries that map most directly to a database.

Shared, governed connections beat a dozen personal setups. When access lives in team workspaces with read-only connections, you control it in one place instead of trusting every laptop. That is also where an AI data analyst earns its keep over a raw, self-built server.

Your pre-flight checklist

Before you connect any AI tool to a database over MCP, confirm:

  1. The connection uses a read-only user.
  2. Access is scoped to the right schema, ideally a replica.
  3. Queries are logged with who, what, and when.
  4. Third-party servers are from trusted sources and reviewed.
  5. A human reviews anything consequential.

Get these right and MCP is safe to put in front of your data. Want a server that ships read-only and scoped by default? Get started free, or see how to query your database with AI using MCP.

Try Sequel

Meet your always-on data analyst.

An AI data analyst that connects to all your data and answers questions with reports and visualizations. Free for up to 3 seats - no credit card required.

Get started free

Frequently asked questions

Is MCP secure?

MCP can be secure, but it introduces real risks like prompt injection, tool poisoning, and over-broad permissions. Security depends on how you deploy it. For databases, the controls that matter most are read-only access, scoped permissions, human review, and logging every query the AI runs.

What is prompt injection in the context of MCP?

Prompt injection is when untrusted content, like a database row or a support ticket, carries hidden instructions that the AI model follows. Because models cannot reliably separate instructions from data, attacker-controlled text can trick an agent into actions you did not intend, such as leaking data.

What is a tool poisoning attack?

A tool poisoning attack hides malicious instructions inside an MCP tool's description, which the model reads but the user usually does not. Invariant Labs demonstrated this in April 2025. A related risk is a rug pull, where a server changes a tool's behavior after you approve it.

Can an AI connected over MCP delete my data?

Not if you connect through a read-only database user, which is the recommended setup. A read-only role can run SELECT but cannot INSERT, UPDATE, DELETE, or DROP. The database itself refuses destructive queries, even if the model generates one. Sequel runs read-only by default.

How does authentication work in MCP?

For remote servers over HTTP, the current spec defines an OAuth 2.1 model where the MCP server acts as a resource server. It requires PKCE and audience-bound tokens, and forbids token passthrough. Local stdio servers do not use this and instead read credentials from the environment.

Are third-party MCP servers safe to install?

Treat them with caution. The community has compared the ecosystem to the early npm wild west, where unvetted packages are a real risk. Prefer servers from trusted sources, review what permissions they request, and run them with least privilege.

How do I audit what queries an AI ran on my database?

Log every query the MCP server issues, with who asked, what ran, and when. Audit logging is a core governance control for AI database access. Combine it with read-only access and scoped permissions so you can review activity and catch anything unexpected.

What is the most common MCP database mistake?

Connecting the AI through an over-privileged database user. OWASP lists excessive agency as a top LLM risk, and the Supabase incident showed what happens when an agent runs with permissions that bypass row-level security. Use a least-privilege, read-only role scoped to the right schema.

Written by

Musthaq Ahamad
Musthaq Ahamad

Co-founder and CEO of Sequel. Previously built developer tools and data infrastructure. Passionate about making data accessible for everyone.