@maksimer/mysql-mcp v1.0.2
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
- Clone this repository
- Install dependencies:
npm install
- 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:
Edit the Claude for Desktop configuration file at:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%AppData%\Claude\claude_desktop_config.json
- macOS:
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"
}
}
}
}
- Restart Claude for Desktop
Available Tools
Once connected, the following tools will be available to your LLM:
- execute-query: Run SQL SELECT queries against the MySQL database (read-only)
- list-tables: List all tables in a database
- describe-table: Get the structure of a specific table
- get-indexes: View index information for a table
- get-foreign-keys: Explore foreign key relationships
- explain-query: Analyze the execution plan for a query
- table-stats: Get comprehensive statistics about a table
- 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