Skip to main content
Glama
SQL Local MCP Server

SQL Local MCP Server

by acoalex

SQL Local MCP Server

A Model Context Protocol (MCP) server for executing SQL queries on MySQL and PostgreSQL databases. This allows Claude and other MCP-compatible AI assistants to connect to and interact with your local databases.

Features

  • Dynamic Database Connections: Connect to any MySQL or PostgreSQL database

  • READ-ONLY Security: Only SELECT, SHOW, DESCRIBE, and EXPLAIN queries are allowed

  • Multi-Statement Protection: Prevents SQL injection

  • Database Exploration: List tables and describe table structures

  • No Configuration Files: Database credentials are provided at runtime

Related MCP server: MCP MySQL

Installation

  1. Clone the repository

  2. Create and activate a virtual environment

  3. Install dependencies:

    pip install -r requirements.txt

Usage

Starting the Server

./start_server.sh

Or:

python3 mcp_server.py

Available Tools

  1. connect_database: Connect to a MySQL or PostgreSQL database

  2. execute_query: Execute READ-ONLY SQL queries

  3. list_tables: List all tables in a database

  4. describe_table: Get the structure of a table

Example: Connecting to a Database

To connect, provide the following details:

  • db_type: mysql or postgresql

  • host: 127.0.0.1

  • port: (e.g., 3306 for MySQL, 5432 for PostgreSQL)

  • user: your_user

  • password: your_password

  • database: your_db

  • connection_name: a unique name for the connection

Security

  • Read-Only: Only SELECT, SHOW, DESCRIBE, EXPLAIN are allowed.

  • Destructive commands are blocked: UPDATE, DELETE, INSERT, etc.

  • Multi-statement queries are blocked.

  • Parameterized queries are supported.

Testing

  • Basic tests: python3 test_mcp.py

  • Security tests: python3 test_readonly.py

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides MySQL database integration for AI assistants and other MCP clients, allowing them to list tables, read table data, and execute SQL queries.
      -
    • F
      license
      A
      quality
      B
      maintenance
      Enables AI assistants to connect to MySQL databases, execute read-only queries, list tables, and describe table schemas via MCP.
      10
      1
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to securely interact with PostgreSQL databases through a standardized MCP interface, supporting SQL queries, schema inspection, and database management.
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to explore and run read-only queries across MySQL/MariaDB, PostgreSQL, SQLite, SQL Server, Oracle, and MongoDB through MCP, with per-API-key database authorization, SQL whitelist and row/timeout limits, and a local web UI for managing connections and keys.
      Apache 2.0