MCP Security Best Practices for Databases: Risks, Controls and Agent Access Without Credentials
Data Security
Published -
November 2026
Updated -
October 2026

MCP Security Best Practices for Databases: Risks, Controls and Agent Access Without Credentials

Manish Shah
Contents

Why MCP security starts at the data layer

The fastest way to make an AI agent useful is to connect it to your data. The fastest way to create a breach is to do it with a shared password.

The Model Context Protocol (MCP) has made the first part easy. A developer can point Claude, Cursor or an internal assistant at a production system in minutes. What the protocol does not do on its own is decide what that agent may see, stop it from running a destructive query, or record what it did.

The rapid adoption of MCP has created new security challenges for every security team. This guide covers the risks that matter most when the target is production data, the security controls to put in place, and how to evaluate any MCP server before agents go live. It is written for platform, security and data teams.

What is the Model Context Protocol?

MCP is an open standard that lets AI applications discover and call external tools through one consistent interface. The MCP architecture has three parts:

  • MCP host. The AI application the user works in, such as Claude Desktop or Cursor.
  • MCP client. The connector inside the host that keeps a session with each server.
  • MCP server. The service that exposes tools (for example list_tables, describe_table, run_query) and executes them.

Every tool call travels from client to server, and tool execution happens with whatever access the server holds. For most integrations, a mistake means a wrong calendar entry or a bad ticket. When the tool sits in front of SQL Server, Oracle or PostgreSQL, the same mistake can mean:

  • exposing customer PII, card data or health records in a model’s context window,
  • running an UPDATE or DELETE that nobody reviewed,
  • leaving no trace of who asked, what was queried and what came back.

That is why securing Model Context Protocol connections to data needs a stricter security model than a typical tool integration. The agent is effectively a new user of your data, and it should be governed like one.

Local vs. remote MCP servers: two different threat models

Before choosing controls, know which kind of MCP server you are running. This is the first security consideration in any review.

Local MCP server (stdio). The server runs as a process on the developer’s laptop, launched by the MCP client. It runs with that user’s operating system privileges, and the MCP server configuration, including the connection string, usually lives in a local mcp.json or claude_desktop_config.json file. This setup is quick, but it is invisible to central IT: no SSO, no shared policy, and credentials scattered across laptops.

Remote MCP server (HTTP). The server runs as a shared service and clients connect over the network. Remote MCP is where proper authentication, OAuth tokens and SSO become possible, and where one policy and one audit trail can cover every user. It also brings transport security into scope: use TLS everywhere and never expose a server without authentication.

For anything beyond a personal sandbox, a centrally governed server is the safer default. If developers must run one locally, it should connect through a governed proxy rather than straight to production with a stored password.

Are MCP servers a security risk? The main MCP security risks

MCP servers are not insecure by design, but a server set up the quick way usually inherits these security risks. Security researchers have already found internet-exposed MCP servers with no authentication at all.

Risk What happens Typical root cause
Raw credentials in agent config A username and password sit in a JSON config file on a laptop or in a repo The MCP server connects with a static connection string
Over-privileged service account The agent can read every schema and often write to it One shared account is reused for all agents and tasks
Prompt injection to SQL Text inside a document, ticket or web page instructs the agent to run a query it should not The agent trusts content it reads and has a broad run_query tool
Malicious or compromised MCP server A third-party package steals credentials or exfiltrates query results Servers installed from unvetted registries or GitHub repos
Sensitive data in the model context Unmasked PII is returned to the model and may reach logs, chats or a third-party API Query results are passed through without masking
Destructive writes An agent runs UPDATE, DELETE or DROP on production Write access is on by default
No audit trail Nobody can say which user, agent or prompt produced a query Agent traffic bypasses the logging that covers human access

Most of these share one cause: the agent gets a second, weaker door into the data, outside the security controls already built for people. Every MCP security risk above is easier to manage when that door is closed.

Malicious MCP servers and tool poisoning

Not every threat comes from the agent. Some come from the MCP server itself.

A malicious MCP server looks like a useful connector, for example a “Postgres helper” published to a public registry, but is built to harvest whatever it is given. Because a server often receives connection strings, API keys and full query results, a single bad install can leak credentials and data in one step. A malicious server could also change its behavior long after you approved it.

Common attack patterns include:

  • Tool poisoning. Hidden instructions in a tool’s description tell the model to read a file, call another MCP tool or send data somewhere it should not. The user never sees the description; the model does.
  • Rug pulls. A server behaves normally when first approved, then changes its tool definitions in a later update.
  • Name squatting. A server with a name close to a trusted one (postgres-mcp vs. postgress-mcp) is installed by mistake. GitHub MCP repositories and public registries are common sources.
  • Cross-server shadowing. One connected server’s tool descriptions influence how the model uses another, trusted server.

How to defend against them:

  1. Keep a list of approved MCP servers, install only from sources you trust and pin versions.
  2. Review tool descriptions before approval, re-review when definitions change, and alert on changes.
  3. Never give a third-party server raw credentials. Route data access through a governed endpoint that holds the connection itself.
  4. Limit what any single MCP server could reach, so a compromise has a small blast radius.

10 MCP security best practices for data access

The rule behind all ten: an agent should never get more access than the human it acts for.

  1. Never put raw credentials in an agent or MCP config. The agent should authenticate to the MCP server, and the server should hold or broker the connection. Secrets belong in a vault (CyberArk, HashiCorp Vault, a cloud secrets manager), not in mcp.json.
  2. Bind every session to a real identity. Let users sign in through your SSO (Okta, Microsoft Entra ID, Google) and have the agent act under that identity. Shared service accounts make access reviews and incident response almost impossible.
  3. Apply least privilege at the object level. Scope access to specific instances, schemas, tables and, where needed, columns. An agent that drafts a sales report does not need the HR schema.
  4. Make read-only the default. Grant write access per role, per data source, only when a workflow truly needs it. Block DDL (DROP, ALTER, TRUNCATE) for agents entirely in most environments.
  5. Scope schema introspection too. Tools like list_tables should only return objects the session may query. Table and column names alone can leak sensitive structure.
  6. Mask sensitive data before it reaches the model. Dynamic data masking on PII, PCI and PHI columns lets the model reason about the shape of the data without ever seeing real values.
  7. Treat every input as potentially hostile. Prompt injection cannot be fully prevented at the model layer, so limit the blast radius at the data layer: narrow tools, query timeouts, row limits and blocked statement types.
  8. Log prompts, queries and results per agent and per user. The audit trail should answer who asked, which agent ran what, against which system, and what came back. Send it to the security tooling and SIEM you already use.
  9. Use one governed endpoint instead of multiple MCP servers. Each extra server is another config, another secret and another gap in monitoring. A single MCP gateway applies the same security policies everywhere.
  10. Keep data and models inside your boundary where regulation requires it. For GDPR, HIPAA, SOX or financial data, prefer a server deployed on-premises or in your VPC and, where possible, a model you host yourself.

For broader guidance on building servers, see the official MCP security guidance and the OWASP MCP Security Cheat Sheet.

MCP authentication and authorization best practices

Authentication answers who is calling; authorization answers what they may touch. Authentication and authorization should both reuse what you already run for people.

  • Follow the MCP authorization specification. For remote servers, MCP authorization is based on OAuth 2.1. The MCP server acts as a resource server, and tokens come from a separate authorization server such as your identity provider.
  • Verify the identity of the MCP server. Clients should confirm they are talking to the real server, and the server should reject tokens that were not issued for it. Never pass a client’s token through to downstream systems.
  • Authenticate the user, not just the client. An API key proves an MCP client is allowed to connect. It does not prove which person is behind the request. Tie each session to an SSO login.
  • Use short-lived, scoped tokens. Issue MCP-specific tokens that can be revoked, expire on their own and carry only the scopes the session needs.
  • Authorize at the data object, not the tool. Allowing the run_query tool says nothing about which tables a query may read. Enforce access control on the data itself.
  • Keep one policy for humans and agents. If a user cannot see the salary column in the SQL editor, an agent acting for that user should not see it either.
  • Review agent access like user access. Include agent permissions in periodic access reviews and offboarding.

Use an MCP gateway or MCP proxy for central control

An MCP proxy server or gateway sits between clients and MCP servers. Instead of every developer running their own server with its own password, all MCP traffic flows through one governed endpoint, and security policies are enforced before anything touches the data.

A good MCP gateway gives you:

  • Central authentication. Every client signs in through SSO; no credentials live on laptops.
  • One policy for all sources. The same permissions, masking and query limits apply to MySQL, Oracle, Snowflake and the rest.
  • Inspection and blocking. Statements can be checked and blocked (for example DROP or unbounded SELECT *) before tool execution.
  • One audit trail. Every prompt, tool call and result is logged in one place.
  • Easy revocation. Removing a user in one place cuts access everywhere.

In practice, the gateway is where most of the security controls in this guide are enforced, and where MCP deployments stay manageable as they grow.

Security controls checklist: map each risk to a control

Risk Controls
Credential leakage Vault-held secrets, brokered connections, no passwords in client configs
Over-privileged access Object-level RBAC, least privilege, separate roles per workflow
Prompt injection Read-only default, statement allow-lists, row limits, query timeouts
Rogue third-party server Approved sources only, version pinning, tool-description review, no raw secrets to third parties
Data exposure to the model Dynamic data masking on PII, PCI and PHI columns
Destructive changes Write access per role, DDL blocked, approval workflow for changes
No accountability Per-user and per-agent audit logs exported to Splunk, Elastic or your SIEM

Checklist: how to evaluate a secure MCP server

Use these questions before any MCP server touches production. Each “no” is a gap to close first. MCP servers must pass every item before they reach regulated data.

Question Why it matters
Does the agent connect without ever holding a password? Removes the most common leak path
Is every session tied to an SSO identity? Makes every query attributable
Can access be limited to specific schemas, tables and columns? Enforces least privilege
Is it read-only by default, with write granted per role? Prevents unreviewed changes
Is schema introspection filtered by permission? Stops structure leaks
Are sensitive columns masked before results reach the model? Keeps PII out of prompts and logs
Are prompts, queries and results logged per user and agent? Supports audits and incident response
Can logs go to Splunk, Elastic or your SIEM? Fits existing monitoring
Is the server from an approved, version-pinned source? Reduces supply-chain risk
Does one endpoint cover all your data sources? Avoids config sprawl
Can it run on-premises or in your VPC? Meets data residency requirements

How DBHawk MCP Server applies these practices

The DBHawk MCP Server (DBHawk AI MCP) was built so that an agent is just another governed DBHawk user, not a side door into your data.

  • No raw credentials. Agents authenticate through the MCP server; no username or password is ever placed in an agent’s configuration.
  • SSO identity. Users sign in through their existing SSO and the agent operates under that identity.
  • Same access control as people. Agents inherit the object-level permissions and dynamic data masking rules that apply to human DBHawk sessions.
  • Read-only by default. Write access is granted per role, and schema introspection only shows what the session may see.
  • Full audit trail. Every agent connection, prompt and query is logged like any other DBHawk session and can be exported to Splunk, Elastic or Azure Monitor.
  • One endpoint for every source. MySQL, PostgreSQL, SQL Server, Oracle, MongoDB, Snowflake and the other supported platforms sit behind a single MCP endpoint.
  • Runs in your infrastructure. Available as SaaS or on-premises and in your VPC, as part of the Zero Trust database access platform.

See how security and audit work for agents on the MCP server security page, or book a demo to watch a live agent query a governed schema.

FAQ

Are MCP servers a security risk?

They can be. An MCP server is a new access path to your systems, and in front of production data it often runs on shared credentials, broad permissions and no audit trail. Governed correctly, with SSO identity, least privilege, masking and logging, it is no riskier than human access.

How do you secure an MCP server?

Remove raw credentials from agent configs, tie each session to a real user, limit access to specific objects, default to read-only, mask sensitive columns and log every prompt and query.

What are the best practices for MCP authentication?

Authenticate the person through SSO, not just the client through an API key. Follow the MCP authorization specification, use short-lived, revocable, scoped tokens, and enforce authorization on the data itself.

What is a malicious MCP server?

A server built or modified to steal credentials or data, often through hidden instructions in tool descriptions or by changing behavior after approval. Use approved sources, pin versions and never hand third-party servers raw credentials.

Can MCP prevent prompt injection?

No protocol fully prevents prompt injection. The practical defense is limiting what an injected instruction could do: read-only access, narrow permissions, masking, row limits and audit.

Should agents have write access to production?

Rarely. Keep agents read-only by default and grant write access per role, per data source, only for reviewed workflows.

Do I need a separate MCP server for each data source?

Not if you use an MCP gateway. One governed endpoint can cover many sources and apply one access policy and audit trail to all of them.

You may also like
Data Security
What Is an MCP Gateway, and Why Your Databases Need One
Data Security
Microsoft Purview: A Practical Guide to Data Security, Governance, and Compliance
Build Advanced SQL Queries with DBHawk
Start a free trial or request a demo today to learn how DBHawk can optimize your database queries. Our free trial includes all of the basic features plus premium access.
Get Started Free
No Credit card required!

Many Databases, Single Tool, No Client Software

Get started for free. Sign Up to see how DBHawk provides zero trust database access and development across all databases.
Get Started Free
No Credit card required!