ReuploadYour AI News
Back home

Tip · Claude.com Official Documentation - Model Context Protocol

Query Live Databases in Claude with MCP

Query Live Databases in Claude with MCP

Photo: Zach Graves on Unsplash

Connect Claude directly to your SQL databases using Model Context Protocol servers to query live data in plain English without pasting CSVs. This eliminates file uploads, keeps data current, and enables instant ad-hoc reporting—ideal for data analysts and engineers who need fast answers from production databases without manual exports.

The Model Context Protocol (MCP) is Anthropic's open standard that lets Claude safely connect to external tools and data sources. When you set up a database MCP server, Claude gains the ability to explore your database schema, write and execute SQL queries, and return results—all within the chat interface, with no copy-paste needed. To get started, you'll first choose an MCP server for your database type. Popular options include sql-mcp (supports PostgreSQL, MySQL, SQLite, MongoDB, and others), Query Streams (specialized for SQL Server and Azure SQL), and the crystaldba/postgres-mcp (lightweight for local Postgres work). Each server acts as a secure bridge between Claude and your database. Installation typically involves adding the server's configuration to your Claude Desktop settings under Developer or pointing Claude Code at the server via command line. Once connected, the workflow is simple: ask Claude a question in plain English such as "Show me orders over $5,000 from this month, grouped by customer." Claude automatically asks the MCP server what tables and columns exist, constructs a valid SQL query, executes it against your live database, and returns results with a summary. For sensitive environments, you control permissions by using a read-only database user with minimal privileges—Claude cannot drop tables or perform destructive actions if the account it connects through doesn't have those permissions. A real example: A fintech analyst needs to reconcile payment failures. Instead of exporting a CSV from their production database, they open Claude Code, connect the SQL Server MCP, and ask: "Group failed payments by error code this month, show count and revenue impact." Claude explores the schema, writes T-SQL (respecting SQL Server idioms like TOP and DATEADD), runs the query live, and delivers a summary with trends. The data stays in the database, refreshes on every query, and there's no upload bottleneck. The security model is built in: data never enters Claude's training set, queries are read-only by default, and MCP keys are scoped, revocable, and rate-limited. Most teams find this pattern transforms data work from batch export-and-analyze to interactive investigation.