1.0.2 • Published 6 months ago

@maksimer/mysql-mcp v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

MySQL MCP Server (Unix Socket Connection)

A Model Context Protocol (MCP) server that allows LLMs to connect to MySQL databases using Unix sockets. This server provides read-only access to MySQL databases with comprehensive analysis tools.

Features

  • Connect to MySQL databases via Unix socket
  • Execute SQL queries directly from LLM tools (SELECT queries only - read-only)
  • List tables in a database
  • Describe table structures
  • Get index information for tables
  • View foreign key relationships
  • Analyze query execution plans
  • Retrieve table statistics and metrics
  • Profile query performance
  • Secure connection using local Unix socket
  • Protection against SQL injection and data modification

Installation

Option 1: Install from npm (recommended)

npm install @maksimer/mysql-mcp

Option 2: Install from source

  1. Clone this repository
  2. Install dependencies:
npm install
  1. Build the project:
npm run build

Configuration

The server uses the following environment variables for configuration:

  • MYSQL_SOCKET_PATH: Path to the MySQL Unix socket (default: /tmp/mysql.sock)
  • MYSQL_USER: MySQL username (default: root)
  • MYSQL_PASSWORD: MySQL password (default: empty)
  • MYSQL_DATABASE: Default database to use (optional)

For LocalWP MySQL connections, the socket path is typically in a format like: /Users/username/Library/Application Support/Local/run/SITE_ID/mysql/mysqld.sock

Usage

As a standalone MCP server

Start the server:

npx maksimer-mysql-mcp

Or with custom environment variables:

MYSQL_SOCKET_PATH=/path/to/socket MYSQL_USER=myuser MYSQL_PASSWORD=mypassword MYSQL_DATABASE=mydb npx maksimer-mysql-mcp

In a Node.js project

// ESM import
import { startMysqlMcpServer } from '@maksimer/mysql-mcp';

// Start the server with custom configuration
startMysqlMcpServer({
  socketPath: '/path/to/mysql.sock',
  user: 'root',
  password: 'password',
  database: 'wordpress'
});

Integrating with Claude for Desktop

To use this MCP server with Claude for Desktop:

  1. Edit the Claude for Desktop configuration file at:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %AppData%\Claude\claude_desktop_config.json
  2. Add the following configuration:

{
  "mcpServers": {
    "maksimer-mysql-mcp": {
      "command": "npx",
      "args": [
        "@maksimer/mysql-mcp"
      ],
      "env": {
        "MYSQL_SOCKET_PATH": "/path/to/mysql.sock",
        "MYSQL_USER": "root",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}
  1. Restart Claude for Desktop

Available Tools

Once connected, the following tools will be available to your LLM:

  1. execute-query: Run SQL SELECT queries against the MySQL database (read-only)
  2. list-tables: List all tables in a database
  3. describe-table: Get the structure of a specific table
  4. get-indexes: View index information for a table
  5. get-foreign-keys: Explore foreign key relationships
  6. explain-query: Analyze the execution plan for a query
  7. table-stats: Get comprehensive statistics about a table
  8. profile-query: Execute a query with detailed performance metrics

Security Features

This MCP server implements several security features:

  • Strict validation of queries to ensure they are SELECT statements only
  • Pattern matching to prevent SQL injection attacks
  • Blocking of all data modification operations (INSERT, UPDATE, DELETE, etc.)
  • Parameterized queries for secure data access
  • Clear error messages that don't expose sensitive information

WordPress Integration

The server works especially well with WordPress databases, providing insights into:

  • Posts, pages, and custom post types
  • Database structure and relationships
  • Query performance and optimization opportunities

License

ISC

1.0.2

6 months ago

1.0.1

6 months ago

1.0.0

6 months ago