mcp-go-mysql

scopweb/mcp-go-mysql

3.2

If you are the rightful owner of mcp-go-mysql and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

Advanced MySQL MCP Server with Intelligent Security is a production-ready server built in Go, offering comprehensive database tools and an intelligent security system to protect against dangerous operations.

Tools
  1. query

    Execute SELECT queries (read-only)

  2. tables

    List all tables

  3. describe

    Describe table/view structure

  4. list_views

    List all views

  5. view_definition

    Show complete view definition

  6. create_view

    Create new views

  7. drop_view

    Delete views

  8. view_dependencies

    Analyze view dependencies

  9. explain_query

    Analyze query execution plans

  10. analyze_object

    Analyze database objects

  11. optimize_tables

    Optimize table performance

  12. process_list

    Show active MySQL processes

  13. execute_write

    INSERT/UPDATE/DELETE with smart protection

  14. execute_ddl

    CREATE/DROP/ALTER with mandatory confirmation

  15. show_safety_info

    Display security configuration

  16. create_report

    Generate custom reports (JSON/CSV/Summary)

  17. view_report

    Comprehensive view analysis

  18. database_report

    Complete database overview

Advanced MySQL MCP Server with Intelligent Security

Production-ready MySQL Model Context Protocol (MCP) server in Go with comprehensive database tools and intelligent security system. Features automatic protection for dangerous operations with confirmation keys and modular architecture.

āš ļø IMPORTANT SECURITY NOTICE

🚨 ALWAYS BACKUP YOUR DATABASE BEFORE USING WRITE OPERATIONS

This server provides powerful database tools that can modify your data. Please:

  • Create backups before performing any write operations
  • Test operations on development databases first
  • Use appropriate MySQL user permissions - create a dedicated MySQL user with only the permissions you need
  • Review SQL statements carefully before execution
  • Monitor operation logs for security auditing

šŸ”’ Recommended MySQL User Setup

Create a dedicated MySQL user with minimal required permissions:

-- Create dedicated user for MCP
CREATE USER 'mcp_user'@'%' IDENTIFIED BY 'secure_password';

-- Grant only necessary permissions (adjust as needed)
GRANT SELECT, INSERT, UPDATE, DELETE ON your_database.* TO 'mcp_user'@'%';
GRANT CREATE, DROP, ALTER ON your_database.* TO 'mcp_user'@'%';  -- Only if DDL needed
GRANT SHOW VIEW, CREATE VIEW, DROP VIEW ON your_database.* TO 'mcp_user'@'%';

-- Refresh privileges
FLUSH PRIVILEGES;

Never use root or admin users in production!

šŸš€ Features

19 Advanced Database Tools

šŸ“‹ Core Operations (3)

  • query - Execute SELECT queries (read-only)
  • tables - List all tables
  • describe - Describe table/view structure

šŸ‘ļø Views Management (5)

  • list_views - List all views
  • view_definition - Show complete view definition
  • create_view - Create new views
  • drop_view - Delete views
  • view_dependencies - Analyze view dependencies

šŸ” Performance Analysis (4)

  • explain_query - Analyze query execution plans
  • analyze_object - Analyze database objects
  • optimize_tables - Optimize table performance
  • process_list - Show active MySQL processes

šŸ›”ļø Secure Write Operations (3)

  • execute_write - INSERT/UPDATE/DELETE with smart protection
  • execute_ddl - CREATE/DROP/ALTER with mandatory confirmation
  • show_safety_info - Display security configuration

šŸ“Š Advanced Reports (3)

  • create_report - Generate custom reports (JSON/CSV/Summary)
  • view_report - Comprehensive view analysis
  • database_report - Complete database overview

šŸ›”ļø Intelligent Security System

Automatic Risk Detection:

  • āœ… Small operations (≤100 rows) → Execute freely
  • šŸ”‘ Large operations (>100 rows) → Require confirmation key
  • šŸ”‘ DDL operations (CREATE/DROP/ALTER) → Always require confirmation
  • āŒ Database drops → Completely blocked

Smart Protection:

-- FREE: Specific updates
UPDATE users SET status='active' WHERE id=123

-- REQUIRES KEY: Mass updates  
UPDATE users SET status='inactive'  -- Affects all rows

-- REQUIRES KEY: Structure changes
CREATE TABLE backup_users AS SELECT * FROM users

-- BLOCKED: Database deletion
DROP DATABASE production  -- Always blocked

šŸ”§ Installation

1. Clone and Build

git clone https://github.com/scopweb/mcp-go-mysql.git
cd mcp-go-mysql
go mod tidy
go build -o mysql-go-mcp.exe ./cmd

2. Configure Environment

Create .env file:

MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=mcp_user
MYSQL_PASSWORD=secure_password
MYSQL_DATABASE=your_database
LOG_PATH=mysql-mcp.log

3. Claude Desktop Configuration

{
  "mcpServers": {
    "mysql-advanced": {
      "command": "C:\\path\\to\\mysql-go-mcp.exe",
      "args": [],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306", 
        "MYSQL_USER": "mcp_user",
        "MYSQL_PASSWORD": "secure_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}

šŸ’” Usage Examples

šŸ” Safe Operations (No Confirmation Required)

-- Query data
SELECT * FROM products WHERE category='electronics' LIMIT 10

-- Small updates
UPDATE orders SET status='shipped' WHERE order_id=12345

-- Describe structures  
DESCRIBE customers

šŸ”‘ Protected Operations (Require Confirmation)

-- Mass updates (requires: confirm_key="PRODUCTION_CONFIRMED_2025")
UPDATE products SET discount=0.1 WHERE category='clearance'

-- DDL operations (always require confirmation)  
CREATE VIEW monthly_sales AS 
SELECT DATE_FORMAT(date,'%Y-%m') as month, SUM(total) 
FROM orders GROUP BY month

-- Table optimization
OPTIMIZE TABLE large_table

šŸ“Š Advanced Reporting

-- Generate CSV report
SELECT customer_name, SUM(order_total) as total_spent 
FROM customer_orders 
GROUP BY customer_name 
ORDER BY total_spent DESC
-- Format: CSV, Limit: 100

-- View analysis report  
ANALYZE VIEW complex_sales_view
-- Includes: schema, sample data, dependencies

šŸ” Security Configuration

Current Safety Key: PRODUCTION_CONFIRMED_2025
Row Limit: 100 rows (configurable)

To change security settings: Edit constants in cmd/main.go:

const (
    SAFETY_KEY    = "YOUR_CUSTOM_KEY_2025"
    MAX_SAFE_ROWS = 50  // Adjust threshold
)

šŸ“ Project Structure

cmd/
ā”œā”€ā”€ main.go           - Main server and configuration
ā”œā”€ā”€ types.go          - MCP message structures  
ā”œā”€ā”€ handlers.go       - Message handling logic
ā”œā”€ā”€ tools.go          - Tool definitions
ā”œā”€ā”€ client_methods.go - Database operations
└── security.go       - Security and validation

internal/
ā”œā”€ā”€ mysql.go          - Core MySQL client
ā”œā”€ā”€ views.go          - Views management
ā”œā”€ā”€ analysis.go       - Performance analysis
ā”œā”€ā”€ reports.go        - Report generation
└── query.go          - Query execution

šŸ”„ Security Workflow

  1. Operation Analysis - Server analyzes SQL commands
  2. Risk Assessment - Determines if confirmation needed
  3. Smart Protection - Blocks/allows/requests confirmation
  4. Audit Logging - All operations logged for security
  5. Graceful Errors - Clear error messages with guidance

šŸš€ Production Best Practices

  • Test thoroughly on development databases
  • Monitor logs regularly for security events
  • Backup before any structural changes
  • Use minimal MySQL user permissions
  • Review operations that require confirmation keys
  • Keep security keys confidential and unique

šŸ“ˆ Performance Benefits

  • Modular architecture - Fast compilation and maintenance
  • Efficient connections - Optimized MySQL driver usage
  • Smart caching - Reduced redundant database calls
  • Comprehensive logging - Detailed operation tracking
  • Memory efficient - Minimal resource usage

Built for production environments with security as the top priority. Always backup your data! šŸ›”ļø