How to Connect Your Database to Claude with MCP
Last updated Apr 23, 2026

Model Context Protocol (MCP) connects your database directly to Claude, letting you ask questions in plain English and get answers from live data. The setup takes under 10 minutes, requires no SQL knowledge, and works with PostgreSQL, MySQL, SQLite, and most other common databases. This guide covers the full process: creating a read-only database user, installing an MCP server, configuring Claude Desktop, and running your first natural language query.
What MCP Is and Why It Matters for Data Work
Before MCP, connecting an AI model to a database required custom code. You would build an API endpoint, write a function to call it, parse the response, and explain your table structure in every conversation. Every schema change meant updating that explanation manually. Every new AI tool required a new integration.
MCP is an open standard developed by Anthropic that creates a universal interface between AI models and external data sources. It uses a client-server architecture. An MCP client (Claude Desktop) connects to an MCP server, which sits in front of your database. The server exposes three types of capabilities: tools (actions like running a query or listing tables), resources (data like your schema definition), and prompts (pre-built templates for common workflows).
The practical result is schema-aware SQL generation. Instead of guessing your table and column names from a natural language question, Claude reads your actual database structure before writing a single line of SQL. Foreign key relationships, data types, constraints, and indexes are all visible. The AI generates SQL that works against your real tables, not a hypothetical database it invented from your question.
By March 2026, over 10,000 public MCP servers were registered across community registries, covering databases, SaaS APIs, file systems, and cloud services. Database servers are the most mature part of the ecosystem, with official implementations for PostgreSQL and SQLite, and community servers for MySQL, MongoDB, Snowflake, BigQuery, ClickHouse, and DuckDB.
What You Need Before Starting
You need four things: Claude Desktop with a Claude Pro subscription (MCP requires Pro or above as of 2026), Node.js 18 or higher, a running database you have credentials for, and about 10 minutes.
To check Claude Desktop compatibility, open Settings and look for a Developer tab. If it exists, MCP is supported. If not, download the latest version from claude.ai/download.
To check Node.js, run node --version in your terminal. Version 18 or higher is required. Download the latest LTS release from nodejs.org if you are below that.
Your connection string format depends on the database:
- PostgreSQL:
postgresql://username:password@hostname:5432/database_name - MySQL:
mysql://username:password@hostname:3306/database_name - SQLite:
sqlite:///absolute/path/to/database.db
Set Up a Read-Only Database User First
Always create a dedicated read-only user before connecting any external tool to your database. Claude executes queries directly through the MCP connection. A read-only user limits the damage if something goes wrong and is good practice for any analytics integration.
For PostgreSQL:
CREATE ROLE mcp_reader WITH LOGIN PASSWORD 'choose_a_strong_password';
GRANT CONNECT ON DATABASE your_database TO mcp_reader;
GRANT USAGE ON SCHEMA public TO mcp_reader;
GRANT SELECT ON ALL TABLES IN SCHEMA public TO mcp_reader;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT SELECT ON TABLES TO mcp_reader;
For MySQL:
CREATE USER 'mcp_reader'@'%' IDENTIFIED BY 'choose_a_strong_password';
GRANT SELECT ON your_database.* TO 'mcp_reader'@'%';
FLUSH PRIVILEGES;
Test the connection from your terminal before moving on. If it fails at the command line, it will also fail in Claude Desktop.
Install the MCP Database Server
DBHub is the most practical starting point. It supports PostgreSQL, MySQL, SQL Server, SQLite, and MariaDB through a single interface and installs via npx with no global installation required.
Test it first by running it directly in your terminal:
npx dbhub --db "postgresql://mcp_reader:your_password@localhost:5432/your_database"
You should see output confirming the server started and listing the tools it exposes: query, list_tables, and describe_table. Stop it with Ctrl+C once confirmed.
For SQLite:
npx dbhub --db "sqlite:///path/to/your/database.db"
Anthropic also ships official reference servers for PostgreSQL (@modelcontextprotocol/server-postgres) and SQLite (@modelcontextprotocol/server-sqlite). These are more minimal than DBHub but well-maintained. Either option works for this guide.
Configure Claude Desktop
The Claude Desktop configuration file location depends on your operating system.
macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
Windows:
%APPDATA%\Claude\claude_desktop_config.json
You can also open it directly from Claude Desktop: Settings > Developer > Edit Config.
Add your MCP server under the mcpServers key. If the file does not exist yet, create it with this structure:
{
"mcpServers": {
"my-database": {
"command": "npx",
"args": [
"dbhub",
"--db",
"postgresql://mcp_reader:your_password@localhost:5432/your_database"
]
}
}
}
Replace the connection string with your read-only credentials. Save the file, then fully restart Claude Desktop (quit and reopen from the dock or taskbar, not just close the window).
When you open a new conversation, a small tool icon appears in the interface confirming the MCP server is active. If it does not appear, verify the JSON is valid and that Node.js is available in your system PATH.
Start Querying in Plain English
With the server connected, Claude reads your schema through MCP before writing any SQL. You do not need to explain table names or paste schema definitions. Ask directly.
Questions that work well out of the box:
"How many new customers signed up in the last 30 days, broken down by week?"
"What are the five products with the highest return rate this year?"
"Show me average order value by region for Q1 2026 compared to Q1 2025."
"Which support tickets have been open for more than 14 days, grouped by assigned team?"
Claude generates the SQL, executes it through the MCP connection, and returns results. If the first result is not accurate, ask a follow-up. Claude uses the same live schema to refine the query rather than starting from scratch.
For databases with hundreds of tables, naming the relevant tables in your question improves accuracy. Creating a focused analytics schema with views of your most-used tables is also effective for keeping the context small and relevant.
Choosing Between MCP Servers
DBHub covers the majority of setups. For cloud data warehouses, Snowflake ships an official MCP integration that exposes Cortex AI capabilities alongside standard query tools. Community-built servers for BigQuery, ClickHouse, and DuckDB are available on GitHub and the MCP registry at glama.ai.
For databases behind a corporate VPC, run the MCP server on a machine with direct network access to the database rather than your local laptop. The MCP protocol supports HTTP transport in addition to stdio, so the server does not have to run on the same machine as Claude Desktop.
Common Issues and Fixes
MCP tools not appearing in Claude Desktop: Confirm the config JSON is valid (paste it into jsonlint.com), that Claude Desktop was fully restarted, and that node --version returns 18 or higher.
Server fails to start: Run the DBHub command manually in your terminal to see the error directly. Common causes are an incorrect connection string, a database that is not accepting connections from your machine's IP, or a firewall blocking the port.
Wrong column names in generated SQL: Usually caused by ambiguous table naming. Add table context to your question: "from the orders table, not order_items." Creating database views with clear, distinct column names for analytics use also reduces errors.
Slow responses on large databases: Schema with many tables increases the context Claude needs to process. Restrict the MCP server to a dedicated analytics schema, or use database views to expose only the tables relevant to your analysis.
The quality of answers improves noticeably compared to any approach that requires you to describe your database structure manually. Schema-aware generation eliminates the most common failure mode of AI SQL generation, which is inventing column names that do not exist.
FAQ
What databases does MCP support for use with Claude?
As of 2026, MCP database servers support PostgreSQL, MySQL, SQL Server, SQLite, MariaDB, MongoDB, Snowflake, BigQuery, ClickHouse, and DuckDB. DBHub covers the first five through a single interface. For cloud warehouses like Snowflake and BigQuery, official or community MCP servers are available separately. The full list of available servers can be found on the MCP registry at glama.ai.
Do I need to know SQL to use MCP with Claude?
No. The point of connecting your database through MCP is that Claude reads your schema and generates SQL on your behalf. You ask questions in plain English and Claude handles the query construction and execution. Some familiarity with your data structure (knowing which tables exist and roughly what they contain) helps you ask better questions, but writing SQL is not required.
Is it safe to connect a production database to Claude via MCP?
Yes, with the right setup. Always create a dedicated read-only database user with SELECT-only permissions on the specific tables you want to analyze. Never use admin credentials in an MCP connection string. The MCP server configuration file contains your credentials in plain text, so store it in a location with appropriate file system permissions and do not commit it to version control.
Which MCP server should I use for PostgreSQL?
DBHub (npx dbhub) is the most practical option for most setups. Anthropic also ships an official reference server at @modelcontextprotocol/server-postgres that is more minimal. For PostgreSQL with performance analysis features, the crystaldba/postgres-mcp project on GitHub adds query plan analysis and index suggestions on top of standard query tools. All three work with Claude Desktop.
Can I connect multiple databases to Claude at the same time?
Yes. The Claude Desktop config file supports multiple MCP servers under the mcpServers key. Each entry points to a different database connection. Claude determines which database to query based on the context of your question. You can connect a production PostgreSQL database, an analytics MySQL instance, and a local SQLite file simultaneously, and switch between them in the same conversation.


