Skip to main content
Glama

MySQL MCP Server

A Model Context Protocol (MCP) server that provides readonly MySQL database operations for AI agents with support for multiple database servers.

Features

  • list_servers: Show all configured MySQL servers

  • list_tables: List all tables in the database

  • describe_table: Show table structure and column information

  • query: Execute SELECT queries (readonly only)

  • show_databases: List available databases

  • use_database: Switch to a different database on a server

Related MCP server: MySQL MCP Server

Installation

For detailed installation instructions, see INSTALLATION.md

From npm (once published)

npm install -g @your-username/mysql-mcp

From source

git clone <repository-url>
cd mysql-mcp
npm install

Configuration

Configure multiple MySQL servers using a JSON environment variable MYSQL_SERVERS:

{
  "production": {
    "host": "prod.example.com",
    "port": 3306,
    "user": "prod_user",
    "password": "prod_password",
    "database": "prod_db"
  },
  "staging": {
    "host": "staging.example.com",
    "port": 3306,
    "user": "staging_user",
    "password": "staging_password",
    "database": "staging_db"
  },
  "local": {
    "host": "localhost",
    "port": 3306,
    "user": "root",
    "password": "local_password",
    "database": "test_db"
  }
}

Option 2: Single Server (Backward Compatible)

Copy .env.example to .env and configure your MySQL connection:

cp .env.example .env

Set the following environment variables:

  • MYSQL_HOST: MySQL server host (default: localhost)

  • MYSQL_PORT: MySQL server port (default: 3306)

  • MYSQL_USER: MySQL username (default: root)

  • MYSQL_PASSWORD: MySQL password

  • MYSQL_DATABASE: Database name to connect to

Usage with Claude Desktop

Multiple Servers Configuration

If installed from npm:

{
  "mcpServers": {
    "mysql": {
      "command": "mysql-mcp",
      "env": {
        "MYSQL_SERVERS": "{\"production\":{\"host\":\"prod.example.com\",\"port\":3306,\"user\":\"prod_user\",\"password\":\"prod_password\",\"database\":\"prod_db\"},\"staging\":{\"host\":\"staging.example.com\",\"port\":3306,\"user\":\"staging_user\",\"password\":\"staging_password\",\"database\":\"staging_db\"}}"
      }
    }
  }
}

If running from source:

{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["path/to/mysql-mcp/server.js"],
      "env": {
        "MYSQL_SERVERS": "{\"production\":{\"host\":\"prod.example.com\",\"port\":3306,\"user\":\"prod_user\",\"password\":\"prod_password\",\"database\":\"prod_db\"},\"staging\":{\"host\":\"staging.example.com\",\"port\":3306,\"user\":\"staging_user\",\"password\":\"staging_password\",\"database\":\"staging_db\"}}"
      }
    }
  }
}

Single Server Configuration

{
  "mcpServers": {
    "mysql": {
      "command": "node",
      "args": ["path/to/mysql-mcp/server.js"],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "your_username",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}

Using Multiple Servers

When multiple servers are configured, all tools accept an optional server parameter:

// List tables from production server
await list_tables({ server: "production" })

// Query staging server
await query({ 
  sql: "SELECT * FROM users LIMIT 10",
  server: "staging"
})

// Describe table on local server
await describe_table({ 
  table_name: "products",
  server: "local"
})

// If no server is specified, "default" is used
await list_tables() // Uses "default" server

Security

This server only allows readonly operations (SELECT, SHOW, DESCRIBE) for safety. All other SQL operations are blocked.

Available Tools

6 tools
describe_tableB

Describe the structure of a specific table

Inputs: table_name (required), server.

list_serversA

List all configured MySQL servers

Inputs: no named parameters.

list_tablesC

List all tables in the database

Inputs: server.

queryA

Execute a SELECT query (readonly operations only)

Inputs: sql (required), server.

show_databasesB

List all databases available

Inputs: server.

use_databaseB

Switch to a different database on a server

Inputs: database (required), server.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A3.6/5.0

    Scored across 6 tools

    Disambiguation5/5

    Each tool targets a distinct resource or action: servers, databases, tables, schema, and querying. There is no meaningful overlap between list_servers, show_databases, list_tables, describe_table, use_database, and query.

    Naming Consistency4/5

    Most tools follow a clear verb_noun snake_case pattern (list_servers, list_tables, describe_table, show_databases, use_database). The single tool 'query' deviates slightly by lacking a noun object, but the imperative style remains consistent.

    Tool Count5/5

    Six tools is well-scoped for a read-only MySQL exploration server. Each tool covers a necessary step in navigating servers, databases, tables, and data without redundancy.

    Completeness4/5

    The tool set provides a complete read-only workflow: discover servers, select databases, list tables, inspect schemas, and run SELECT queries. It intentionally lacks write and administrative operations, which is a minor limitation if broader MySQL management is expected.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to safely query MySQL databases with read-only access by default, supporting table listing, structure inspection, and SQL queries with optional write operation control.
      13 npm
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides AI assistants with secure read-only access to MySQL databases through validated SELECT queries. Supports SSL/TLS connections and implements multiple security layers to prevent data modification.
      554 npm
      3
      MIT
    • A
      license
      A
      quality
      C
      maintenance
      Enables AI assistants to inspect and query a MySQL database through safe, structured tools, including schema discovery and read-only queries.
      9
      104 npm
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Enables AI agents to safely interact with MySQL/MariaDB databases, supporting read-only queries by default with optional write operations and access control.
      8
      MIT