home / mcp / sql mcp server

SQL MCP Server

Unified MCP server that enables AI models to query multiple databases via a standardized toolset.

Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
  "mcpServers": {
    "bryr0-sql-mcp": {
      "command": "C:\\path\\to\\venv\\python.exe",
      "args": [
        "-m",
        "sql_mcp"
      ],
      "env": {
        "DB_HOST": "localhost",
        "DB_PORT": "3306",
        "DB_TYPE": "mysql",
        "DB_USER": "root",
        "DB_DATABASE": "my_db",
        "DB_PASSWORD": "password"
      }
    }
  }
}

The SQL MCP Server provides a unified interface for AI models to inspect, query, and interact with multiple databases through a single, standardized set of tools. It abstracts away individual database drivers and adapters, letting you connect to MySQL, MSSQL, Sybase, Oracle, and more with consistent commands.

How to use

You run the SQL MCP Server as a local process and connect to it from your MCP client. The server exposes a standardized toolset that lets you execute queries, describe tables, and retrieve the database version, regardless of the underlying database type. Ensure your client is configured to communicate with the server using the provided MCP entry points, so the AI can issue execute_query, describe_table, and get_db_version calls and receive uniform JSON responses.

How to install

Prerequisites include Python and a virtual environment. Follow these steps to install and prepare the server for use.

# 1. Create and activate a virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: .\venv\Scripts\activate

# 2. Install the package in editable mode
pip install -e .

Configuration and usage notes

Configure your MCP clients to start the server using the Python-based entry point and environment variables shown in the example configuration. You will specify the database type, host, user, password, and database name to tailor the adapter for each environment.

{
  "mcpServers": {
    "sql_mcp_mysql": {
      "command": "C:\\path\\to\\venv\\python.exe",
      "args": ["-m", "sql_mcp"],
      "env": {
        "DB_TYPE": "mysql",
        "DB_HOST": "localhost",
        "DB_USER": "root",
        "DB_PASSWORD": "password",
        "DB_DATABASE": "my_db"
      }
    },
    "sql_mcp_mssql": {
      "command": "C:\\path\\to\\venv\\python.exe",
      "args": ["-m", "sql_mcp"],
      "env": {
        "DB_TYPE": "mssql",
        "DB_HOST": "192.168.1.50",
        "DB_USER": "sa",
        "DB_PASSWORD": "password",
        "DB_DATABASE": "DataWarehouse"
      }
    }
  }
}

Notes on architecture and adapters

The server uses an Adapter Pattern to translate generic requests into database-specific driver calls. A Factory selects the right adapter based on DB_TYPE, and responses are normalized to a consistent JSON structure for the AI to consume.

Troubleshooting and tips

If you encounter connection issues, verify the environment variables match your database credentials and that network access to the database host is allowed. Check that the correct adapter is selected for your database type and ensure the relevant Python drivers are available in your virtual environment.

Security considerations

Treat database credentials as secret data. Use strong passwords, limit user permissions to only what is necessary, and consider network isolation or VPNs for database access. Monitor your MCP clientโ€™s access patterns to detect unusual activity.

Examples of capabilities

Common actions you can perform include executing SQL queries, inspecting table schemas, and retrieving the database version. These capabilities are exposed through a uniform toolset, making it straightforward to work with multiple database backends without changing your AI prompts or integration logic.

Available tools

execute_query

Execute a SQL query against the connected database and return results in a structured JSON form.

describe_table

Describe the schema of a specified table, including column names and types.

get_db_version

Retrieve the database version information from the connected DBMS.