Labsco
SagenKoder logo

MySQL MCP Server

β˜… 4

from SagenKoder

Provides AI agents with direct access to query, search, and analyze MySQL databases.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredAdvanced setup

MySQL MCP Server

A Model Context Protocol (MCP) server that provides AI agents with direct access to MySQL databases. This server enables AI models to query, search, and analyze MySQL database content through a set of well-defined tools.

Features

  • Schema exploration - List all schemas/databases with pagination
  • Table discovery - Browse tables in any schema with detailed metadata
  • Structure inspection - Get column definitions, types, and indexes
  • Safe querying - Execute SELECT queries with automatic result limiting
  • Full-text search - Search for values across all text columns in a table
  • DDL retrieval - Get CREATE TABLE statements for any table

Building from Source

Prerequisites

  • Go 1.23 or later
  • Docker (optional, for building Docker images)

Build Steps

# Clone the repository
git clone https://github.com/sagenkoder/go-mysql-mcp-server.git
cd go-mysql-mcp-server

# Build all binaries
./build.sh

# Build Docker images
./build.sh docker

This will create:

  • Binaries:
    • mysql-mcp-stdio - For stdio-based MCP communication
    • mysql-mcp-http - HTTP server mode
    • mysql-mcp-interactive - Interactive CLI mode for testing
  • Docker images:
    • ghcr.io/sagenkoder/go-mysql-mcp-server:stdio (also tagged as mysql-mcp:latest)
    • ghcr.io/sagenkoder/go-mysql-mcp-server:http
    • ghcr.io/sagenkoder/go-mysql-mcp-server:interactive

Available Tools

list_schemas

List all schemas/databases available in the MySQL server.

Parameters:

  • page (optional): Page number for pagination (default: 1)
  • page_size (optional): Number of items per page (default: 20, max: 100)

list_tables

List all tables in a specific schema with metadata.

Parameters:

  • schema (required): The schema/database name
  • page (optional): Page number for pagination
  • page_size (optional): Number of items per page

get_table_structure

Get detailed column and index information for a table.

Parameters:

  • schema (required): The schema/database name
  • table (required): The table name

get_table_create

Get the CREATE TABLE statement for a specific table.

Parameters:

  • schema (required): The schema/database name
  • table (required): The table name

execute_query

Execute a SQL query (SELECT, SHOW, DESCRIBE, EXPLAIN only).

Parameters:

  • query (required): The SQL query to execute
  • limit (optional): Maximum rows to return (default: 100)

search_table

Search for a value across all text columns in a table.

Parameters:

  • schema (required): The schema/database name
  • table (required): The table name
  • search_term (required): The term to search for
  • limit (optional): Maximum rows to return (default: 100)

Testing the Connection

Use the interactive mode to test your connection:

# With Docker
docker run -it --rm \
  --network host \
  -e MYSQL_HOST=localhost \
  -e MYSQL_USER=test \
  -e MYSQL_PASSWORD=test \
  ghcr.io/sagenkoder/go-mysql-mcp-server:interactive

# With binary
MYSQL_USER=test MYSQL_PASSWORD=test ./mysql-mcp-interactive

Security Considerations

  • Only SELECT, SHOW, DESCRIBE, and EXPLAIN queries are allowed
  • All queries are automatically limited to prevent large result sets
  • Table searches only scan text-based columns
  • Connection details should be stored securely as environment variables
  • The Docker image runs as a non-root user for security

License

MIT License - see LICENSE file for details.