Connect Claude Code to a database with MCP, safely

One command adds an MCP server to Claude Code. For a database, the command is the easy part: the scope, the login and the limits decide whether it is safe. The command, the three scopes, and a checklist before you connect.

Short answer: add the server with claude mcp add, a name, and the command that starts it after --, for example claude mcp add --transport stdio warehouse -- <command that starts your database MCP server>. Pick the scope: local (you, this project, the default), project (the team, saved in .mcp.json), or user (you, every project). For a database, connect with a read-only login to a test or reporting copy, and never put the password in .mcp.json.

Once Claude Code can query the database itself, it stops guessing column names and starts checking its own answers. That is the benefit. The risk is the same: it can run whatever the login allows.

Nothing loads from YouTube until you press play. Then Google receives your IP address and may set its own storage. Narrated with an AI-generated voice. Privacy

What are the three scopes?

ScopeSaved inWho has itGood for
local (default)your user settings, for this projectOnly you, in this projectTrying a server, personal credentials
project.mcp.json in the projectEveryone who opens the projectA shared, read-only reporting database
useryour user settingsYou, in every projectA server you use everywhere
Where the server is saved, and who gets it

Choose project scope with --scope project. Claude Code asks each person to approve project servers before they are used.

What should you check before connecting?

Logina database user that can only read, on the schemas it needs
Targeta test or reporting copy, not the production system
Limitsa row limit and a timeout on queries
Secretspasswords from environment variables, never in .mcp.json
Four checks for a database server

How do you see that it works?

Type /mcp in Claude Code: it lists the servers, whether each is connected, and its tools. Then ask something you can check: "How many rows are in the orders table?" and compare with your own count.

Where can you check this?

Where do you start?

Read what a server can offer in MCP for data: tools, resources and prompts. For the access rules inside a Power BI model, see row-level security.

Keep reading

More from the blog.

Every post

Next

Building this? Say hello.

A question about this post, a pattern you would build differently, or the next thing you want written out: Behnia reads every message.