Skip to main content
Glama
keleshteri

MCP MySQL Server

by keleshteri

MCP MySQL Server

A clean, simple, and well-organized Model Context Protocol (MCP) server for MySQL database interactions with Claude Desktop.

Features

  • ๐Ÿ” Query Execution: Run SQL queries with proper validation and security

  • ๐Ÿ—‚๏ธ Multi-Database Support: Switch between multiple databases easily

  • ๐Ÿ”’ Security First: Read-only by default, configurable write permissions

  • ๐Ÿ“Š Schema Discovery: Automatic database and table schema information

  • โšก Connection Pooling: Efficient database connection management

  • ๐Ÿ›ก๏ธ Query Validation: Built-in SQL injection protection

  • ๐Ÿ“ Comprehensive Logging: Optional detailed logging for debugging

Related MCP server: MySQL MCP Server

Quick Start

1. Clone and Install

git clone <your-repo-url>
cd mcp-mysql-server
npm install

2. Configure Environment

cp .env.example .env
# Edit .env with your MySQL credentials

3. Build

npm run build

4. Configure Claude Desktop

Add to your claude_desktop_config.json:

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

Configuration Options

Basic Connection

  • MYSQL_HOST: Database host (default: localhost)

  • MYSQL_PORT: Database port (default: 3306)

  • MYSQL_USER: Database username (default: root)

  • MYSQL_PASSWORD: Database password

  • MYSQL_DATABASE: Target database (leave empty for multi-DB mode)

  • MYSQL_SOCKET_PATH: Unix socket path (optional, overrides host/port)

Security & Permissions

  • ALLOW_WRITE: Enable all write operations (default: false)

  • ALLOW_INSERT: Enable INSERT statements (default: false)

  • ALLOW_UPDATE: Enable UPDATE statements (default: false)

  • ALLOW_DELETE: Enable DELETE statements (default: false)

  • ALLOW_DDL: Enable DDL operations CREATE/ALTER/DROP (default: false)

Performance Settings

  • POOL_SIZE: Connection pool size (default: 10)

  • QUERY_TIMEOUT: Query timeout in milliseconds (default: 30000)

Logging

  • ENABLE_LOGGING: Enable detailed logging (default: false)

Multi-Database Mode

Leave MYSQL_DATABASE empty to enable multi-database mode. This allows querying any database the MySQL user has access to.

Example queries in multi-DB mode:

-- Use qualified table names
SELECT * FROM database_name.table_name;

-- Switch databases
USE database_name;
SELECT * FROM table_name;

Security Best Practices

  1. Use Read-Only by Default: Only enable write operations when necessary

  2. Create Dedicated MySQL User: Don't use root account

  3. Limit Database Access: Grant permissions only to required databases

  4. Backup Before Writes: Always backup data before enabling write operations

  5. Monitor Query Logs: Enable logging to track database activities

Project Structure

src/
โ”œโ”€โ”€ config/         # Configuration management
โ”œโ”€โ”€ database/       # Database connection and management  
โ”œโ”€โ”€ handlers/       # MCP request handlers
โ”œโ”€โ”€ types/          # TypeScript type definitions
โ””โ”€โ”€ utils/          # Utility functions (logger, validator)

Development

# Development mode with auto-reload
npm run dev

# Watch mode for building
npm run watch

# Run tests
npm test

# Lint code
npm run lint

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides Claude Desktop with secure access to multiple database connections, allowing users to query MySQL, PostgreSQL, SQLite, and SQL Server databases directly through natural language.
    -
  • A
    license
    Not graded
    quality
    D
    maintenance
    Connects AI assistants like Claude Desktop directly to MySQL databases, enabling natural language interaction for schema inspection, data querying, CRUD operations, and database administration tasks.
    6 npm
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables Claude Desktop to interact with MySQL, PostgreSQL, and Redis databases using natural language for data querying and schema analysis. It provides a secure interface with a default read-only mode to prevent unauthorized database modifications.
    115 npm
    929
    MIT
  • A
    license
    A
    quality
    B
    maintenance
    Enables Claude Desktop to execute read-only SQL queries on MySQL databases via natural language, with dynamic connection switching and built-in security.
    3
    184 npm
    7
    MIT