All How-To Guides

4 Ways to Query Databases with Claude Code

How to query databases with Claude Code?

4 MCP servers featured

Database operations are central to most applications, but Claude Code doesn't have built-in database connectivity. MCP servers provide secure, controlled access to your databases, enabling Claude to explore schemas, execute queries, and even optimize performance. Here are the best options for working with databases.

Recommended MCP Servers

Supabase MCP

supabase-community/supabase-mcp

>2k

Official Supabase MCP server connecting AI assistants directly with Supabase projects for table management, config, and data queries.

Key Features

  • Official Supabase integration with OAuth
  • Read-only mode for safe exploration
  • Project-scoped access control
  • Works with CLI and self-hosted setups

Installation

Remote server: https://mcp.supabase.com/mcp

If you're already using Supabase, this is the obvious choice. The official MCP server provides seamless integration with OAuth authentication, read-only mode for safety, and project-scoped access. Just add the URL to your config and you're connected.

Best for: Supabase projects View on GitHub

Postgres MCP Pro

crystaldba/postgres-mcp

>2k

All-in-one PostgreSQL MCP server with index tuning, query plans, health checks, and safe SQL execution.

Key Features

  • Database health analysis and monitoring
  • Index tuning with industrial-strength algorithms
  • EXPLAIN plan analysis and optimization
  • Safe SQL execution with read-only mode

Installation

pip install postgres-mcp

Postgres MCP Pro goes far beyond basic queries. It includes index tuning that explores thousands of possible indexes, health monitoring for connections and vacuum status, and EXPLAIN plan analysis. Essential for anyone serious about PostgreSQL performance.

Best for: PostgreSQL performance optimization View on GitHub

MCP Toolbox for Databases

googleapis/genai-toolbox

>10k

Google's open source MCP server for databases with connection pooling, authentication, and multi-database support.

Key Features

  • Connection pooling and authentication
  • Multi-database support
  • Tool reuse between agents and frameworks
  • Best practices baked in

Installation

See docs at googleapis.github.io/genai-toolbox

Google's MCP Toolbox is built for production use with connection pooling, authentication handling, and support for multiple databases. It's ideal for enterprise environments where you need robust, reusable database tools across multiple agents.

Best for: Multi-database enterprise environments View on GitHub

MySQL MCP Server

designcomputer/mysql_mcp_server

>1k

MySQL database integration with configurable access controls, schema inspection, and comprehensive security.

Key Features

  • List and read MySQL tables as resources
  • Execute SQL queries with error handling
  • Environment variable configuration
  • Comprehensive logging

Installation

pip install mysql-mcp-server

A straightforward MCP server for MySQL that does exactly what you need: list tables, read data, and execute queries. Configuration via environment variables keeps credentials secure. Perfect for developers who just need reliable MySQL access.

Best for: MySQL databases View on GitHub

Quick Comparison

MCPStarsBest ForProsCons
Supabase MCP2k+Supabase projectsZero config, OAuthSupabase only
Postgres MCP Pro1.6k+PostgreSQL tuningIndex & query optimizationPostgreSQL only
MCP Toolbox11k+Enterprise multi-DBConnection poolingMore complex setup
MySQL MCP1k+MySQL databasesSimple and focusedBasic features

Getting Started

To get started with database queries in Claude Code:

  1. Choose your MCP based on your database:

    • Supabase → Use the remote Supabase MCP server
    • PostgreSQL → Install postgres-mcp
    • MySQL → Install mysql-mcp-server
  2. Configure credentials via environment variables or OAuth.

  3. Enable read-only mode for safe exploration (recommended).

Example prompt: "Show me the schema of the users table and find users who signed up in the last 7 days."

Related Guides