Labsco
dkabx logo

MySQL MCP Server

from dkabx

Provides tools for AI assistants to interact with a MySQL database.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedAccount requiredNeeds API keys

MySQL MCP Server

A Model Context Protocol (MCP) server that provides MySQL database access tools for AI assistants like Cursor.

Overview

This MCP server enables AI assistants to interact with MySQL databases by providing three essential tools:

  • Execute SQL queries
  • Describe table structures
  • List all database tables

Features

  • Query Execution: Run any SQL query against your MySQL database
  • Table Description: Get detailed schema information for any table
  • Table Listing: View all tables in your database
  • Error Handling: Comprehensive error handling for database operations
  • MCP Protocol Compliance: Fully compatible with MCP 2024-11-05 specification

Cursor Integration

To use this MCP server with Cursor, add the following configuration to your Cursor MCP settings file (~/.cursor/mcp.json):

{
  "mcpServers": {
    "mysql-mcp": {
      "label": "MySQL MCP",
      "command": "node",
      "args": ["/path/to/your/mysql-mcp-server.js"],
      "env": {
        "MYSQL_HOST": "your-mysql-host",
        "MYSQL_USER": "your-username",
        "MYSQL_PASSWORD": "your-password",
        "MYSQL_DATABASE": "your-database",
        "MYSQL_PORT": "3306"
      }
    }
  }
}

Replace /path/to/your/mysql-mcp-server.js with the actual path to your server file and update the environment variables with your database credentials.

Available Tools

1. mysql_query

Execute any SQL query against the database.

Parameters:

  • query (string): The SQL query to execute

Example:

SELECT * FROM users WHERE role = 'admin'

2. mysql_describe_table

Get the structure and schema information for a specific table.

Parameters:

  • table_name (string): Name of the table to describe

Example:

mysql_describe_table("users")

3. mysql_list_tables

List all tables in the database.

Parameters: None required.

Security Considerations

  • Database Credentials: Store sensitive credentials securely and never commit them to version control
  • Query Permissions: The server executes queries with the provided database user's permissions
  • Network Access: Ensure your database is properly secured and accessible only from authorized sources
  • Input Validation: While the server handles errors, always validate and sanitize inputs in production

Development

File Structure

mcp/
โ”œโ”€โ”€ mysql-mcp-server.js    # Main MCP server implementation
โ”œโ”€โ”€ package.json           # Node.js dependencies
โ””โ”€โ”€ README.md             # This file

Dependencies

  • mysql2: MySQL client for Node.js with promise support

Changelog

v1.0.0

  • Initial release
  • Basic MCP protocol implementation
  • Three core database tools (query, describe, list)
  • Error handling and logging
  • Cursor integration support