Easy to use, zero dependency MySQL MCP server built with Golang with configurable readonly mode and schema inspection.
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.
EXPLAIN
statement analysis to validate query plans before execution, ensuring optimal performance and preventing unexpected behavior.$PATH
environment variable for easy access.Ensure you have Go installed and configured on your system.
Execute the following command in your terminal:
go install -v github.com/Zhwt/go-mcp-mysql@latest
go-mcp-mysql
offers two convenient methods for configuring the connection to your MySQL database:
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" ] } } }
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": [ ... ] } } }
--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.go-mcp-mysql
provides a rich set of tools for interacting with your MySQL database:
list_database
: Retrieves a list of all databases on the MySQL server.
list_table
: Retrieves a list of tables.
name
(Optional): Filters the list to tables matching the specified name (using SHOW TABLES LIKE '%name%'
).create_table
: Creates a new table.
query
: The SQL CREATE TABLE
statement.alter_table
: Modifies an existing table. Important: Instruct your LLM to avoid dropping existing tables or columns.
query
: The SQL ALTER TABLE
statement.desc_table
: Describes the structure of a table.
name
: The name of the table to describe.read_query
: Executes a read-only SQL query.
query
: The SQL SELECT
statement.write_query
: Executes a write SQL query (e.g., INSERT
).
query
: The SQL INSERT
statement.update_query
: Executes an update SQL query.
query
: The SQL UPDATE
statement.delete_query
: Executes a delete SQL query.
query
: The SQL DELETE
statement.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.
๐ โ๏ธ Biomedical research server providing access to PubMed, ClinicalTrials.gov, and MyVariant.info.
๐ MCP server that provides SQL analysis, linting, and dialect conversion using [SQLGlot](https://github.com/tobymao/sqlglot)
๐ ๐ All-in-one MCP server for Postgres development and operations, with tools for performance analysis, tuning, and health checks
Supabase MCP Server with support for SQL query execution and database exploration tools