How to Configure Claude Code MariaDB MCP Server

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a claude code mariadb mcp server by linking the agent to your database with a connection string. You should always use a read-only database user in that string so the agent cannot change data. Many engineering teams rush this setup during testing and use admin accounts instead. Broad database roles let an AI coding agent alter tables or read sensitive rows by mistake. How a claude code mariadb mcp server works Claude Code talks to external systems and databases through the Model Co

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up a claude code mariadb mcp server by linking the agent to your database with a connection string. You should always use a read-only database user in that string so the agent cannot change data. Many engineering teams rush this setup during testing and use admin accounts instead. Broad database roles let an AI coding agent alter tables or read sensitive rows by mistake.

How a claude code mariadb mcp server works

Claude Code talks to external systems and databases through the Model Context Protocol. This protocol lets the AI agent run queries against your tables to help you write and debug code. You register a database server tool with the agent and give it a database connection string. The official docs show DBHub as an example server for querying databases.

When you ask a question about your schema, the agent sends a query to the server. The server runs that query against MariaDB using the account in your connection string. The database checks the user permissions and sends the matching rows back to the local agent. Aside from MCP servers, the agent can also run shell commands through its Bash tool. In Manual mode, the Bash tool asks for your approval before running non-read-only commands.

The vendor docs warn you to verify that you trust each MCP server before connecting. The server holds your database credentials and runs every query the model generates. Because of this risk, the docs advise using a read-only database user in your connection string. A read-only role stops the agent from running write queries that modify or delete your data.

What native MariaDB roles solve and what they miss

A read-only MariaDB user is a great first step for any team. It blocks the AI agent from dropping tables, changing rows, or deleting production records. The database engine enforces this rule at login and rejects write statements right away. For simple test databases with fake data, a read-only user is often enough.

Still, native database roles only control who logs in and which tables they can read. They do not inspect what individual queries do in flight or what data comes back. If a table holds customer details, a read-only user can still read every column in that table by default. When the agent runs a broad select query, MariaDB sends raw sensitive fields back to the model.

This means emails, phone numbers, card numbers, and national IDs flow straight into the model context. You also have to store a static database password on every developer laptop for the connection string. If a developer shares their local config file, that database password leaks out. Native roles also cannot pause a single risky query to ask a human for approval first.

Claude Code Security + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

How to plan your database permissions for AI agents

Start by creating a dedicated MariaDB account just for your AI coding workflows. Never reuse the account that your main backend app uses to run in production. Grant select rights only on the specific schemas and tables that developers need to inspect. Leave out sensitive tables like billing records or user auth logs whenever you can.

Even inside safe tables, you may still have columns with emails or phone numbers. Native MariaDB grants get hard to manage when you try to restrict access column by column. You also need a clear audit trail that ties each query to a specific person. When ten engineers share one read-only user, the database logs look identical for everyone.

Teams need a way to remove static passwords from local machines and control queries in flight. You want to rewrite sensitive fields like card numbers in query results before they reach the model. This keeps the database schema useful for coding while protecting real customer values.

Check MySQL queries and results on the wire

MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.

Frequently asked questions

How does Claude Code run queries against a MariaDB database?

Claude Code uses the Model Context Protocol or its Bash tool to reach external databases. You configure an MCP server with a connection string, and the agent sends queries through it.

Why should I use a read-only user in my connection string?

The official docs recommend a read-only user so the queries the agent runs cannot modify data. This stops accidental updates, deletes, or schema drops while the model explores your database.

Does a read-only MariaDB role stop sensitive data from reaching the model?

No, a read-only user can still read all columns inside any table you grant it by default. Without data masking in flight, raw emails, phone numbers, and card numbers still reach the agent.

The query runs. The emails stay hidden.