go

go-mcp-mysql

Easy to use, zero dependency MySQL MCP server built with Golang with configurable readonly mode and schema inspection.

Publishergo-mcp-mysql
Submitted date4/13/2025

Unleashing LLMs with go-mcp-mysql: A Zero-Burden MCP Server for MySQL Integration

The Model Context Protocol (MCP) is revolutionizing how Large Language Models (LLMs) interact with external data and tools. This article introduces go-mcp-mysql, a lightweight, ready-to-use MCP server designed to seamlessly connect your LLM applications with MySQL databases. Forget the complexities of Node.js or Python environments โ€“ go-mcp-mysql offers a streamlined solution for CRUD operations and data retrieval, empowering you to build intelligent, data-driven AI applications with ease.

Key Features and Benefits

  • Zero-Burden Integration: Eliminates the need for external runtime dependencies like Node.js or Python, simplifying deployment and reducing overhead.
  • Comprehensive CRUD Operations: Provides a full suite of tools for creating, reading, updating, and deleting data within your MySQL database.
  • Read-Only Mode: Enhances security by restricting operations to read-only actions, preventing unintended data modifications.
  • Query Plan Validation: (Optional) Integrates EXPLAIN statement analysis to validate query plans before execution, ensuring optimal performance and preventing unexpected behavior.
  • Flexible Configuration: Supports both command-line arguments and DSN-based configuration for easy setup and customization.
  • MCP Compliance: Adheres to the Model Context Protocol, ensuring seamless integration with any MCP-compatible LLM application.

Installation Guide

Option 1: Pre-built Binary

  1. Download the latest release from the GitHub Releases page.
  2. Place the executable in a directory included in your system's $PATH environment variable for easy access.

Option 2: Build from Source (Requires Go)

  1. Ensure you have Go installed and configured on your system.

  2. Execute the following command in your terminal:

    go install -v github.com/Zhwt/go-mcp-mysql@latest

Configuration

go-mcp-mysql offers two convenient methods for configuring the connection to your MySQL database:

Method A: Command Line Arguments

This method involves specifying connection parameters directly as command-line arguments within your MCP server configuration file (e.g., JSON).

{ "mcpServers": { "mysql": { "command": "go-mcp-mysql", "args": [ "--host", "localhost", "--user", "root", "--pass", "password", "--port", "3306", "--db", "mydb" ] } } }

Method B: Data Source Name (DSN)

Leverage the power and flexibility of MySQL DSN strings to define your connection parameters.

{ "mcpServers": { "mysql": { "command": "go-mcp-mysql", "args": [ "--dsn", "username:password@tcp(localhost:3306)/mydb?parseTime=true&loc=Local" ] } } }

Refer to the official MySQL DSN documentation for a comprehensive understanding of DSN string formatting and available options.

Important Note: If the go-mcp-mysql binary is not located in your system's $PATH, you must provide the full path to the executable in the command field.

{ "mcpServers": { "mysql": { "command": "C:\\Users\\<username>\\Downloads\\go-mcp-mysql.exe", "args": [ ... ] } } }

Advanced Configuration Options

  • --read-only: Enables read-only mode, restricting access to list, read_, and desc_ tools. Important: Refresh/restart the MCP server after enabling this flag.
  • --with-explain-check: Disables the default query plan validation using EXPLAIN. Use this flag if you don't require query plan analysis.

Available Tools

go-mcp-mysql provides a rich set of tools for interacting with your MySQL database:

Schema Management Tools

  1. list_database: Retrieves a list of all databases on the MySQL server.

    • Parameters: None
    • Returns: A list of database names.
  2. list_table: Retrieves a list of tables.

    • Parameters:
      • name (Optional): Filters the list to tables matching the specified name (using SHOW TABLES LIKE '%name%').
    • Returns: A list of table names.
  3. create_table: Creates a new table.

    • Parameters:
      • query: The SQL CREATE TABLE statement.
    • Returns: Number of rows affected.
  4. alter_table: Modifies an existing table. Important: Instruct your LLM to avoid dropping existing tables or columns.

    • Parameters:
      • query: The SQL ALTER TABLE statement.
    • Returns: Number of rows affected.
  5. desc_table: Describes the structure of a table.

    • Parameters:
      • name: The name of the table to describe.
    • Returns: Table schema information.

Data Manipulation Tools

  1. read_query: Executes a read-only SQL query.

    • Parameters:
      • query: The SQL SELECT statement.
    • Returns: Query results.
  2. write_query: Executes a write SQL query (e.g., INSERT).

    • Parameters:
      • query: The SQL INSERT statement.
    • Returns: Number of rows affected and the last inserted ID.
  3. update_query: Executes an update SQL query.

    • Parameters:
      • query: The SQL UPDATE statement.
    • Returns: Number of rows affected.
  4. delete_query: Executes a delete SQL query.

    • Parameters:
      • query: The SQL DELETE statement.
    • Returns: Number of rows affected.

Conclusion

go-mcp-mysql empowers developers to seamlessly integrate LLMs with MySQL databases, unlocking a new era of intelligent applications. Its lightweight design, comprehensive feature set, and flexible configuration options make it an ideal choice for building data-driven AI solutions. While still under active development, go-mcp-mysql holds immense promise for simplifying and accelerating the development of LLM-powered applications.

Visit More

View All